[NEW_FEATURE] Modification state vertical bar (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@428 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2009-02-19 01:29:06 +00:00
parent 4e74b2dff4
commit 29a3bf1b12
9 changed files with 273 additions and 21 deletions

View File

@ -35,7 +35,6 @@
#include "ShortcutMapper.h" #include "ShortcutMapper.h"
#include "preferenceDlg.h" #include "preferenceDlg.h"
#include "TaskListDlg.h" #include "TaskListDlg.h"
#include "xpm_icons.h"
#include <algorithm> #include <algorithm>
#include "xmlMatchedTagsHighlighter.h" #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), _recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _isRTL(false),
_linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false), _linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false),
_autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg), _autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg),
_nativeLangEncoding(CP_ACP) _nativeLangEncoding(CP_ACP), _isNppReady(false)
{ {
ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange));
@ -319,6 +318,8 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL
scnN.nmhdr.idFrom = 0; scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
_isNppReady = true;
} }
@ -1990,6 +1991,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_isDocModifing = true; _isDocModifing = true;
::InvalidateRect(notifyView->getHSelf(), NULL, TRUE); ::InvalidateRect(notifyView->getHSelf(), NULL, TRUE);
} }
if (notification->modificationType & SC_MOD_CHANGEFOLD) if (notification->modificationType & SC_MOD_CHANGEFOLD)
{ {
if (prevWasEdit) { if (prevWasEdit) {
@ -1998,11 +2000,145 @@ BOOL Notepad_plus::notify(SCNotification *notification)
prevWasEdit = false; prevWasEdit = false;
} }
} }
else else if (!(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)))
if (!(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)))
{ {
prevWasEdit = false; prevWasEdit = false;
} }
if (_isNppReady)
{
bool isProcessed = false;
int fromLine = _pEditView->execute(SCI_LINEFROMPOSITION, notification->position);
pair<size_t, bool> 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<size_t, bool> 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<size_t, bool> 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<size_t, bool> 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<size_t, bool> 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<size_t, bool> 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; break;
@ -6658,15 +6794,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_mainEditView.display(); _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.init(_hInst, hwnd);
_invisibleEditView.execute(SCI_SETUNDOCOLLECTION); _invisibleEditView.execute(SCI_SETUNDOCOLLECTION);
_invisibleEditView.execute(SCI_EMPTYUNDOBUFFER); _invisibleEditView.execute(SCI_EMPTYUNDOBUFFER);

View File

@ -333,6 +333,8 @@ private:
bool _isRTL; bool _isRTL;
winVer _winVersion; winVer _winVersion;
bool _isNppReady;
class ScintillaCtrls { class ScintillaCtrls {
public : public :
//ScintillaCtrls(); //ScintillaCtrls();

View File

@ -326,6 +326,34 @@ void Buffer::setDeferredReload() { //triggers a reload on the next Document acce
doNotify(BufferChangeDirty); doNotify(BufferChangeDirty);
} }
pair<size_t, bool> 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<size_t, bool>(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<size_t, pair<size_t, bool> >(currentLine, pair<size_t, bool>(undoLevel, false)));
}
}
//filemanager //filemanager
@ -551,6 +579,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) {
buffer->setDirty(false); buffer->setDirty(false);
buffer->setStatus(DOC_REGULAR); buffer->setStatus(DOC_REGULAR);
_pscratchTilla->execute(SCI_SETSAVEPOINT); _pscratchTilla->execute(SCI_SETSAVEPOINT);
_pscratchTilla->markSavedLines();
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
return true; return true;

View File

@ -319,6 +319,9 @@ public :
void setNeedReload(bool reload) { void setNeedReload(bool reload) {
_needReloading = reload; _needReloading = reload;
} }
pair<size_t, bool> getLineUndoState(size_t currentLine) const;
void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false);
private : private :
FileManager * _pManager; FileManager * _pManager;
bool _canNotify; bool _canNotify;
@ -336,9 +339,10 @@ private :
bool _needLexer; //initially true bool _needLexer; //initially true
//these properties have to be duplicated because of multiple references //these properties have to be duplicated because of multiple references
//All the vectors must have the same size at all times //All the vectors must have the same size at all times
std::vector< ScintillaEditView * > _referees; vector< ScintillaEditView * > _referees;
std::vector< Position > _positions; vector< Position > _positions;
std::vector< std::vector<HeaderLineState> > _foldStates; vector< vector<HeaderLineState> > _foldStates;
vector< pair<size_t, pair<size_t, bool> > > _linesUndoState;
//Environment properties //Environment properties
DocFileStatus _currentStatus; DocFileStatus _currentStatus;

View File

@ -31,6 +31,7 @@ UserDefineDialog ScintillaEditView::_userDefineDlg;
const int ScintillaEditView::_SC_MARGE_LINENUMBER = 0; const int ScintillaEditView::_SC_MARGE_LINENUMBER = 0;
const int ScintillaEditView::_SC_MARGE_SYBOLE = 1; const int ScintillaEditView::_SC_MARGE_SYBOLE = 1;
const int ScintillaEditView::_SC_MARGE_FOLDER = 2; const int ScintillaEditView::_SC_MARGE_FOLDER = 2;
const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3;
const int ScintillaEditView::_MARGE_LINENUMBER_NB_CHIFFRE = 5; 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); execute(SCI_SETMARGINMASKN, _SC_MARGE_FOLDER, SC_MASK_FOLDERS);
showMargin(_SC_MARGE_FOLDER, true); showMargin(_SC_MARGE_FOLDER, true);
//showMargin(3, true);
//showMargin(4, true);
execute(SCI_SETMARGINMASKN, _SC_MARGE_SYBOLE, (1<<MARK_BOOKMARK) | (1<<MARK_HIDELINESBEGIN) | (1<<MARK_HIDELINESEND));
execute(SCI_SETMARGINMASKN, _SC_MARGE_MODIFMARKER, (1<<MARK_LINEMODIFIEDUNSAVED)|(1<<MARK_LINEMODIFIEDSAVED));
execute(SCI_SETMARGINTYPEN, _SC_MARGE_MODIFMARKER, SC_MARGIN_BACK);
showMargin(_SC_MARGE_MODIFMARKER, true);
execute(SCI_MARKERSETFORE, MARK_LINEMODIFIEDUNSAVED, (LPARAM)red);
execute(SCI_MARKERDEFINEPIXMAP, MARK_LINEMODIFIEDUNSAVED, (LPARAM)modifUnsaved_xpm);
execute(SCI_MARKERDEFINEPIXMAP, MARK_LINEMODIFIEDSAVED, (LPARAM)modifSaved_xpm);
execute(SCI_MARKERSETALPHA, MARK_BOOKMARK, 70);
execute(SCI_MARKERDEFINEPIXMAP, MARK_BOOKMARK, (LPARAM)bookmark_xpm);
execute(SCI_MARKERDEFINEPIXMAP, MARK_HIDELINESBEGIN, (LPARAM)acTop_xpm);
execute(SCI_MARKERDEFINEPIXMAP, MARK_HIDELINESEND, (LPARAM)acBottom_xpm);
execute(SCI_SETMARGINSENSITIVEN, _SC_MARGE_FOLDER, true); execute(SCI_SETMARGINSENSITIVEN, _SC_MARGE_FOLDER, true);
execute(SCI_SETMARGINSENSITIVEN, _SC_MARGE_SYBOLE, true); execute(SCI_SETMARGINSENSITIVEN, _SC_MARGE_SYBOLE, true);

View File

@ -26,6 +26,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "colors.h" #include "colors.h"
#include "UserDefineDialog.h" #include "UserDefineDialog.h"
#include "xpm_icons.h"
#include "resource.h" #include "resource.h"
#ifndef WM_MOUSEWHEEL #ifndef WM_MOUSEWHEEL
@ -101,6 +102,8 @@ const UCHAR BASE_02 = 0x03; // Bin
const int MARK_BOOKMARK = 24; const int MARK_BOOKMARK = 24;
const int MARK_HIDELINESBEGIN = 23; const int MARK_HIDELINESBEGIN = 23;
const int MARK_HIDELINESEND = 22; const int MARK_HIDELINESEND = 22;
const int MARK_LINEMODIFIEDUNSAVED = 21;
const int MARK_LINEMODIFIEDSAVED = 20;
// 24 - 16 reserved for Notepad++ internal used // 24 - 16 reserved for Notepad++ internal used
// 15 - 0 are free to use for plugins // 15 - 0 are free to use for plugins
@ -241,6 +244,7 @@ public:
static const int _SC_MARGE_LINENUMBER; static const int _SC_MARGE_LINENUMBER;
static const int _SC_MARGE_SYBOLE; static const int _SC_MARGE_SYBOLE;
static const int _SC_MARGE_FOLDER; static const int _SC_MARGE_FOLDER;
static const int _SC_MARGE_MODIFMARKER;
static const int _MARGE_LINENUMBER_NB_CHIFFRE; static const int _MARGE_LINENUMBER_NB_CHIFFRE;
@ -504,6 +508,28 @@ public:
}; };
void setHiLiteResultWords(const TCHAR *keywords); void setHiLiteResultWords(const TCHAR *keywords);
pair<size_t, bool> 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<size_t, bool> st = getLineUndoState(i);
setLineUndoState(i, st.first, true);
}
}
};
protected: protected:
static HINSTANCE _hLib; static HINSTANCE _hLib;
static int _refCount; static int _refCount;

View File

@ -100,8 +100,9 @@ void StaticDialog::create(int dialogID, bool isRTL)
if (!_hSelf) if (!_hSelf)
{ {
systemMessage(TEXT("StaticDialog")); //systemMessage(TEXT("StaticDialog"));
throw int(666); //throw int(666);
return;
} }
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf); ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf);

View File

@ -76,6 +76,8 @@ int update(TiXmlNode *modelNode, TiXmlNode *srcNode, TiXmlNode *destNode) {
const char *name = (modelChildNode->ToElement())->Attribute("name"); const char *name = (modelChildNode->ToElement())->Attribute("name");
if (nodeName) if (nodeName)
{ {
if (!srcNode)
return 0;
srcChildNode = srcNode->FirstChild(nodeName); srcChildNode = srcNode->FirstChild(nodeName);
if (!srcChildNode) if (!srcChildNode)
throw int(4); throw int(4);
@ -115,6 +117,10 @@ int update(TiXmlNode *modelNode, TiXmlNode *srcNode, TiXmlNode *destNode) {
destNode->InsertEndChild(*srcChildNode); destNode->InsertEndChild(*srcChildNode);
//return 0; //return 0;
} }
else
{
update(modelChildNode, srcChildNode, destChildNode);
}
} }
srcChildNode = srcChildNode->NextSibling(nodeName); srcChildNode = srcChildNode->NextSibling(nodeName);
} }
@ -127,7 +133,7 @@ int update(TiXmlNode *modelNode, TiXmlNode *srcNode, TiXmlNode *destNode) {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc < 4) if (argc != 4)
{ {
printf("Syntax : xmlUpdater model.xml src.xml dest.xml"); printf("Syntax : xmlUpdater model.xml src.xml dest.xml");
return -1; return -1;

View File

@ -238,3 +238,47 @@ static char * bookmark_xpm[] = {
" r*@s(tut(s@*r ", " r*@s(tut(s@*r ",
" v*w{x&x{w*v ", " v*w{x&x{w*v ",
" l*yyy*l "}; " 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"};