diff options
| -rw-r--r-- | FL/Fl_Text_Buffer.H | 18 | ||||
| -rw-r--r-- | src/Fl_Text_Buffer.cxx | 24 | ||||
| -rw-r--r-- | src/Fl_Text_Display.cxx | 2 |
3 files changed, 40 insertions, 4 deletions
diff --git a/FL/Fl_Text_Buffer.H b/FL/Fl_Text_Buffer.H index dabe5677a..4a0d0034b 100644 --- a/FL/Fl_Text_Buffer.H +++ b/FL/Fl_Text_Buffer.H @@ -328,12 +328,28 @@ public: int undo(int *cp=0); /** + Check if undo is anabled and if the last action can be undone. + \see canUndo() + */ + bool can_undo(); + + /** Redo previous undo action. */ int redo(int *cp=0); /** - Lets the undo system know if we can undo changes + Check if undo is anabled and if the last undo action can be redone. + \see canUndo() + */ + bool can_redo(); + + /** + Enable or disable undo actions for this text buffer. + Undo actions are enable for text buffer by default. If used as a style buffer + in Fl_Text_Display, undo actions are disabled as they are handled by the + text buffer. + \see can_undo() */ void canUndo(char flag=1); diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index e6eb70c55..2cfe6f1e3 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -158,6 +158,10 @@ public: clear(); } + int size() { + return list_size_; + } + void push(Fl_Text_Undo_Action* action) { if (list_size_ == list_capacity_) { list_capacity_ += 25; @@ -628,6 +632,13 @@ int Fl_Text_Buffer::undo(int *cursorPos) { return ret; } +/* + Check if undo is anabled and if the last action can be undone. + */ +bool Fl_Text_Buffer::can_undo() { + return (mCanUndo && mUndo && !mUndo->empty()); +} + /** Redo previous undo action. */ @@ -642,7 +653,18 @@ int Fl_Text_Buffer::redo(int *cursorPos) { // running the redo action will also generate a new undo action // Note: there is a slight chance that the current undo action and the // generated action merge into one. - return apply_undo(redo_action, cursorPos); + int ret = apply_undo(redo_action, cursorPos); + + delete redo_action; + return ret; +} + +/** + Check if undo is anabled and if the last undo action can be redone. + \see canUndo() + */ +bool Fl_Text_Buffer::can_redo() { + return (mCanUndo && mRedoList->size()); } /* diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index c49434c79..029d7fef9 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -442,8 +442,6 @@ void Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer, damage(FL_DAMAGE_EXPOSE); } - - /** \brief Find the longest line of all visible lines. |
