From 29a3bf1b129135bc3b720ea315dd5b6e6cb736bf Mon Sep 17 00:00:00 2001 From: donho Date: Thu, 19 Feb 2009 01:29:06 +0000 Subject: [PATCH] [NEW_FEATURE] Modification state vertical bar (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@428 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 153 ++++++++++++++++-- PowerEditor/src/Notepad_plus.h | 2 + PowerEditor/src/ScitillaComponent/Buffer.cpp | 29 ++++ PowerEditor/src/ScitillaComponent/Buffer.h | 10 +- .../ScitillaComponent/ScintillaEditView.cpp | 17 +- .../src/ScitillaComponent/ScintillaEditView.h | 26 +++ .../WinControls/StaticDialog/StaticDialog.cpp | 5 +- .../src/tools/xmlUpdater/xmlUpdater.cpp | 8 +- PowerEditor/src/xpm_icons.h | 44 +++++ 9 files changed, 273 insertions(+), 21 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 52db00a12..a9e14d644 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -35,7 +35,6 @@ #include "ShortcutMapper.h" #include "preferenceDlg.h" #include "TaskListDlg.h" -#include "xpm_icons.h" #include #include "xmlMatchedTagsHighlighter.h" @@ -73,7 +72,7 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p _recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _isRTL(false), _linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false), _autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg), - _nativeLangEncoding(CP_ACP) + _nativeLangEncoding(CP_ACP), _isNppReady(false) { ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); @@ -319,6 +318,8 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL scnN.nmhdr.idFrom = 0; _pluginsManager.notify(&scnN); + _isNppReady = true; + } @@ -1990,6 +1991,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) _isDocModifing = true; ::InvalidateRect(notifyView->getHSelf(), NULL, TRUE); } + if (notification->modificationType & SC_MOD_CHANGEFOLD) { if (prevWasEdit) { @@ -1998,11 +2000,145 @@ BOOL Notepad_plus::notify(SCNotification *notification) prevWasEdit = false; } } - else - if (!(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT))) + else if (!(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT))) { prevWasEdit = false; } + + if (_isNppReady) + { + bool isProcessed = false; + + int fromLine = _pEditView->execute(SCI_LINEFROMPOSITION, notification->position); + pair undolevel = _pEditView->getLineUndoState(fromLine); + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_USER)) + { + //printStr(TEXT("user type")); + + _pEditView->setLineUndoState(fromLine, undolevel.first+1); + + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + + + if (notification->linesAdded > 0) + { + for (int i = 0 ; i < notification->linesAdded ; i++) + { + ++fromLine; + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + pair modifInfo = _pEditView->getLineUndoState(fromLine); + _pEditView->execute(modifInfo.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_REDO) && + (notification->modificationType & SC_MULTISTEPUNDOREDO)) + { + //printStr(TEXT("redo multiple")); + isProcessed = true; + + _pEditView->setLineUndoState(fromLine, undolevel.first+1); + + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + if (notification->linesAdded > 0) + { + for (int i = 0 ; i < notification->linesAdded ; i++) + { + ++fromLine; + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + pair modifInfo = _pEditView->getLineUndoState(fromLine); + _pEditView->execute(modifInfo.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_UNDO) && + (notification->modificationType & SC_MULTISTEPUNDOREDO)) + { + //printStr(TEXT("undo multiple")); + isProcessed = true; + + --undolevel.first; + if (undolevel.first == 0) + { + _pEditView->execute(SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + else + { + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + _pEditView->setLineUndoState(fromLine, undolevel.first); + + if (notification->linesAdded > 0) + { + for (int i = fromLine + 1 ; i < fromLine + notification->linesAdded ; i++) + { + pair level = _pEditView->getLineUndoState(i); + if (level.first > 0) + _pEditView->execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(level.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_REDO) && + (notification->modificationType & SC_LASTSTEPINUNDOREDO) && !isProcessed) + { + //printStr(TEXT("redo LASTO")); + _pEditView->setLineUndoState(fromLine, undolevel.first+1); + + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + + if (notification->linesAdded > 0) + { + for (int i = 0 ; i < notification->linesAdded ; i++) + { + ++fromLine; + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + pair modifInfo = _pEditView->getLineUndoState(fromLine); + _pEditView->execute(modifInfo.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_UNDO) && + (notification->modificationType & SC_LASTSTEPINUNDOREDO) && !isProcessed) + { + //printStr(TEXT("undo LASTO")); + --undolevel.first; + if (undolevel.first == 0) + { + _pEditView->execute(SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + else + { + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + _pEditView->setLineUndoState(fromLine, undolevel.first); + + if (notification->linesAdded > 0) + { + for (int i = fromLine + 1 ; i < fromLine + notification->linesAdded ; i++) + { + pair level = _pEditView->getLineUndoState(i); + if (level.first > 0) + _pEditView->execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(level.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + } } break; @@ -6658,15 +6794,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _mainEditView.display(); - _mainEditView.execute(SCI_MARKERSETALPHA, MARK_BOOKMARK, 70); - _mainEditView.execute(SCI_MARKERDEFINEPIXMAP, MARK_BOOKMARK, (LPARAM)bookmark_xpm); - _mainEditView.execute(SCI_MARKERDEFINEPIXMAP, MARK_HIDELINESBEGIN, (LPARAM)acTop_xpm); - _mainEditView.execute(SCI_MARKERDEFINEPIXMAP, MARK_HIDELINESEND, (LPARAM)acBottom_xpm); - _subEditView.execute(SCI_MARKERSETALPHA, MARK_BOOKMARK, 70); - _subEditView.execute(SCI_MARKERDEFINEPIXMAP, MARK_BOOKMARK, (LPARAM)bookmark_xpm); - _subEditView.execute(SCI_MARKERDEFINEPIXMAP, MARK_HIDELINESBEGIN, (LPARAM)acTop_xpm); - _subEditView.execute(SCI_MARKERDEFINEPIXMAP, MARK_HIDELINESEND, (LPARAM)acBottom_xpm); - _invisibleEditView.init(_hInst, hwnd); _invisibleEditView.execute(SCI_SETUNDOCOLLECTION); _invisibleEditView.execute(SCI_EMPTYUNDOBUFFER); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 4873558c6..455facb35 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -333,6 +333,8 @@ private: bool _isRTL; winVer _winVersion; + bool _isNppReady; + class ScintillaCtrls { public : //ScintillaCtrls(); diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index ca8076cce..1a5cac1a2 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -326,6 +326,34 @@ void Buffer::setDeferredReload() { //triggers a reload on the next Document acce doNotify(BufferChangeDirty); } + +pair Buffer::getLineUndoState(size_t currentLine) const +{ + for (size_t i = 0 ; i < _linesUndoState.size() ; i++) + { + if (_linesUndoState[i].first == currentLine) + return _linesUndoState[i].second; + } + return pair(0, false); +} + +void Buffer::setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved) +{ + bool found = false; + for (size_t i = 0 ; i < _linesUndoState.size() ; i++) + { + if (_linesUndoState[i].first == currentLine) + { + _linesUndoState[i].second.first = undoLevel; + _linesUndoState[i].second.second = isSaved; + } + } + if (!found) + { + _linesUndoState.push_back(pair >(currentLine, pair(undoLevel, false))); + } +} + //filemanager @@ -551,6 +579,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) { buffer->setDirty(false); buffer->setStatus(DOC_REGULAR); _pscratchTilla->execute(SCI_SETSAVEPOINT); + _pscratchTilla->markSavedLines(); _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); return true; diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index cfa01d85d..84882d342 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -319,6 +319,9 @@ public : void setNeedReload(bool reload) { _needReloading = reload; } + pair getLineUndoState(size_t currentLine) const; + void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false); + private : FileManager * _pManager; bool _canNotify; @@ -336,9 +339,10 @@ private : bool _needLexer; //initially true //these properties have to be duplicated because of multiple references //All the vectors must have the same size at all times - std::vector< ScintillaEditView * > _referees; - std::vector< Position > _positions; - std::vector< std::vector > _foldStates; + vector< ScintillaEditView * > _referees; + vector< Position > _positions; + vector< vector > _foldStates; + vector< pair > > _linesUndoState; //Environment properties DocFileStatus _currentStatus; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 7727bf2dc..c368fb98d 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -31,6 +31,7 @@ UserDefineDialog ScintillaEditView::_userDefineDlg; const int ScintillaEditView::_SC_MARGE_LINENUMBER = 0; const int ScintillaEditView::_SC_MARGE_SYBOLE = 1; const int ScintillaEditView::_SC_MARGE_FOLDER = 2; +const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3; const int ScintillaEditView::_MARGE_LINENUMBER_NB_CHIFFRE = 5; @@ -153,9 +154,21 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) execute(SCI_SETMARGINMASKN, _SC_MARGE_FOLDER, SC_MASK_FOLDERS); showMargin(_SC_MARGE_FOLDER, true); - //showMargin(3, true); - //showMargin(4, true); + execute(SCI_SETMARGINMASKN, _SC_MARGE_SYBOLE, (1< getLineUndoState(size_t currentLine) { + Buffer * buf = getCurrentBuffer(); + return buf->getLineUndoState(currentLine); + }; + void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false) { + Buffer * buf = getCurrentBuffer(); + buf->setLineUndoState(currentLine, undoLevel, isSaved); + }; + + void markSavedLines() { + 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); + } + } + }; + protected: static HINSTANCE _hLib; static int _refCount; diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index 2698cc90c..9544f19f1 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -100,8 +100,9 @@ void StaticDialog::create(int dialogID, bool isRTL) if (!_hSelf) { - systemMessage(TEXT("StaticDialog")); - throw int(666); + //systemMessage(TEXT("StaticDialog")); + //throw int(666); + return; } ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf); diff --git a/PowerEditor/src/tools/xmlUpdater/xmlUpdater.cpp b/PowerEditor/src/tools/xmlUpdater/xmlUpdater.cpp index 766e82db1..27ca968d5 100644 --- a/PowerEditor/src/tools/xmlUpdater/xmlUpdater.cpp +++ b/PowerEditor/src/tools/xmlUpdater/xmlUpdater.cpp @@ -76,6 +76,8 @@ int update(TiXmlNode *modelNode, TiXmlNode *srcNode, TiXmlNode *destNode) { const char *name = (modelChildNode->ToElement())->Attribute("name"); if (nodeName) { + if (!srcNode) + return 0; srcChildNode = srcNode->FirstChild(nodeName); if (!srcChildNode) throw int(4); @@ -115,6 +117,10 @@ int update(TiXmlNode *modelNode, TiXmlNode *srcNode, TiXmlNode *destNode) { destNode->InsertEndChild(*srcChildNode); //return 0; } + else + { + update(modelChildNode, srcChildNode, destChildNode); + } } srcChildNode = srcChildNode->NextSibling(nodeName); } @@ -127,7 +133,7 @@ int update(TiXmlNode *modelNode, TiXmlNode *srcNode, TiXmlNode *destNode) { int main(int argc, char *argv[]) { - if (argc < 4) + if (argc != 4) { printf("Syntax : xmlUpdater model.xml src.xml dest.xml"); return -1; diff --git a/PowerEditor/src/xpm_icons.h b/PowerEditor/src/xpm_icons.h index 6881e5859..b0ea8e894 100644 --- a/PowerEditor/src/xpm_icons.h +++ b/PowerEditor/src/xpm_icons.h @@ -238,3 +238,47 @@ static char * bookmark_xpm[] = { " r*@s(tut(s@*r ", " v*w{x&x{w*v ", " 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"}; + +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"};