Undo/Redo will now label the menu item with the last respective action.

This commit is contained in:
Marco Cawthorne 2021-10-31 23:15:41 +01:00
parent 7d04f846c6
commit 6a9f283c64
Signed by: eukara
GPG key ID: C196CD8BA993248A
2 changed files with 59 additions and 2 deletions

View file

@ -1899,6 +1899,38 @@ ui::MenuItem create_file_menu()
return file_menu_item; 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() ui::MenuItem create_edit_menu()
{ {
// Edit menu // Edit menu
@ -1907,8 +1939,10 @@ ui::MenuItem create_edit_menu()
/*if (g_Layout_enableOpenStepUX.m_value) { /*if (g_Layout_enableOpenStepUX.m_value) {
menu_tearoff(menu); menu_tearoff(menu);
}*/ }*/
create_menu_item_with_mnemonic(menu, "_Undo", "Undo"); undobutton = create_menu_item_with_mnemonic(menu, "_Undo", "Undo");
create_menu_item_with_mnemonic(menu, "_Redo", "Redo"); 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); menu_separator(menu);
create_menu_item_with_mnemonic(menu, "_Copy", "Copy"); create_menu_item_with_mnemonic(menu, "_Copy", "Copy");
create_menu_item_with_mnemonic(menu, "_Paste", "Paste"); create_menu_item_with_mnemonic(menu, "_Paste", "Paste");

View file

@ -37,6 +37,12 @@
#include "timer.h" #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 { class DebugScopeTimer {
Timer m_timer; Timer m_timer;
const char *m_operation; const char *m_operation;
@ -363,6 +369,8 @@ void finish(const char *command)
{ {
if (finishUndo(command)) { if (finishUndo(command)) {
globalOutputStream() << command << '\n'; globalOutputStream() << command << '\n';
Undo_SetButtonlabel(command);
Redo_DisableButton();
} }
} }
@ -373,12 +381,19 @@ void undo()
} else { } else {
Operation *operation = m_undo_stack.back(); Operation *operation = m_undo_stack.back();
globalOutputStream() << "Undo: " << operation->m_command.c_str() << "\n"; globalOutputStream() << "Undo: " << operation->m_command.c_str() << "\n";
Redo_SetButtonlabel(operation->m_command.c_str());
startRedo(); startRedo();
trackersUndo(); trackersUndo();
operation->m_snapshot.restore(); operation->m_snapshot.restore();
finishRedo(operation->m_command.c_str()); finishRedo(operation->m_command.c_str());
m_undo_stack.pop_back(); 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(); operation->m_snapshot.restore();
finishUndo(operation->m_command.c_str()); finishUndo(operation->m_command.c_str());
m_redo_stack.pop_back(); 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());
} }
} }