[NEW_FEATURE] Automatic Backup System: uniq untitled tab name.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1229 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
e1a3fe91b9
commit
85a6d2c054
|
@ -692,8 +692,6 @@ LRESULT Notepad_plus::init(HWND hwnd)
|
||||||
loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW);
|
loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW);
|
||||||
activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW);
|
activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW);
|
||||||
activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW);
|
activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW);
|
||||||
MainFileManager->increaseDocNr(); //so next doc starts at 2
|
|
||||||
|
|
||||||
::SetFocus(_mainEditView.getHSelf());
|
::SetFocus(_mainEditView.getHSelf());
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1120,218 +1120,6 @@ bool Notepad_plus::isFileSession(const TCHAR * filename) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// return true if all the session files are loaded
|
|
||||||
// return false if one or more sessions files fail to load (and session is modify to remove invalid files)
|
|
||||||
bool Notepad_plus::loadSession(Session & session)
|
|
||||||
{
|
|
||||||
NppParameters *pNppParam = NppParameters::getInstance();
|
|
||||||
bool allSessionFilesLoaded = true;
|
|
||||||
BufferID lastOpened = BUFFER_INVALID;
|
|
||||||
size_t i = 0;
|
|
||||||
showView(MAIN_VIEW);
|
|
||||||
switchEditViewTo(MAIN_VIEW); //open files in main
|
|
||||||
|
|
||||||
int mainIndex2Update = -1;
|
|
||||||
|
|
||||||
for ( ; i < session.nbMainFiles() ; )
|
|
||||||
{
|
|
||||||
const TCHAR *pFn = session._mainViewFiles[i]._fileName.c_str();
|
|
||||||
if (isFileSession(pFn))
|
|
||||||
{
|
|
||||||
vector<sessionFileInfo>::iterator posIt = session._mainViewFiles.begin() + i;
|
|
||||||
session._mainViewFiles.erase(posIt);
|
|
||||||
continue; //skip session files, not supporting recursive sessions
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isWow64Off = false;
|
|
||||||
if (!PathFileExists(pFn))
|
|
||||||
{
|
|
||||||
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
|
|
||||||
isWow64Off = true;
|
|
||||||
}
|
|
||||||
if (PathFileExists(pFn))
|
|
||||||
{
|
|
||||||
lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lastOpened = BUFFER_INVALID;
|
|
||||||
}
|
|
||||||
if (isWow64Off)
|
|
||||||
{
|
|
||||||
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
|
|
||||||
isWow64Off = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastOpened != BUFFER_INVALID)
|
|
||||||
{
|
|
||||||
showView(MAIN_VIEW);
|
|
||||||
const TCHAR *pLn = session._mainViewFiles[i]._langName.c_str();
|
|
||||||
int id = getLangFromMenuName(pLn);
|
|
||||||
LangType typeToSet = L_TEXT;
|
|
||||||
if (id != 0 && id != IDM_LANG_USER)
|
|
||||||
typeToSet = menuID2LangType(id);
|
|
||||||
if (typeToSet == L_EXTERNAL )
|
|
||||||
typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
|
|
||||||
|
|
||||||
Buffer *buf = MainFileManager->getBufferByID(lastOpened);
|
|
||||||
|
|
||||||
if (session._mainViewFiles[i]._foldStates.size() > 0)
|
|
||||||
{
|
|
||||||
if (buf == _mainEditView.getCurrentBuffer()) // current document
|
|
||||||
// Set floding state in the current doccument
|
|
||||||
mainIndex2Update = i;
|
|
||||||
else
|
|
||||||
// Set fold states in the buffer
|
|
||||||
buf->setHeaderLineState(session._mainViewFiles[i]._foldStates, &_mainEditView);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf->setPosition(session._mainViewFiles[i], &_mainEditView);
|
|
||||||
buf->setLangType(typeToSet, pLn);
|
|
||||||
if (session._mainViewFiles[i]._encoding != -1)
|
|
||||||
buf->setEncoding(session._mainViewFiles[i]._encoding);
|
|
||||||
|
|
||||||
//Force in the document so we can add the markers
|
|
||||||
//Dont use default methods because of performance
|
|
||||||
Document prevDoc = _mainEditView.execute(SCI_GETDOCPOINTER);
|
|
||||||
_mainEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
|
||||||
for (size_t j = 0, len = session._mainViewFiles[i]._marks.size(); j < len ; ++j)
|
|
||||||
{
|
|
||||||
_mainEditView.execute(SCI_MARKERADD, session._mainViewFiles[i]._marks[j], MARK_BOOKMARK);
|
|
||||||
}
|
|
||||||
_mainEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vector<sessionFileInfo>::iterator posIt = session._mainViewFiles.begin() + i;
|
|
||||||
session._mainViewFiles.erase(posIt);
|
|
||||||
allSessionFilesLoaded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mainIndex2Update != -1)
|
|
||||||
_mainEditView.syncFoldStateWith(session._mainViewFiles[mainIndex2Update]._foldStates);
|
|
||||||
|
|
||||||
size_t k = 0;
|
|
||||||
showView(SUB_VIEW);
|
|
||||||
switchEditViewTo(SUB_VIEW); //open files in sub
|
|
||||||
int subIndex2Update = -1;
|
|
||||||
|
|
||||||
for ( ; k < session.nbSubFiles() ; )
|
|
||||||
{
|
|
||||||
const TCHAR *pFn = session._subViewFiles[k]._fileName.c_str();
|
|
||||||
if (isFileSession(pFn)) {
|
|
||||||
vector<sessionFileInfo>::iterator posIt = session._subViewFiles.begin() + k;
|
|
||||||
session._subViewFiles.erase(posIt);
|
|
||||||
continue; //skip session files, not supporting recursive sessions
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isWow64Off = false;
|
|
||||||
if (!PathFileExists(pFn))
|
|
||||||
{
|
|
||||||
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
|
|
||||||
isWow64Off = true;
|
|
||||||
}
|
|
||||||
if (PathFileExists(pFn))
|
|
||||||
{
|
|
||||||
lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding);
|
|
||||||
|
|
||||||
//check if already open in main. If so, clone
|
|
||||||
if (_mainDocTab.getIndexByBuffer(lastOpened) != -1) {
|
|
||||||
loadBufferIntoView(lastOpened, SUB_VIEW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lastOpened = BUFFER_INVALID;
|
|
||||||
}
|
|
||||||
if (isWow64Off)
|
|
||||||
{
|
|
||||||
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
|
|
||||||
isWow64Off = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastOpened != BUFFER_INVALID)
|
|
||||||
{
|
|
||||||
showView(SUB_VIEW);
|
|
||||||
if (canHideView(MAIN_VIEW))
|
|
||||||
hideView(MAIN_VIEW);
|
|
||||||
const TCHAR *pLn = session._subViewFiles[k]._langName.c_str();
|
|
||||||
int id = getLangFromMenuName(pLn);
|
|
||||||
LangType typeToSet = L_TEXT;
|
|
||||||
|
|
||||||
if (id != 0)
|
|
||||||
typeToSet = menuID2LangType(id);
|
|
||||||
if (typeToSet == L_EXTERNAL )
|
|
||||||
typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
|
|
||||||
|
|
||||||
Buffer * buf = MainFileManager->getBufferByID(lastOpened);
|
|
||||||
|
|
||||||
// Set fold states
|
|
||||||
if (session._subViewFiles[k]._foldStates.size() > 0)
|
|
||||||
{
|
|
||||||
if (buf == _subEditView.getCurrentBuffer()) // current document
|
|
||||||
// Set floding state in the current doccument
|
|
||||||
subIndex2Update = k;
|
|
||||||
else
|
|
||||||
// Set fold states in the buffer
|
|
||||||
buf->setHeaderLineState(session._subViewFiles[k]._foldStates, &_subEditView);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf->setPosition(session._subViewFiles[k], &_subEditView);
|
|
||||||
if (typeToSet == L_USER) {
|
|
||||||
if (!lstrcmp(pLn, TEXT("User Defined"))) {
|
|
||||||
pLn = TEXT(""); //default user defined
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf->setLangType(typeToSet, pLn);
|
|
||||||
buf->setEncoding(session._subViewFiles[k]._encoding);
|
|
||||||
|
|
||||||
//Force in the document so we can add the markers
|
|
||||||
//Dont use default methods because of performance
|
|
||||||
Document prevDoc = _subEditView.execute(SCI_GETDOCPOINTER);
|
|
||||||
_subEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
|
||||||
for (size_t j = 0, len = session._subViewFiles[k]._marks.size(); j < len ; ++j)
|
|
||||||
{
|
|
||||||
_subEditView.execute(SCI_MARKERADD, session._subViewFiles[k]._marks[j], MARK_BOOKMARK);
|
|
||||||
}
|
|
||||||
_subEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
|
||||||
|
|
||||||
++k;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vector<sessionFileInfo>::iterator posIt = session._subViewFiles.begin() + k;
|
|
||||||
session._subViewFiles.erase(posIt);
|
|
||||||
allSessionFilesLoaded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (subIndex2Update != -1)
|
|
||||||
_subEditView.syncFoldStateWith(session._subViewFiles[subIndex2Update]._foldStates);
|
|
||||||
|
|
||||||
_mainEditView.restoreCurrentPos();
|
|
||||||
_subEditView.restoreCurrentPos();
|
|
||||||
|
|
||||||
if (session._activeMainIndex < (size_t)_mainDocTab.nbItem())//session.nbMainFiles())
|
|
||||||
activateBuffer(_mainDocTab.getBufferByIndex(session._activeMainIndex), MAIN_VIEW);
|
|
||||||
|
|
||||||
if (session._activeSubIndex < (size_t)_subDocTab.nbItem())//session.nbSubFiles())
|
|
||||||
activateBuffer(_subDocTab.getBufferByIndex(session._activeSubIndex), SUB_VIEW);
|
|
||||||
|
|
||||||
if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW))
|
|
||||||
switchEditViewTo(session._activeView);
|
|
||||||
else
|
|
||||||
switchEditViewTo(MAIN_VIEW);
|
|
||||||
|
|
||||||
if (canHideView(otherView()))
|
|
||||||
hideView(otherView());
|
|
||||||
else if (canHideView(currentView()))
|
|
||||||
hideView(currentView());
|
|
||||||
return allSessionFilesLoaded;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode)
|
bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode)
|
||||||
{
|
{
|
||||||
NppParameters *pNppParam = NppParameters::getInstance();
|
NppParameters *pNppParam = NppParameters::getInstance();
|
||||||
|
|
|
@ -961,12 +961,52 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t FileManager::nextUntitledNewNumber() const
|
||||||
|
{
|
||||||
|
std::vector<size_t> usedNumbers;
|
||||||
|
for(size_t i = 0; i < _buffers.size(); i++)
|
||||||
|
{
|
||||||
|
Buffer *buf = _buffers.at(i);
|
||||||
|
if (buf->isUntitled())
|
||||||
|
{
|
||||||
|
TCHAR *numberStr = buf->_fileName + lstrlen(UNTITLED_STR);
|
||||||
|
int usedNumber = generic_atoi(numberStr);
|
||||||
|
usedNumbers.push_back(usedNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t newNumber = 1;
|
||||||
|
bool numberAvailable = true;
|
||||||
|
bool found = false;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
for(size_t j = 0; j < usedNumbers.size(); j++)
|
||||||
|
{
|
||||||
|
numberAvailable = true;
|
||||||
|
found = false;
|
||||||
|
if (usedNumbers[j] == newNumber)
|
||||||
|
{
|
||||||
|
numberAvailable = false;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!numberAvailable)
|
||||||
|
newNumber++;
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
break;
|
||||||
|
|
||||||
|
} while (!numberAvailable);
|
||||||
|
|
||||||
|
return newNumber;
|
||||||
|
}
|
||||||
|
|
||||||
BufferID FileManager::newEmptyDocument()
|
BufferID FileManager::newEmptyDocument()
|
||||||
{
|
{
|
||||||
generic_string newTitle = UNTITLED_STR;
|
generic_string newTitle = UNTITLED_STR;
|
||||||
TCHAR nb[10];
|
TCHAR nb[10];
|
||||||
wsprintf(nb, TEXT(" %d"), _nextNewNumber);
|
wsprintf(nb, TEXT(" %d"), nextUntitledNewNumber());
|
||||||
++_nextNewNumber;
|
|
||||||
newTitle += nb;
|
newTitle += nb;
|
||||||
|
|
||||||
Document doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT); //this already sets a reference for filemanager
|
Document doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT); //this already sets a reference for filemanager
|
||||||
|
@ -983,7 +1023,7 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d
|
||||||
{
|
{
|
||||||
generic_string newTitle = UNTITLED_STR;
|
generic_string newTitle = UNTITLED_STR;
|
||||||
TCHAR nb[10];
|
TCHAR nb[10];
|
||||||
wsprintf(nb, TEXT(" %d"), _nextNewNumber);
|
wsprintf(nb, TEXT(" %d"), 0);
|
||||||
newTitle += nb;
|
newTitle += nb;
|
||||||
|
|
||||||
if (!dontRef)
|
if (!dontRef)
|
||||||
|
|
|
@ -102,28 +102,24 @@ public:
|
||||||
bool createEmptyFile(const TCHAR * path);
|
bool createEmptyFile(const TCHAR * path);
|
||||||
static FileManager * getInstance() {return _pSelf;};
|
static FileManager * getInstance() {return _pSelf;};
|
||||||
void destroyInstance() { delete _pSelf; };
|
void destroyInstance() { delete _pSelf; };
|
||||||
void increaseDocNr() {_nextNewNumber++;};
|
|
||||||
int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy);
|
int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy);
|
||||||
int docLength(Buffer * buffer) const;
|
int docLength(Buffer * buffer) const;
|
||||||
int getEOLFormatForm(const char *data) const;
|
int getEOLFormatForm(const char *data) const;
|
||||||
|
size_t nextUntitledNewNumber() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileManager() : _nextNewNumber(1), _nextBufferID(0), _pNotepadPlus(NULL), _nrBufs(0), _pscratchTilla(NULL){};
|
FileManager() : _nextBufferID(0), _pNotepadPlus(NULL), _nrBufs(0), _pscratchTilla(NULL){};
|
||||||
~FileManager();
|
~FileManager();
|
||||||
static FileManager *_pSelf;
|
static FileManager *_pSelf;
|
||||||
|
|
||||||
Notepad_plus * _pNotepadPlus;
|
Notepad_plus * _pNotepadPlus;
|
||||||
ScintillaEditView * _pscratchTilla;
|
ScintillaEditView * _pscratchTilla;
|
||||||
Document _scratchDocDefault;
|
Document _scratchDocDefault;
|
||||||
|
|
||||||
int _nextNewNumber;
|
|
||||||
|
|
||||||
std::vector<Buffer *> _buffers;
|
std::vector<Buffer *> _buffers;
|
||||||
BufferID _nextBufferID;
|
BufferID _nextBufferID;
|
||||||
size_t _nrBufs;
|
size_t _nrBufs;
|
||||||
int detectCodepage(char* buf, size_t len);
|
int detectCodepage(char* buf, size_t len);
|
||||||
|
|
||||||
|
|
||||||
bool loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language, int & encoding, formatType *pFormat = NULL);
|
bool loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language, int & encoding, formatType *pFormat = NULL);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue