mirror of https://github.com/buggins/dlangide.git
close file confirmation
This commit is contained in:
parent
6b51d36741
commit
807796e3d1
|
@ -30,6 +30,7 @@ enum IDEActions : int {
|
||||||
DebugStop,
|
DebugStop,
|
||||||
DebugPause,
|
DebugPause,
|
||||||
HelpAbout,
|
HelpAbout,
|
||||||
|
WindowCloseAllDocuments,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Action ACTION_FILE_NEW_SOURCE_FILE = new Action(IDEActions.FileNew, "MENU_FILE_NEW_SOURCE_FILE"c, "document-new", KeyCode.KEY_N, KeyFlag.Control);
|
const Action ACTION_FILE_NEW_SOURCE_FILE = new Action(IDEActions.FileNew, "MENU_FILE_NEW_SOURCE_FILE"c, "document-new", KeyCode.KEY_N, KeyFlag.Control);
|
||||||
|
@ -60,3 +61,4 @@ const Action ACTION_EDIT_CUT = new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "
|
||||||
const Action ACTION_EDIT_UNDO = new Action(EditorActions.Undo, "MENU_EDIT_UNDO"c, "edit-undo"c, KeyCode.KEY_Z, KeyFlag.Control);
|
const Action ACTION_EDIT_UNDO = new Action(EditorActions.Undo, "MENU_EDIT_UNDO"c, "edit-undo"c, KeyCode.KEY_Z, KeyFlag.Control);
|
||||||
const Action ACTION_EDIT_REDO = new Action(EditorActions.Redo, "MENU_EDIT_REDO"c, "edit-redo"c, KeyCode.KEY_Z, KeyFlag.Control|KeyFlag.Shift);
|
const Action ACTION_EDIT_REDO = new Action(EditorActions.Redo, "MENU_EDIT_REDO"c, "edit-redo"c, KeyCode.KEY_Z, KeyFlag.Control|KeyFlag.Shift);
|
||||||
const Action ACTION_HELP_ABOUT = new Action(IDEActions.HelpAbout, "MENU_HELP_ABOUT"c);
|
const Action ACTION_HELP_ABOUT = new Action(IDEActions.HelpAbout, "MENU_HELP_ABOUT"c);
|
||||||
|
const Action ACTION_WINDOW_CLOSE_ALL_DOCUMENTS = new Action(IDEActions.WindowCloseAllDocuments, "MENU_WINDOW_CLOSE_ALL_DOCUMENTS"c);
|
||||||
|
|
|
@ -142,6 +142,68 @@ class IDEFrame : AppFrame {
|
||||||
_tabs.removeTab(tabId);
|
_tabs.removeTab(tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// close all editor tabs
|
||||||
|
void closeAllDocuments() {
|
||||||
|
for (int i = _tabs.tabCount - 1; i >= 0; i--) {
|
||||||
|
DSourceEdit ed = cast(DSourceEdit)_tabs.tabBody(i);
|
||||||
|
if (ed) {
|
||||||
|
closeTab(ed.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// returns first unsaved document
|
||||||
|
protected DSourceEdit hasUnsavedEdits() {
|
||||||
|
for (int i = _tabs.tabCount - 1; i >= 0; i--) {
|
||||||
|
DSourceEdit ed = cast(DSourceEdit)_tabs.tabBody(i);
|
||||||
|
if (ed && ed.content.modified) {
|
||||||
|
return ed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void askForUnsavedEdits(void delegate() onConfirm) {
|
||||||
|
DSourceEdit ed = hasUnsavedEdits();
|
||||||
|
if (!ed) {
|
||||||
|
// no unsaved edits
|
||||||
|
onConfirm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string tabId = ed.id;
|
||||||
|
// tab content is modified - ask for confirmation
|
||||||
|
window.showMessageBox(UIString("Close file "d ~ toUTF32(baseName(tabId))), UIString("Content of this file has been changed."d),
|
||||||
|
[ACTION_SAVE, ACTION_SAVE_ALL, ACTION_DISCARD_CHANGES, ACTION_DISCARD_ALL, ACTION_CANCEL],
|
||||||
|
0, delegate(const Action result) {
|
||||||
|
if (result == StandardAction.Save) {
|
||||||
|
// save and close
|
||||||
|
ed.save();
|
||||||
|
askForUnsavedEdits(onConfirm);
|
||||||
|
} else if (result == StandardAction.DiscardChanges) {
|
||||||
|
// close, don't save
|
||||||
|
closeTab(tabId);
|
||||||
|
closeAllDocuments();
|
||||||
|
onConfirm();
|
||||||
|
} else if (result == StandardAction.SaveAll) {
|
||||||
|
ed.save();
|
||||||
|
for(;;) {
|
||||||
|
DSourceEdit editor = hasUnsavedEdits();
|
||||||
|
if (!editor)
|
||||||
|
break;
|
||||||
|
editor.save();
|
||||||
|
}
|
||||||
|
closeAllDocuments();
|
||||||
|
onConfirm();
|
||||||
|
} else if (result == StandardAction.DiscardAll) {
|
||||||
|
// close, don't save
|
||||||
|
closeAllDocuments();
|
||||||
|
onConfirm();
|
||||||
|
}
|
||||||
|
// else ignore
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected void onTabClose(string tabId) {
|
protected void onTabClose(string tabId) {
|
||||||
Log.d("onTabClose ", tabId);
|
Log.d("onTabClose ", tabId);
|
||||||
int index = _tabs.tabIndex(tabId);
|
int index = _tabs.tabIndex(tabId);
|
||||||
|
@ -149,7 +211,7 @@ class IDEFrame : AppFrame {
|
||||||
DSourceEdit d = cast(DSourceEdit)_tabs.tabBody(tabId);
|
DSourceEdit d = cast(DSourceEdit)_tabs.tabBody(tabId);
|
||||||
if (d && d.content.modified) {
|
if (d && d.content.modified) {
|
||||||
// tab content is modified - ask for confirmation
|
// tab content is modified - ask for confirmation
|
||||||
window.showMessageBox(UIString("Close tab"d), UIString("Content of "d ~ toUTF32(baseName(id)) ~ " file has been changed."d),
|
window.showMessageBox(UIString("Close tab"d), UIString("Content of "d ~ toUTF32(baseName(tabId)) ~ " file has been changed."d),
|
||||||
[ACTION_SAVE, ACTION_DISCARD_CHANGES, ACTION_CANCEL],
|
[ACTION_SAVE, ACTION_DISCARD_CHANGES, ACTION_CANCEL],
|
||||||
0, delegate(const Action result) {
|
0, delegate(const Action result) {
|
||||||
if (result == StandardAction.Save) {
|
if (result == StandardAction.Save) {
|
||||||
|
@ -231,6 +293,7 @@ class IDEFrame : AppFrame {
|
||||||
|
|
||||||
MenuItem windowItem = new MenuItem(new Action(3, "MENU_WINDOW"c));
|
MenuItem windowItem = new MenuItem(new Action(3, "MENU_WINDOW"c));
|
||||||
windowItem.add(new Action(30, "MENU_WINDOW_PREFERENCES"));
|
windowItem.add(new Action(30, "MENU_WINDOW_PREFERENCES"));
|
||||||
|
windowItem.add(ACTION_WINDOW_CLOSE_ALL_DOCUMENTS);
|
||||||
MenuItem helpItem = new MenuItem(new Action(4, "MENU_HELP"c));
|
MenuItem helpItem = new MenuItem(new Action(4, "MENU_HELP"c));
|
||||||
helpItem.add(new Action(40, "MENU_HELP_VIEW_HELP"));
|
helpItem.add(new Action(40, "MENU_HELP_VIEW_HELP"));
|
||||||
helpItem.add(ACTION_HELP_ABOUT);
|
helpItem.add(ACTION_HELP_ABOUT);
|
||||||
|
@ -295,6 +358,11 @@ class IDEFrame : AppFrame {
|
||||||
};
|
};
|
||||||
dlg.show();
|
dlg.show();
|
||||||
return true;
|
return true;
|
||||||
|
case IDEActions.WindowCloseAllDocuments:
|
||||||
|
askForUnsavedEdits(delegate() {
|
||||||
|
closeAllDocuments();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
case IDEActions.FileOpenWorkspace:
|
case IDEActions.FileOpenWorkspace:
|
||||||
UIString caption;
|
UIString caption;
|
||||||
caption = "Open Workspace or Project"d;
|
caption = "Open Workspace or Project"d;
|
||||||
|
|
|
@ -43,6 +43,7 @@ MENU_VIEW_THEME_DEFAULT=&Default
|
||||||
MENU_VIEW_THEME_CUSTOM1=&Custom 1
|
MENU_VIEW_THEME_CUSTOM1=&Custom 1
|
||||||
MENU_WINDOW=&WINDOW
|
MENU_WINDOW=&WINDOW
|
||||||
MENU_WINDOW_PREFERENCES=&Preferences
|
MENU_WINDOW_PREFERENCES=&Preferences
|
||||||
|
MENU_WINDOW_CLOSE_ALL_DOCUMENTS=Close All Documents
|
||||||
MENU_HELP=&HELP
|
MENU_HELP=&HELP
|
||||||
MENU_HELP_VIEW_HELP=&View help
|
MENU_HELP_VIEW_HELP=&View help
|
||||||
MENU_HELP_ABOUT=&About
|
MENU_HELP_ABOUT=&About
|
||||||
|
|
Loading…
Reference in New Issue