From 16ebb8c3dbc6bf21eda0cc4267fbc8dc5be240e9 Mon Sep 17 00:00:00 2001 From: donho Date: Sun, 30 Sep 2007 02:09:38 +0000 Subject: [PATCH] [BUG_FIXED] Fix a regression bug for the lang saving in session file. ADD NPPN_FILEBEFOREOPENED and NPPN_FILECLOSED plugins notification message. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@47 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 14 ++- PowerEditor/src/Notepad_plus.cpp | 117 +++++++++--------- PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/Parameters.h | 7 +- 4 files changed, 76 insertions(+), 64 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 281414ae7..28dee0304 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -206,8 +206,18 @@ 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_FILEJUSTOPENED (NPPN_FIRST + 4) // To notify plugins that the current file is just opened - //scnNotification->nmhdr.code = NPPN_FILEJUSTOPENED; + #define NPPN_FILEOPENED (NPPN_FIRST + 4) // To notify plugins that the current file is just opened + //scnNotification->nmhdr.code = NPPN_FILEOPENED; + //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 + //scnNotification->nmhdr.code = NPPN_FILECLOSED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_FILEBEFOREOPEN (NPPN_FIRST + 6) // To notify plugins that the current file is about to be opened + //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = 0; diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 91566ee40..10939e8ca 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -213,8 +213,7 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine) if (nppGUI._rememberLastSession) { //--LS: Session SubView restore: Code replaced to load session.xml with new loadSessionToEditView() function!! - Session lastSession = (NppParameters::getInstance())->getSession(); - bool shouldBeResaved = loadSessionToEditView(&lastSession); + bool shouldBeResaved = loadSessionToEditView((NppParameters::getInstance())->getSession()); } if (cmdLine) @@ -358,8 +357,17 @@ bool Notepad_plus::doOpen(const char *fileName, bool isReadOnly) bool isNewDoc2Close = false; FILE *fp = fopen(longFileName, "rb"); + + if (fp) { + // Notify plugins that current file is just opened + SCNotification scnN; + scnN.nmhdr.code = NPPN_FILEBEFOREOPEN; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = 0; + _pluginsManager.notify(&scnN); + if ((_pEditView->getNbDoc() == 1) && Buffer::isUntitled(_pEditView->getCurrentTitle()) && (!_pEditView->isCurrentDocDirty()) && (_pEditView->getCurrentDocLen() == 0)) @@ -452,10 +460,7 @@ bool Notepad_plus::doOpen(const char *fileName, bool isReadOnly) setWorkingDir(longFileName); // Notify plugins that current file is just opened - SCNotification scnN; - scnN.nmhdr.code = NPPN_FILEJUSTOPENED; - scnN.nmhdr.hwndFrom = _hSelf; - scnN.nmhdr.idFrom = 0; + scnN.nmhdr.code = NPPN_FILEOPENED; _pluginsManager.notify(&scnN); return true; @@ -3981,6 +3986,10 @@ bool Notepad_plus::fileClose() checkDocState(); _linkTriggered = true; + // Notify plugins that current file is closed + scnN.nmhdr.code = NPPN_FILECLOSED; + _pluginsManager.notify(&scnN); + return true; } @@ -4600,27 +4609,6 @@ void Notepad_plus::changeMenuLang(string & pluginsTrans, string & windowTrans) } ::DrawMenuBar(_hSelf); } -/* -const char * Notepad_plus::getNativeTip(int btnID) -{ - if (!_nativeLang) return NULL; - - TiXmlNode *tips = _nativeLang->FirstChild("Tips"); - if (!tips) return NULL; - - for (TiXmlNode *childNode = tips->FirstChildElement("Item"); - childNode ; - childNode = childNode->NextSibling("Item") ) - { - TiXmlElement *element = childNode->ToElement(); - int id; - element->Attribute("id", &id); - if (id == btnID) - return element->Attribute("name"); - } - return NULL; -} -*/ void Notepad_plus::changeConfigLang() { @@ -5285,8 +5273,8 @@ ToolBarButtonUnit toolBarIcons[] = { //{IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, STD_PRINT} {IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, -1} -}; - +}; + int stdIcons[] = {IDR_FILENEW, IDR_FILEOPEN, IDR_FILESAVE, IDR_SAVEALL, IDR_CLOSEFILE, IDR_CLOSEALL, IDR_CUT, IDR_COPY, IDR_PASTE,\ IDR_UNDO, IDR_REDO, IDR_FIND, IDR_REPLACE, IDR_ZOOMIN, IDR_ZOOMOUT, IDR_SYNCV, IDR_SYNCH,\ IDR_WRAP, IDR_INVISIBLECHAR, IDR_INDENTGUIDE, IDR_SHOWPANNEL, IDR_STARTRECORD, IDR_STOPRECORD, IDR_PLAYRECORD, IDR_M_PLAYRECORD, IDR_SAVERECORD, IDR_PRINT}; @@ -7105,9 +7093,13 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) const Buffer & buf = _mainEditView.getBufferAt((size_t)i); if (PathFileExists(buf._fullPathName)) { - sessionFileInfo sfi(buf._fullPathName, buf._pos); + string languageName = getLangFromMenu( buf ); + const char *langName = languageName.c_str(); + + sessionFileInfo sfi(buf._fullPathName, langName, buf._pos); + //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) - sfi._editViewIndex =MAIN_VIEW; + sfi._editViewIndex = MAIN_VIEW; _mainEditView.activateDocAt(i); int maxLine = _mainEditView.execute(SCI_GETLINECOUNT); for (int j = 0 ; j < maxLine ; j++) @@ -7117,7 +7109,6 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) sfi.marks.push_back(j); } } - session._files.push_back(sfi); } } @@ -7131,7 +7122,10 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) const Buffer & buf = _subEditView.getBufferAt((size_t)i); if (PathFileExists(buf._fullPathName)) { - sessionFileInfo sfi(buf._fullPathName, buf._pos); + string languageName = getLangFromMenu( buf ); + const char *langName = languageName.c_str(); + + sessionFileInfo sfi(buf._fullPathName, langName, buf._pos); //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) sfi._editViewIndex =SUB_VIEW; _subEditView.activateDocAt(i); @@ -7177,9 +7171,10 @@ void Notepad_plus::fileLoadSession(const char *fn) bool shouldBeResaved = false; Session session2Load; //--LS: fileLoadSession splitted to loadSessionToEditView(session2Load) for re-use! - if ((NppParameters::getInstance())->loadSession(session2Load, sessionFileName)) { - const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); - shouldBeResaved = loadSessionToEditView(&session2Load); + if ((NppParameters::getInstance())->loadSession(session2Load, sessionFileName)) + { + //const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + shouldBeResaved = loadSessionToEditView(session2Load); } if (shouldBeResaved) @@ -7189,7 +7184,7 @@ void Notepad_plus::fileLoadSession(const char *fn) } //---- fileLoadSession() ---------------------------------------------------- //--LS: Session SubView restore: New function loadSessionToEditView(session2Load) for re-use! -bool Notepad_plus::loadSessionToEditView(Session *session2Load) +bool Notepad_plus::loadSessionToEditView(const Session & session2Load) { bool shouldBeResaved = false; bool otherViewOpened = false; @@ -7217,24 +7212,27 @@ bool Notepad_plus::loadSessionToEditView(Session *session2Load) } size_t rgNSessionFilesLoaded[2] = {0, 0}; - for (size_t i = 0 ; i < session2Load->_files.size() ; ) + for (size_t i = 0 ; i < session2Load._files.size() ; ) { - const char *pFn = session2Load->_files[i]._fileName.c_str(); + const char *pFn = session2Load._files[i]._fileName.c_str(); //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) //--LS: doOpen(pFn) replaced by doOpen(pFn, false, true), due to reundancy of session-loading with RestoreFileEditView - if (doOpen(pFn, false)) + if (doOpen(pFn)) { - cureentEditView->getCurrentBuffer().setPosition(session2Load->_files[i]); - cureentEditView->restoreCurrentPos(session2Load->_files[i]); + const char *pLn = session2Load._files[i]._langName.c_str(); + setLangFromName(pLn); + + cureentEditView->getCurrentBuffer().setPosition(session2Load._files[i]); + cureentEditView->restoreCurrentPos(session2Load._files[i]); - for (size_t j = 0 ; j < session2Load->_files[i].marks.size() ; j++) + for (size_t j = 0 ; j < session2Load._files[i].marks.size() ; j++) { - bookmarkAdd(session2Load->_files[i].marks[j]); + bookmarkAdd(session2Load._files[i].marks[j]); } rgNSessionFilesLoaded[iCurrentView]++; //--LS: Restore Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) // After the file is opened, it is moved to the other view, if applicable, using already available function docGotoAnotherEditView(). - int editViewIndex = session2Load->_files[i]._editViewIndex; + int editViewIndex = session2Load._files[i]._editViewIndex; if (editViewIndex == MAIN_VIEW && iCurrentView != MAIN_VIEW) { docGotoAnotherEditView(MODE_TRANSFER); @@ -7257,36 +7255,39 @@ bool Notepad_plus::loadSessionToEditView(Session *session2Load) else { //--LS: Check, if file was not already loaded. Erase it only from session, if not already loaded!! - if ((_mainDocTab.find(pFn) == -1) && (_subDocTab.find(pFn) == -1)) { - vector::iterator posIt = session2Load->_files.begin() + i; - session2Load->_files.erase(posIt); + if ((_mainDocTab.find(pFn) == -1) && (_subDocTab.find(pFn) == -1)) + { + Session & session2BeModified = (Session & )session2Load; + vector::iterator posIt = session2BeModified._files.begin() + i; + session2BeModified._files.erase(posIt); shouldBeResaved = true; } } } //--LS: restore actifSubIndex in subEditView!!! // There are mainDocTab and subDocTab!! - if (otherViewOpened) { + if (otherViewOpened) + { size_t actifIndexCurrentView, actifIndexNonCurrentView, activView; DocTabView *pNonCurrentDocTab = getNonCurrentDocTab(); if (iCurrentView == MAIN_VIEW) { - actifIndexCurrentView = session2Load->_actifIndex; - actifIndexNonCurrentView = session2Load->_actifSubIndex; + actifIndexCurrentView = session2Load._actifIndex; + actifIndexNonCurrentView = session2Load._actifSubIndex; } else { - actifIndexCurrentView = session2Load->_actifSubIndex; - actifIndexNonCurrentView = session2Load->_actifIndex; + actifIndexCurrentView = session2Load._actifSubIndex; + actifIndexNonCurrentView = session2Load._actifIndex; } - activView = session2Load->_actifView; + activView = session2Load._actifView; //--LS: If there were already files loaded when the session is loaded, those number of files // is used as offset to the actifIndexes, so that the active file of the session is activated. - if (actifIndexCurrentView < session2Load->_files.size() && actifIndexCurrentView < rgNSessionFilesLoaded[iCurrentView]) { + if (actifIndexCurrentView < session2Load._files.size() && actifIndexCurrentView < rgNSessionFilesLoaded[iCurrentView]) { _pDocTab->activate(actifIndexCurrentView + rgNOpenedOldFiles[iCurrentView]); } - if (actifIndexNonCurrentView < session2Load->_files.size() && actifIndexNonCurrentView < rgNSessionFilesLoaded[iNonCurrentView]) { + if (actifIndexNonCurrentView < session2Load._files.size() && actifIndexNonCurrentView < rgNSessionFilesLoaded[iNonCurrentView]) { pNonCurrentDocTab->activate(actifIndexNonCurrentView + rgNOpenedOldFiles[iNonCurrentView]); } //--LS: restore view (MAIN_VIEW or SUB_VIEW). @@ -7302,8 +7303,8 @@ bool Notepad_plus::loadSessionToEditView(Session *session2Load) } } - else if (session2Load->_actifIndex < session2Load->_files.size()) - _pDocTab->activate(session2Load->_actifIndex + rgNOpenedOldFiles[iCurrentView]); + else if (session2Load._actifIndex < session2Load._files.size()) + _pDocTab->activate(session2Load._actifIndex + rgNOpenedOldFiles[iCurrentView]); } return shouldBeResaved; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index e0d6a0913..235563ec1 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -318,7 +318,7 @@ public: const char * fileSaveSession(size_t nbFile = 0, char ** fileNames = NULL); //--LS: New function loadSessionToEditView(session2Load) for re-use! - bool Notepad_plus::loadSessionToEditView(Session *session2Load); + bool Notepad_plus::loadSessionToEditView(const Session & session2Load); bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 0da587070..e22654669 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -92,9 +92,6 @@ struct Position }; struct sessionFileInfo : public Position { - string _fileName; - string _langName; - sessionFileInfo(const char *fn) { if (fn) _fileName = fn; }; @@ -102,8 +99,12 @@ struct sessionFileInfo : public Position { if (fn) _fileName = fn; if (ln) _langName = ln; }; + sessionFileInfo(string fn) : _fileName(fn){}; sessionFileInfo(string fn, Position pos) : Position(pos), _fileName(fn){}; + + string _fileName; + string _langName; //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) size_t _editViewIndex; vector marks;