Code improvement for FileManager

This commit is contained in:
Don HO 2019-08-14 01:32:01 +02:00
parent 48f83a9d0f
commit 2c764d7221
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
9 changed files with 128 additions and 128 deletions

View File

@ -219,7 +219,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
_subEditView.init(_pPublicInterface->getHinst(), hwnd); _subEditView.init(_pPublicInterface->getHinst(), hwnd);
_fileEditView.init(_pPublicInterface->getHinst(), hwnd); _fileEditView.init(_pPublicInterface->getHinst(), hwnd);
MainFileManager->init(this, &_fileEditView); //get it up and running asap. MainFileManager.init(this, &_fileEditView); //get it up and running asap.
pNppParam->setFontList(hwnd); pNppParam->setFontList(hwnd);
@ -1084,7 +1084,7 @@ bool Notepad_plus::replaceInOpenedFiles() {
{ {
for (size_t i = 0, len = _mainDocTab.nbItem(); i < len ; ++i) for (size_t i = 0, len = _mainDocTab.nbItem(); i < len ; ++i)
{ {
pBuf = MainFileManager->getBufferByID(_mainDocTab.getBufferByIndex(i)); pBuf = MainFileManager.getBufferByID(_mainDocTab.getBufferByIndex(i));
if (pBuf->isReadOnly()) if (pBuf->isReadOnly())
continue; continue;
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
@ -1101,7 +1101,7 @@ bool Notepad_plus::replaceInOpenedFiles() {
{ {
for (size_t i = 0, len = _subDocTab.nbItem(); i < len; ++i) for (size_t i = 0, len = _subDocTab.nbItem(); i < len; ++i)
{ {
pBuf = MainFileManager->getBufferByID(_subDocTab.getBufferByIndex(i)); pBuf = MainFileManager.getBufferByID(_subDocTab.getBufferByIndex(i));
if (pBuf->isReadOnly()) if (pBuf->isReadOnly())
continue; continue;
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
@ -1543,16 +1543,16 @@ bool Notepad_plus::replaceInFiles()
bool closeBuf = false; bool closeBuf = false;
BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); BufferID id = MainFileManager.getBufferFromName(fileNames.at(i).c_str());
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
{ {
id = MainFileManager->loadFile(fileNames.at(i).c_str()); id = MainFileManager.loadFile(fileNames.at(i).c_str());
closeBuf = true; closeBuf = true;
} }
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
{ {
Buffer * pBuf = MainFileManager->getBufferByID(id); Buffer * pBuf = MainFileManager.getBufferByID(id);
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE); auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE);
_invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8); _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8);
@ -1564,11 +1564,11 @@ bool Notepad_plus::replaceInFiles()
nbTotal += nbReplaced; nbTotal += nbReplaced;
if (nbReplaced) if (nbReplaced)
{ {
MainFileManager->saveBuffer(id, pBuf->getFullPathName()); MainFileManager.saveBuffer(id, pBuf->getFullPathName());
} }
if (closeBuf) if (closeBuf)
MainFileManager->closeBuffer(id, _pEditView); MainFileManager.closeBuffer(id, _pEditView);
} }
if (i == updateOnCount) if (i == updateOnCount)
{ {
@ -1639,16 +1639,16 @@ bool Notepad_plus::findInFinderFiles(FindersInfo *findInFolderInfo)
if (progress.isCancelled()) break; if (progress.isCancelled()) break;
bool closeBuf = false; bool closeBuf = false;
BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); BufferID id = MainFileManager.getBufferFromName(fileNames.at(i).c_str());
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
{ {
id = MainFileManager->loadFile(fileNames.at(i).c_str()); id = MainFileManager.loadFile(fileNames.at(i).c_str());
closeBuf = true; closeBuf = true;
} }
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
{ {
Buffer * pBuf = MainFileManager->getBufferByID(id); Buffer * pBuf = MainFileManager.getBufferByID(id);
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE); auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE);
_invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8); _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8);
@ -1656,7 +1656,7 @@ bool Notepad_plus::findInFinderFiles(FindersInfo *findInFolderInfo)
findInFolderInfo->_pFileName = fileNames.at(i).c_str(); findInFolderInfo->_pFileName = fileNames.at(i).c_str();
nbTotal += _findReplaceDlg.processAll(ProcessFindInFinder, &(findInFolderInfo->_findOption), true, findInFolderInfo); nbTotal += _findReplaceDlg.processAll(ProcessFindInFinder, &(findInFolderInfo->_findOption), true, findInFolderInfo);
if (closeBuf) if (closeBuf)
MainFileManager->closeBuffer(id, _pEditView); MainFileManager.closeBuffer(id, _pEditView);
} }
if (i == updateOnCount) if (i == updateOnCount)
{ {
@ -1724,16 +1724,16 @@ bool Notepad_plus::findInFiles()
if (progress.isCancelled()) break; if (progress.isCancelled()) break;
bool closeBuf = false; bool closeBuf = false;
BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); BufferID id = MainFileManager.getBufferFromName(fileNames.at(i).c_str());
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
{ {
id = MainFileManager->loadFile(fileNames.at(i).c_str()); id = MainFileManager.loadFile(fileNames.at(i).c_str());
closeBuf = true; closeBuf = true;
} }
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
{ {
Buffer * pBuf = MainFileManager->getBufferByID(id); Buffer * pBuf = MainFileManager.getBufferByID(id);
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE); auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE);
_invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8); _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8);
@ -1741,7 +1741,7 @@ bool Notepad_plus::findInFiles()
findersInfo._pFileName = fileNames.at(i).c_str(); findersInfo._pFileName = fileNames.at(i).c_str();
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, true, &findersInfo); nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, true, &findersInfo);
if (closeBuf) if (closeBuf)
MainFileManager->closeBuffer(id, _pEditView); MainFileManager.closeBuffer(id, _pEditView);
} }
if (i == updateOnCount) if (i == updateOnCount)
{ {
@ -1787,7 +1787,7 @@ bool Notepad_plus::findInOpenedFiles()
{ {
for (size_t i = 0, len = _mainDocTab.nbItem(); i < len ; ++i) for (size_t i = 0, len = _mainDocTab.nbItem(); i < len ; ++i)
{ {
pBuf = MainFileManager->getBufferByID(_mainDocTab.getBufferByIndex(i)); pBuf = MainFileManager.getBufferByID(_mainDocTab.getBufferByIndex(i));
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE); auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE);
_invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8); _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8);
@ -1801,7 +1801,7 @@ bool Notepad_plus::findInOpenedFiles()
{ {
for (size_t i = 0, len2 = _subDocTab.nbItem(); i < len2 ; ++i) for (size_t i = 0, len2 = _subDocTab.nbItem(); i < len2 ; ++i)
{ {
pBuf = MainFileManager->getBufferByID(_subDocTab.getBufferByIndex(i)); pBuf = MainFileManager.getBufferByID(_subDocTab.getBufferByIndex(i));
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE); auto cp = _invisibleEditView.execute(SCI_GETCODEPAGE);
_invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8); _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8);
@ -1967,9 +1967,9 @@ void Notepad_plus::checkDocState()
bool isFileExisting = PathFileExists(curBuf->getFullPathName()) != FALSE; bool isFileExisting = PathFileExists(curBuf->getFullPathName()) != FALSE;
if (!isCurrentDirty) if (!isCurrentDirty)
{ {
for (size_t i = 0; i < MainFileManager->getNbBuffers(); ++i) for (size_t i = 0; i < MainFileManager.getNbBuffers(); ++i)
{ {
if (MainFileManager->getBufferByIndex(i)->isDirty()) if (MainFileManager.getBufferByIndex(i)->isDirty())
{ {
isSeveralDirty = true; isSeveralDirty = true;
break; break;
@ -3325,7 +3325,7 @@ void Notepad_plus::dropFiles(HDROP hdrop)
void Notepad_plus::checkModifiedDocument(bool bCheckOnlyCurrentBuffer) void Notepad_plus::checkModifiedDocument(bool bCheckOnlyCurrentBuffer)
{ {
//this will trigger buffer updates. If the status changes, Notepad++ will be informed and can do its magic //this will trigger buffer updates. If the status changes, Notepad++ will be informed and can do its magic
MainFileManager->checkFilesystemChanges(bCheckOnlyCurrentBuffer); MainFileManager.checkFilesystemChanges(bCheckOnlyCurrentBuffer);
} }
void Notepad_plus::getMainClientRect(RECT &rc) const void Notepad_plus::getMainClientRect(RECT &rc) const
@ -3419,7 +3419,7 @@ bool Notepad_plus::canHideView(int whichOne)
if (!bothActive()) if (!bothActive())
return false; //cannot hide only window return false; //cannot hide only window
DocTabView * tabToCheck = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab; DocTabView * tabToCheck = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab;
Buffer * buf = MainFileManager->getBufferByID(tabToCheck->getBufferByIndex(0)); Buffer * buf = MainFileManager.getBufferByID(tabToCheck->getBufferByIndex(0));
bool canHide = ((tabToCheck->nbItem() == 1) && !buf->isDirty() && buf->isUntitled()); bool canHide = ((tabToCheck->nbItem() == 1) && !buf->isDirty() && buf->isUntitled());
return canHide; return canHide;
} }
@ -3430,7 +3430,7 @@ bool Notepad_plus::isEmpty()
DocTabView * tabToCheck = (_mainWindowStatus & WindowMainActive) ? &_mainDocTab : &_subDocTab; DocTabView * tabToCheck = (_mainWindowStatus & WindowMainActive) ? &_mainDocTab : &_subDocTab;
Buffer * buf = MainFileManager->getBufferByID(tabToCheck->getBufferByIndex(0)); Buffer * buf = MainFileManager.getBufferByID(tabToCheck->getBufferByIndex(0));
bool isEmpty = ((tabToCheck->nbItem() == 1) && !buf->isDirty() && buf->isUntitled()); bool isEmpty = ((tabToCheck->nbItem() == 1) && !buf->isDirty() && buf->isUntitled());
return isEmpty; return isEmpty;
} }
@ -3450,21 +3450,21 @@ void Notepad_plus::loadBufferIntoView(BufferID id, int whichOne, bool dontClose)
if (!dontClose && tabToOpen->nbItem() == 1) if (!dontClose && tabToOpen->nbItem() == 1)
{ {
idToClose = tabToOpen->getBufferByIndex(0); idToClose = tabToOpen->getBufferByIndex(0);
Buffer * buf = MainFileManager->getBufferByID(idToClose); Buffer * buf = MainFileManager.getBufferByID(idToClose);
if (buf->isDirty() || !buf->isUntitled()) if (buf->isDirty() || !buf->isUntitled())
{ {
idToClose = BUFFER_INVALID; idToClose = BUFFER_INVALID;
} }
} }
MainFileManager->addBufferReference(id, viewToOpen); MainFileManager.addBufferReference(id, viewToOpen);
//close clean doc. Use special logic to prevent flicker of tab showing then hiding //close clean doc. Use special logic to prevent flicker of tab showing then hiding
if (idToClose != BUFFER_INVALID) if (idToClose != BUFFER_INVALID)
{ {
tabToOpen->setBuffer(0, id); //index 0 since only one open tabToOpen->setBuffer(0, id); //index 0 since only one open
activateBuffer(id, whichOne); //activate. DocTab already activated but not a problem activateBuffer(id, whichOne); //activate. DocTab already activated but not a problem
MainFileManager->closeBuffer(idToClose, viewToOpen); //delete the buffer MainFileManager.closeBuffer(idToClose, viewToOpen); //delete the buffer
if (_pFileSwitcherPanel) if (_pFileSwitcherPanel)
_pFileSwitcherPanel->closeItem(idToClose, whichOne); _pFileSwitcherPanel->closeItem(idToClose, whichOne);
} }
@ -3484,7 +3484,7 @@ bool Notepad_plus::removeBufferFromView(BufferID id, int whichOne)
if (index == -1) //doesn't exist, done if (index == -1) //doesn't exist, done
return false; return false;
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
//Cannot close doc if last and clean //Cannot close doc if last and clean
if (tabToClose->nbItem() == 1) if (tabToClose->nbItem() == 1)
@ -3500,8 +3500,8 @@ bool Notepad_plus::removeBufferFromView(BufferID id, int whichOne)
{ {
if (tabToClose->nbItem() == 1) //need alternative doc, add new one. Use special logic to prevent flicker of adding new tab then closing other if (tabToClose->nbItem() == 1) //need alternative doc, add new one. Use special logic to prevent flicker of adding new tab then closing other
{ {
BufferID newID = MainFileManager->newEmptyDocument(); BufferID newID = MainFileManager.newEmptyDocument();
MainFileManager->addBufferReference(newID, viewToClose); MainFileManager.addBufferReference(newID, viewToClose);
tabToClose->setBuffer(0, newID); //can safely use id 0, last (only) tab open tabToClose->setBuffer(0, newID); //can safely use id 0, last (only) tab open
activateBuffer(newID, whichOne); //activate. DocTab already activated but not a problem activateBuffer(newID, whichOne); //activate. DocTab already activated but not a problem
} }
@ -3528,7 +3528,7 @@ bool Notepad_plus::removeBufferFromView(BufferID id, int whichOne)
tabToClose->deletItemAt((size_t)index); tabToClose->deletItemAt((size_t)index);
} }
MainFileManager->closeBuffer(id, viewToClose); MainFileManager.closeBuffer(id, viewToClose);
return true; return true;
} }
@ -3560,7 +3560,7 @@ int Notepad_plus::switchEditViewTo(int gid)
if (NppParameters::getInstance()->getNppGUI().isSnapshotMode()) if (NppParameters::getInstance()->getNppGUI().isSnapshotMode())
{ {
// Before switching off, synchronize backup file // Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer(); MainFileManager.backupCurrentBuffer();
} }
notifyBufferActivated(_pEditView->getCurrentBufferID(), currentView()); notifyBufferActivated(_pEditView->getCurrentBufferID(), currentView());
@ -3615,7 +3615,7 @@ void Notepad_plus::undockUserDlg()
void Notepad_plus::docOpenInNewInstance(FileTransferMode mode, int x, int y) void Notepad_plus::docOpenInNewInstance(FileTransferMode mode, int x, int y)
{ {
BufferID bufferID = _pEditView->getCurrentBufferID(); BufferID bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
if (buf->isUntitled() || buf->isDirty()) if (buf->isUntitled() || buf->isDirty())
return; return;
@ -3704,7 +3704,7 @@ void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode)
} }
loadBufferIntoView(current, viewToGo); loadBufferIntoView(current, viewToGo);
Buffer *buf = MainFileManager->getBufferByID(current); Buffer *buf = MainFileManager.getBufferByID(current);
_pEditView->saveCurrentPos(); //allow copying of position _pEditView->saveCurrentPos(); //allow copying of position
buf->setPosition(buf->getPosition(_pEditView), _pNonEditView); buf->setPosition(buf->getPosition(_pEditView), _pNonEditView);
_pNonEditView->restoreCurrentPos(); //set position _pNonEditView->restoreCurrentPos(); //set position
@ -3723,7 +3723,7 @@ void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode)
//Close the document if we transfered the document instead of cloning it //Close the document if we transfered the document instead of cloning it
if (mode == TransferMove) if (mode == TransferMove)
{ {
Buffer *buf = MainFileManager->getBufferByID(current); Buffer *buf = MainFileManager.getBufferByID(current);
monitoringWasOn = buf->isMonitoringOn(); monitoringWasOn = buf->isMonitoringOn();
//just close the activate document, since thats the one we moved (no search) //just close the activate document, since thats the one we moved (no search)
@ -3745,13 +3745,13 @@ bool Notepad_plus::activateBuffer(BufferID id, int whichOne)
if (isSnapshotMode) if (isSnapshotMode)
{ {
// Before switching off, synchronize backup file // Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer(); MainFileManager.backupCurrentBuffer();
} }
Buffer * pBuf = MainFileManager->getBufferByID(id); Buffer * pBuf = MainFileManager.getBufferByID(id);
bool reload = pBuf->getNeedReload(); bool reload = pBuf->getNeedReload();
if (reload) if (reload)
{ {
MainFileManager->reloadBuffer(id); MainFileManager.reloadBuffer(id);
pBuf->setNeedReload(false); pBuf->setNeedReload(false);
} }
if (whichOne == MAIN_VIEW) if (whichOne == MAIN_VIEW)
@ -4488,14 +4488,14 @@ void Notepad_plus::getTaskListInfo(TaskListInfo *tli)
for (int i = 0 ; i < currentNbDoc ; ++i) for (int i = 0 ; i < currentNbDoc ; ++i)
{ {
BufferID bufID = _pDocTab->getBufferByIndex(i); BufferID bufID = _pDocTab->getBufferByIndex(i);
Buffer * b = MainFileManager->getBufferByID(bufID); Buffer * b = MainFileManager.getBufferByID(bufID);
int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved);
tli->_tlfsLst.push_back(TaskLstFnStatus(currentView(), i, b->getFullPathName(), status, (void *)bufID)); tli->_tlfsLst.push_back(TaskLstFnStatus(currentView(), i, b->getFullPathName(), status, (void *)bufID));
} }
for (int i = 0 ; i < nonCurrentNbDoc ; ++i) for (int i = 0 ; i < nonCurrentNbDoc ; ++i)
{ {
BufferID bufID = _pNonDocTab->getBufferByIndex(i); BufferID bufID = _pNonDocTab->getBufferByIndex(i);
Buffer * b = MainFileManager->getBufferByID(bufID); Buffer * b = MainFileManager.getBufferByID(bufID);
int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved);
tli->_tlfsLst.push_back(TaskLstFnStatus(otherView(), i, b->getFullPathName(), status, (void *)bufID)); tli->_tlfsLst.push_back(TaskLstFnStatus(otherView(), i, b->getFullPathName(), status, (void *)bufID));
} }
@ -4980,7 +4980,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledD
size_t activeIndex = k == 0 ? session._activeMainIndex : session._activeSubIndex; size_t activeIndex = k == 0 ? session._activeMainIndex : session._activeSubIndex;
vector<sessionFileInfo> *viewFiles = (vector<sessionFileInfo> *)(k == 0?&(session._mainViewFiles):&(session._subViewFiles)); vector<sessionFileInfo> *viewFiles = (vector<sessionFileInfo> *)(k == 0?&(session._mainViewFiles):&(session._subViewFiles));
Buffer * buf = MainFileManager->getBufferByID(bufID); Buffer * buf = MainFileManager.getBufferByID(bufID);
if (buf->isUntitled() && buf->docLength() == 0) if (buf->isUntitled() && buf->docLength() == 0)
continue; continue;
@ -5041,9 +5041,9 @@ bool Notepad_plus::dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix) {
TCHAR savePath[MAX_PATH] = {0}; TCHAR savePath[MAX_PATH] = {0};
//rescue primary //rescue primary
for (size_t i = 0; i < MainFileManager->getNbBuffers(); ++i) for (size_t i = 0; i < MainFileManager.getNbBuffers(); ++i)
{ {
Buffer * docbuf = MainFileManager->getBufferByIndex(i); Buffer * docbuf = MainFileManager.getBufferByIndex(i);
if (!docbuf->isDirty()) //skip saved documents if (!docbuf->isDirty()) //skip saved documents
continue; continue;
else else
@ -5052,7 +5052,7 @@ bool Notepad_plus::dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix) {
const TCHAR * unitext = (docbuf->getUnicodeMode() != uni8Bit)?TEXT("_utf8"):TEXT(""); const TCHAR * unitext = (docbuf->getUnicodeMode() != uni8Bit)?TEXT("_utf8"):TEXT("");
wsprintf(savePath, TEXT("%s\\%s%03d%s.dump"), outdir, fileprefix, i, unitext); wsprintf(savePath, TEXT("%s\\%s%03d%s.dump"), outdir, fileprefix, i, unitext);
bool res = MainFileManager->saveBuffer(docbuf->getID(), savePath); bool res = MainFileManager.saveBuffer(docbuf->getID(), savePath);
somethingsaved |= res; somethingsaved |= res;
} }
@ -5277,7 +5277,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) void Notepad_plus::notifyBufferActivated(BufferID bufid, int view)
{ {
Buffer * buf = MainFileManager->getBufferByID(bufid); Buffer * buf = MainFileManager.getBufferByID(bufid);
buf->increaseRecentTag(); buf->increaseRecentTag();
if (view == MAIN_VIEW) if (view == MAIN_VIEW)
@ -5382,7 +5382,7 @@ std::vector<generic_string> Notepad_plus::loadCommandlineParams(const TCHAR * co
if (lt != L_EXTERNAL && lt < nppParams->L_END) if (lt != L_EXTERNAL && lt < nppParams->L_END)
{ {
Buffer * pBuf = MainFileManager->getBufferByID(bufID); Buffer * pBuf = MainFileManager.getBufferByID(bufID);
pBuf->setLangType(lt); pBuf->setLangType(lt);
} }
@ -5638,7 +5638,7 @@ bool Notepad_plus::noOpenedDoc() const
if (_pDocTab->nbItem() == 1) if (_pDocTab->nbItem() == 1)
{ {
BufferID buffer = _pDocTab->getBufferByIndex(0); BufferID buffer = _pDocTab->getBufferByIndex(0);
Buffer * buf = MainFileManager->getBufferByID(buffer); Buffer * buf = MainFileManager.getBufferByID(buffer);
if (!buf->isDirty() && buf->isUntitled()) if (!buf->isDirty() && buf->isUntitled())
return true; return true;
} }

View File

@ -58,8 +58,8 @@ struct SortTaskListPred final
bool operator()(const TaskLstFnStatus &l, const TaskLstFnStatus &r) const { bool operator()(const TaskLstFnStatus &l, const TaskLstFnStatus &r) const {
BufferID lID = _views[l._iView]->getBufferByIndex(l._docIndex); BufferID lID = _views[l._iView]->getBufferByIndex(l._docIndex);
BufferID rID = _views[r._iView]->getBufferByIndex(r._docIndex); BufferID rID = _views[r._iView]->getBufferByIndex(r._docIndex);
Buffer * bufL = MainFileManager->getBufferByID(lID); Buffer * bufL = MainFileManager.getBufferByID(lID);
Buffer * bufR = MainFileManager->getBufferByID(rID); Buffer * bufR = MainFileManager.getBufferByID(rID);
return bufL->getRecentTag() > bufR->getRecentTag(); return bufL->getRecentTag() > bufR->getRecentTag();
} }
}; };
@ -171,9 +171,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
generic_string name{userLangName}; generic_string name{userLangName};
//loop through buffers and reset the language (L_USER, TEXT("")) if (L_USER, name) //loop through buffers and reset the language (L_USER, TEXT("")) if (L_USER, name)
for (size_t i = 0; i < MainFileManager->getNbBuffers(); ++i) for (size_t i = 0; i < MainFileManager.getNbBuffers(); ++i)
{ {
Buffer* buf = MainFileManager->getBufferByIndex(i); Buffer* buf = MainFileManager.getBufferByIndex(i);
if (buf->getLangType() == L_USER && name == buf->getUserDefineLangName()) if (buf->getLangType() == L_USER && name == buf->getUserDefineLangName())
buf->setLangType(L_USER, TEXT("")); buf->setLangType(L_USER, TEXT(""));
} }
@ -189,9 +189,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
generic_string newName{ reinterpret_cast<TCHAR *>(wParam) }; generic_string newName{ reinterpret_cast<TCHAR *>(wParam) };
//loop through buffers and reset the language (L_USER, newName) if (L_USER, oldName) //loop through buffers and reset the language (L_USER, newName) if (L_USER, oldName)
for (size_t i = 0; i < MainFileManager->getNbBuffers(); ++i) for (size_t i = 0; i < MainFileManager.getNbBuffers(); ++i)
{ {
Buffer* buf = MainFileManager->getBufferByIndex(i); Buffer* buf = MainFileManager.getBufferByIndex(i);
if (buf->getLangType() == L_USER && oldName == buf->getUserDefineLangName()) if (buf->getLangType() == L_USER && oldName == buf->getUserDefineLangName())
buf->setLangType(L_USER, newName.c_str()); buf->setLangType(L_USER, newName.c_str());
} }
@ -296,7 +296,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
if (!lParam && !wParam) if (!lParam && !wParam)
return FALSE; return FALSE;
BufferID id = (BufferID)wParam; BufferID id = (BufferID)wParam;
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager.getBufferByID(id);
if (b && b->getStatus() == DOC_UNNAMED) { if (b && b->getStatus() == DOC_UNNAMED) {
b->setFileName(reinterpret_cast<const TCHAR*>(lParam)); b->setFileName(reinterpret_cast<const TCHAR*>(lParam));
return TRUE; return TRUE;
@ -309,7 +309,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
if (!wParam) if (!wParam)
return -1; return -1;
BufferID id = (BufferID)wParam; BufferID id = (BufferID)wParam;
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager.getBufferByID(id);
return b->getLangType(); return b->getLangType();
} }
@ -321,7 +321,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return FALSE; return FALSE;
BufferID id = (BufferID)wParam; BufferID id = (BufferID)wParam;
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager.getBufferByID(id);
b->setLangType((LangType)lParam); b->setLangType((LangType)lParam);
return TRUE; return TRUE;
} }
@ -331,7 +331,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
if (!wParam) if (!wParam)
return -1; return -1;
BufferID id = (BufferID)wParam; BufferID id = (BufferID)wParam;
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager.getBufferByID(id);
return b->getUnicodeMode(); return b->getUnicodeMode();
} }
@ -343,7 +343,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return FALSE; return FALSE;
BufferID id = (BufferID)wParam; BufferID id = (BufferID)wParam;
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager.getBufferByID(id);
if (b->getStatus() != DOC_UNNAMED || b->isDirty()) //do not allow to change the encoding if the file has any content if (b->getStatus() != DOC_UNNAMED || b->isDirty()) //do not allow to change the encoding if the file has any content
return FALSE; return FALSE;
b->setUnicodeMode((UniMode)lParam); b->setUnicodeMode((UniMode)lParam);
@ -355,7 +355,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
if (!wParam) if (!wParam)
return -1; return -1;
BufferID id = (BufferID)wParam; BufferID id = (BufferID)wParam;
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager.getBufferByID(id);
return static_cast<LRESULT>(b->getEolFormat()); return static_cast<LRESULT>(b->getEolFormat());
} }
@ -372,7 +372,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
} }
BufferID id = (BufferID)wParam; BufferID id = (BufferID)wParam;
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager.getBufferByID(id);
b->setEolFormat(newFormat); b->setEolFormat(newFormat);
return TRUE; return TRUE;
} }
@ -407,7 +407,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_RELOADFILE: case NPPM_RELOADFILE:
{ {
BufferID id = MainFileManager->getBufferFromName(reinterpret_cast<const TCHAR *>(lParam)); BufferID id = MainFileManager.getBufferFromName(reinterpret_cast<const TCHAR *>(lParam));
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
doReload(id, wParam != 0); doReload(id, wParam != 0);
break; break;
@ -415,7 +415,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_SWITCHTOFILE : case NPPM_SWITCHTOFILE :
{ {
BufferID id = MainFileManager->getBufferFromName(reinterpret_cast<const TCHAR *>(lParam)); BufferID id = MainFileManager.getBufferFromName(reinterpret_cast<const TCHAR *>(lParam));
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
return switchToFile(id); return switchToFile(id);
return false; return false;
@ -632,7 +632,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
if (NppParameters::getInstance()->getNppGUI().isSnapshotMode()) if (NppParameters::getInstance()->getNppGUI().isSnapshotMode())
{ {
MainFileManager->backupCurrentBuffer(); MainFileManager.backupCurrentBuffer();
} }
return TRUE; return TRUE;
@ -874,7 +874,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
for (size_t i = 0; i < _mainDocTab.nbItem() && j < nbFileNames; ++i) for (size_t i = 0; i < _mainDocTab.nbItem() && j < nbFileNames; ++i)
{ {
BufferID id = _mainDocTab.getBufferByIndex(i); BufferID id = _mainDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
lstrcpy(fileNames[j++], buf->getFullPathName()); lstrcpy(fileNames[j++], buf->getFullPathName());
} }
} }
@ -884,7 +884,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
for (size_t i = 0; i < _subDocTab.nbItem() && j < nbFileNames; ++i) for (size_t i = 0; i < _subDocTab.nbItem() && j < nbFileNames; ++i)
{ {
BufferID id = _subDocTab.getBufferByIndex(i); BufferID id = _subDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
lstrcpy(fileNames[j++], buf->getFullPathName()); lstrcpy(fileNames[j++], buf->getFullPathName());
} }
} }
@ -1615,7 +1615,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_GETFULLPATHFROMBUFFERID: case NPPM_GETFULLPATHFROMBUFFERID:
{ {
return MainFileManager->getFileNameFromBuffer(reinterpret_cast<BufferID>(wParam), reinterpret_cast<TCHAR *>(lParam)); return MainFileManager.getFileNameFromBuffer(reinterpret_cast<BufferID>(wParam), reinterpret_cast<TCHAR *>(lParam));
} }
case NPPM_INTERNAL_ENABLECHECKDOCOPT: case NPPM_INTERNAL_ENABLECHECKDOCOPT:
@ -1752,7 +1752,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
if (isSnapshotMode) if (isSnapshotMode)
{ {
::LockWindowUpdate(hwnd); ::LockWindowUpdate(hwnd);
MainFileManager->backupCurrentBuffer(); MainFileManager.backupCurrentBuffer();
} }
Session currentSession; Session currentSession;

View File

@ -3166,7 +3166,7 @@ void Notepad_plus::command(int id)
NppGUI & nppGUI = const_cast<NppGUI &>((NppParameters::getInstance())->getNppGUI()); NppGUI & nppGUI = const_cast<NppGUI &>((NppParameters::getInstance())->getNppGUI());
::ShowWindow(_pPublicInterface->getHSelf(), nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); ::ShowWindow(_pPublicInterface->getHSelf(), nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW);
BufferID bufferID = _pEditView->getCurrentBufferID(); BufferID bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
if (!buf->isUntitled() || buf->docLength() != 0) if (!buf->isUntitled() || buf->docLength() != 0)
{ {
fileNew(); fileNew();

View File

@ -164,14 +164,14 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive,
// 3. a file name with relative path to open or create // 3. a file name with relative path to open or create
// Search case 1 & 2 firstly // Search case 1 & 2 firstly
BufferID foundBufID = MainFileManager->getBufferFromName(fileName.c_str()); BufferID foundBufID = MainFileManager.getBufferFromName(fileName.c_str());
if (foundBufID == BUFFER_INVALID) if (foundBufID == BUFFER_INVALID)
fileName2Find = longFileName; fileName2Find = longFileName;
// if case 1 & 2 not found, search case 3 // if case 1 & 2 not found, search case 3
if (foundBufID == BUFFER_INVALID) if (foundBufID == BUFFER_INVALID)
foundBufID = MainFileManager->getBufferFromName(fileName2Find.c_str()); foundBufID = MainFileManager.getBufferFromName(fileName2Find.c_str());
// If we found the document, then we don't open the existing doc. We return the found buffer ID instead. // If we found the document, then we don't open the existing doc. We return the found buffer ID instead.
if (foundBufID != BUFFER_INVALID && !isSnapshotMode) if (foundBufID != BUFFER_INVALID && !isSnapshotMode)
@ -231,7 +231,7 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive,
if (res == IDYES) if (res == IDYES)
{ {
bool isOK = MainFileManager->createEmptyFile(longFileName); bool isOK = MainFileManager.createEmptyFile(longFileName);
if (isOK) if (isOK)
{ {
isCreateFileSuccessful = true; isCreateFileSuccessful = true;
@ -286,7 +286,7 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive,
BufferID buffer; BufferID buffer;
if (isSnapshotMode) if (isSnapshotMode)
{ {
buffer = MainFileManager->loadFile(longFileName, NULL, encoding, backupFileName, fileNameTimestamp); buffer = MainFileManager.loadFile(longFileName, NULL, encoding, backupFileName, fileNameTimestamp);
if (buffer != BUFFER_INVALID) if (buffer != BUFFER_INVALID)
{ {
@ -306,14 +306,14 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive,
} }
else else
{ {
buffer = MainFileManager->loadFile(longFileName, NULL, encoding); buffer = MainFileManager.loadFile(longFileName, NULL, encoding);
} }
if (buffer != BUFFER_INVALID) if (buffer != BUFFER_INVALID)
{ {
_isFileOpening = true; _isFileOpening = true;
Buffer * buf = MainFileManager->getBufferByID(buffer); Buffer * buf = MainFileManager.getBufferByID(buffer);
// if file is read only, we set the view read only // if file is read only, we set the view read only
if (isReadOnly) if (isReadOnly)
@ -455,11 +455,11 @@ bool Notepad_plus::doReload(BufferID id, bool alert)
if (!mainVisisble && !subVisisble) if (!mainVisisble && !subVisisble)
{ {
return MainFileManager->reloadBufferDeferred(id); return MainFileManager.reloadBufferDeferred(id);
} }
bool res = MainFileManager->reloadBuffer(id); bool res = MainFileManager.reloadBuffer(id);
Buffer * pBuf = MainFileManager->getBufferByID(id); Buffer * pBuf = MainFileManager.getBufferByID(id);
if (mainVisisble) if (mainVisisble)
{ {
_mainEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); _mainEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
@ -480,7 +480,7 @@ bool Notepad_plus::doReload(BufferID id, bool alert)
bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
{ {
const int index = MainFileManager->getBufferIndexByID(id); const int index = MainFileManager.getBufferIndexByID(id);
if (index == -1) if (index == -1)
{ {
_nativeLangSpeaker.messageBox("BufferInvalidWarning", _nativeLangSpeaker.messageBox("BufferInvalidWarning",
@ -504,7 +504,7 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
} }
generic_string error_msg; generic_string error_msg;
bool res = MainFileManager->saveBuffer(id, filename, isCopy, &error_msg); bool res = MainFileManager.saveBuffer(id, filename, isCopy, &error_msg);
if (!isCopy) if (!isCopy)
{ {
@ -567,7 +567,7 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
::GetModuleFileName(NULL, nppFullPath, MAX_PATH); ::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
BufferID bufferID = _pEditView->getCurrentBufferID(); BufferID bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
//process the fileNamePath into LRF //process the fileNamePath into LRF
generic_string fileNamePath = buf->getFullPathName(); generic_string fileNamePath = buf->getFullPathName();
@ -631,9 +631,9 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
((_mainWindowStatus & WindowSubActive) == WindowSubActive ? _subDocTab.nbItem() : 0); ((_mainWindowStatus & WindowSubActive) == WindowSubActive ? _subDocTab.nbItem() : 0);
if (doDeleteBackup) if (doDeleteBackup)
MainFileManager->deleteBufferBackup(id); MainFileManager.deleteBufferBackup(id);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
// Notify plugins that current file is about to be closed // Notify plugins that current file is about to be closed
SCNotification scnN; SCNotification scnN;
@ -707,7 +707,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
} }
// Add to recent file only if file is removed and does not exist in any of the views // Add to recent file only if file is removed and does not exist in any of the views
BufferID buffID = MainFileManager->getBufferFromName(fileFullPath.c_str()); BufferID buffID = MainFileManager.getBufferFromName(fileFullPath.c_str());
if (buffID == BUFFER_INVALID && fileFullPath.length() > 0) if (buffID == BUFFER_INVALID && fileFullPath.length() > 0)
_lastRecentFileList.add(fileFullPath.c_str()); _lastRecentFileList.add(fileFullPath.c_str());
} }
@ -855,7 +855,7 @@ bool Notepad_plus::fileClose(BufferID id, int curView)
BufferID bufferID = id; BufferID bufferID = id;
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
bufferID = _pEditView->getCurrentBufferID(); bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
int res; int res;
@ -904,7 +904,7 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
for (size_t i = 0; i < _mainDocTab.nbItem() && !noSaveToAll; ++i) for (size_t i = 0; i < _mainDocTab.nbItem() && !noSaveToAll; ++i)
{ {
BufferID id = _mainDocTab.getBufferByIndex(i); BufferID id = _mainDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0) if (buf->isUntitled() && buf->docLength() == 0)
{ {
// Do nothing // Do nothing
@ -982,7 +982,7 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
for (size_t i = 0; i < _subDocTab.nbItem() && !noSaveToAll; ++i) for (size_t i = 0; i < _subDocTab.nbItem() && !noSaveToAll; ++i)
{ {
BufferID id = _subDocTab.getBufferByIndex(i); BufferID id = _subDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0) if (buf->isUntitled() && buf->docLength() == 0)
{ {
// Do nothing // Do nothing
@ -1087,7 +1087,7 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
for (std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) for (std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex)
{ {
BufferID id = _pDocTab->getBufferByIndex(*itIndex); BufferID id = _pDocTab->getBufferByIndex(*itIndex);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0) if (buf->isUntitled() && buf->docLength() == 0)
{ {
@ -1182,7 +1182,7 @@ bool Notepad_plus::fileCloseAllUnchanged()
for (int i = int(_pDocTab->nbItem()) - 1; i >= 0; i--) for (int i = int(_pDocTab->nbItem()) - 1; i >= 0; i--)
{ {
BufferID id = _mainDocTab.getBufferByIndex(i); BufferID id = _mainDocTab.getBufferByIndex(i);
Buffer* buf = MainFileManager->getBufferByID(id); Buffer* buf = MainFileManager.getBufferByID(id);
if ((buf->isUntitled() && buf->docLength() == 0) || !buf->isDirty()) if ((buf->isUntitled() && buf->docLength() == 0) || !buf->isDirty())
{ {
vecIndexesToClose.push_back(i); vecIndexesToClose.push_back(i);
@ -1208,7 +1208,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
BufferID id = _mainDocTab.getBufferByIndex(i); BufferID id = _mainDocTab.getBufferByIndex(i);
if (id == current) if (id == current)
continue; continue;
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0) if (buf->isUntitled() && buf->docLength() == 0)
{ {
// Do nothing // Do nothing
@ -1254,7 +1254,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
for (size_t i = 0; i < _subDocTab.nbItem() && !noSaveToAll; ++i) for (size_t i = 0; i < _subDocTab.nbItem() && !noSaveToAll; ++i)
{ {
BufferID id = _subDocTab.getBufferByIndex(i); BufferID id = _subDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
if (id == current) if (id == current)
continue; continue;
if (buf->isUntitled() && buf->docLength() == 0) if (buf->isUntitled() && buf->docLength() == 0)
@ -1335,7 +1335,7 @@ bool Notepad_plus::fileSave(BufferID id)
BufferID bufferID = id; BufferID bufferID = id;
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
bufferID = _pEditView->getCurrentBufferID(); bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
if (!buf->getFileReadOnly() && buf->isDirty()) //cannot save if readonly if (!buf->getFileReadOnly() && buf->isDirty()) //cannot save if readonly
{ {
@ -1479,7 +1479,7 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy)
BufferID bufferID = id; BufferID bufferID = id;
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
bufferID = _pEditView->getCurrentBufferID(); bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
@ -1535,7 +1535,7 @@ bool Notepad_plus::fileRename(BufferID id)
BufferID bufferID = id; BufferID bufferID = id;
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
bufferID = _pEditView->getCurrentBufferID(); bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
SCNotification scnN; SCNotification scnN;
scnN.nmhdr.code = NPPN_FILEBEFORERENAME; scnN.nmhdr.code = NPPN_FILEBEFORERENAME;
@ -1556,7 +1556,7 @@ bool Notepad_plus::fileRename(BufferID id)
TCHAR *pfn = fDlg.doSaveDlg(); TCHAR *pfn = fDlg.doSaveDlg();
if (pfn) if (pfn)
success = MainFileManager->moveFile(bufferID, pfn); success = MainFileManager.moveFile(bufferID, pfn);
} }
else else
{ {
@ -1588,7 +1588,7 @@ bool Notepad_plus::fileRename(BufferID id)
// Create new backup // Create new backup
buf->setModifiedStatus(true); buf->setModifiedStatus(true);
bool bRes = MainFileManager->backupCurrentBuffer(); bool bRes = MainFileManager.backupCurrentBuffer();
// Delete old backup // Delete old backup
if (bRes) if (bRes)
@ -1610,7 +1610,7 @@ bool Notepad_plus::fileDelete(BufferID id)
if (id == BUFFER_INVALID) if (id == BUFFER_INVALID)
bufferID = _pEditView->getCurrentBufferID(); bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID); Buffer * buf = MainFileManager.getBufferByID(bufferID);
const TCHAR *fileNamePath = buf->getFullPathName(); const TCHAR *fileNamePath = buf->getFullPathName();
winVer winVersion = (NppParameters::getInstance())->getWinVersion(); winVer winVersion = (NppParameters::getInstance())->getWinVersion();
@ -1629,7 +1629,7 @@ bool Notepad_plus::fileDelete(BufferID id)
scnN.nmhdr.idFrom = (uptr_t)bufferID; scnN.nmhdr.idFrom = (uptr_t)bufferID;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
if (!MainFileManager->deleteFile(bufferID)) if (!MainFileManager.deleteFile(bufferID))
{ {
_nativeLangSpeaker.messageBox("DeleteFileFailed", _nativeLangSpeaker.messageBox("DeleteFileFailed",
_pPublicInterface->getHSelf(), _pPublicInterface->getHSelf(),
@ -1680,7 +1680,7 @@ void Notepad_plus::fileOpen()
void Notepad_plus::fileNew() void Notepad_plus::fileNew()
{ {
BufferID newBufID = MainFileManager->newEmptyDocument(); BufferID newBufID = MainFileManager.newEmptyDocument();
loadBufferIntoView(newBufID, currentView(), true); //true, because we want multiple new files if possible loadBufferIntoView(newBufID, currentView(), true); //true, because we want multiple new files if possible
activateBuffer(newBufID, currentView()); activateBuffer(newBufID, currentView());
@ -1812,7 +1812,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode)
if (typeToSet == L_EXTERNAL ) if (typeToSet == L_EXTERNAL )
typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL); typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
Buffer *buf = MainFileManager->getBufferByID(lastOpened); Buffer *buf = MainFileManager.getBufferByID(lastOpened);
if (session._mainViewFiles[i]._foldStates.size() > 0) if (session._mainViewFiles[i]._foldStates.size() > 0)
{ {
@ -1921,7 +1921,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode)
if (typeToSet == L_EXTERNAL ) if (typeToSet == L_EXTERNAL )
typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL); typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
Buffer * buf = MainFileManager->getBufferByID(lastOpened); Buffer * buf = MainFileManager.getBufferByID(lastOpened);
// Set fold states // Set fold states
if (session._subViewFiles[k]._foldStates.size() > 0) if (session._subViewFiles[k]._foldStates.size() > 0)
@ -2034,8 +2034,8 @@ bool Notepad_plus::fileLoadSession(const TCHAR *fn)
bool isEmptyNpp = false; bool isEmptyNpp = false;
if (_mainDocTab.nbItem() == 1 && _subDocTab.nbItem() == 1) if (_mainDocTab.nbItem() == 1 && _subDocTab.nbItem() == 1)
{ {
Buffer * buf1 = MainFileManager->getBufferByID(_mainDocTab.getBufferByIndex(0)); Buffer * buf1 = MainFileManager.getBufferByID(_mainDocTab.getBufferByIndex(0));
Buffer * buf2 = MainFileManager->getBufferByID(_subDocTab.getBufferByIndex(0)); Buffer * buf2 = MainFileManager.getBufferByID(_subDocTab.getBufferByIndex(0));
isEmptyNpp = (!buf1->isDirty() && buf1->isUntitled() && !buf2->isDirty() && buf2->isUntitled()); isEmptyNpp = (!buf1->isDirty() && buf1->isUntitled() && !buf2->isDirty() && buf2->isUntitled());
} }
if (!isEmptyNpp && (nppGUI._multiInstSetting == multiInstOnSession || nppGUI._multiInstSetting == multiInst)) if (!isEmptyNpp && (nppGUI._multiInstSetting == multiInstOnSession || nppGUI._multiInstSetting == multiInst))

View File

@ -109,18 +109,18 @@ BOOL Notepad_plus::notify(SCNotification *notification)
BufferID id = BUFFER_INVALID; BufferID id = BUFFER_INVALID;
if (notification->nmhdr.hwndFrom == _invisibleEditView.getHSelf()) if (notification->nmhdr.hwndFrom == _invisibleEditView.getHSelf())
{ {
id = MainFileManager->getBufferFromDocument(_invisibleEditView.execute(SCI_GETDOCPOINTER)); id = MainFileManager.getBufferFromDocument(_invisibleEditView.execute(SCI_GETDOCPOINTER));
} }
else if (notification->nmhdr.hwndFrom == _fileEditView.getHSelf()) else if (notification->nmhdr.hwndFrom == _fileEditView.getHSelf())
{ {
id = MainFileManager->getBufferFromDocument(_fileEditView.execute(SCI_GETDOCPOINTER)); id = MainFileManager.getBufferFromDocument(_fileEditView.execute(SCI_GETDOCPOINTER));
} }
else else
break; //wrong scintilla break; //wrong scintilla
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
{ {
buf = MainFileManager->getBufferByID(id); buf = MainFileManager.getBufferByID(id);
} }
else else
break; break;
@ -164,7 +164,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (pTabDocView) if (pTabDocView)
{ {
BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin); BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin);
Buffer *pBuf = MainFileManager->getBufferByID(id); Buffer *pBuf = MainFileManager.getBufferByID(id);
Buffer *currentBufMain = _mainEditView.getCurrentBuffer(); Buffer *currentBufMain = _mainEditView.getCurrentBuffer();
Buffer *currentBufSub = _subEditView.getCurrentBuffer(); Buffer *currentBufSub = _subEditView.getCurrentBuffer();
@ -194,7 +194,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (pTabDocView) if (pTabDocView)
{ {
BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin); BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin);
Buffer *pBuf = MainFileManager->getBufferByID(id); Buffer *pBuf = MainFileManager.getBufferByID(id);
Buffer *currentBufMain = _mainEditView.getCurrentBuffer(); Buffer *currentBufMain = _mainEditView.getCurrentBuffer();
Buffer *currentBufSub = _subEditView.getCurrentBuffer(); Buffer *currentBufSub = _subEditView.getCurrentBuffer();
@ -294,7 +294,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
{ {
int index = _pDocTab->getCurrentTabIndex(); int index = _pDocTab->getCurrentTabIndex();
BufferID bufferToClose = notifyDocTab->getBufferByIndex(index); BufferID bufferToClose = notifyDocTab->getBufferByIndex(index);
Buffer * buf = MainFileManager->getBufferByID(bufferToClose); Buffer * buf = MainFileManager.getBufferByID(bufferToClose);
int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW;
if (buf->isDirty()) if (buf->isDirty())
{ {
@ -332,7 +332,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
{ {
int index = tabNotification->_tabOrigin; int index = tabNotification->_tabOrigin;
BufferID bufferToClose = notifyDocTab->getBufferByIndex(index); BufferID bufferToClose = notifyDocTab->getBufferByIndex(index);
Buffer * buf = MainFileManager->getBufferByID(bufferToClose); Buffer * buf = MainFileManager.getBufferByID(bufferToClose);
int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW;
if (buf->isDirty()) if (buf->isDirty())
{ {
@ -392,7 +392,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (isSnapshotMode) if (isSnapshotMode)
{ {
// Before switching off, synchronize backup file // Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer(); MainFileManager.backupCurrentBuffer();
} }
// Switch off // Switch off
switchEditViewTo(MAIN_VIEW); switchEditViewTo(MAIN_VIEW);
@ -403,7 +403,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (isSnapshotMode) if (isSnapshotMode)
{ {
// Before switching off, synchronize backup file // Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer(); MainFileManager.backupCurrentBuffer();
} }
// Switch off // Switch off
switchEditViewTo(SUB_VIEW); switchEditViewTo(SUB_VIEW);
@ -886,7 +886,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
else if (hWin == _mainDocTab.getHSelf()) else if (hWin == _mainDocTab.getHSelf())
{ {
BufferID idd = _mainDocTab.getBufferByIndex(id); BufferID idd = _mainDocTab.getBufferByIndex(id);
Buffer * buf = MainFileManager->getBufferByID(idd); Buffer * buf = MainFileManager.getBufferByID(idd);
tipTmp = buf->getFullPathName(); tipTmp = buf->getFullPathName();
if (tipTmp.length() >= tipMaxLen) if (tipTmp.length() >= tipMaxLen)
@ -898,7 +898,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
else if (hWin == _subDocTab.getHSelf()) else if (hWin == _subDocTab.getHSelf())
{ {
BufferID idd = _subDocTab.getBufferByIndex(id); BufferID idd = _subDocTab.getBufferByIndex(id);
Buffer * buf = MainFileManager->getBufferByID(idd); Buffer * buf = MainFileManager.getBufferByID(idd);
tipTmp = buf->getFullPathName(); tipTmp = buf->getFullPathName();
if (tipTmp.length() >= tipMaxLen) if (tipTmp.length() >= tipMaxLen)

View File

@ -106,9 +106,9 @@ public:
bool deleteFile(BufferID id); bool deleteFile(BufferID id);
bool moveFile(BufferID id, const TCHAR * newFilename); bool moveFile(BufferID id, const TCHAR * newFilename);
bool createEmptyFile(const TCHAR * path); bool createEmptyFile(const TCHAR * path);
static FileManager * getInstance() { static FileManager& getInstance() {
static FileManager instance; static FileManager instance;
return &instance; return instance;
}; };
int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy); int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy);
int docLength(Buffer * buffer) const; int docLength(Buffer * buffer) const;

View File

@ -43,7 +43,7 @@ void DocTabView::addBuffer(BufferID buffer)
return; return;
if (this->getIndexByBuffer(buffer) != -1) //no duplicates if (this->getIndexByBuffer(buffer) != -1) //no duplicates
return; return;
Buffer * buf = MainFileManager->getBufferByID(buffer); Buffer * buf = MainFileManager.getBufferByID(buffer);
TCITEM tie; TCITEM tie;
tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM; tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM;
@ -95,7 +95,7 @@ BufferID DocTabView::findBufferByName(const TCHAR * fullfilename) //-1 if not fo
{ {
::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast<LPARAM>(&tie)); ::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast<LPARAM>(&tie));
BufferID id = reinterpret_cast<BufferID>(tie.lParam); BufferID id = reinterpret_cast<BufferID>(tie.lParam);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
if (OrdinalIgnoreCaseCompareStrings(fullfilename, buf->getFullPathName()) == 0) if (OrdinalIgnoreCaseCompareStrings(fullfilename, buf->getFullPathName()) == 0)
{ {
return id; return id;
@ -204,7 +204,7 @@ void DocTabView::setBuffer(size_t index, BufferID id)
tie.mask = TCIF_PARAM; tie.mask = TCIF_PARAM;
::SendMessage(_hSelf, TCM_SETITEM, index, reinterpret_cast<LPARAM>(&tie)); ::SendMessage(_hSelf, TCM_SETITEM, index, reinterpret_cast<LPARAM>(&tie));
bufferUpdated(MainFileManager->getBufferByID(id), BufferChangeMask); //update tab, everything has changed bufferUpdated(MainFileManager.getBufferByID(id), BufferChangeMask); //update tab, everything has changed
::SendMessage(_hParent, WM_SIZE, 0, 0); ::SendMessage(_hParent, WM_SIZE, 0, 0);
} }

View File

@ -1524,7 +1524,7 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
setSpecialStyle(nfoStyle); setSpecialStyle(nfoStyle);
execute(SCI_STYLECLEARALL); execute(SCI_STYLECLEARALL);
Buffer * buf = MainFileManager->getBufferByID(_currentBufferID); Buffer * buf = MainFileManager.getBufferByID(_currentBufferID);
if (buf->getEncoding() != NPP_CP_DOS_437) if (buf->getEncoding() != NPP_CP_DOS_437)
{ {
@ -1762,10 +1762,10 @@ BufferID ScintillaEditView::attachDefaultDoc()
// get the doc pointer attached (by default) on the view Scintilla // get the doc pointer attached (by default) on the view Scintilla
Document doc = execute(SCI_GETDOCPOINTER, 0, 0); Document doc = execute(SCI_GETDOCPOINTER, 0, 0);
execute(SCI_ADDREFDOCUMENT, 0, doc); execute(SCI_ADDREFDOCUMENT, 0, doc);
BufferID id = MainFileManager->bufferFromDocument(doc, false, true);//true, true); //keep counter on 1 BufferID id = MainFileManager.bufferFromDocument(doc, false, true);//true, true); //keep counter on 1
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager.getBufferByID(id);
MainFileManager->addBufferReference(id, this); //add a reference. Notepad only shows the buffer in tabbar MainFileManager.addBufferReference(id, this); //add a reference. Notepad only shows the buffer in tabbar
_currentBufferID = id; _currentBufferID = id;
_currentBuffer = buf; _currentBuffer = buf;
@ -1781,7 +1781,7 @@ void ScintillaEditView::saveCurrentPos()
int32_t docLine = static_cast<int32_t>(execute(SCI_DOCLINEFROMVISIBLE, displayedLine)); //linenumber of the line displayed in the top int32_t docLine = static_cast<int32_t>(execute(SCI_DOCLINEFROMVISIBLE, displayedLine)); //linenumber of the line displayed in the top
//int offset = displayedLine - execute(SCI_VISIBLEFROMDOCLINE, docLine); //use this to calc offset of wrap. If no wrap this should be zero //int offset = displayedLine - execute(SCI_VISIBLEFROMDOCLINE, docLine); //use this to calc offset of wrap. If no wrap this should be zero
Buffer * buf = MainFileManager->getBufferByID(_currentBufferID); Buffer * buf = MainFileManager.getBufferByID(_currentBufferID);
Position pos; Position pos;
// the correct visible line number // the correct visible line number
@ -1797,7 +1797,7 @@ void ScintillaEditView::saveCurrentPos()
void ScintillaEditView::restoreCurrentPos() void ScintillaEditView::restoreCurrentPos()
{ {
Buffer * buf = MainFileManager->getBufferByID(_currentBufferID); Buffer * buf = MainFileManager.getBufferByID(_currentBufferID);
Position & pos = buf->getPosition(this); Position & pos = buf->getPosition(this);
execute(SCI_GOTOPOS, 0); //make sure first line visible by setting caret there, will scroll to top of document execute(SCI_GOTOPOS, 0); //make sure first line visible by setting caret there, will scroll to top of document
@ -1834,7 +1834,7 @@ void ScintillaEditView::activateBuffer(BufferID buffer)
return; return;
if (buffer == _currentBuffer) if (buffer == _currentBuffer)
return; return;
Buffer * newBuf = MainFileManager->getBufferByID(buffer); Buffer * newBuf = MainFileManager.getBufferByID(buffer);
// before activating another document, we get the current position // before activating another document, we get the current position
// from the Scintilla view then save it to the current document // from the Scintilla view then save it to the current document

View File

@ -159,8 +159,8 @@ struct BufferEquivalent
{ {
BufferID bid1 = _pTab->getBufferByIndex(i1); BufferID bid1 = _pTab->getBufferByIndex(i1);
BufferID bid2 = _pTab->getBufferByIndex(i2); BufferID bid2 = _pTab->getBufferByIndex(i2);
Buffer * b1 = MainFileManager->getBufferByID(bid1); Buffer * b1 = MainFileManager.getBufferByID(bid1);
Buffer * b2 = MainFileManager->getBufferByID(bid2); Buffer * b2 = MainFileManager.getBufferByID(bid2);
if (_iColumn == 0) if (_iColumn == 0)
{ {
@ -321,7 +321,7 @@ INT_PTR CALLBACK WindowsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPa
//const Buffer& buffer = _pView->getBufferAt(index); //const Buffer& buffer = _pView->getBufferAt(index);
BufferID bufID = _pTab->getBufferByIndex(index); BufferID bufID = _pTab->getBufferByIndex(index);
Buffer * buf = MainFileManager->getBufferByID(bufID); Buffer * buf = MainFileManager.getBufferByID(bufID);
if (pLvdi->item.iSubItem == 0) // file name if (pLvdi->item.iSubItem == 0) // file name
{ {
int len = pLvdi->item.cchTextMax; int len = pLvdi->item.cchTextMax;
@ -888,7 +888,7 @@ void WindowsMenu::initPopupMenu(HMENU hMenu, DocTabView *pTab)
for (id = IDM_WINDOW_MRU_FIRST, pos = 0; id < IDM_WINDOW_MRU_FIRST + static_cast<int32_t>(nDoc); ++id, ++pos) for (id = IDM_WINDOW_MRU_FIRST, pos = 0; id < IDM_WINDOW_MRU_FIRST + static_cast<int32_t>(nDoc); ++id, ++pos)
{ {
BufferID bufID = pTab->getBufferByIndex(pos); BufferID bufID = pTab->getBufferByIndex(pos);
Buffer * buf = MainFileManager->getBufferByID(bufID); Buffer * buf = MainFileManager.getBufferByID(bufID);
MENUITEMINFO mii; MENUITEMINFO mii;
memset(&mii, 0, sizeof(mii)); memset(&mii, 0, sizeof(mii));