From d0b9ff8a0e28d3ce1e201bc00c08448021c70b9d Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 15 Aug 2017 17:47:02 +0300 Subject: [PATCH] implementation of #237 - save file as -- first part --- dub.json | 5 ++- src/dlangide/ui/dsourceedit.d | 9 ++++++ src/dlangide/ui/frame.d | 52 ++++++++++++++++++++++++++++++-- src/dlangide/workspace/project.d | 5 +++ views/res/i18n/en.ini | 1 + views/res/i18n/ru.ini | 1 + 6 files changed, 67 insertions(+), 6 deletions(-) diff --git a/dub.json b/dub.json index bc01c49..84f40d2 100644 --- a/dub.json +++ b/dub.json @@ -12,9 +12,8 @@ "stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi", "views/res/hdpi"], "dependencies": { - "dlangui": "==0.9.89", - "dsymbol": "~>0.2.8", - "dcd": "~>0.9.0" + "dlangui": "==0.9.90", + "dcd": "~>0.9.1" }, "copyFiles-windows": [ diff --git a/src/dlangide/ui/dsourceedit.d b/src/dlangide/ui/dsourceedit.d index b1939cf..fbdeb66 100644 --- a/src/dlangide/ui/dsourceedit.d +++ b/src/dlangide/ui/dsourceedit.d @@ -125,6 +125,7 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener { protected ProjectSourceFile _projectSourceFile; @property ProjectSourceFile projectSourceFile() { return _projectSourceFile; } + @property void projectSourceFile(ProjectSourceFile v) { _projectSourceFile = v; } /// load by filename override bool load(string fn) { _projectSourceFile = null; @@ -224,6 +225,14 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener { return _content.save(); } + /// save to the same file + override bool save(string fn) { + bool res = super.save(fn); + //if (res && projectSourceFile) + // projectSourceFile.setFilename(filename); + return res; + } + void insertCompletion(dstring completionText) { TextRange range; TextPosition p = caretPos; diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index 02f47ca..42f7e92 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -46,7 +46,7 @@ import std.path; immutable string HELP_PAGE_URL = "https://github.com/buggins/dlangide/wiki"; // TODO: get version from GIT commit -immutable dstring DLANGIDE_VERSION = "v0.7.44"d; +immutable dstring DLANGIDE_VERSION = "v0.7.45"d; bool isSupportedSourceTextFileFormat(string filename) { return (filename.endsWith(".d") || filename.endsWith(".di") || filename.endsWith(".dt") || filename.endsWith(".txt") || filename.endsWith(".cpp") || filename.endsWith(".h") || filename.endsWith(".c") @@ -514,6 +514,18 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL _tabs.removeTab(tabId); } + void renameTab(string oldfilename, string newfilename) { + int index = _tabs.tabIndex(newfilename); + if (index >= 0) { + // file is already opened in tab - close it + _tabs.removeTab(newfilename); + } + int oldindex = _tabs.tabIndex(oldfilename); + if (oldindex >= 0) { + _tabs.renameTab(oldindex, newfilename, UIString.fromRaw(newfilename.baseName)); + } + } + /// close all editor tabs void closeAllDocuments() { for (int i = _tabs.tabCount - 1; i >= 0; i--) { @@ -879,8 +891,8 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL } } - FileDialog createFileDialog(UIString caption) { - FileDialog dlg = new FileDialog(caption, window, null); + FileDialog createFileDialog(UIString caption, int fileDialogFlags = DialogFlag.Modal | DialogFlag.Resizable | FileDialogFlag.FileMustExist) { + FileDialog dlg = new FileDialog(caption, window, null, fileDialogFlags); dlg.filetypeIcons[".d"] = "text-d"; dlg.filetypeIcons["dub.json"] = "project-d"; dlg.filetypeIcons["dub.sdl"] = "project-d"; @@ -910,6 +922,40 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL case StandardAction.OpenUrl: platform.openURL(a.stringParam); return true; + case IDEActions.FileSaveAs: + DSourceEdit ed = currentEditor; + UIString caption; + caption = UIString.fromId("HEADER_SAVE_FILE_AS"c); + FileDialog dlg = createFileDialog(caption, DialogFlag.Modal | DialogFlag.Resizable | FileDialogFlag.Save); + dlg.addFilter(FileFilterEntry(UIString.fromId("SOURCE_FILES"c), "*.d;*.dd;*.ddoc;*.di;*.dt;*.dh;*.json;*.sdl;*.xml;*.ini")); + dlg.addFilter(FileFilterEntry(UIString.fromId("ALL_FILES"c), "*.*")); + dlg.path = ed.filename.dirName; + dlg.filename = ed.filename; + dlg.dialogResult = delegate(Dialog d, const Action result) { + if (result.id == ACTION_SAVE.id) { + string oldfilename = ed.filename; + string filename = result.stringParam; + ed.save(filename); + if (oldfilename == filename) + return; + renameTab(oldfilename, filename); + ed.id = filename; + if( filename.endsWith(".d") || filename.endsWith(".di") ) + ed.editorTool = new DEditorTool(this); + else + ed.editorTool = new DefaultEditorTool(this); + //openSourceFile(filename); + refreshWorkspace(); + ProjectSourceFile file = _wsPanel.findSourceFileItem(filename, false); + if (file) + ed.projectSourceFile = file; + else + ed.projectSourceFile = null; + _settings.setRecentPath(dlg.path, "FILE_OPEN_PATH"); + } + }; + dlg.show(); + return true; case IDEActions.FileOpen: UIString caption; caption = UIString.fromId("HEADER_OPEN_TEXT_FILE"c); diff --git a/src/dlangide/workspace/project.d b/src/dlangide/workspace/project.d index a4fef92..fc2db3b 100644 --- a/src/dlangide/workspace/project.d +++ b/src/dlangide/workspace/project.d @@ -227,6 +227,11 @@ class ProjectSourceFile : ProjectItem { @property string projectFilePath() { return project.absoluteToRelativePath(filename); } + + void setFilename(string filename) { + _filename = buildNormalizedPath(filename); + _name = toUTF32(baseName(_filename)); + } } class WorkspaceItem { diff --git a/views/res/i18n/en.ini b/views/res/i18n/en.ini index 99f95ca..ca920c0 100644 --- a/views/res/i18n/en.ini +++ b/views/res/i18n/en.ini @@ -117,6 +117,7 @@ MENU_PROJECT_REVEAL_IN_EXPLORER=Reveal in Explorer HEADER_SETTINGS=DlangIDE settings HEADER_OPEN_WORKSPACE_OR_PROJECT=Open Workspace or Project HEADER_OPEN_TEXT_FILE=Open Text File +HEADER_SAVE_FILE_AS=Save File As OPTION_ADD_TO_CURRENT_WORKSPACE=Add to current workspace OPTION_AUTO_OPEN_LAST_PROJECT=Auto open last project diff --git a/views/res/i18n/ru.ini b/views/res/i18n/ru.ini index 7c0a4cc..14258ec 100644 --- a/views/res/i18n/ru.ini +++ b/views/res/i18n/ru.ini @@ -117,6 +117,7 @@ MENU_PROJECT_REVEAL_IN_EXPLORER=Открыть в проводнике HEADER_SETTINGS=DlangIDE настройки HEADER_OPEN_WORKSPACE_OR_PROJECT=Открыть рабочее пространство или проект HEADER_OPEN_TEXT_FILE=Открыть текстовый файл +HEADER_SAVE_FILE_AS=Сохранить как OPTION_ADD_TO_CURRENT_WORKSPACE=Добавить в текущее пр-во OPTION_AUTO_OPEN_LAST_PROJECT=Авт.открывать последний проект