From d16e9beb15cdfcd6e01cd7d61ed1c6b5e05bc22d Mon Sep 17 00:00:00 2001 From: donho Date: Sat, 21 Feb 2009 10:08:38 +0000 Subject: [PATCH] [BUG_FIXED] Fix read only file SaveAs bug. [NEW_FEATURE] Don't save empty untitled document. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@429 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 81 +++++++++++++----- PowerEditor/src/ScitillaComponent/Buffer.cpp | 15 +++- PowerEditor/src/ScitillaComponent/Buffer.h | 7 ++ .../src/ScitillaComponent/ScintillaEditView.h | 6 +- PowerEditor/src/xpm_icons.h | 82 ++++++++++--------- 5 files changed, 125 insertions(+), 66 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index a9e14d64..957db48d 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -537,7 +537,8 @@ bool Notepad_plus::loadSession(Session & session) //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 ; j < session._mainViewFiles[i].marks.size() ; j++) { + for (size_t j = 0 ; j < session._mainViewFiles[i].marks.size() ; j++) + { _mainEditView.execute(SCI_MARKERADD, session._mainViewFiles[i].marks[j], MARK_BOOKMARK); } _mainEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc); @@ -597,7 +598,8 @@ bool Notepad_plus::loadSession(Session & session) //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 ; j < session._subViewFiles[k].marks.size() ; j++) { + for (size_t j = 0 ; j < session._subViewFiles[k].marks.size() ; j++) + { _subEditView.execute(SCI_MARKERADD, session._subViewFiles[k].marks[j], MARK_BOOKMARK); } _subEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc); @@ -1235,8 +1237,13 @@ bool Notepad_plus::fileClose(BufferID id, int curView) //process the fileNamePath into LRF const TCHAR *fileNamePath = buf->getFullPathName(); - if (buf->isDirty()) + if (buf->isUntitled() && buf->docLength() == 0) { + // Do nothing + } + else if (buf->isDirty()) + { + res = doSaveOrNot(fileNamePath); if (res == IDYES) { @@ -1271,29 +1278,46 @@ bool Notepad_plus::fileCloseAll() //closes all documents, makes the current view the only one visible //first check if we need to save any file - for(int i = 0; i < _mainDocTab.nbItem(); i++) { + for(int i = 0; i < _mainDocTab.nbItem(); i++) + { BufferID id = _mainDocTab.getBufferByIndex(i); Buffer * buf = MainFileManager->getBufferByID(id); - if (buf->isDirty()) { + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { int res = doSaveOrNot(buf->getFullPathName()); - if (res == IDYES) { + if (res == IDYES) + { if (!fileSave(id)) return false; //abort entire procedure - } else if (res == IDCANCEL) { + } + else if (res == IDCANCEL) + { return false; - //otherwise continue (IDNO) } } } - for(int i = 0; i < _subDocTab.nbItem(); i++) { + for(int i = 0; i < _subDocTab.nbItem(); i++) + { BufferID id = _subDocTab.getBufferByIndex(i); Buffer * buf = MainFileManager->getBufferByID(id); - if (buf->isDirty()) { + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { int res = doSaveOrNot(buf->getFullPathName()); - if (res == IDYES) { + if (res == IDYES) + { if (!fileSave(id)) return false; //abort entire procedure - } else if (res == IDCANCEL) { + } + else if (res == IDCANCEL) + { return false; //otherwise continue (IDNO) } @@ -1330,30 +1354,45 @@ bool Notepad_plus::fileCloseAllButCurrent() if (id == current) continue; Buffer * buf = MainFileManager->getBufferByID(id); - if (buf->isDirty()) { + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { int res = doSaveOrNot(buf->getFullPathName()); - if (res == IDYES) { + if (res == IDYES) + { if (!fileSave(id)) return false; //abort entire procedure - } else if (res == IDCANCEL) { + } + else if (res == IDCANCEL) + { return false; - //otherwise continue (IDNO) } } } - for(int i = 0; i < _subDocTab.nbItem(); i++) { + for(int i = 0; i < _subDocTab.nbItem(); i++) + { BufferID id = _subDocTab.getBufferByIndex(i); Buffer * buf = MainFileManager->getBufferByID(id); if (id == current) continue; - if (buf->isDirty()) { + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { int res = doSaveOrNot(buf->getFullPathName()); - if (res == IDYES) { + if (res == IDYES) + { if (!fileSave(id)) return false; //abort entire procedure - } else if (res == IDCANCEL) { + } + else if (res == IDCANCEL) + { return false; - //otherwise continue (IDNO) } } } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 1a5cac1a..cd7bbbd4 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -578,6 +578,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) { buffer->setFileName(fullpath); buffer->setDirty(false); buffer->setStatus(DOC_REGULAR); + buffer->checkFileState(); _pscratchTilla->execute(SCI_SETSAVEPOINT); _pscratchTilla->markSavedLines(); _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); @@ -602,7 +603,8 @@ BufferID FileManager::newEmptyDocument() { return id; } -BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool dontRef) { +BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool dontRef) +{ TCHAR newTitle[10]; lstrcpy(newTitle, UNTITLED_STR); wsprintf(newTitle+4, TEXT("%d"), _nextNewNumber); @@ -619,7 +621,8 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d return id; } -bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language) { +bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language) +{ const int blockSize = 128 * 1024; //128 kB char data[blockSize]; FILE *fp = generic_fopen(filename, TEXT("rb")); @@ -707,3 +710,11 @@ int FileManager::getFileNameFromBuffer(BufferID id, TCHAR * fn2copy) { lstrcpy(fn2copy, buf->getFullPathName()); return lstrlen(buf->getFullPathName()); } + +int FileManager::docLength(Buffer * buffer) const +{ + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, buffer->_doc); + int docLen = _pscratchTilla->getCurrentDocLen(); + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); + return docLen; +} diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 84882d34..6e0bca5c 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -100,6 +100,9 @@ public: void increaseDocNr() {_nextNewNumber++;}; int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy); + + int docLength(Buffer * buffer) const; + private: FileManager() : _nextNewNumber(1), _nextBufferID(0), _pNotepadPlus(NULL), _nrBufs(0), _pscratchTilla(NULL){}; ~FileManager(){}; @@ -322,6 +325,10 @@ public : pair getLineUndoState(size_t currentLine) const; void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false); + int docLength() const { + return _pManager->docLength(_id); + }; + private : FileManager * _pManager; bool _canNotify; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 35ef9d3d..8a88d95c 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -518,14 +518,14 @@ public: }; void markSavedLines() { - for (int i = 0 ; i < lastZeroBasedLineNumber() ; i++) + for (int i = 0 ; i <= lastZeroBasedLineNumber() ; i++) { if ((execute(SCI_MARKERGET, i) & (1 << MARK_LINEMODIFIEDUNSAVED)) != 0) { execute(SCI_MARKERDELETE, i, MARK_LINEMODIFIEDUNSAVED); execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDSAVED); - pair st = getLineUndoState(i); - setLineUndoState(i, st.first, true); + //pair st = getLineUndoState(i); + setLineUndoState(i, 0, true); } } }; diff --git a/PowerEditor/src/xpm_icons.h b/PowerEditor/src/xpm_icons.h index b0ea8e89..766ea393 100644 --- a/PowerEditor/src/xpm_icons.h +++ b/PowerEditor/src/xpm_icons.h @@ -240,45 +240,47 @@ static char * bookmark_xpm[] = { " l*yyy*l "}; static char * modifUnsaved_xpm[] = { -"6 18 1 1", -"z c #FF0000", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz"}; +"6 18 2 1", +"z c #FF8000", +"o c #FFC000", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz"}; static char * modifSaved_xpm[] = { -"6 18 1 1", -"z c #00FF00", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz", -"zzzzzz"}; +"6 18 2 1", +"z c #008000", +"o c #FFFFFF", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz"};