[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:
donho 2009-02-21 10:08:38 +00:00
parent 29a3bf1b12
commit d16e9beb15
5 changed files with 125 additions and 66 deletions

View File

@ -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)
}
}
}

View File

@ -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;
}

View File

@ -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<size_t, bool> 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;

View File

@ -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<size_t, bool> st = getLineUndoState(i);
setLineUndoState(i, st.first, true);
//pair<size_t, bool> st = getLineUndoState(i);
setLineUndoState(i, 0, true);
}
}
};

View File

@ -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"};