diff --git a/src/mainframe.cpp b/src/mainframe.cpp index 24296c6..15589b7 100644 --- a/src/mainframe.cpp +++ b/src/mainframe.cpp @@ -1899,6 +1899,38 @@ ui::MenuItem create_file_menu() return file_menu_item; } +ui::MenuItem undobutton{ui::null}; +void +Undo_SetButtonlabel(const char *title) +{ + StringOutputStream name(128); + name << "Undo ("<< title << ")"; + gtk_menu_item_set_label(undobutton, name.c_str()); + gtk_widget_set_sensitive(undobutton, true); +} +void +Undo_DisableButton(void) +{ + gtk_menu_item_set_label(undobutton, "Undo"); + gtk_widget_set_sensitive(undobutton, false); +} + +ui::MenuItem redobutton{ui::null}; +void +Redo_SetButtonlabel(const char *title) +{ + StringOutputStream name(128); + name << "Redo (" << title << ")"; + gtk_menu_item_set_label(redobutton, name.c_str()); + gtk_widget_set_sensitive(redobutton, true); +} +void +Redo_DisableButton(void) +{ + gtk_menu_item_set_label(redobutton, "Redo"); + gtk_widget_set_sensitive(redobutton, false); +} + ui::MenuItem create_edit_menu() { // Edit menu @@ -1907,8 +1939,10 @@ ui::MenuItem create_edit_menu() /*if (g_Layout_enableOpenStepUX.m_value) { menu_tearoff(menu); }*/ - create_menu_item_with_mnemonic(menu, "_Undo", "Undo"); - create_menu_item_with_mnemonic(menu, "_Redo", "Redo"); + undobutton = create_menu_item_with_mnemonic(menu, "_Undo", "Undo"); + redobutton = create_menu_item_with_mnemonic(menu, "_Redo", "Redo"); + gtk_menu_item_set_label(undobutton, "Undo (Nothing...)"); + gtk_menu_item_set_label(redobutton, "Redo (Nothing...)"); menu_separator(menu); create_menu_item_with_mnemonic(menu, "_Copy", "Copy"); create_menu_item_with_mnemonic(menu, "_Paste", "Paste"); diff --git a/src/undo.cpp b/src/undo.cpp index c2f00ae..364edd2 100644 --- a/src/undo.cpp +++ b/src/undo.cpp @@ -37,6 +37,12 @@ #include "timer.h" +void Undo_SetButtonlabel(const char *title); +void Undo_DisableButton(void); + +void Redo_SetButtonlabel(const char *title); +void Redo_DisableButton(void); + class DebugScopeTimer { Timer m_timer; const char *m_operation; @@ -363,6 +369,8 @@ void finish(const char *command) { if (finishUndo(command)) { globalOutputStream() << command << '\n'; + Undo_SetButtonlabel(command); + Redo_DisableButton(); } } @@ -373,12 +381,19 @@ void undo() } else { Operation *operation = m_undo_stack.back(); globalOutputStream() << "Undo: " << operation->m_command.c_str() << "\n"; + Redo_SetButtonlabel(operation->m_command.c_str()); startRedo(); trackersUndo(); operation->m_snapshot.restore(); finishRedo(operation->m_command.c_str()); m_undo_stack.pop_back(); + + Operation *operation2 = m_undo_stack.back(); + if (operation2) { + Undo_SetButtonlabel(operation2->m_command.c_str()); + } else + Undo_DisableButton(); } } @@ -395,6 +410,14 @@ void redo() operation->m_snapshot.restore(); finishUndo(operation->m_command.c_str()); m_redo_stack.pop_back(); + Operation *operationu = m_undo_stack.back(); + Undo_SetButtonlabel(operationu->m_command.c_str()); + + Operation *next = m_redo_stack.back(); + if (!next) + Redo_DisableButton(); + else + Redo_SetButtonlabel(next->m_command.c_str()); } }