[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
This commit is contained in:
parent
29a3bf1b12
commit
d16e9beb15
@ -537,7 +537,8 @@ bool Notepad_plus::loadSession(Session & session)
|
|||||||
//Dont use default methods because of performance
|
//Dont use default methods because of performance
|
||||||
Document prevDoc = _mainEditView.execute(SCI_GETDOCPOINTER);
|
Document prevDoc = _mainEditView.execute(SCI_GETDOCPOINTER);
|
||||||
_mainEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
_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_MARKERADD, session._mainViewFiles[i].marks[j], MARK_BOOKMARK);
|
||||||
}
|
}
|
||||||
_mainEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
_mainEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
||||||
@ -597,7 +598,8 @@ bool Notepad_plus::loadSession(Session & session)
|
|||||||
//Dont use default methods because of performance
|
//Dont use default methods because of performance
|
||||||
Document prevDoc = _subEditView.execute(SCI_GETDOCPOINTER);
|
Document prevDoc = _subEditView.execute(SCI_GETDOCPOINTER);
|
||||||
_subEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
_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_MARKERADD, session._subViewFiles[k].marks[j], MARK_BOOKMARK);
|
||||||
}
|
}
|
||||||
_subEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
_subEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
||||||
@ -1235,8 +1237,13 @@ bool Notepad_plus::fileClose(BufferID id, int curView)
|
|||||||
//process the fileNamePath into LRF
|
//process the fileNamePath into LRF
|
||||||
const TCHAR *fileNamePath = buf->getFullPathName();
|
const TCHAR *fileNamePath = buf->getFullPathName();
|
||||||
|
|
||||||
if (buf->isDirty())
|
if (buf->isUntitled() && buf->docLength() == 0)
|
||||||
{
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
else if (buf->isDirty())
|
||||||
|
{
|
||||||
|
|
||||||
res = doSaveOrNot(fileNamePath);
|
res = doSaveOrNot(fileNamePath);
|
||||||
if (res == IDYES)
|
if (res == IDYES)
|
||||||
{
|
{
|
||||||
@ -1271,29 +1278,46 @@ bool Notepad_plus::fileCloseAll()
|
|||||||
//closes all documents, makes the current view the only one visible
|
//closes all documents, makes the current view the only one visible
|
||||||
|
|
||||||
//first check if we need to save any file
|
//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);
|
BufferID id = _mainDocTab.getBufferByIndex(i);
|
||||||
Buffer * buf = MainFileManager->getBufferByID(id);
|
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());
|
int res = doSaveOrNot(buf->getFullPathName());
|
||||||
if (res == IDYES) {
|
if (res == IDYES)
|
||||||
|
{
|
||||||
if (!fileSave(id))
|
if (!fileSave(id))
|
||||||
return false; //abort entire procedure
|
return false; //abort entire procedure
|
||||||
} else if (res == IDCANCEL) {
|
}
|
||||||
|
else if (res == IDCANCEL)
|
||||||
|
{
|
||||||
return false;
|
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);
|
BufferID id = _subDocTab.getBufferByIndex(i);
|
||||||
Buffer * buf = MainFileManager->getBufferByID(id);
|
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());
|
int res = doSaveOrNot(buf->getFullPathName());
|
||||||
if (res == IDYES) {
|
if (res == IDYES)
|
||||||
|
{
|
||||||
if (!fileSave(id))
|
if (!fileSave(id))
|
||||||
return false; //abort entire procedure
|
return false; //abort entire procedure
|
||||||
} else if (res == IDCANCEL) {
|
}
|
||||||
|
else if (res == IDCANCEL)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
//otherwise continue (IDNO)
|
//otherwise continue (IDNO)
|
||||||
}
|
}
|
||||||
@ -1330,30 +1354,45 @@ bool Notepad_plus::fileCloseAllButCurrent()
|
|||||||
if (id == current)
|
if (id == current)
|
||||||
continue;
|
continue;
|
||||||
Buffer * buf = MainFileManager->getBufferByID(id);
|
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());
|
int res = doSaveOrNot(buf->getFullPathName());
|
||||||
if (res == IDYES) {
|
if (res == IDYES)
|
||||||
|
{
|
||||||
if (!fileSave(id))
|
if (!fileSave(id))
|
||||||
return false; //abort entire procedure
|
return false; //abort entire procedure
|
||||||
} else if (res == IDCANCEL) {
|
}
|
||||||
|
else if (res == IDCANCEL)
|
||||||
|
{
|
||||||
return false;
|
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);
|
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->isDirty()) {
|
if (buf->isUntitled() && buf->docLength() == 0)
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
else if (buf->isDirty())
|
||||||
|
{
|
||||||
int res = doSaveOrNot(buf->getFullPathName());
|
int res = doSaveOrNot(buf->getFullPathName());
|
||||||
if (res == IDYES) {
|
if (res == IDYES)
|
||||||
|
{
|
||||||
if (!fileSave(id))
|
if (!fileSave(id))
|
||||||
return false; //abort entire procedure
|
return false; //abort entire procedure
|
||||||
} else if (res == IDCANCEL) {
|
}
|
||||||
|
else if (res == IDCANCEL)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
//otherwise continue (IDNO)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -578,6 +578,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) {
|
|||||||
buffer->setFileName(fullpath);
|
buffer->setFileName(fullpath);
|
||||||
buffer->setDirty(false);
|
buffer->setDirty(false);
|
||||||
buffer->setStatus(DOC_REGULAR);
|
buffer->setStatus(DOC_REGULAR);
|
||||||
|
buffer->checkFileState();
|
||||||
_pscratchTilla->execute(SCI_SETSAVEPOINT);
|
_pscratchTilla->execute(SCI_SETSAVEPOINT);
|
||||||
_pscratchTilla->markSavedLines();
|
_pscratchTilla->markSavedLines();
|
||||||
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
||||||
@ -602,7 +603,8 @@ BufferID FileManager::newEmptyDocument() {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool dontRef) {
|
BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool dontRef)
|
||||||
|
{
|
||||||
TCHAR newTitle[10];
|
TCHAR newTitle[10];
|
||||||
lstrcpy(newTitle, UNTITLED_STR);
|
lstrcpy(newTitle, UNTITLED_STR);
|
||||||
wsprintf(newTitle+4, TEXT("%d"), _nextNewNumber);
|
wsprintf(newTitle+4, TEXT("%d"), _nextNewNumber);
|
||||||
@ -619,7 +621,8 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d
|
|||||||
return id;
|
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
|
const int blockSize = 128 * 1024; //128 kB
|
||||||
char data[blockSize];
|
char data[blockSize];
|
||||||
FILE *fp = generic_fopen(filename, TEXT("rb"));
|
FILE *fp = generic_fopen(filename, TEXT("rb"));
|
||||||
@ -707,3 +710,11 @@ int FileManager::getFileNameFromBuffer(BufferID id, TCHAR * fn2copy) {
|
|||||||
lstrcpy(fn2copy, buf->getFullPathName());
|
lstrcpy(fn2copy, buf->getFullPathName());
|
||||||
return lstrlen(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;
|
||||||
|
}
|
||||||
|
@ -100,6 +100,9 @@ public:
|
|||||||
void increaseDocNr() {_nextNewNumber++;};
|
void increaseDocNr() {_nextNewNumber++;};
|
||||||
|
|
||||||
int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy);
|
int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy);
|
||||||
|
|
||||||
|
int docLength(Buffer * buffer) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileManager() : _nextNewNumber(1), _nextBufferID(0), _pNotepadPlus(NULL), _nrBufs(0), _pscratchTilla(NULL){};
|
FileManager() : _nextNewNumber(1), _nextBufferID(0), _pNotepadPlus(NULL), _nrBufs(0), _pscratchTilla(NULL){};
|
||||||
~FileManager(){};
|
~FileManager(){};
|
||||||
@ -322,6 +325,10 @@ public :
|
|||||||
pair<size_t, bool> getLineUndoState(size_t currentLine) const;
|
pair<size_t, bool> getLineUndoState(size_t currentLine) const;
|
||||||
void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false);
|
void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false);
|
||||||
|
|
||||||
|
int docLength() const {
|
||||||
|
return _pManager->docLength(_id);
|
||||||
|
};
|
||||||
|
|
||||||
private :
|
private :
|
||||||
FileManager * _pManager;
|
FileManager * _pManager;
|
||||||
bool _canNotify;
|
bool _canNotify;
|
||||||
|
@ -518,14 +518,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void markSavedLines() {
|
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)
|
if ((execute(SCI_MARKERGET, i) & (1 << MARK_LINEMODIFIEDUNSAVED)) != 0)
|
||||||
{
|
{
|
||||||
execute(SCI_MARKERDELETE, i, MARK_LINEMODIFIEDUNSAVED);
|
execute(SCI_MARKERDELETE, i, MARK_LINEMODIFIEDUNSAVED);
|
||||||
execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDSAVED);
|
execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDSAVED);
|
||||||
pair<size_t, bool> st = getLineUndoState(i);
|
//pair<size_t, bool> st = getLineUndoState(i);
|
||||||
setLineUndoState(i, st.first, true);
|
setLineUndoState(i, 0, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -240,45 +240,47 @@ static char * bookmark_xpm[] = {
|
|||||||
" l*yyy*l "};
|
" l*yyy*l "};
|
||||||
|
|
||||||
static char * modifUnsaved_xpm[] = {
|
static char * modifUnsaved_xpm[] = {
|
||||||
"6 18 1 1",
|
"6 18 2 1",
|
||||||
"z c #FF0000",
|
"z c #FF8000",
|
||||||
"zzzzzz",
|
"o c #FFC000",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz"};
|
"zozozo",
|
||||||
|
"ozozoz"};
|
||||||
|
|
||||||
static char * modifSaved_xpm[] = {
|
static char * modifSaved_xpm[] = {
|
||||||
"6 18 1 1",
|
"6 18 2 1",
|
||||||
"z c #00FF00",
|
"z c #008000",
|
||||||
"zzzzzz",
|
"o c #FFFFFF",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz",
|
"zozozo",
|
||||||
"zzzzzz",
|
"ozozoz",
|
||||||
"zzzzzz"};
|
"zozozo",
|
||||||
|
"ozozoz"};
|
||||||
|
Loading…
Reference in New Issue
Block a user