Skip to content

Commit

Permalink
Change panel menu items to linkbutton (elementary#1223)
Browse files Browse the repository at this point in the history
* Change menu items to linkbutton

* Lots of actions stuff

* Add icons

* revert unnecessary change

* Get action from method args

Co-authored-by: Jeremy Wootten <[email protected]>
  • Loading branch information
danirabbit and Jeremy Wootten authored Jan 13, 2023
1 parent 2c2e583 commit 3eb601c
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 43 deletions.
16 changes: 16 additions & 0 deletions data/icons/panel-bottom-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions data/icons/panel-left-rtl-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions data/icons/panel-left-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions data/icons/panel-right-rtl-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions data/icons/panel-right-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions data/io.elementary.code.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
<file alias="lang-property-virtual.svg" compressed="true" preprocess="xml-stripblanks">icons/SymbolOutline/virtualproperty.svg</file>
<file alias="plugin-outline-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/SymbolOutline/plugin-outline-symbolic.svg</file>
<file alias="scalable/actions/edit-find-on-page-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/find-on-page-symbolic.svg</file>
<file alias="scalable/actions/panel-bottom-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/panel-bottom-symbolic.svg</file>
<file alias="scalable/actions/panel-left-rtl-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/panel-left-rtl-symbolic.svg</file>
<file alias="scalable/actions/panel-left-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/panel-left-symbolic.svg</file>
<file alias="scalable/actions/panel-right-rtl-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/panel-right-rtl-symbolic.svg</file>
<file alias="scalable/actions/panel-right-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/panel-right-symbolic.svg</file>
</gresource>
</gresources>
93 changes: 69 additions & 24 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 on Page…")
);
} 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;
Expand Down Expand Up @@ -285,10 +267,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 on Page…")
);
}

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;
Expand Down Expand Up @@ -1058,16 +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;
}

sidebar.visible = !sidebar.visible;
action.set_state (!action.get_state ().get_boolean ());
sidebar.visible = action.get_state ().get_boolean ();
}

private void action_toggle_outline () {
document_view.outline_visible = !document_view.outline_visible;
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 () {
Expand Down
40 changes: 21 additions & 19 deletions src/Widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Scratch.Widgets {
public Code.FormatBar format_bar;

public Gtk.ToggleButton find_button { get; private set; }
public Gtk.ToggleButton outline_button { get; private set; }
public Gtk.ToggleButton sidebar_button { get; private set; }

private const string STYLE_SCHEME_HIGH_CONTRAST = "classic";
private const string STYLE_SCHEME_LIGHT = "elementary-light";
Expand Down Expand Up @@ -182,25 +184,26 @@ 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 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);
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)
};

var toggle_outline_accellabel = new Granite.AccelLabel.from_action_name (
_("Toggle Symbol Outline"),
MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_OUTLINE
);
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)
};

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");
Expand All @@ -215,9 +218,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 ();

Expand Down

0 comments on commit 3eb601c

Please sign in to comment.