From dfaed129b5491766202be6bdfe6a46301f049063 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 22 Sep 2009 21:30:29 +0000 Subject: [PATCH] [NEW_FEATURE] Set extension automatically (according to set document language) in save as dialog. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@542 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 26 ++++++++++++++++--- PowerEditor/src/Notepad_plus.h | 2 +- .../OpenSaveFileDialog/FileDialog.cpp | 17 +++++++++--- .../OpenSaveFileDialog/FileDialog.h | 3 ++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index bf1c77b3d..2a41d73dc 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -983,7 +983,7 @@ generic_string exts2Filters(generic_string exts) { return filters; }; -void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg) +int Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType) { NppParameters *pNppParam = NppParameters::getInstance(); NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); @@ -991,6 +991,8 @@ void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg) int i = 0; Lang *l = NppParameters::getInstance()->getLangFromIndex(i++); + int ltIndex = 0; + bool ltFound = false; while (l) { LangType lid = l->getLangID(); @@ -1032,10 +1034,27 @@ void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg) if (filters[0]) { fDlg.setExtsFilter(getLangDesc(lid, true).c_str(), filters); + + // + // Get index of lang type to find + // + if (langType != -1 && !ltFound) + { + ltFound = langType == lid; + } + + if (langType != -1 && !ltFound) + { + ltIndex++; + } } } l = (NppParameters::getInstance())->getLangFromIndex(i++); } + + if (!ltFound) + return -1; + return ltIndex; } void Notepad_plus::fileOpen() @@ -1198,9 +1217,10 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy) FileDialog fDlg(_hSelf, _hInst); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); - setFileOpenSaveDlgFilters(fDlg); - + int langTypeIndex = setFileOpenSaveDlgFilters(fDlg, buf->getLangType()); fDlg.setDefFileName(buf->getFileName()); + + fDlg.setExtIndex(langTypeIndex+1); // +1 for "All types" TCHAR *pfn = fDlg.doSaveDlg(); if (pfn) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 500f007ac..c4e1b234a 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -557,7 +557,7 @@ private: int getLangFromMenuName(const TCHAR * langName); generic_string getLangFromMenu(const Buffer * buf); - void setFileOpenSaveDlgFilters(FileDialog & fDlg); + int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1); void markSelectedTextInc(bool enable); Style * getStyleFromName(const TCHAR *styleName); bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp index d7de59b19..771a296cd 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -24,7 +24,7 @@ FileDialog *FileDialog::staticThis = NULL; //int FileDialog::_dialogFileBoxId = (NppParameters::getInstance())->getWinVersion() < WV_W2K?edt1:cmb13; FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst) - : _nbCharFileExt(0), _nbExt(0), _fileExt(NULL) + : _nbCharFileExt(0), _nbExt(0), _fileExt(NULL), _extTypeIndex(-1) { staticThis = this; //for (int i = 0 ; i < nbExtMax ; i++) @@ -374,13 +374,25 @@ BOOL APIENTRY FileDialog::run(HWND hWnd, UINT uMsg, WPARAM, LPARAM lParam) LPNMHDR pNmhdr = (LPNMHDR)lParam; switch(pNmhdr->code) { + case CDN_INITDONE : + { + if (_extTypeIndex == -1) + return TRUE; + + HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId); + HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); + ::SendMessage(typeControl, CB_SETCURSEL, _extTypeIndex, 0); + + currentExt = addExt(fnControl, typeControl); + return TRUE; + } + case CDN_TYPECHANGE : { HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId); HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); currentExt = addExt(fnControl, typeControl); return TRUE; - //break; } case CDN_FILEOK : @@ -390,7 +402,6 @@ BOOL APIENTRY FileDialog::run(HWND hWnd, UINT uMsg, WPARAM, LPARAM lParam) NppParameters *pNppParam = NppParameters::getInstance(); pNppParam->setFileSaveDlgFilterIndex(index); return TRUE; - //break; } default : diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h index a85e37cfc..51453b6e0 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h @@ -70,6 +70,7 @@ public: stringVector * doOpenMultiFilesDlg(); TCHAR * doOpenSingleFileDlg(); bool isReadOnly() {return _ofn.Flags & OFN_READONLY;}; + void setExtIndex(int extTypeIndex) {_extTypeIndex = extTypeIndex;}; static int _dialogFileBoxId; protected : @@ -90,7 +91,7 @@ private: //TCHAR _extArray[nbExtMax][extLenMax]; int _nbExt; - + int _extTypeIndex; static FileDialog *staticThis; };