From fd437c9c7db6eff2f4c994efbdcbb8454d43f2b3 Mon Sep 17 00:00:00 2001 From: donho Date: Thu, 8 May 2008 23:17:43 +0000 Subject: [PATCH] [NEW_FEATURE] Add "Save Copy As" feature. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@199 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 55 ++++++++++++++++++++------------ PowerEditor/src/Notepad_plus.h | 4 +-- PowerEditor/src/Notepad_plus.rc | 1 + PowerEditor/src/menuCmdID.h | 1 + 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 140201212..7dd7a5f62 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -940,7 +940,7 @@ bool Notepad_plus::doReload(const char *fileName, bool alert) return false; } -bool Notepad_plus::doSave(const char *filename, UniMode mode) +bool Notepad_plus::doSave(const char *filename, UniMode mode, bool isCopy) { bool isHidden = false; bool isSys = false; @@ -974,13 +974,16 @@ 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); - + // Notify plugins that current file is about to be saved + if (!isCopy) + { + + 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) @@ -994,17 +997,20 @@ bool Notepad_plus::doSave(const char *filename, UniMode mode) } UnicodeConvertor.fclose(); - _pEditView->updateCurrentBufTimeStamp(); - _pEditView->execute(SCI_SETSAVEPOINT); - if (isHidden) - ::SetFileAttributes(filename, attrib | FILE_ATTRIBUTE_HIDDEN); + ::SetFileAttributes(filename, attrib | FILE_ATTRIBUTE_HIDDEN); if (isSys) ::SetFileAttributes(filename, attrib | FILE_ATTRIBUTE_SYSTEM); - scnN.nmhdr.code = NPPN_FILESAVED; - _pluginsManager.notify(&scnN); + if (!isCopy) + { + _pEditView->updateCurrentBufTimeStamp(); + _pEditView->execute(SCI_SETSAVEPOINT); + + 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); @@ -1397,7 +1403,7 @@ bool Notepad_plus::findInOpenedFiles() { return true; } -bool Notepad_plus::fileSaveAs() +bool Notepad_plus::fileSaveAs(bool isSaveCopy) { FileDialog fDlg(_hSelf, _hInst); @@ -1418,13 +1424,16 @@ bool Notepad_plus::fileSaveAs() int i = _pEditView->findDocIndexByName(pfn); if ((i == -1) || (i == currentDocIndex)) { - doSave(pfn, _pEditView->getCurrentBuffer().getUnicodeMode()); - _pEditView->setCurrentTitle(pfn); - _pEditView->setCurrentDocReadOnly(false); - _pDocTab->updateCurrentTabItem(PathFindFileName(pfn)); - setTitleWith(pfn); - setLangStatus(_pEditView->getCurrentDocType()); - checkLangsMenu(-1); + doSave(pfn, _pEditView->getCurrentBuffer().getUnicodeMode(), isSaveCopy); + if (!isSaveCopy) + { + _pEditView->setCurrentTitle(pfn); + _pEditView->setCurrentDocReadOnly(false); + _pDocTab->updateCurrentTabItem(PathFindFileName(pfn)); + setTitleWith(pfn); + setLangStatus(_pEditView->getCurrentDocType()); + checkLangsMenu(-1); + } return true; } else @@ -2652,6 +2661,10 @@ void Notepad_plus::command(int id) fileSaveAs(); break; + case IDM_FILE_SAVECOPYAS : + fileSaveAs(true); + break; + case IDM_FILE_LOADSESSION: fileLoadSession(); break; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 9142ff4ac..cc5bce972 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -117,9 +117,9 @@ public: bool fileCloseAllButCurrent(); bool fileSave(); bool fileSaveAll(); - bool fileSaveAs(); + bool fileSaveAs(bool isSaveCopy = false); - bool doSave(const char *filename, UniMode mode); + bool doSave(const char *filename, UniMode mode, bool isSaveCopy = false); // end fileOperation void filePrint(bool showDialog); diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 37f78c827..77749c33c 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -249,6 +249,7 @@ BEGIN MENUITEM "Re&load from disk", IDM_FILE_RELOAD MENUITEM "&Save", IDM_FILE_SAVE MENUITEM "Save &As...", IDM_FILE_SAVEAS + MENUITEM "Save Copy As...", IDM_FILE_SAVECOPYAS MENUITEM "Sav&e All", IDM_FILE_SAVEALL MENUITEM "&Close", IDM_FILE_CLOSE MENUITEM "Cl&ose All", IDM_FILE_CLOSEALL diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 860fc0580..85eb48c90 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -36,6 +36,7 @@ #define IDM_FILE_LOADSESSION (IDM_FILE + 12) #define IDM_FILE_SAVESESSION (IDM_FILE + 13) #define IDM_FILE_RELOAD (IDM_FILE + 14) + #define IDM_FILE_SAVECOPYAS (IDM_FILE + 15) // A mettre à jour si on ajoute nouveau menu item dans le menu "File" #define IDM_FILEMENU_LASTONE IDM_FILE_RELOAD