summaryrefslogtreecommitdiff
path: root/DevTools
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-21 17:19:27 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-21 17:21:28 +0200
commit705cee528a803b1671d16eeaf222d3318708500b (patch)
treea80dc8135ed1a15fddd4c26c0e52fd2c241820e7 /DevTools
parent1032ae014053ccf5482b78465f02554165212ba9 (diff)
downloadserenity-705cee528a803b1671d16eeaf222d3318708500b.zip
LibGUI: Make it easier to create checkable GUI::Actions
This patch adds GUI::Action::create_checkable() helpers that work just like the existing create() helpers, but the actions become checkable(!) Clients are no longer required to manage the checked state of their actions manually, but instead they will be checked/unchecked as needed by GUI::Action itself before the activation hook is fired.
Diffstat (limited to 'DevTools')
-rw-r--r--DevTools/HackStudio/main.cpp6
-rw-r--r--DevTools/ProfileViewer/main.cpp8
2 files changed, 4 insertions, 10 deletions
diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp
index 0edabf04cf..372886a161 100644
--- a/DevTools/HackStudio/main.cpp
+++ b/DevTools/HackStudio/main.cpp
@@ -274,10 +274,9 @@ int main(int argc, char** argv)
GUI::ActionGroup tool_actions;
tool_actions.set_exclusive(true);
- auto cursor_tool_action = GUI::Action::create("Cursor", Gfx::Bitmap::load_from_file("/res/icons/widgets/Cursor.png"), [&](auto&) {
+ auto cursor_tool_action = GUI::Action::create_checkable("Cursor", Gfx::Bitmap::load_from_file("/res/icons/widgets/Cursor.png"), [&](auto&) {
g_form_editor_widget->set_tool(make<CursorTool>(*g_form_editor_widget));
});
- cursor_tool_action->set_checkable(true);
cursor_tool_action->set_checked(true);
tool_actions.add_action(cursor_tool_action);
@@ -285,14 +284,13 @@ int main(int argc, char** argv)
GUI::WidgetClassRegistration::for_each([&](const GUI::WidgetClassRegistration& reg) {
auto icon_path = String::format("/res/icons/widgets/G%s.png", reg.class_name().characters());
- auto action = GUI::Action::create(reg.class_name(), Gfx::Bitmap::load_from_file(icon_path), [&reg](auto&) {
+ auto action = GUI::Action::create_checkable(reg.class_name(), Gfx::Bitmap::load_from_file(icon_path), [&reg](auto&) {
g_form_editor_widget->set_tool(make<WidgetTool>(*g_form_editor_widget, reg));
auto widget = reg.construct();
g_form_editor_widget->form_widget().add_child(widget);
widget->set_relative_rect(30, 30, 30, 30);
g_form_editor_widget->model().update();
});
- action->set_checkable(true);
action->set_checked(false);
tool_actions.add_action(action);
form_widgets_toolbar.add_action(move(action));
diff --git a/DevTools/ProfileViewer/main.cpp b/DevTools/ProfileViewer/main.cpp
index 325f3dfad9..193e52173b 100644
--- a/DevTools/ProfileViewer/main.cpp
+++ b/DevTools/ProfileViewer/main.cpp
@@ -85,21 +85,17 @@ int main(int argc, char** argv)
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); }));
auto& view_menu = menubar->add_menu("View");
- auto invert_action = GUI::Action::create("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) {
- action.set_checked(!action.is_checked());
+ auto invert_action = GUI::Action::create_checkable("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) {
profile->set_inverted(action.is_checked());
});
- invert_action->set_checkable(true);
invert_action->set_checked(false);
view_menu.add_action(invert_action);
- auto percent_action = GUI::Action::create("Show percentages", { Mod_Ctrl, Key_P }, [&](auto& action) {
- action.set_checked(!action.is_checked());
+ auto percent_action = GUI::Action::create_checkable("Show percentages", { Mod_Ctrl, Key_P }, [&](auto& action) {
profile->set_show_percentages(action.is_checked());
tree_view.update();
disassembly_view.update();
});
- percent_action->set_checkable(true);
percent_action->set_checked(false);
view_menu.add_action(percent_action);