diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 575236b9..91566ee4 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -212,34 +212,9 @@ 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(); - ScintillaEditView *cureentEditView = getCurrentEditView(); - for (size_t i = 0 ; i < lastSession._files.size() ; ) - { - const char *pFn = lastSession._files[i]._fileName.c_str(); - if (PathFileExists(pFn)) - { - doOpen(pFn); - const char *pLn = lastSession._files[i]._langName.c_str(); - setLangFromName(pLn); - - cureentEditView->getCurrentBuffer().setPosition(lastSession._files[i]); - cureentEditView->restoreCurrentPos(lastSession._files[i]); - - for (size_t j = 0 ; j < lastSession._files[i].marks.size() ; j++) - bookmarkAdd(lastSession._files[i].marks[j]); - - i++; - } - else - { - vector::iterator posIt = lastSession._files.begin() + i; - lastSession._files.erase(posIt); - } - } - - if (lastSession._actifIndex < lastSession._files.size()) - _mainDocTab.activate(lastSession._actifIndex); + bool shouldBeResaved = loadSessionToEditView(&lastSession); } if (cmdLine) @@ -7119,6 +7094,8 @@ void Notepad_plus::changeMenuShortcut(unsigned long cmdID, const char *shortcutS void Notepad_plus::getCurrentOpenedFiles(Session & session) { _pEditView->saveCurrentPos(); + //--LS: Session SubView restore: _actifView for setting focus on right view. + session._actifView = getCurrentView(); //MAIN_VIEW or SUB_VIEW session._actifIndex = _mainEditView.getCurrentDocIndex(); int currentDocIndex = _mainEditView.getCurrentDocIndex(); @@ -7128,12 +7105,9 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) const Buffer & buf = _mainEditView.getBufferAt((size_t)i); if (PathFileExists(buf._fullPathName)) { - string languageName = getLangFromMenu( buf ); - const char *langName = languageName.c_str(); - - sessionFileInfo sfi(buf._fullPathName, langName, buf._pos); - //sessionFileInfo sfi(buf._fullPathName, buf._pos); - + sessionFileInfo sfi(buf._fullPathName, buf._pos); + //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) + sfi._editViewIndex =MAIN_VIEW; _mainEditView.activateDocAt(i); int maxLine = _mainEditView.execute(SCI_GETLINECOUNT); for (int j = 0 ; j < maxLine ; j++) @@ -7149,6 +7123,8 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) } _mainEditView.activateDocAt(currentDocIndex); + //--LS: Session SubView restore: _actifSubIndex + session._actifSubIndex = _subEditView.getCurrentDocIndex(); currentDocIndex = _subEditView.getCurrentDocIndex(); for (size_t i = 0 ; i < _subEditView.getNbDoc() ; i++) { @@ -7156,7 +7132,8 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) if (PathFileExists(buf._fullPathName)) { sessionFileInfo sfi(buf._fullPathName, buf._pos); - + //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) + sfi._editViewIndex =SUB_VIEW; _subEditView.activateDocAt(i); int maxLine = _subEditView.execute(SCI_GETLINECOUNT); for (int j = 0 ; j < maxLine ; j++) @@ -7175,6 +7152,12 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) void Notepad_plus::fileLoadSession(const char *fn) { const char *sessionFileName = NULL; + //--LS: ToDo: subViewRestoreBehaviour has to be replaced lateron by a value from the parameter settings menu!! + // 0 = all documents into current view, as the old default behaviour + // 1 = restore original subView, indipendent on current view + // 2 = starting from current view, restore to current or other view, dependent on editViewindex of file in session. + //0=old default, restore in currentView; 1=restore in original view; 2=restore in same or other view, dependent on current view. + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); if (fn == NULL) { FileDialog fDlg(_hSelf, _hInst); @@ -7188,48 +7171,143 @@ void Notepad_plus::fileLoadSession(const char *fn) if (PathFileExists(fn)) sessionFileName = fn; } - bool shouldBeResaved = false; + if (sessionFileName) { bool shouldBeResaved = false; Session session2Load; - if ((NppParameters::getInstance())->loadSession(session2Load, sessionFileName)) - { - ScintillaEditView *cureentEditView = getCurrentEditView(); - - for (size_t i = 0 ; i < session2Load._files.size() ; ) - { - const char *pFn = session2Load._files[i]._fileName.c_str(); - if (doOpen(pFn)) - { - 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++) - { - bookmarkAdd(session2Load._files[i].marks[j]); - } - - i++; - } - else - { - vector::iterator posIt = session2Load._files.begin() + i; - session2Load._files.erase(posIt); - shouldBeResaved = true; - } - } - - if (session2Load._actifIndex < session2Load._files.size()) - _pDocTab->activate(session2Load._actifIndex); + //--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 (shouldBeResaved) (NppParameters::getInstance())->writeSession(session2Load, sessionFileName); } -} + return; +} //---- fileLoadSession() ---------------------------------------------------- + +//--LS: Session SubView restore: New function loadSessionToEditView(session2Load) for re-use! +bool Notepad_plus::loadSessionToEditView(Session *session2Load) +{ + bool shouldBeResaved = false; + bool otherViewOpened = false; + size_t rgNOpenedOldFiles[2] = {0, 0}; + + { + ScintillaEditView *cureentEditView = getCurrentEditView(); + //--LS: Save current editView and some parameters. + int iOldView = getCurrentView(); + int iCurrentView = iOldView; + ScintillaEditView *pNonCurrentEditView = getNonCurrentEditView(); + int iNonCurrentView = getNonCurrentView(); + //--LS: Get already loaded files in order to be used as offset to actifIndex of the session!! + rgNOpenedOldFiles[iCurrentView] = _pEditView->getNbDoc(); + if ((rgNOpenedOldFiles[iCurrentView] == 1) + && Buffer::isUntitled(_pEditView->getCurrentTitle()) + && (!_pEditView->isCurrentDocDirty()) && (_pEditView->getCurrentDocLen() == 0)) { + rgNOpenedOldFiles[iCurrentView] = 0; // because only an empty dummy document is opened! + } + rgNOpenedOldFiles[iNonCurrentView] = _pEditView->getNbDoc(); + if ((rgNOpenedOldFiles[iNonCurrentView] == 1) + && Buffer::isUntitled(pNonCurrentEditView->getCurrentTitle()) + && (!pNonCurrentEditView->isCurrentDocDirty()) && (pNonCurrentEditView->getCurrentDocLen() == 0)) { + rgNOpenedOldFiles[iNonCurrentView] = 0; // because only an empty dummy document is opened! + } + size_t rgNSessionFilesLoaded[2] = {0, 0}; + + for (size_t i = 0 ; i < session2Load->_files.size() ; ) + { + 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)) + { + cureentEditView->getCurrentBuffer().setPosition(session2Load->_files[i]); + cureentEditView->restoreCurrentPos(session2Load->_files[i]); + + for (size_t j = 0 ; j < session2Load->_files[i].marks.size() ; 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; + + if (editViewIndex == MAIN_VIEW && iCurrentView != MAIN_VIEW) { + docGotoAnotherEditView(MODE_TRANSFER); + otherViewOpened = true; + rgNSessionFilesLoaded[iCurrentView]--; + rgNSessionFilesLoaded[iNonCurrentView]++; + } + else if (editViewIndex == SUB_VIEW && iCurrentView != SUB_VIEW) { + docGotoAnotherEditView(MODE_TRANSFER); + otherViewOpened = true; + rgNSessionFilesLoaded[iCurrentView]--; + rgNSessionFilesLoaded[iNonCurrentView]++; + } + + //--LS: Get new CurrentView and NonCurrentView, if edit view has changed!! + iCurrentView = getCurrentView(); + iNonCurrentView = getNonCurrentView(); + i++; + } + 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); + shouldBeResaved = true; + } + } + } + //--LS: restore actifSubIndex in subEditView!!! + // There are mainDocTab and subDocTab!! + if (otherViewOpened) { + size_t actifIndexCurrentView, actifIndexNonCurrentView, activView; + DocTabView *pNonCurrentDocTab = getNonCurrentDocTab(); + + if (iCurrentView == MAIN_VIEW) { + actifIndexCurrentView = session2Load->_actifIndex; + actifIndexNonCurrentView = session2Load->_actifSubIndex; + } + else { + actifIndexCurrentView = session2Load->_actifSubIndex; + actifIndexNonCurrentView = session2Load->_actifIndex; + } + 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]) { + _pDocTab->activate(actifIndexCurrentView + rgNOpenedOldFiles[iCurrentView]); + } + if (actifIndexNonCurrentView < session2Load->_files.size() && actifIndexNonCurrentView < rgNSessionFilesLoaded[iNonCurrentView]) { + pNonCurrentDocTab->activate(actifIndexNonCurrentView + rgNOpenedOldFiles[iNonCurrentView]); + } + //--LS: restore view (MAIN_VIEW or SUB_VIEW). + //-- restore view only, if there are files loaded. + ScintillaEditView *pRestoreEditView; + if (activView == MAIN_VIEW || activView == SUB_VIEW) { + pRestoreEditView = (activView == MAIN_VIEW)?&_mainEditView:&_subEditView; + if (!((pRestoreEditView->getNbDoc() == 1) + && Buffer::isUntitled(pRestoreEditView->getCurrentTitle()) + && (!pRestoreEditView->isCurrentDocDirty()) && (pRestoreEditView->getCurrentDocLen() == 0))) { + switchEditViewTo(activView); + } + } + + } + else if (session2Load->_actifIndex < session2Load->_files.size()) + _pDocTab->activate(session2Load->_actifIndex + rgNOpenedOldFiles[iCurrentView]); + + } + return shouldBeResaved; +} //---- loadSessionToEditView() ---------------------------------------------- const char * Notepad_plus::fileSaveSession(size_t nbFile, char ** fileNames, const char *sessionFile2save) { diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index f09868c0..e0d6a091 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -317,6 +317,9 @@ public: const char * fileSaveSession(size_t nbFile, char ** fileNames, const char *sessionFile2save); 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 changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index ceb325f3..a31359af 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -327,15 +327,20 @@ bool NppParameters::load(/*bool noUserPath*/) strcpy(_sessionPath, userPath); PathAppend(_sessionPath, "session.xml"); - _pXmlSessionDoc = new TiXmlDocument(_sessionPath); - loadOkay = _pXmlSessionDoc->LoadFile(); - if (!loadOkay) - isAllLaoded = false; - else - getSessionFromXmlTree(); + //--LS: Don't load session.xml if not required in order to speed up!! + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + if (nppGUI._rememberLastSession) + { + _pXmlSessionDoc = new TiXmlDocument(_sessionPath); + loadOkay = _pXmlSessionDoc->LoadFile(); + if (!loadOkay) + isAllLaoded = false; + else + getSessionFromXmlTree(); - delete _pXmlSessionDoc; - _pXmlSessionDoc = NULL; + delete _pXmlSessionDoc; + _pXmlSessionDoc = NULL; + } return isAllLaoded; } @@ -613,7 +618,18 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p { (*ptrSession)._actifIndex = index; } - + //--LS: Session SubView restore: _actifView + str = actIndex->Attribute("actifView", (int *)&index); + if (str) + { + (*ptrSession)._actifView = index; + } + //--LS: Session SubView restore: _actifSubIndex + str = actIndex->Attribute("actifSubIndex", (int *)&index); + if (str) + { + (*ptrSession)._actifSubIndex = index; + } for (TiXmlNode *childNode = sessionRoot->FirstChildElement("File"); childNode ; childNode = childNode->NextSibling("File") ) @@ -632,9 +648,11 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p (childNode->ToElement())->Attribute("endPos", &position._endPos); const char *langName; langName = (childNode->ToElement())->Attribute( "lang" ); - sessionFileInfo sfi( fileName, langName, position ); - //sessionFileInfo sfi(fileName, position); + //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) + int editViewIndex; + (childNode->ToElement())->Attribute("editViewIndex", &editViewIndex); + sfi._editViewIndex = editViewIndex; for (TiXmlNode *markNode = fnNode->NextSibling("Mark"); markNode ; @@ -1031,6 +1049,9 @@ void NppParameters::writeSession(const Session & session, const char *fileName) { TiXmlNode *sessionNode = root->InsertEndChild(TiXmlElement("Session")); (sessionNode->ToElement())->SetAttribute("actifIndex", (int)session._actifIndex); + //--LS: Session SubView restore: _actifView and _actifSubIndex + (sessionNode->ToElement())->SetAttribute("actifSubIndex", (int)session._actifSubIndex); + (sessionNode->ToElement())->SetAttribute("actifView", (int)session._actifView); for (size_t i = 0 ; i < session._files.size() ; i++) { TiXmlNode *fileNameNode = sessionNode->InsertEndChild(TiXmlElement("File")); @@ -1040,6 +1061,8 @@ void NppParameters::writeSession(const Session & session, const char *fileName) (fileNameNode->ToElement())->SetAttribute("startPos", session._files[i]._startPos); (fileNameNode->ToElement())->SetAttribute("endPos", session._files[i]._endPos); (fileNameNode->ToElement())->SetAttribute("lang", session._files[i]._langName.c_str()); + //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) + (fileNameNode->ToElement())->SetAttribute("editViewIndex", session._files[i]._editViewIndex); TiXmlText fileNameFullPath(session._files[i]._fileName.c_str()); fileNameNode->InsertEndChild(fileNameFullPath); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index a00f4c63..0da58707 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -104,12 +104,18 @@ struct sessionFileInfo : public Position { }; sessionFileInfo(string fn) : _fileName(fn){}; sessionFileInfo(string fn, Position pos) : Position(pos), _fileName(fn){}; + //--LS: Session SubView restore: _editViewIndex (MAIN_VIEW=0=mainEditView, SUB_VIEW=1=subEditView) + size_t _editViewIndex; vector marks; }; struct Session { int nbFiles() const {return _files.size();}; + //--LS: Session SubView restore: _actifView for setting focus on right view. + size_t _actifView; size_t _actifIndex; + //--LS: Session SubView restore: _actifSubIndex for subEditView acitve file index. + size_t _actifSubIndex; vector _files; };