Skip to content

Commit

Permalink
CategoryView: absorb headerbar
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jan 23, 2024
1 parent be73a08 commit e7fd714
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
38 changes: 1 addition & 37 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@

namespace Switchboard {
public class SwitchboardApp : Gtk.Application {
private string all_settings_label = N_("All Settings");

private GLib.HashTable <Gtk.Widget, Switchboard.Plug> plug_widgets;
private Gtk.Button navigation_button;
private Adw.Leaflet leaflet;
private Gtk.HeaderBar headerbar;
private Gtk.Window main_window;
private Switchboard.CategoryView category_view;
private Gtk.Label title_label;

private static bool opened_directly = false;
private static string? link = null;
Expand Down Expand Up @@ -135,22 +130,6 @@ namespace Switchboard {

plug_widgets = new GLib.HashTable <Gtk.Widget, Switchboard.Plug> (null, null);

navigation_button = new Gtk.Button.with_label (_(all_settings_label));
navigation_button.action_name = "app.back";
navigation_button.set_tooltip_markup (
Granite.markup_accel_tooltip (get_accels_for_action (navigation_button.action_name))
);
navigation_button.get_style_context ().add_class ("back-button");

title_label = new Gtk.Label ("");
title_label.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL);

headerbar = new Gtk.HeaderBar () {
show_title_buttons = true,
title_widget = title_label
};
headerbar.pack_start (navigation_button);

category_view = new Switchboard.CategoryView (plug_to_open);
category_view.load_default_plugs.begin ();

Expand All @@ -166,13 +145,11 @@ namespace Switchboard {
child = leaflet,
icon_name = application_id,
title = _("System Settings"),
titlebar = headerbar
titlebar = new Gtk.Grid () { visible = false }
};
add_window (main_window);
main_window.present ();

navigation_button.hide ();

/*
* This is very finicky. Bind size after present else set_titlebar gives us bad sizes
* Set maximize after height/width else window is min size on unmaximize
Expand All @@ -188,8 +165,6 @@ namespace Switchboard {

settings.bind ("window-maximized", main_window, "maximized", SettingsBindFlags.SET);

main_window.bind_property ("title", title_label, "label");

shutdown.connect (() => {
if (plug_widgets[leaflet.visible_child] != null && plug_widgets[leaflet.visible_child] is Switchboard.Plug) {
plug_widgets[leaflet.visible_child].hidden ();
Expand Down Expand Up @@ -219,8 +194,6 @@ namespace Switchboard {
var visible_widget = leaflet.visible_child;
if (visible_widget is Switchboard.CategoryView) {
main_window.title = _("System Settings");

navigation_button.hide ();
} else {
var plug = plug_widgets[visible_widget];
if (plug != null) {
Expand All @@ -229,15 +202,6 @@ namespace Switchboard {
} else {
critical ("Visible child is not CategoryView nor is associated with a Plug.");
}


if (previous_child != null && previous_child is Switchboard.Plug) {
navigation_button.label = previous_child.display_name;
} else {
navigation_button.label = _(all_settings_label);
}

navigation_button.show ();
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/CategoryView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ namespace Switchboard {
var search_box_eventcontrollerkey = new Gtk.EventControllerKey ();

search_box = new Gtk.SearchEntry () {
margin_top = 12,
margin_end = 12,
margin_bottom = 12,
margin_start = 12,
placeholder_text = _("Search Settings")
};
search_box.add_controller (search_box_eventcontrollerkey);
Expand Down Expand Up @@ -99,8 +95,14 @@ namespace Switchboard {
search_stack.add_child (clamp);
search_stack.add_child (searchview);

var headerbar = new Gtk.HeaderBar () {
show_title_buttons = true,
title_widget = search_clamp
};
headerbar.add_css_class (Granite.STYLE_CLASS_FLAT);

orientation = VERTICAL;
append (search_clamp);
append (headerbar);
append (search_stack);

if (Switchboard.PlugsManager.get_default ().has_plugs () == false) {
Expand Down

0 comments on commit e7fd714

Please sign in to comment.