From a088bf7f0fed3a1f444416bf81d9975568221448 Mon Sep 17 00:00:00 2001 From: donho Date: Mon, 8 Oct 2007 01:00:13 +0000 Subject: [PATCH] [NEW_FEATURE] Add NPPN_FILESAVED and NPPN_FILEBEFORESAVE notifications. Enhance the File save Dialog (add ext). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@50 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 12 +++- PowerEditor/src/Notepad_plus.cpp | 36 ++++++------ PowerEditor/src/Notepad_plus.h | 4 ++ PowerEditor/src/Notepad_plus.rc | 4 +- .../OpenSaveFileDialog/FileDialog.cpp | 15 +++-- .../OpenSaveFileDialog/FileDialog.h | 57 ++++++++++++++++++- 6 files changed, 102 insertions(+), 26 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 28dee030..456833f5 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -211,7 +211,7 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = 0; - #define NPPN_FILECLOSED (NPPN_FIRST + 5) // To notify plugins that the current file is about to be closed + #define NPPN_FILECLOSED (NPPN_FIRST + 5) // To notify plugins that the current file is just closed //scnNotification->nmhdr.code = NPPN_FILECLOSED; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = 0; @@ -220,5 +220,15 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_FILEBEFORESAVE (NPPN_FIRST + 7) // To notify plugins that the current file is about to be saved + //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_FILESAVED (NPPN_FIRST + 8) // To notify plugins that the current file is just saved + //scnNotification->nmhdr.code = NPPN_FILECLOSED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; #endif //NOTEPAD_PLUS_MSGS_H diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 45926702..c5acad07 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -524,12 +524,8 @@ string exts2Filters(string exts) { return filters; }; -void Notepad_plus::fileOpen() +void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg) { - FileDialog fDlg(_hSelf, _hInst); - fDlg.setExtFilter("All types", ".*", NULL); - - NppParameters *pNppParam = NppParameters::getInstance(); NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); @@ -578,6 +574,14 @@ void Notepad_plus::fileOpen() } l = (NppParameters::getInstance())->getLangFromIndex(i++); } +} + +void Notepad_plus::fileOpen() +{ + FileDialog fDlg(_hSelf, _hInst); + fDlg.setExtFilter("All types", ".*", NULL); + + setFileOpenSaveDlgFilters(fDlg); if (stringVector *pfns = fDlg.doOpenMultiFilesDlg()) { @@ -645,6 +649,13 @@ bool Notepad_plus::doSave(const char *filename, UniMode mode) if (fp) { + // Notify plugins that current file is about to be saved + SCNotification scnN; + scnN.nmhdr.code = NPPN_FILEBEFORESAVE; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = 0; + _pluginsManager.notify(&scnN); + char data[blockSize + 1]; int lengthDoc = _pEditView->getCurrentDocLen(); for (int i = 0; i < lengthDoc; i += blockSize) @@ -666,6 +677,9 @@ bool Notepad_plus::doSave(const char *filename, UniMode mode) if (isSys) ::SetFileAttributes(filename, attrib | FILE_ATTRIBUTE_SYSTEM); + + scnN.nmhdr.code = NPPN_FILESAVED; + _pluginsManager.notify(&scnN); return true; } ::MessageBox(_hSelf, "Please check whether if this file is opened in another program", "Save failed", MB_OK); @@ -1010,18 +1024,8 @@ bool Notepad_plus::fileSaveAs() FileDialog fDlg(_hSelf, _hInst); fDlg.setExtFilter("All types", ".*", NULL); + setFileOpenSaveDlgFilters(fDlg); - fDlg.setExtFilter("c src file", ".c", NULL); - fDlg.setExtFilter("c++ src file", ".cpp", NULL); - fDlg.setExtFilter("Window Resource File", ".rc", NULL); - fDlg.setExtFilter("c/c++ header file", ".h", NULL); - fDlg.setExtFilter("Java src file", ".java", NULL); - fDlg.setExtFilter("HTML file", ".html", NULL); - fDlg.setExtFilter("XML file", ".xml", NULL); - fDlg.setExtFilter("php file", ".php",NULL); - fDlg.setExtFilter("ini file", ".ini", NULL); - fDlg.setExtFilter("bat file", ".bat", NULL); - fDlg.setExtFilter("Normal text file", ".txt", NULL); char str[MAX_PATH]; strcpy(str, _pEditView->getCurrentTitle()); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 235563ec..d099d97e 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -74,6 +74,8 @@ struct iconLocator { : listIndex(iList), iconIndex(iIcon), iconLocation(iconLoc){}; }; +class FileDialog; + class Notepad_plus : public Window { public: Notepad_plus(); @@ -926,6 +928,8 @@ private: hideLinesMarkDelete(_hideLinesMarks[i].second, MARK_HIDELINESEND); } }; + + void setFileOpenSaveDlgFilters(FileDialog & fDlg); }; #endif //NOTEPAD_PLUS_H diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 9dd3f179..c43e81af 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -376,13 +376,14 @@ BEGIN END MENUITEM "Unfold all\tAlt+Shift+0", IDM_VIEW_TOGGLE_UNFOLDALL MENUITEM SEPARATOR - MENUITEM "Hide lines", IDM_VIEW_HIDELINES + MENUITEM "Hide lines\tAlt+H", IDM_VIEW_HIDELINES MENUITEM SEPARATOR MENUITEM "Go to another view", IDM_VIEW_GOTO_ANOTHER_VIEW MENUITEM "Clone to another view", IDM_VIEW_CLONE_TO_ANOTHER_VIEW MENUITEM "Synchronize Vertical Scrolling", IDM_VIEW_SYNSCROLLV MENUITEM "Synchronize Horizontal Scrolling", IDM_VIEW_SYNSCROLLH END + POPUP "For&mat" BEGIN MENUITEM "Convert to Windows Format", IDM_FORMAT_TODOS @@ -604,6 +605,7 @@ BEGIN "L", IDM_EDIT_LTR, VIRTKEY, CONTROL, ALT "R", IDM_EDIT_RTL, VIRTKEY, CONTROL, ALT "C", IDM_EDIT_COLUMNMODE, VIRTKEY, ALT + "H", IDM_VIEW_HIDELINES, VIRTKEY, ALT VK_HOME, IDC_KEY_HOME, VIRTKEY VK_END, IDC_KEY_END, VIRTKEY diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp index fe9a446f..27c28606 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -17,11 +17,11 @@ #include #include "FileDialog.h" -//FileDialog *FileDialog::staticThis = NULL; +FileDialog *FileDialog::staticThis = NULL; FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst) : _nbCharFileExt(0), _nbExt(0) -{//staticThis = this; +{staticThis = this; for (int i = 0 ; i < nbExtMax ; i++) _extArray[i][0] = '\0'; @@ -43,6 +43,7 @@ FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst) _ofn.lpstrTitle = NULL; _ofn.nFileOffset = 0; _ofn.nFileExtension = 0; + _ofn.lpfnHook = NULL; _ofn.lpstrDefExt = NULL; // No default extension _ofn.lCustData = 0; _ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_LONGNAMES | DS_CENTER | OFN_HIDEREADONLY; @@ -186,6 +187,9 @@ char * FileDialog::doSaveDlg() _ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + _ofn.Flags |= OFN_ENABLEHOOK; + _ofn.lpfnHook = OFNHookProc; + char *fn = NULL; try { fn = ::GetSaveFileName(&_ofn)?_fileName:NULL; @@ -196,7 +200,7 @@ char * FileDialog::doSaveDlg() return (fn); } -/* + UINT_PTR CALLBACK FileDialog::OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) @@ -204,8 +208,9 @@ UINT_PTR CALLBACK FileDialog::OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, L case WM_INITDIALOG : { ::SetWindowLong(hWnd, GWL_USERDATA, (long)staticThis); + //printStr("en train"); //pStaticDlg->run_dlgProc(message, wParam, lParam); - return TRUE; + return FALSE; } default : @@ -219,4 +224,4 @@ UINT_PTR CALLBACK FileDialog::OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, L //::OFNHookProc(hWnd, uMsg, wParam, lParam); return FALSE; } -*/ + diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h index 4212c670..43f4df0d 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h @@ -24,11 +24,14 @@ #include #include +#include "SysMsg.h" const int nbExtMax = 10; const int extLenMax = 10; -typedef std::vector stringVector; +using namespace std; + +typedef vector stringVector; //const bool styleOpen = true; //const bool styleSave = false; @@ -45,7 +48,7 @@ public: stringVector * doOpenMultiFilesDlg(); char * doOpenSingleFileDlg(); bool isReadOnly() {return _ofn.Flags & OFN_READONLY;}; -/* + protected : static UINT APIENTRY OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); BOOL APIENTRY run(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -58,13 +61,51 @@ protected : { case CDN_FILEOK : { + printStr("CDN_FILEOK"); if ((_fileName)&&(!strrchr(_extArray[_ofn.nFilterIndex - 1], '*')) && (strcmp(_extArray[_ofn.nFilterIndex - 1], _fileName + _ofn.nFileExtension - 1))) { strcat(_fileName, _extArray[_ofn.nFilterIndex - 1]); } + break; } + case CDN_TYPECHANGE : + { + HWND fnControl = ::GetDlgItem(::GetParent(hWnd), edt1); + char fn[256]; + ::GetWindowText(fnControl, fn, sizeof(fn)); + if (*fn == '\0') + return TRUE; + HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); + int i = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0); + char ext[256]; + ::SendMessage(typeControl, CB_GETLBTEXT, i, (LPARAM)ext); + //printInt(i); + // + char *pExt = get1stExt(ext); + if (*pExt == '\0') + return TRUE; + //::SendMessage(::GetParent(hWnd), CDM_SETDEFEXT, 0, (LPARAM)pExt); + + string fnExt = fn; + + int index = fnExt.find_last_of("."); + string extension = "."; + extension += pExt; + if (index == string::npos) + { + fnExt += extension; + } + else + { + int len = (extension.length() > fnExt.length() - index + 1)?extension.length():fnExt.length() - index + 1; + fnExt.replace(index, len, extension); + } + + ::SetWindowText(fnControl, fnExt.c_str()); + break; + } default : return FALSE; } @@ -74,7 +115,7 @@ protected : return FALSE; } }; -*/ + private: char _fileName[MAX_PATH*8]; @@ -87,6 +128,16 @@ private: char _extArray[nbExtMax][extLenMax]; int _nbExt; + char * get1stExt(char *ext) { // precondition : ext should be under the format : Batch (*.bat;*.cmd;*.nt) + char *begin = ext; + for ( ; *begin != '.' ; begin++); + char *end = ++begin; + for ( ; *end != ';' && *end != ')' ; end++); + *end = '\0'; + if (*begin == '*') + *begin = '\0'; + return begin; + }; static FileDialog *staticThis; };