mirror of https://github.com/buggins/dlangide.git
remove file, refresh workspace, close workspace actions
This commit is contained in:
parent
dc5ce73c09
commit
a222c2de68
|
@ -41,10 +41,12 @@ enum IDEActions : int {
|
||||||
ProjectFolderRemoveItem,
|
ProjectFolderRemoveItem,
|
||||||
ProjectFolderOpenItem,
|
ProjectFolderOpenItem,
|
||||||
ProjectFolderRenameItem,
|
ProjectFolderRenameItem,
|
||||||
|
ProjectFolderRefresh,
|
||||||
GoToDefinition,
|
GoToDefinition,
|
||||||
GetCompletionSuggestions,
|
GetCompletionSuggestions,
|
||||||
InsertCompletion,
|
InsertCompletion,
|
||||||
FindText,
|
FindText,
|
||||||
|
CloseWorkspace,
|
||||||
}
|
}
|
||||||
|
|
||||||
__gshared static this() {
|
__gshared static this() {
|
||||||
|
@ -57,6 +59,8 @@ __gshared static this() {
|
||||||
const Action ACTION_PROJECT_FOLDER_OPEN_ITEM = new Action(IDEActions.ProjectFolderOpenItem, "MENU_PROJECT_FOLDER_OPEN_ITEM"c);
|
const Action ACTION_PROJECT_FOLDER_OPEN_ITEM = new Action(IDEActions.ProjectFolderOpenItem, "MENU_PROJECT_FOLDER_OPEN_ITEM"c);
|
||||||
const Action ACTION_PROJECT_FOLDER_REMOVE_ITEM = new Action(IDEActions.ProjectFolderRemoveItem, "MENU_PROJECT_FOLDER_REMOVE_ITEM"c);
|
const Action ACTION_PROJECT_FOLDER_REMOVE_ITEM = new Action(IDEActions.ProjectFolderRemoveItem, "MENU_PROJECT_FOLDER_REMOVE_ITEM"c);
|
||||||
const Action ACTION_PROJECT_FOLDER_RENAME_ITEM = new Action(IDEActions.ProjectFolderRenameItem, "MENU_PROJECT_FOLDER_RENAME_ITEM"c);
|
const Action ACTION_PROJECT_FOLDER_RENAME_ITEM = new Action(IDEActions.ProjectFolderRenameItem, "MENU_PROJECT_FOLDER_RENAME_ITEM"c);
|
||||||
|
const Action ACTION_PROJECT_FOLDER_REFRESH = new Action(IDEActions.ProjectFolderRefresh, "MENU_PROJECT_FOLDER_REFRESH"c);
|
||||||
|
const Action ACTION_FILE_WORKSPACE_CLOSE = new Action(IDEActions.CloseWorkspace, "MENU_FILE_WORKSPACE_CLOSE"c);
|
||||||
|
|
||||||
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);
|
||||||
const Action ACTION_FILE_NEW_PROJECT = new Action(IDEActions.FileNewProject, "MENU_FILE_NEW_PROJECT"c);
|
const Action ACTION_FILE_NEW_PROJECT = new Action(IDEActions.FileNewProject, "MENU_FILE_NEW_PROJECT"c);
|
||||||
|
|
|
@ -234,6 +234,19 @@ class IDEFrame : AppFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// close editor tabs for which files are removed from filesystem
|
||||||
|
void closeRemovedDocuments() {
|
||||||
|
import std.file;
|
||||||
|
for (int i = _tabs.tabCount - 1; i >= 0; i--) {
|
||||||
|
DSourceEdit ed = cast(DSourceEdit)_tabs.tabBody(i);
|
||||||
|
if (ed) {
|
||||||
|
if (!exists(ed.id) || !isFile(ed.id)) {
|
||||||
|
closeTab(ed.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// returns first unsaved document
|
/// returns first unsaved document
|
||||||
protected DSourceEdit hasUnsavedEdits() {
|
protected DSourceEdit hasUnsavedEdits() {
|
||||||
for (int i = _tabs.tabCount - 1; i >= 0; i--) {
|
for (int i = _tabs.tabCount - 1; i >= 0; i--) {
|
||||||
|
@ -369,7 +382,7 @@ class IDEFrame : AppFrame {
|
||||||
fileNewItem.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_FILE_NEW_WORKSPACE, ACTION_FILE_NEW_PROJECT);
|
fileNewItem.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_FILE_NEW_WORKSPACE, ACTION_FILE_NEW_PROJECT);
|
||||||
fileItem.add(fileNewItem);
|
fileItem.add(fileNewItem);
|
||||||
fileItem.add(ACTION_FILE_OPEN_WORKSPACE, ACTION_FILE_OPEN,
|
fileItem.add(ACTION_FILE_OPEN_WORKSPACE, ACTION_FILE_OPEN,
|
||||||
ACTION_FILE_SAVE, ACTION_FILE_SAVE_AS, ACTION_FILE_SAVE_ALL, ACTION_FILE_EXIT);
|
ACTION_FILE_SAVE, ACTION_FILE_SAVE_AS, ACTION_FILE_SAVE_ALL, ACTION_FILE_WORKSPACE_CLOSE, ACTION_FILE_EXIT);
|
||||||
|
|
||||||
MenuItem editItem = new MenuItem(new Action(2, "MENU_EDIT"));
|
MenuItem editItem = new MenuItem(new Action(2, "MENU_EDIT"));
|
||||||
editItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE,
|
editItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE,
|
||||||
|
@ -637,6 +650,15 @@ class IDEFrame : AppFrame {
|
||||||
return true;
|
return true;
|
||||||
case IDEActions.FileNew:
|
case IDEActions.FileNew:
|
||||||
addProjectItem(a.objectParam);
|
addProjectItem(a.objectParam);
|
||||||
|
return true;
|
||||||
|
case IDEActions.ProjectFolderRemoveItem:
|
||||||
|
removeProjectItem(a.objectParam);
|
||||||
|
return true;
|
||||||
|
case IDEActions.ProjectFolderRefresh:
|
||||||
|
refreshProjectItem(a.objectParam);
|
||||||
|
return true;
|
||||||
|
case IDEActions.CloseWorkspace:
|
||||||
|
closeWorkspace();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.handleAction(a);
|
return super.handleAction(a);
|
||||||
|
@ -653,6 +675,71 @@ class IDEFrame : AppFrame {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void closeWorkspace() {
|
||||||
|
askForUnsavedEdits(delegate() {
|
||||||
|
setWorkspace(null);
|
||||||
|
showHomeScreen();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void refreshProjectItem(const Object obj) {
|
||||||
|
if (currentWorkspace is null)
|
||||||
|
return;
|
||||||
|
Project project;
|
||||||
|
ProjectFolder folder;
|
||||||
|
if (cast(Project)obj) {
|
||||||
|
project = cast(Project)obj;
|
||||||
|
} else if (cast(ProjectFolder)obj) {
|
||||||
|
folder = cast(ProjectFolder)obj;
|
||||||
|
project = folder.project;
|
||||||
|
} else if (cast(ProjectSourceFile)obj) {
|
||||||
|
ProjectSourceFile srcfile = cast(ProjectSourceFile)obj;
|
||||||
|
folder = cast(ProjectFolder)srcfile.parent;
|
||||||
|
project = srcfile.project;
|
||||||
|
} else {
|
||||||
|
ProjectSourceFile srcfile = currentEditorSourceFile;
|
||||||
|
if (srcfile) {
|
||||||
|
folder = cast(ProjectFolder)srcfile.parent;
|
||||||
|
project = srcfile.project;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (project) {
|
||||||
|
project.refresh();
|
||||||
|
refreshWorkspace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeProjectItem(const Object obj) {
|
||||||
|
if (currentWorkspace is null)
|
||||||
|
return;
|
||||||
|
ProjectSourceFile srcfile = cast(ProjectSourceFile)obj;
|
||||||
|
if (!srcfile)
|
||||||
|
return;
|
||||||
|
Project project = srcfile.project;
|
||||||
|
if (!project)
|
||||||
|
return;
|
||||||
|
window.showMessageBox(UIString("Remove file"d),
|
||||||
|
UIString("Do you want to remove file "d ~ srcfile.name ~ "?"),
|
||||||
|
[ACTION_YES, ACTION_NO],
|
||||||
|
1, delegate(const Action result) {
|
||||||
|
if (result == StandardAction.Yes) {
|
||||||
|
// save and close
|
||||||
|
try {
|
||||||
|
import std.file : remove;
|
||||||
|
closeTab(srcfile.filename);
|
||||||
|
remove(srcfile.filename);
|
||||||
|
project.refresh();
|
||||||
|
refreshWorkspace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("Error while removing file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else ignore
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void addProjectItem(const Object obj) {
|
void addProjectItem(const Object obj) {
|
||||||
if (currentWorkspace is null)
|
if (currentWorkspace is null)
|
||||||
return;
|
return;
|
||||||
|
@ -818,6 +905,7 @@ class IDEFrame : AppFrame {
|
||||||
void refreshWorkspace() {
|
void refreshWorkspace() {
|
||||||
_logPanel.logLine("Refreshing workspace");
|
_logPanel.logLine("Refreshing workspace");
|
||||||
_wsPanel.reloadItems();
|
_wsPanel.reloadItems();
|
||||||
|
closeRemovedDocuments();
|
||||||
}
|
}
|
||||||
|
|
||||||
void createNewWorkspaceForExistingProject(Project project) {
|
void createNewWorkspaceForExistingProject(Project project) {
|
||||||
|
|
|
@ -75,18 +75,27 @@ class WorkspacePanel : DockWindow {
|
||||||
_tree.popupMenu = &onTreeItemPopupMenu;
|
_tree.popupMenu = &onTreeItemPopupMenu;
|
||||||
|
|
||||||
_workspacePopupMenu = new MenuItem();
|
_workspacePopupMenu = new MenuItem();
|
||||||
_workspacePopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE.clone());
|
_workspacePopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_FILE_WORKSPACE_CLOSE);
|
||||||
|
|
||||||
_projectPopupMenu = new MenuItem();
|
_projectPopupMenu = new MenuItem();
|
||||||
_projectPopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
_projectPopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE,
|
||||||
ACTION_PROJECT_FOLDER_REMOVE_ITEM);
|
ACTION_PROJECT_FOLDER_REFRESH,
|
||||||
|
ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
||||||
|
//ACTION_PROJECT_FOLDER_REMOVE_ITEM
|
||||||
|
);
|
||||||
|
|
||||||
_folderPopupMenu = new MenuItem();
|
_folderPopupMenu = new MenuItem();
|
||||||
_folderPopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
_folderPopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_PROJECT_FOLDER_REFRESH, ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
||||||
ACTION_PROJECT_FOLDER_REMOVE_ITEM, ACTION_PROJECT_FOLDER_RENAME_ITEM);
|
//ACTION_PROJECT_FOLDER_REMOVE_ITEM,
|
||||||
|
//ACTION_PROJECT_FOLDER_RENAME_ITEM
|
||||||
|
);
|
||||||
|
|
||||||
_filePopupMenu = new MenuItem();
|
_filePopupMenu = new MenuItem();
|
||||||
_filePopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
_filePopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_PROJECT_FOLDER_REFRESH,
|
||||||
ACTION_PROJECT_FOLDER_REMOVE_ITEM, ACTION_PROJECT_FOLDER_RENAME_ITEM);
|
ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
||||||
|
ACTION_PROJECT_FOLDER_REMOVE_ITEM,
|
||||||
|
//ACTION_PROJECT_FOLDER_RENAME_ITEM
|
||||||
|
);
|
||||||
return _tree;
|
return _tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,10 @@ class ProjectFolder : ProjectItem {
|
||||||
string relativeToAbsolutePath(string path) {
|
string relativeToAbsolutePath(string path) {
|
||||||
if (isAbsolute(path))
|
if (isAbsolute(path))
|
||||||
return path;
|
return path;
|
||||||
return buildNormalizedPath(_filename, path);
|
string fn = _filename;
|
||||||
|
if (exists(fn) && isFile(fn))
|
||||||
|
fn = dirName(fn);
|
||||||
|
return buildNormalizedPath(fn, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void refresh() {
|
override void refresh() {
|
||||||
|
@ -456,7 +459,10 @@ class Project : WorkspaceItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh() {
|
void refresh() {
|
||||||
_items.refresh();
|
for (int i = _items._children.count - 1; i >= 0; i--) {
|
||||||
|
if (_items._children[i].isFolder)
|
||||||
|
_items._children[i].refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void findMainSourceFile() {
|
void findMainSourceFile() {
|
||||||
|
|
|
@ -74,3 +74,6 @@ MENU_PROJECT_FOLDER_ADD_ITEM=Add...
|
||||||
MENU_PROJECT_FOLDER_OPEN_ITEM=Open
|
MENU_PROJECT_FOLDER_OPEN_ITEM=Open
|
||||||
MENU_PROJECT_FOLDER_REMOVE_ITEM=Remove
|
MENU_PROJECT_FOLDER_REMOVE_ITEM=Remove
|
||||||
MENU_PROJECT_FOLDER_RENAME_ITEM=Rename...
|
MENU_PROJECT_FOLDER_RENAME_ITEM=Rename...
|
||||||
|
MENU_PROJECT_FOLDER_REFRESH=Refresh
|
||||||
|
|
||||||
|
MENU_FILE_WORKSPACE_CLOSE=Close Workspace
|
||||||
|
|
|
@ -75,3 +75,4 @@ MENU_PROJECT_FOLDER_ADD_ITEM=Añadir...
|
||||||
MENU_PROJECT_FOLDER_OPEN_ITEM=Abrir
|
MENU_PROJECT_FOLDER_OPEN_ITEM=Abrir
|
||||||
MENU_PROJECT_FOLDER_REMOVE_ITEM=Remover
|
MENU_PROJECT_FOLDER_REMOVE_ITEM=Remover
|
||||||
MENU_PROJECT_FOLDER_RENAME_ITEM=Renombrar...
|
MENU_PROJECT_FOLDER_RENAME_ITEM=Renombrar...
|
||||||
|
MENU_PROJECT_FOLDER_REFRESH=Refresh
|
||||||
|
|
Loading…
Reference in New Issue