From d3712460e89331f71b66d03d0fab346c8de73617 Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Wed, 22 Jun 2022 22:37:58 -0400 Subject: [PATCH] feat: add clear button to console panel --- CHANGES.md | 1 + data/en.mse-locale/locale | 21 ++++++++++++---- resource/tool/clear_console.png | Bin 0 -> 384 bytes resource/win32_res.rc | 2 ++ src/gui/set/console_panel.cpp | 43 ++++++++++++++++++++++++++------ src/gui/set/console_panel.hpp | 7 ++++-- src/util/window_id.hpp | 3 ++- 7 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 resource/tool/clear_console.png diff --git a/CHANGES.md b/CHANGES.md index 40e7e11f..73400588 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Features: * Add Button to Center the loaded image in the Image Slice Window. * Add "Created At", "Last Modified At" columns to card list. * Add filter box to Game and Stylesheet selection. + * Add Clear button to console panel. ------------------------------------------------------------------------------ HEAD: new items added as changes are made diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index 20227ec2..cf3f8a41 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -80,7 +80,10 @@ menu: stack: &Stacked Bars 3 scatter: S&catter Plot 4 scatter pie: Sc&atter-Pie 5 - + + console: Console + clear console: &Clear Console Ctrl+L + window: &Window new window: &New Window cards tab: &Cards Alt+1 @@ -196,7 +199,10 @@ help: stack: A bar graph with stacked bars scatter: A scatter plot, the size indicates the number of cards scatter pie: A scatter plot where each item is a small pie graph - + + #console: + clear console: Clear the console + #window: new window: Creates another window to edit the same set cards tab: Edit the cards in the set @@ -351,7 +357,9 @@ tool: curve segment: Curve free point: Free smooth point: Smooth - symmetric point: Symmetric + symmetric point: Symmetric + + clear console: Clear Console ############################################################## Toolbar help text tooltip: @@ -426,7 +434,9 @@ tooltip: curve segment: To curve free point: Unlock point smooth point: Make point smooth - symmetric point: Make point symmetric + symmetric point: Make point symmetric + + clear console: Clear Console ############################################################## Labels in the GUI label: @@ -582,7 +592,8 @@ button: add custom pack: Add &Custom Pack... # Console panel - evaluate: &Evaluate + evaluate: &Evaluate + clear: &Clear # Welcome new set: New set diff --git a/resource/tool/clear_console.png b/resource/tool/clear_console.png new file mode 100644 index 0000000000000000000000000000000000000000..e05eea8eef56e652b639f9268aaf0403e6541faf GIT binary patch literal 384 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFY3CLkD@$_|Nf5axmU?4eX;u)az z3~`<=jv*Y^RnJ`HJYc}VazVR4oMp<|a! zXHWZLrnuHod8)DD9Um#as_*k8s#)gUnZUVXw|8Pruh*Wi^oKQ5D?Ly0&&g(#KWNJP z)n4cX$R^bi*NBpo#FA92(type,text,joined_to_previous)); + } + + void clear_console() { + messages.clear(); + layout_all(); + selection = messages.size(); + update_scrollbar(); + Refresh(false); } bool have_selection() const { @@ -455,6 +463,7 @@ END_EVENT_TABLE() ConsolePanel::ConsolePanel(Window* parent, int id) : SetWindowPanel(parent, id) + , menuConsole(nullptr) , messages(nullptr) , entry(nullptr) , is_active_window(false) @@ -466,11 +475,13 @@ ConsolePanel::ConsolePanel(Window* parent, int id) messages = new MessageCtrl(splitter, ID_MESSAGE_LIST); entry_panel = new wxPanel(splitter, wxID_ANY); entry = new HistoryTextCtrl(entry_panel, wxID_ANY); - wxButton* evaluate = new wxButton(entry_panel, ID_EVALUATE, _BUTTON_("evaluate")); + wxButton* evaluate = new wxButton(entry_panel, ID_EVALUATE, _BUTTON_("evaluate")); + wxButton* clear = new wxButton(entry_panel, ID_CLEAR_CONSOLE, _BUTTON_("clear")); // init sizer for entry_panel wxSizer* se = new wxBoxSizer(wxHORIZONTAL); se->Add(entry, 1, wxEXPAND, 2); - se->Add(evaluate, 0, wxEXPAND | wxLEFT, 2); + se->Add(evaluate, 0, wxEXPAND | wxLEFT, 2); + se->Add(clear, 0, wxEXPAND | wxLEFT, 2); entry_panel->SetSizer(se); // init splitter splitter->SetMinimumPaneSize(40); @@ -480,7 +491,15 @@ ConsolePanel::ConsolePanel(Window* parent, int id) wxSizer* s = new wxBoxSizer(wxVERTICAL); s->Add(splitter, 1, wxEXPAND); s->SetSizeHints(this); - SetSizer(s); + SetSizer(s); + + // init menus + menuConsole = new wxMenu(); + add_menu_item_tr(menuConsole, ID_CLEAR_CONSOLE, "clear_console", "clear console"); +} + +ConsolePanel::~ConsolePanel() { + delete menuConsole; } void ConsolePanel::onChangeSet() { @@ -500,13 +519,20 @@ void ConsolePanel::initUI(wxToolBar* tb, wxMenuBar* mb) { // stop blinker is_active_window = true; - stop_blinker(); + stop_blinker(); + + add_tool_tr(tb, ID_CLEAR_CONSOLE, "clear_console", "clear console"); + tb->Realize(); + + mb->Insert(2, menuConsole, _MENU_("console")); } void ConsolePanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) { - // Toolbar - // Menus - + // Toolbar + tb->DeleteTool(ID_CLEAR_CONSOLE); + // Menus + mb->Remove(2); + // we are no longer active, allow blinker is_active_window = false; } @@ -524,6 +550,9 @@ void ConsolePanel::onCommand(int id) { if (id == ID_EVALUATE) { exec(entry->get_command_and_clear()); } + else if (id == ID_CLEAR_CONSOLE) { + messages->clear_console(); + } } void ConsolePanel::onIdle(wxIdleEvent&) { diff --git a/src/gui/set/console_panel.hpp b/src/gui/set/console_panel.hpp index 4289d0ae..be6322e1 100644 --- a/src/gui/set/console_panel.hpp +++ b/src/gui/set/console_panel.hpp @@ -19,7 +19,8 @@ class HistoryTextCtrl; class ConsolePanel : public SetWindowPanel { public: - ConsolePanel(Window* parent, int id); + ConsolePanel(Window* parent, int id); + ~ConsolePanel(); // --------------------------------------------------- : UI @@ -48,7 +49,9 @@ private: wxSplitterWindow* splitter; MessageCtrl* messages; wxPanel* entry_panel; - HistoryTextCtrl* entry; + HistoryTextCtrl* entry; + + wxMenu* menuConsole; void get_pending_errors(); void exec(String const& code); diff --git a/src/util/window_id.hpp b/src/util/window_id.hpp index 96b5cfcf..2ec455f4 100644 --- a/src/util/window_id.hpp +++ b/src/util/window_id.hpp @@ -208,7 +208,8 @@ enum ChildMenuID { ID_CUSTOM_PACK, // Console panel - ID_EVALUATE, + ID_EVALUATE, + ID_CLEAR_CONSOLE, // SymbolFont (Format menu) ID_INSERT_SYMBOL_MENU_MIN = 9001,