Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # HG changeset patch
- # User Jérôme LAFORGE <jerome.laforge@gmail.com>
- # Date 1321047465 -3600
- # Node ID 2bfb11c2b9ae9ed46f1bb76fece40bda986af896
- # Parent 2c003ff12a8663eb51830764d440d59b238f8d1b
- Draft for ChangeLine.
- diff -r 2c003ff12a86 -r 2bfb11c2b9ae include/Scintilla.h
- --- a/include/Scintilla.h lun. nov. 07 12:55:32 2011 +1100
- +++ b/include/Scintilla.h ven. nov. 11 22:37:45 2011 +0100
- @@ -2,7 +2,7 @@
- /** @file Scintilla.h
- ** Interface to the edit control.
- **/
- -/* Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
- +/* Copyright 1998-2011 by Neil Hodgson <neilh@scintilla.org>
- * The License.txt file describes the conditions under which this software may be distributed. */
- /* Most of this file is automatically generated from the Scintilla.iface interface definition
- @@ -832,6 +832,7 @@
- #define SCI_SETTECHNOLOGY 2630
- #define SCI_GETTECHNOLOGY 2631
- #define SCI_CREATELOADER 2632
- +#define SCI_CLEARCHANGEMARGIN 2633
- #define SCI_STARTRECORD 3001
- #define SCI_STOPRECORD 3002
- #define SCI_SETLEXER 4001
- diff -r 2c003ff12a86 -r 2bfb11c2b9ae include/Scintilla.iface
- --- a/include/Scintilla.iface lun. nov. 07 12:55:32 2011 +1100
- +++ b/include/Scintilla.iface ven. nov. 11 22:37:45 2011 +0100
- @@ -2205,6 +2205,9 @@
- # Create an ILoader*.
- fun int CreateLoader=2632(int bytes,)
- +# Clear Change Margin
- +fun void ClearChangeMargin=2633(,)
- +
- # Start notifying the container of all key presses and commands.
- fun void StartRecord=3001(,)
- diff -r 2c003ff12a86 -r 2bfb11c2b9ae src/CellBuffer.cxx
- --- a/src/CellBuffer.cxx lun. nov. 07 12:55:32 2011 +1100
- +++ b/src/CellBuffer.cxx ven. nov. 11 22:37:45 2011 +0100
- @@ -1,8 +1,10 @@
- // Scintilla source code edit control
- +// -*- coding: utf-8 -*-
- /** @file CellBuffer.cxx
- ** Manages a buffer of cells.
- **/
- -// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
- +// Copyright 1998-2011 by Neil Hodgson <neilh@scintilla.org>
- +// 2011 : Add Line Change Margin by Jérôme LAFORGE <jerome.laforge@gmail.com>
- // The License.txt file describes the conditions under which this software may be distributed.
- #include <stdio.h>
- @@ -21,6 +23,227 @@
- using namespace Scintilla;
- #endif
- +ChangeUndo::ChangeUndo() {
- + lineChangeUndo = NULL;
- + line = -1;
- + isFrozen = false;
- +}
- +
- +ChangeUndo::~ChangeUndo() {
- + Destroy();
- +}
- +
- +void ChangeUndo::Create(int line) {
- + Destroy();
- + this->line = line;
- +}
- +
- +void ChangeUndo::Freeze() {
- + isFrozen = true;
- +}
- +
- +void ChangeUndo::Update(LineChangeStatus status) {
- + if (isFrozen || line == -1) return;
- +
- + if (lineChangeUndo == NULL)
- + lineChangeUndo = new std::vector<LineChangeStatus>();
- + lineChangeUndo->push_back(status);
- +}
- +
- +void ChangeUndo::Destroy() {
- + if (lineChangeUndo != NULL) {
- + delete lineChangeUndo;
- + lineChangeUndo = NULL;
- + }
- + line = -1;
- + isFrozen = false;
- +}
- +
- +void ChangeMargin::SetNeedRedraw(int line, typeOfAction type) {
- + //needRedraw = lineChange[line]->current == lineChange[line]->atSavePoint ||
- + // lineChange[line]->current == lineChange[line]->atSavePoint + (type == modifyOrRedo) ? 1 : -1; // perform redraw only if needed.
- + // For debuging, force to redraw.
- + needRedraw = true;
- +}
- +
- +bool ChangeMargin::IsEnabled() const {
- + return isEnable;
- +}
- +
- +void ChangeMargin::SetEnabled(bool isEnable) {
- + if (isEnable)
- + Init();
- + else
- + Destroy();
- +}
- +
- +void ChangeMargin::Init() {
- + if (isEnable) return;
- + isEnable = true;
- + needRedraw = false;
- + // FIXME: When the empty file. Normally, lineChange[0].current have to be set to 1 (not 0).
- + // Ensure at least one empty line.
- + lineChange.EnsureLength(1);
- + lineChange[0] = new LineChangeStatus();
- + changeUndos.resize(100);
- +}
- +
- +void ChangeMargin::Destroy() {
- + if (!isEnable) return;
- + for (int i = 0; i < lineChange.Length(); i++)
- + delete lineChange[i];
- + lineChange.DeleteAll();
- + ClearAllChangeUndo();
- + isEnable = false;
- +}
- +
- +void ChangeMargin::InsertLine(int line, bool isRedoOrUndoStep, int undoAction, bool lineStart) {
- + if (!isEnable) return;
- +
- + if ((line > 0) && lineStart)
- + line--;
- +
- + LineChangeStatus *status = new LineChangeStatus(1);
- +
- + if (undoAction > 0) {
- + if (!isRedoOrUndoStep)
- + undoAction--;
- + int undoneLines = changeUndos[undoAction].line;
- + if (changeUndos[undoAction].lineChangeUndo != NULL && (changeUndos[undoAction].lineChangeUndo->size() <= static_cast<size_t> (line - undoneLines)))
- + line--;// Try to fix the line number.
- + if (undoneLines != -1 && changeUndos[undoAction].lineChangeUndo != NULL) {
- + status->atSavePoint = (*changeUndos[undoAction].lineChangeUndo)[line - undoneLines].atSavePoint;
- + status->current = (*changeUndos[undoAction].lineChangeUndo)[line - undoneLines].current;
- + }
- + }
- +
- + lineChange.Insert(line, status);
- +}
- +
- +void ChangeMargin::RemoveLine(int line, bool isRedoOrUndoStep, int undoAction) {
- + if (!isEnable) return;
- +
- + if (undoAction > 0) {
- + if (!isRedoOrUndoStep)
- + undoAction--;
- + changeUndos[undoAction].Update(*(lineChange[line]));
- + }
- +
- + if (lineChange.Length() && (line < lineChange.Length())) {
- + delete lineChange[line];
- + lineChange.Delete(line);
- + }
- +}
- +
- +void ChangeMargin::Modify(int line) {
- + if (!isEnable) return;
- +
- + if (lineChange[line]->current < lineChange[line]->atSavePoint){
- + lineChange[line]->current = LineChangeStatus::sticky; // Impossible to come back to orginal, so the status is sticked.
- + } else if (lineChange[line]->current != LineChangeStatus::sticky) {
- + lineChange[line]->current += 1;
- + SetNeedRedraw(line, modifyOrRedo);
- + }
- +}
- +
- +void ChangeMargin::PerformUndoStep(int line) {
- + if (!isEnable ||
- + lineChange[line]->current == 0 ||
- + lineChange[line]->current == LineChangeStatus::sticky)
- + return;
- +
- + lineChange[line]->current -= 1;
- + SetNeedRedraw(line, undo);
- +}
- +
- +void ChangeMargin::PerformRedoStep(int line, bool ignorePreviousUpdate) {
- + if (!isEnable || lineChange[line]->current >= LineChangeStatus::sticky - 1)
- + return;
- +
- + if (!ignorePreviousUpdate)
- + lineChange[line]->current += 1;
- + else
- + lineChange[line]->current = 1;
- + SetNeedRedraw(line, modifyOrRedo);
- +}
- +
- +void ChangeMargin::ReachSavePoint() {
- + if (!isEnable) return;
- + for (int i = 0; i < lineChange.Length(); i++) {
- + if (lineChange[i]->current != lineChange[i]->atSavePoint) {
- + if (lineChange[i]->current != LineChangeStatus::sticky) {
- + if (lineChange[i]->current == 0)
- + lineChange[i]->current += 1; //undo all changes and save it, but this line still change. Otherwise, this line appears like unmodify.
- + lineChange[i]->atSavePoint = lineChange[i]->current;
- + } else {
- + lineChange[i]->current = lineChange[i]->atSavePoint;
- + }
- + needRedraw = true;
- + }
- + }
- +}
- +
- +void ChangeMargin::ClearAll() {
- + if (!isEnable) return;
- + for (int i = 0; i < lineChange.Length(); i++) {
- + if (lineChange[i]->current != 0) {
- + lineChange[i]->current = 0;
- + lineChange[i]->atSavePoint = 0;
- + needRedraw = true;
- + }
- + }
- + ClearAllChangeUndo();
- +}
- +
- +LineChangeStatus ChangeMargin::GetLineChange(int line) const {
- + if (!isEnable) return LineChangeStatus();
- +
- + return *lineChange[line];
- +}
- +
- +ChangeMargin::status ChangeMargin::GetStatus(int line) const {
- + if (!isEnable) return original;
- + LineChangeStatus status = GetLineChange(line);
- + if (status.current < status.atSavePoint)
- + return undone;
- + else if (status.current == 0 && status.atSavePoint == 0)
- + return original;
- + else if (status.current == status.atSavePoint)
- + return saved;
- + else
- + return changed;
- +}
- +
- +bool ChangeMargin::HasChangeOccuredAndClear() {
- + bool b = needRedraw;
- + needRedraw = false;
- + return b;
- +}
- +
- +void ChangeMargin::EnsureUndoRoom(int size) {
- + if (!isEnable) return;
- + if (changeUndos.size() < static_cast<size_t> (size))
- + changeUndos.resize(size);
- +}
- +
- +void ChangeMargin::StoreChangeUndo(int line, int undoAction) {
- + changeUndos[undoAction].Create(line);
- +}
- +
- +void ChangeMargin::FreezeChangeUndo(int undoAction) {
- + changeUndos[undoAction].Freeze();
- +}
- +
- +void ChangeMargin::DestroyChangeUndo(int undoAction) {
- + if (!isEnable) return;
- + changeUndos[undoAction].Destroy();
- +}
- +
- +void ChangeMargin::ClearAllChangeUndo() {
- + if (!isEnable) return;
- + changeUndos.clear();
- +}
- +
- LineVector::LineVector() : starts(256), perLine(0) {
- Init();
- }
- @@ -329,6 +552,14 @@
- currentAction++;
- }
- +int UndoHistory::GetCurrentAction() {
- + return currentAction;
- +}
- +
- +int UndoHistory::GetLengthAction() {
- + return lenActions;
- +}
- +
- CellBuffer::CellBuffer() {
- readOnly = false;
- collectingUndo = true;
- @@ -388,9 +619,27 @@
- data[i] = s[i];
- }
- uh.AppendAction(insertAction, position, data, insertLength, startSequence);
- +
- + if (cm.IsEnabled()) {
- + cm.EnsureUndoRoom(uh.GetLengthAction());
- + cm.StoreChangeUndo(LineFromPosition(position), uh.GetCurrentAction() - 1);
- + cm.DestroyChangeUndo(uh.GetCurrentAction()); // Destroy for startAction.
- + }
- }
- + int previousNbLine = cm.IsEnabled() ? Lines() : -1;
- + bool atLineStart = cm.IsEnabled() ? IsLineStartPosition(position) : false;
- + bool atLineEnd = cm.IsEnabled() ? IsLineEndPosition(position + insertLength - 1) : false;
- +
- BasicInsertString(position, s, insertLength);
- +
- + if (cm.IsEnabled()) {
- + int newNbLine = Lines();
- + if ((!atLineStart && !atLineEnd) || newNbLine == previousNbLine)
- + cm.Modify(LineFromPosition(position));
- + else if (!atLineStart && !atLineEnd && (newNbLine - previousNbLine > 1))
- + cm.Modify(LineFromPosition(position + insertLength));
- + }
- }
- return data;
- }
- @@ -434,9 +683,20 @@
- data[i] = substance.ValueAt(position + i);
- }
- uh.AppendAction(removeAction, position, data, deleteLength, startSequence);
- +
- + if (cm.IsEnabled()) {
- + cm.EnsureUndoRoom(uh.GetLengthAction());
- + cm.StoreChangeUndo(LineFromPosition(position), uh.GetCurrentAction() - 1);
- + }
- }
- + bool atLineStart = cm.IsEnabled() ? IsLineStartPosition(position) : false;
- + bool atLineEnd = cm.IsEnabled() ? IsLineEndPosition(position + deleteLength - 1) : false;
- +
- BasicDeleteChars(position, deleteLength);
- +
- + if (cm.IsEnabled() && (!atLineStart || !atLineEnd))
- + cm.Modify(LineFromPosition(position));
- }
- return data;
- }
- @@ -467,6 +727,27 @@
- return lv.LineStart(line);
- }
- +int CellBuffer::LineEnd(int line) const {
- + if (line == Lines() - 1) {
- + return lv.LineStart(line + 1);
- + } else {
- + int position = lv.LineStart(line + 1) - 1;
- + // When line terminator is CR+LF, may need to go back one more
- + if ((position > lv.LineStart(line)) && (CharAt(position - 1) == '\r')) {
- + position--;
- + }
- + return position;
- + }
- +}
- +
- +bool CellBuffer::IsLineStartPosition(int position) const {
- + return LineStart(LineFromPosition(position)) == position;
- +}
- +
- +bool CellBuffer::IsLineEndPosition(int position) const {
- + return LineEnd(LineFromPosition(position)) == position;
- +}
- +
- bool CellBuffer::IsReadOnly() const {
- return readOnly;
- }
- @@ -477,6 +758,7 @@
- void CellBuffer::SetSavePoint() {
- uh.SetSavePoint();
- + cm.ReachSavePoint();
- }
- bool CellBuffer::IsSavePoint() {
- @@ -487,10 +769,14 @@
- void CellBuffer::InsertLine(int line, int position, bool lineStart) {
- lv.InsertLine(line, position, lineStart);
- + cm.InsertLine(line, uh.GetRedoStep().at != startAction, uh.GetCurrentAction(), lineStart);
- }
- -void CellBuffer::RemoveLine(int line) {
- +void CellBuffer::RemoveLine(int line, bool atLineStart) {
- lv.RemoveLine(line);
- + if (atLineStart)
- + line--;
- + cm.RemoveLine(line, uh.GetRedoStep().at != startAction, uh.GetCurrentAction());
- }
- void CellBuffer::BasicInsertString(int position, const char *s, int insertLength) {
- @@ -501,6 +787,7 @@
- substance.InsertFromArray(position, s, 0, insertLength);
- style.InsertValue(position, insertLength, 0);
- +
- int lineInsert = lv.LineFromPosition(position) + 1;
- bool atLineStart = lv.LineStart(lineInsert-1) == position;
- // Point all the lines after the insertion point further along in the buffer
- @@ -546,11 +833,13 @@
- // If whole buffer is being deleted, faster to reinitialise lines data
- // than to delete each line.
- lv.Init();
- + cm.ClearAll(); // For now, we lost all informations (e.g. status for each line, undo history).
- } else {
- // Have to fix up line positions before doing deletion as looking at text in buffer
- // to work out which lines have been removed
- int lineRemove = lv.LineFromPosition(position) + 1;
- + bool atLineStart = IsLineStartPosition(position);
- lv.InsertText(lineRemove-1, - (deleteLength));
- char chPrev = substance.ValueAt(position - 1);
- char chBefore = chPrev;
- @@ -568,16 +857,15 @@
- chNext = substance.ValueAt(position + i + 1);
- if (ch == '\r') {
- if (chNext != '\n') {
- - RemoveLine(lineRemove);
- + RemoveLine(lineRemove, atLineStart);
- }
- } else if (ch == '\n') {
- if (ignoreNL) {
- ignoreNL = false; // Further \n are real deletions
- } else {
- - RemoveLine(lineRemove);
- + RemoveLine(lineRemove, atLineStart);
- }
- }
- -
- ch = chNext;
- }
- // May have to fix up end if last deletion causes cr to be next to lf
- @@ -585,7 +873,7 @@
- char chAfter = substance.ValueAt(position + deleteLength);
- if (chBefore == '\r' && chAfter == '\n') {
- // Using lineRemove-1 as cr ended line before start of deletion
- - RemoveLine(lineRemove - 1);
- + RemoveLine(lineRemove - 1, atLineStart);
- lv.SetLineStart(lineRemove - 1, position + 1);
- }
- }
- @@ -614,10 +902,17 @@
- void CellBuffer::AddUndoAction(int token, bool mayCoalesce) {
- bool startSequence;
- uh.AppendAction(containerAction, token, 0, 0, startSequence, mayCoalesce);
- +
- + if (cm.IsEnabled()) {
- + cm.EnsureUndoRoom(uh.GetLengthAction());
- + cm.DestroyChangeUndo(uh.GetCurrentAction() - 1);
- + }
- +
- }
- void CellBuffer::DeleteUndoHistory() {
- uh.DeleteUndoHistory();
- + cm.ClearAllChangeUndo();
- }
- bool CellBuffer::CanUndo() {
- @@ -633,12 +928,36 @@
- }
- void CellBuffer::PerformUndoStep() {
- + int previousNbLine = cm.IsEnabled() ? Lines() : -1;
- const Action &actionStep = uh.GetUndoStep();
- if (actionStep.at == insertAction) {
- BasicDeleteChars(actionStep.position, actionStep.lenData);
- } else if (actionStep.at == removeAction) {
- BasicInsertString(actionStep.position, actionStep.data, actionStep.lenData);
- }
- +
- + if (cm.IsEnabled()) {
- + bool atLineStart = IsLineStartPosition(actionStep.position);
- + bool atLineEnd = IsLineEndPosition(actionStep.position);
- + switch (actionStep.at) {
- + case insertAction:
- + if (!atLineStart || !atLineEnd)
- + cm.PerformUndoStep(LineFromPosition(actionStep.position));
- + break;
- + case removeAction: {
- + int newNbLine = Lines();
- + bool atLineEnd = IsLineEndPosition(actionStep.position + actionStep.lenData - 1);
- + if ((!atLineStart && !atLineEnd) || newNbLine == previousNbLine)
- + cm.PerformUndoStep(LineFromPosition(actionStep.position));
- + else if (!atLineStart)
- + cm.PerformUndoStep(LineFromPosition(actionStep.position + actionStep.lenData));
- + }
- + default:
- + //nothing to do.
- + break;
- + }
- + }
- + cm.FreezeChangeUndo(uh.GetCurrentAction());
- uh.CompletedUndoStep();
- }
- @@ -655,12 +974,49 @@
- }
- void CellBuffer::PerformRedoStep() {
- + int previousNbLine = cm.IsEnabled() ? Lines() : -1;
- const Action &actionStep = uh.GetRedoStep();
- if (actionStep.at == insertAction) {
- BasicInsertString(actionStep.position, actionStep.data, actionStep.lenData);
- } else if (actionStep.at == removeAction) {
- BasicDeleteChars(actionStep.position, actionStep.lenData);
- }
- + if (cm.IsEnabled()) {
- + bool atLineStart = IsLineStartPosition(actionStep.position);
- + bool atLineEnd = IsLineEndPosition(actionStep.position + actionStep.lenData - 1);
- + switch (actionStep.at) {
- + case removeAction:
- + if (!atLineStart)
- + cm.PerformRedoStep(LineFromPosition(actionStep.position));
- + break;
- + case insertAction: {
- + int newNbLine = Lines();
- + if ((!atLineStart && !atLineEnd) || newNbLine == previousNbLine)
- + cm.PerformRedoStep(LineFromPosition(actionStep.position));
- + else if (!atLineStart)
- + cm.PerformRedoStep(LineFromPosition(actionStep.position + actionStep.lenData), true);
- + }
- + default:
- + //nothing to do.
- + break;
- + }
- + }
- + cm.FreezeChangeUndo(uh.GetCurrentAction());
- uh.CompletedRedoStep();
- }
- +void CellBuffer::ClearChangeMargin() {
- + cm.ClearAll();
- +}
- +
- +ChangeMargin::status CellBuffer::GetChangeMarginStatus(int line) const {
- + return cm.GetStatus(line);
- +}
- +
- +LineChangeStatus CellBuffer::GetChangeMargin(int line) const {
- + return cm.GetLineChange(line);
- +}
- +
- +bool CellBuffer::HasChangeMarginOccured() {
- + return cm.HasChangeOccuredAndClear();
- +}
- diff -r 2c003ff12a86 -r 2bfb11c2b9ae src/CellBuffer.h
- --- a/src/CellBuffer.h lun. nov. 07 12:55:32 2011 +1100
- +++ b/src/CellBuffer.h ven. nov. 11 22:37:45 2011 +0100
- @@ -1,8 +1,10 @@
- // Scintilla source code edit control
- +// -*- coding: utf-8 -*-
- /** @file CellBuffer.h
- ** Manages the text of the document.
- **/
- -// Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
- +// Copyright 1998-2011 by Neil Hodgson <neilh@scintilla.org>
- +// 2011 : Add Line Change Margin by Jérôme LAFORGE <jerome.laforge@gmail.com>
- // The License.txt file describes the conditions under which this software may be distributed.
- #ifndef CELLBUFFER_H
- @@ -12,6 +14,84 @@
- namespace Scintilla {
- #endif
- +#include <vector>
- +
- +struct LineChangeStatus {
- + unsigned short int atSavePoint;
- + unsigned short int current;
- +
- + enum { noSaved = 0x0000, sticky = 0xFFFF };
- + LineChangeStatus () {
- + atSavePoint = noSaved;
- + current = noSaved;
- + }
- +
- + LineChangeStatus(int current) {
- + atSavePoint = noSaved;
- + this->current = current;
- + }
- +};
- +
- +class ChangeUndo {
- +public:
- + std::vector<LineChangeStatus> *lineChangeUndo;
- + int line;
- + int isFrozen;
- +
- + ChangeUndo();
- + ~ChangeUndo();
- + void Create(int line);
- + void Freeze();
- + void Update(LineChangeStatus status);
- + void Destroy();
- +};
- +
- +class ChangeMargin {
- +private:
- + bool isEnable;
- + bool needRedraw;
- + enum typeOfAction { modifyOrRedo, undo };
- + void SetNeedRedraw(int line, typeOfAction type);
- + SplitVector<LineChangeStatus *> lineChange;
- + std::vector<ChangeUndo> changeUndos;
- +
- +public:
- + enum status { original, changed, saved, undone };
- +
- + ChangeMargin() : isEnable(false) {
- + Init();
- + }
- + ~ChangeMargin() {
- + Destroy();
- + }
- + bool IsEnabled() const;
- + void SetEnabled(bool isEnable);
- + void Init();
- + void Destroy();
- +
- + void InsertLine(int line, bool isRedoOrUndoStep, int undoAction, bool lineStart);
- + void RemoveLine(int line, bool isRedoOrUndoStep, int undoAction);
- +
- + void Modify(int line);
- + void ReachSavePoint();
- + void ClearAll();
- +
- + LineChangeStatus GetLineChange(int line) const;
- + status GetStatus(int line) const;
- + bool HasChangeOccuredAndClear();
- +
- + // For managing the undo/redo.
- + void PerformUndoStep(int line);
- + void PerformRedoStep(int line, bool ignorePrevisousUpdate=false);
- +
- + // For managing the undo stack.
- + void EnsureUndoRoom(int size);
- + void StoreChangeUndo(int line, int undoAction);
- + void FreezeChangeUndo(int undoAction);
- + void DestroyChangeUndo(int undoAction);
- + void ClearAllChangeUndo();
- +};
- +
- // Interface to per-line data that wants to see each line insertion and deletion
- class PerLine {
- public:
- @@ -124,6 +204,8 @@
- int StartRedo();
- const Action &GetRedoStep() const;
- void CompletedRedoStep();
- + int GetCurrentAction();
- + int GetLengthAction();
- };
- /**
- @@ -142,6 +224,8 @@
- LineVector lv;
- + ChangeMargin cm;
- +
- /// Actions without undo
- void BasicInsertString(int position, const char *s, int insertLength);
- void BasicDeleteChars(int position, int deleteLength);
- @@ -163,9 +247,12 @@
- void SetPerLine(PerLine *pl);
- int Lines() const;
- int LineStart(int line) const;
- + int LineEnd(int line) const;
- + bool IsLineStartPosition(int position) const;
- + bool IsLineEndPosition(int position) const;
- int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
- void InsertLine(int line, int position, bool lineStart);
- - void RemoveLine(int line);
- + void RemoveLine(int line, bool lineStart=false);
- const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
- /// Setting styles for positions outside the range of the buffer is safe and has no effect.
- @@ -200,6 +287,11 @@
- int StartRedo();
- const Action &GetRedoStep() const;
- void PerformRedoStep();
- +
- + void ClearChangeMargin();
- + ChangeMargin::status GetChangeMarginStatus(int line) const;
- + LineChangeStatus GetChangeMargin(int line) const;
- + bool HasChangeMarginOccured();
- };
- #ifdef SCI_NAMESPACE
- diff -r 2c003ff12a86 -r 2bfb11c2b9ae src/Document.cxx
- --- a/src/Document.cxx lun. nov. 07 12:55:32 2011 +1100
- +++ b/src/Document.cxx ven. nov. 11 22:37:45 2011 +0100
- @@ -2028,6 +2028,22 @@
- return - 1;
- }
- +void Document::ClearChangeMargin() {
- + return cb.ClearChangeMargin();
- +}
- +
- +ChangeMargin::status Document::GetChangeMarginStatus(int line) {
- + return cb.GetChangeMarginStatus(line);
- +}
- +
- +LineChangeStatus Document::GetChangeMargin(int line) {
- + return cb.GetChangeMargin(line);
- +}
- +
- +bool Document::HasChangeMarginOccured() {
- + return cb.HasChangeMarginOccured();
- +}
- +
- /**
- * Implementation of RegexSearchBase for the default built-in regular expression engine
- */
- diff -r 2c003ff12a86 -r 2bfb11c2b9ae src/Document.h
- --- a/src/Document.h lun. nov. 07 12:55:32 2011 +1100
- +++ b/src/Document.h ven. nov. 11 22:37:45 2011 +0100
- @@ -413,6 +413,11 @@
- int IndentSize() { return actualIndentInChars; }
- int BraceMatch(int position, int maxReStyle);
- + void ClearChangeMargin();
- + ChangeMargin::status GetChangeMarginStatus(int line);
- + LineChangeStatus GetChangeMargin(int line);
- + bool HasChangeMarginOccured();
- +
- private:
- bool IsWordStartAt(int pos);
- bool IsWordEndAt(int pos);
- diff -r 2c003ff12a86 -r 2bfb11c2b9ae src/Editor.cxx
- --- a/src/Editor.cxx lun. nov. 07 12:55:32 2011 +1100
- +++ b/src/Editor.cxx ven. nov. 11 22:37:45 2011 +0100
- @@ -659,6 +659,7 @@
- PRectangle rcClient = GetClientRectangle();
- wMain.InvalidateRectangle(rcClient);
- //wMain.InvalidateAll();
- + pdoc->HasChangeMarginOccured(); // Reset change line.
- }
- void Editor::RedrawSelMargin(int line, bool allAfter) {
- @@ -1936,8 +1937,25 @@
- if (vs.ms[margin].style == SC_MARGIN_NUMBER) {
- char number[100];
- number[0] = '\0';
- - if (firstSubLine)
- - sprintf(number, "%d", lineDoc + 1);
- + if (firstSubLine) {
- + if (true) { // for testing and helping during the developpment process. Have to be removed after.
- + LineChangeStatus lineChange = pdoc->GetChangeMargin(lineDoc);
- + switch (pdoc->GetChangeMarginStatus(lineDoc)) {
- + case ChangeMargin::saved:
- + sprintf(number, "[%4X][%4X]#%d", lineChange.atSavePoint, lineChange.current, lineDoc + 1);
- + break;
- + case ChangeMargin::changed:
- + case ChangeMargin::undone:
- + sprintf(number, "[%4X][%4X]#%d", lineChange.atSavePoint, lineChange.current, lineDoc + 1);
- + break;
- + case ChangeMargin::original:
- + sprintf(number, "[%4X][%4X]-%d", lineChange.atSavePoint, lineChange.current, lineDoc + 1);
- + break;
- + }
- + } else {
- + sprintf(number, "%d", lineDoc + 1);
- + }
- + }
- if (foldFlags & SC_FOLDFLAG_LEVELNUMBERS) {
- int lev = pdoc->GetLevel(lineDoc);
- sprintf(number, "%c%c %03X %03X",
- @@ -1952,9 +1970,23 @@
- int width = surface->WidthText(vs.styles[STYLE_LINENUMBER].font, number, istrlen(number));
- int xpos = rcNumber.right - width - 3;
- rcNumber.left = xpos;
- + ColourDesired fore = vs.styles[STYLE_LINENUMBER].fore;
- + switch (pdoc->GetChangeMarginStatus(lineDoc)) {
- + case ChangeMargin::saved:
- + fore = ColourDesired(0, 255, 0);
- + break;
- + case ChangeMargin::changed:
- + case ChangeMargin::undone:
- + fore = ColourDesired(255, 0, 0);
- + break;
- + case ChangeMargin::original:
- + //do nothing
- + break;
- + }
- surface->DrawTextNoClip(rcNumber, vs.styles[STYLE_LINENUMBER].font,
- rcNumber.top + vs.maxAscent, number, istrlen(number),
- - vs.styles[STYLE_LINENUMBER].fore,
- + fore,
- + //vs.styles[STYLE_LINENUMBER].fore,
- vs.styles[STYLE_LINENUMBER].back);
- } else if (vs.ms[margin].style == SC_MARGIN_TEXT || vs.ms[margin].style == SC_MARGIN_RTEXT) {
- if (firstSubLine) {
- @@ -4088,6 +4120,9 @@
- if (recordingMacro) {
- NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(s));
- }
- +
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- }
- void Editor::InsertPaste(SelectionPosition selStart, const char *text, int len) {
- @@ -4281,6 +4316,8 @@
- if (newPos >= 0)
- SetEmptySelection(newPos);
- EnsureCaretVisible();
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- }
- }
- @@ -4290,6 +4327,8 @@
- if (newPos >= 0)
- SetEmptySelection(newPos);
- EnsureCaretVisible();
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- }
- }
- @@ -4299,6 +4338,9 @@
- }
- // Avoid blinking during rapid typing:
- ShowCaretAtCurrentPosition();
- +
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- }
- void Editor::DelCharBack(bool allowLineStartDeletion) {
- @@ -4344,6 +4386,9 @@
- sel.RemoveDuplicates();
- // Avoid blinking during rapid typing:
- ShowCaretAtCurrentPosition();
- +
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- }
- void Editor::NotifyFocus(bool) {}
- @@ -5013,6 +5058,9 @@
- EnsureCaretVisible();
- // Avoid blinking during rapid typing:
- ShowCaretAtCurrentPosition();
- +
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- }
- void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) {
- @@ -7610,6 +7658,8 @@
- case SCI_SETSAVEPOINT:
- pdoc->SetSavePoint();
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- break;
- case SCI_GETSTYLEDTEXT: {
- @@ -9259,6 +9309,12 @@
- case SCI_GETTECHNOLOGY:
- return technology;
- + case SCI_CLEARCHANGEMARGIN:
- + pdoc->ClearChangeMargin();
- + if (pdoc->HasChangeMarginOccured())
- + RedrawSelMargin();
- + break;
- +
- default:
- return DefWndProc(iMessage, wParam, lParam);
- }
Add Comment
Please, Sign In to add comment