mirror of https://github.com/buggins/dlangide.git
implementation of #237 - save file as -- first part
This commit is contained in:
parent
d15e6e769a
commit
d0b9ff8a0e
5
dub.json
5
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": [
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=Авт.открывать последний проект
|
||||
|
|
Loading…
Reference in New Issue