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 7c88a79 commit 490ba57
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 @@ -126,22 +121,6 @@ namespace Switchboard {
set_accels_for_action ("app.back", {"<Alt>Left", "Back"});
set_accels_for_action ("app.quit", {"<Control>q"});

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 @@ -157,13 +136,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 @@ -179,8 +156,6 @@ namespace Switchboard {

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

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

back_action.activate.connect (() => {
handle_navigation_button_clicked ();
});
Expand Down Expand Up @@ -218,8 +193,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 @@ -228,15 +201,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 490ba57

Please sign in to comment.