From edd746d31078a2d928b4d9ad4fec08691fbef1e5 Mon Sep 17 00:00:00 2001 From: Udo Hoffmann Date: Sun, 24 May 2020 19:29:19 +0200 Subject: [PATCH] Improve save (new style) dialog by adding file extension automatically 1. Add file extension automatically while changing file type via combobox in new style dialog. 2. Add file extension automatically for session files and workspace files while saving in new style dialog. Fix #4876, close #8311, close #8312 --- PowerEditor/src/NppIO.cpp | 1 + PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp | 1 + PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h | 2 ++ PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp | 1 + 4 files changed, 5 insertions(+) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index f528aa992..4ef9a5380 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -2217,6 +2217,7 @@ const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames) sessionExt += TEXT("."); sessionExt += ext; fDlg.setExtFilter(TEXT("Session file"), sessionExt.c_str(), NULL); + fDlg.setDefExt(ext); fDlg.setExtIndex(0); // 0 index for "custom extension types" } fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp index d6389147f..273f56a7c 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -267,6 +267,7 @@ TCHAR * FileDialog::doSaveDlg() NppParameters& params = NppParameters::getInstance(); _ofn.lpstrInitialDir = params.getWorkingDir(); + _ofn.lpstrDefExt = _defExt.c_str(); _ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING; diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h index 394381266..96ea4a0c9 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h @@ -49,6 +49,7 @@ public: int setExtsFilter(const TCHAR *extText, const TCHAR *exts); void setDefFileName(const TCHAR *fn){ wcscpy_s(_fileName, fn);} + void setDefExt(const TCHAR *ext){ _defExt = ext;} TCHAR * doSaveDlg(); stringVector * doOpenMultiFilesDlg(); @@ -63,6 +64,7 @@ protected : private: TCHAR _fileName[MAX_PATH*8]; + generic_string _defExt; TCHAR * _fileExt; int _nbCharFileExt; diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index f4f6508af..5faf0937e 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -1188,6 +1188,7 @@ void ProjectPanel::setFileExtFilter(FileDialog & fDlg) workspaceExt += TEXT("."); workspaceExt += ext; fDlg.setExtFilter(TEXT("Workspace file"), workspaceExt.c_str(), NULL); + fDlg.setDefExt(ext); } fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); }