From 7f92464df7a00f4da34c7d06f10d41166688e818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 9 Jan 2023 12:34:58 -0800 Subject: [PATCH 1/5] Change menu items to linkbutton --- data/io.elementary.code.gresource.xml | 5 ++++ src/Widgets/HeaderBar.vala | 42 ++++++++++++++++----------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/data/io.elementary.code.gresource.xml b/data/io.elementary.code.gresource.xml index fbd48b25d0..e36d4dd2cc 100644 --- a/data/io.elementary.code.gresource.xml +++ b/data/io.elementary.code.gresource.xml @@ -22,5 +22,10 @@ icons/SymbolOutline/virtualmethod.svg icons/SymbolOutline/virtualproperty.svg icons/SymbolOutline/plugin-outline-symbolic.svg + icons/panel-bottom-symbolic.svg + icons/panel-left-rtl-symbolic.svg + icons/panel-left-symbolic.svg + icons/panel-right-rtl-symbolic.svg + icons/panel-right-symbolic.svg diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 724b0fc38b..674b2542fe 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -166,25 +166,34 @@ namespace Scratch.Widgets { margin_top = 3 }; - var toggle_sidebar_accellabel = new Granite.AccelLabel.from_action_name ( - _("Toggle Sidebar"), - MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_SIDEBAR + var sidebar_button = new Gtk.ToggleButton () { + action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_SIDEBAR, + image = new Gtk.Image.from_icon_name ("panel-left-symbolic", Gtk.IconSize.MENU) + }; + sidebar_button.tooltip_markup = Granite.markup_accel_tooltip ( + app_instance.get_accels_for_action (sidebar_button.action_name), + _("Toggle Sidebar") ); - var toggle_sidebar_menuitem = new Gtk.ModelButton (); - toggle_sidebar_menuitem.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_SIDEBAR; - toggle_sidebar_menuitem.get_child ().destroy (); - toggle_sidebar_menuitem.add (toggle_sidebar_accellabel); - - var toggle_outline_accellabel = new Granite.AccelLabel.from_action_name ( - _("Toggle Symbol Outline"), - MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_OUTLINE + var outline_button = new Gtk.ToggleButton () { + action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_OUTLINE, + image = new Gtk.Image.from_icon_name ("panel-right-symbolic", Gtk.IconSize.MENU) + }; + outline_button.tooltip_markup = Granite.markup_accel_tooltip ( + app_instance.get_accels_for_action (outline_button.action_name), + _("Toggle Symbol Outline") ); - var toggle_outline_menuitem = new Gtk.ModelButton (); - toggle_outline_menuitem.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_OUTLINE; - toggle_outline_menuitem.get_child ().destroy (); - toggle_outline_menuitem.add (toggle_outline_accellabel); + var panels_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { + homogeneous = true, + margin_top = 6, + margin_end = 12, + margin_bottom = 6, + margin_start = 12 + }; + panels_box.get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED); + panels_box.add (sidebar_button); + panels_box.add (outline_button); var preferences_menuitem = new Gtk.ModelButton (); preferences_menuitem.text = _("Preferences"); @@ -198,9 +207,8 @@ namespace Scratch.Widgets { menu_box.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); menu_box.add (follow_system_switchmodelbutton); menu_box.add (color_revealer); + menu_box.add (panels_box); menu_box.add (menu_separator); - menu_box.add (toggle_sidebar_menuitem); - menu_box.add (toggle_outline_menuitem); menu_box.add (preferences_menuitem); menu_box.show_all (); From 853083b2cd044e34581f01a5d0ed5137c3f5d013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 9 Jan 2023 13:13:25 -0800 Subject: [PATCH 2/5] Lots of actions stuff --- src/MainWindow.vala | 95 +++++++++++++++++++++++++++++--------- src/Widgets/HeaderBar.vala | 14 ++---- 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e986f28f6b..8a7c667806 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -53,7 +53,7 @@ namespace Scratch { // Delegates delegate void HookFunc (); - public SimpleActionGroup actions { get; construct; } + public SimpleActionGroup actions { get; private set; } public const string ACTION_GROUP = "win"; public const string ACTION_PREFIX = ACTION_GROUP + "."; @@ -131,8 +131,8 @@ namespace Scratch { { ACTION_ZOOM_IN, action_zoom_in }, { ACTION_ZOOM_OUT, action_zoom_out}, { ACTION_TOGGLE_COMMENT, action_toggle_comment }, - { ACTION_TOGGLE_SIDEBAR, action_toggle_sidebar }, - { ACTION_TOGGLE_OUTLINE, action_toggle_outline }, + { ACTION_TOGGLE_SIDEBAR, action_toggle_sidebar, null, "true" }, + { ACTION_TOGGLE_OUTLINE, action_toggle_outline, null, "false" }, { ACTION_NEXT_TAB, action_next_tab }, { ACTION_PREVIOUS_TAB, action_previous_tab }, { ACTION_CLEAR_LINES, action_clear_lines }, @@ -209,24 +209,6 @@ namespace Scratch { actions.add_action_entries (ACTION_ENTRIES, this); insert_action_group (ACTION_GROUP, actions); - actions.action_state_changed.connect ((name, new_state) => { - if (name == ACTION_SHOW_FIND) { - if (new_state.get_boolean () == false) { - toolbar.find_button.tooltip_markup = Granite.markup_accel_tooltip ( - app.get_accels_for_action (ACTION_PREFIX + ACTION_FIND), - _("Find…") - ); - } else { - toolbar.find_button.tooltip_markup = Granite.markup_accel_tooltip ( - {"Escape"}, - _("Hide search bar") - ); - } - - search_revealer.set_reveal_child (new_state.get_boolean ()); - } - }); - foreach (var action in action_accelerators.get_keys ()) { var accels_array = action_accelerators[action].to_array (); accels_array += null; @@ -286,10 +268,71 @@ namespace Scratch { // Create folder for unsaved documents create_unsaved_documents_directory (); + actions.action_state_changed.connect ((name, new_state) => { + update_toolbar_button (name, new_state.get_boolean ()); + }); + + var sidebar_action = Utils.action_from_group (ACTION_TOGGLE_SIDEBAR, actions); + sidebar_action.set_state (saved_state.get_boolean ("sidebar-visible")); + update_toolbar_button (ACTION_TOGGLE_SIDEBAR, saved_state.get_boolean ("sidebar-visible")); + + var outline_action = Utils.action_from_group (ACTION_TOGGLE_OUTLINE, actions); + outline_action.set_state (saved_state.get_boolean ("outline-visible")); + update_toolbar_button (ACTION_TOGGLE_OUTLINE, saved_state.get_boolean ("outline-visible")); + Unix.signal_add (Posix.Signal.INT, quit_source_func, Priority.HIGH); Unix.signal_add (Posix.Signal.TERM, quit_source_func, Priority.HIGH); } + private void update_toolbar_button (string name, bool new_state) { + switch (name) { + case ACTION_SHOW_FIND: + if (new_state) { + toolbar.find_button.tooltip_markup = Granite.markup_accel_tooltip ( + {"Escape"}, + _("Hide search bar") + ); + } else { + toolbar.find_button.tooltip_markup = Granite.markup_accel_tooltip ( + app.get_accels_for_action (ACTION_PREFIX + name), + _("Find…") + ); + } + + search_revealer.set_reveal_child (new_state); + + break; + case ACTION_TOGGLE_SIDEBAR: + if (new_state) { + toolbar.sidebar_button.tooltip_markup = Granite.markup_accel_tooltip ( + app.get_accels_for_action (ACTION_PREFIX + name), + _("Hide Projects Sidebar") + ); + } else { + toolbar.sidebar_button.tooltip_markup = Granite.markup_accel_tooltip ( + app.get_accels_for_action (ACTION_PREFIX + name), + _("Show Projects Sidebar") + ); + } + + break; + case ACTION_TOGGLE_OUTLINE: + if (new_state) { + toolbar.outline_button.tooltip_markup = Granite.markup_accel_tooltip ( + app.get_accels_for_action (ACTION_PREFIX + name), + _("Hide Symbol Outline") + ); + } else { + toolbar.outline_button.tooltip_markup = Granite.markup_accel_tooltip ( + app.get_accels_for_action (ACTION_PREFIX + name), + _("Show Symbol Outline") + ); + } + + break; + }; + } + private void init_layout () { toolbar = new Scratch.Widgets.HeaderBar (); toolbar.title = title; @@ -1054,11 +1097,17 @@ namespace Scratch { return; } - sidebar.visible = !sidebar.visible; + var sidebar_action = Utils.action_from_group (ACTION_TOGGLE_SIDEBAR, actions); + sidebar_action.set_state (!sidebar_action.get_state ().get_boolean ()); + + sidebar.visible = sidebar_action.get_state ().get_boolean (); } private void action_toggle_outline () { - document_view.outline_visible = !document_view.outline_visible; + var outline_action = Utils.action_from_group (ACTION_TOGGLE_OUTLINE, actions); + outline_action.set_state (!outline_action.get_state ().get_boolean ()); + + document_view.outline_visible = outline_action.get_state ().get_boolean (); } private void action_next_tab () { diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 674b2542fe..43b9d6da9a 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -25,6 +25,8 @@ namespace Scratch.Widgets { public Gtk.MenuButton share_app_menu; public Gtk.MenuButton app_menu; public Gtk.ToggleButton find_button; + public Gtk.ToggleButton outline_button; + public Gtk.ToggleButton sidebar_button; public Gtk.Button templates_button; public Code.FormatBar format_bar; public Code.ChooseProjectButton choose_project_button; @@ -166,23 +168,15 @@ namespace Scratch.Widgets { margin_top = 3 }; - var sidebar_button = new Gtk.ToggleButton () { + sidebar_button = new Gtk.ToggleButton () { action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_SIDEBAR, image = new Gtk.Image.from_icon_name ("panel-left-symbolic", Gtk.IconSize.MENU) }; - sidebar_button.tooltip_markup = Granite.markup_accel_tooltip ( - app_instance.get_accels_for_action (sidebar_button.action_name), - _("Toggle Sidebar") - ); - var outline_button = new Gtk.ToggleButton () { + outline_button = new Gtk.ToggleButton () { action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_OUTLINE, image = new Gtk.Image.from_icon_name ("panel-right-symbolic", Gtk.IconSize.MENU) }; - outline_button.tooltip_markup = Granite.markup_accel_tooltip ( - app_instance.get_accels_for_action (outline_button.action_name), - _("Toggle Symbol Outline") - ); var panels_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { homogeneous = true, From 2b87f03b6b5151916bd9b9abf4fdcedfbb170937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 9 Jan 2023 13:13:45 -0800 Subject: [PATCH 3/5] Add icons --- data/icons/panel-bottom-symbolic.svg | 16 ++++++++++++++++ data/icons/panel-left-rtl-symbolic.svg | 16 ++++++++++++++++ data/icons/panel-left-symbolic.svg | 16 ++++++++++++++++ data/icons/panel-right-rtl-symbolic.svg | 16 ++++++++++++++++ data/icons/panel-right-symbolic.svg | 16 ++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 data/icons/panel-bottom-symbolic.svg create mode 100644 data/icons/panel-left-rtl-symbolic.svg create mode 100644 data/icons/panel-left-symbolic.svg create mode 100644 data/icons/panel-right-rtl-symbolic.svg create mode 100644 data/icons/panel-right-symbolic.svg diff --git a/data/icons/panel-bottom-symbolic.svg b/data/icons/panel-bottom-symbolic.svg new file mode 100644 index 0000000000..7362d82bd3 --- /dev/null +++ b/data/icons/panel-bottom-symbolic.svg @@ -0,0 +1,16 @@ + + diff --git a/data/icons/panel-left-rtl-symbolic.svg b/data/icons/panel-left-rtl-symbolic.svg new file mode 100644 index 0000000000..18e7a4cfdf --- /dev/null +++ b/data/icons/panel-left-rtl-symbolic.svg @@ -0,0 +1,16 @@ + + diff --git a/data/icons/panel-left-symbolic.svg b/data/icons/panel-left-symbolic.svg new file mode 100644 index 0000000000..11dfe83236 --- /dev/null +++ b/data/icons/panel-left-symbolic.svg @@ -0,0 +1,16 @@ + + diff --git a/data/icons/panel-right-rtl-symbolic.svg b/data/icons/panel-right-rtl-symbolic.svg new file mode 100644 index 0000000000..f11aaae9a0 --- /dev/null +++ b/data/icons/panel-right-rtl-symbolic.svg @@ -0,0 +1,16 @@ + + diff --git a/data/icons/panel-right-symbolic.svg b/data/icons/panel-right-symbolic.svg new file mode 100644 index 0000000000..ac8d3d62c3 --- /dev/null +++ b/data/icons/panel-right-symbolic.svg @@ -0,0 +1,16 @@ + + From a1e43079c7968f29a15d022507787e3f97ae344a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 9 Jan 2023 13:15:06 -0800 Subject: [PATCH 4/5] revert unnecessary change --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 8a7c667806..b443e303f4 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -53,7 +53,7 @@ namespace Scratch { // Delegates delegate void HookFunc (); - public SimpleActionGroup actions { get; private set; } + public SimpleActionGroup actions { get; construct; } public const string ACTION_GROUP = "win"; public const string ACTION_PREFIX = ACTION_GROUP + "."; From b8673245ee470a6fc57df66d9f7ef2584b8a128b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 12 Jan 2023 13:29:34 -0800 Subject: [PATCH 5/5] Get action from method args --- src/MainWindow.vala | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3f193c46b8..2c0f378308 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -1101,22 +1101,18 @@ namespace Scratch { doc.source_view.sort_selected_lines (); } - private void action_toggle_sidebar () { + private void action_toggle_sidebar (SimpleAction action) { if (sidebar == null) { return; } - var sidebar_action = Utils.action_from_group (ACTION_TOGGLE_SIDEBAR, actions); - sidebar_action.set_state (!sidebar_action.get_state ().get_boolean ()); - - sidebar.visible = sidebar_action.get_state ().get_boolean (); + action.set_state (!action.get_state ().get_boolean ()); + sidebar.visible = action.get_state ().get_boolean (); } - private void action_toggle_outline () { - var outline_action = Utils.action_from_group (ACTION_TOGGLE_OUTLINE, actions); - outline_action.set_state (!outline_action.get_state ().get_boolean ()); - - document_view.outline_visible = outline_action.get_state ().get_boolean (); + private void action_toggle_outline (SimpleAction action) { + action.set_state (!action.get_state ().get_boolean ()); + document_view.outline_visible = action.get_state ().get_boolean (); } private void action_next_tab () {