From cea210d005d316629f00d0ca1371b34d703c8db2 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Wed, 22 Nov 2023 00:21:31 +0100 Subject: [PATCH] Headerbar ported --- src/MainWindow.vala | 9 ++++-- src/Models/TreeViewModel.vala | 4 +++ .../{HeaderbarContent.vala => Headerbar.vala} | 23 +++++++++------ src/Widgets/Headerbar/Search.vala | 28 +++++++++---------- src/meson.build | 4 +-- 5 files changed, 40 insertions(+), 28 deletions(-) rename src/Widgets/Headerbar/{HeaderbarContent.vala => Headerbar.vala} (66%) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index c85e6f82..b4b834fa 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -5,7 +5,7 @@ public class Monitor.MainWindow : Gtk.ApplicationWindow { private Resources resources; // Widgets - // public HeaderbarContent headerbar_content; + public Headerbar headerbar; // public ProcessView process_view; // public SystemView system_view; @@ -36,8 +36,8 @@ public class Monitor.MainWindow : Gtk.ApplicationWindow { stack = new Gtk.Stack (); stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT); - // stack.add_titled (process_view, "process_view", _("Processes")); - // stack.add_titled (system_view, "system_view", _("System")); + stack.add_titled (new Gtk.Label ("string? str"), "process_view", _("Processes")); + stack.add_titled (new Gtk.Label ("string? str"), "system_view", _("System")); if (MonitorApp.settings.get_boolean ("containers-view-state")) { stack.add_titled (container_view, "container_view", _("Containers")); @@ -48,6 +48,9 @@ public class Monitor.MainWindow : Gtk.ApplicationWindow { stack_switcher.valign = Gtk.Align.CENTER; stack_switcher.set_stack (stack); + headerbar = new Headerbar (stack_switcher); + set_titlebar (headerbar); + // var headerbar = new Gtk.HeaderBar () { // title_widget = stack_switcher, // hexpand = true diff --git a/src/Models/TreeViewModel.vala b/src/Models/TreeViewModel.vala index 4394f823..cc469528 100644 --- a/src/Models/TreeViewModel.vala +++ b/src/Models/TreeViewModel.vala @@ -8,6 +8,10 @@ public enum Monitor.Column { } public class Monitor.TreeViewModel : Gtk.TreeStore { + private static GLib.Once instance; + public static unowned TreeViewModel get_default () { + return instance.once (() => { return new TreeViewModel (); }); + } public ProcessManager process_manager; private Gee.Map process_rows; public signal void added_first_row (); diff --git a/src/Widgets/Headerbar/HeaderbarContent.vala b/src/Widgets/Headerbar/Headerbar.vala similarity index 66% rename from src/Widgets/Headerbar/HeaderbarContent.vala rename to src/Widgets/Headerbar/Headerbar.vala index 7b6b142a..34fdf6c9 100644 --- a/src/Widgets/Headerbar/HeaderbarContent.vala +++ b/src/Widgets/Headerbar/Headerbar.vala @@ -1,5 +1,4 @@ -public class Monitor.HeaderbarContent { - private MainWindow window; +public class Monitor.Headerbar : Gtk.Box { public Search search; public Gtk.Grid preferences_grid; @@ -9,19 +8,23 @@ public class Monitor.HeaderbarContent { }; construct { - show_title_buttons = true; + // show_title_buttons = true; // has_subtitle = false; // title_widget = new Gtk.Label(_("Monitor")); } - public HeaderbarContent (MainWindow window) { - this.window = window; + public Headerbar (Gtk.Widget widget) { + + var headerbar = new Gtk.HeaderBar () { + hexpand = true, + }; + headerbar.set_title_widget (widget); var preferences_button = new Gtk.MenuButton (); preferences_button.has_tooltip = true; preferences_button.tooltip_text = (_("Settings")); preferences_button.set_icon_name ("open-menu"); - pack_end (preferences_button); + headerbar.pack_end (preferences_button); preferences_grid = new Gtk.Grid () { orientation = Gtk.Orientation.VERTICAL @@ -33,13 +36,17 @@ public class Monitor.HeaderbarContent { // preferences_grid.show_all (); - search = new Search (window) { + search = new Search () { valign = Gtk.Align.CENTER }; search_revealer.set_child (search); - pack_start (search_revealer); + headerbar.pack_start (search_revealer); + append (headerbar); + } + + public void set_title_widget (Gtk.Widget widget) { } } diff --git a/src/Widgets/Headerbar/Search.vala b/src/Widgets/Headerbar/Search.vala index 16388533..bef2767d 100644 --- a/src/Widgets/Headerbar/Search.vala +++ b/src/Widgets/Headerbar/Search.vala @@ -1,28 +1,26 @@ -public class Monitor.Search : Gtk.SearchEntry { - public MainWindow window { get; construct; } +public class Monitor.Search : Gtk.Box { private Gtk.TreeModelFilter filter_model; private CPUProcessTreeView process_tree_view; - - public Search (MainWindow window) { - Object (window: window); - } + private Gtk.SearchEntry search_entry; construct { - this.process_tree_view = window.process_view.process_tree_view; - this.placeholder_text = _("Search Process"); - this.tooltip_markup = Granite.markup_accel_tooltip ({ "F" }, _("Type process name or PID to search")); + search_entry = new Gtk.SearchEntry () { + tooltip_markup = Granite.markup_accel_tooltip ({ "F" }, _("Type process name or PID to search")), + }; + search_entry.placeholder_text = _("Search Process"); - filter_model = new Gtk.TreeModelFilter (window.process_view.treeview_model, null); + filter_model = new Gtk.TreeModelFilter (Monitor.TreeViewModel.get_default (), null); connect_signal (); filter_model.set_visible_func (filter_func); // process_tree_view.set_model (filter_model); var sort_model = new Gtk.TreeModelSort.with_model (filter_model); process_tree_view.set_model (sort_model); + append (search_entry); } private void connect_signal () { - this.search_changed.connect (() => { + search_entry.search_changed.connect (() => { // collapse tree only when search is focused and changed // if (this.is_focus) { // process_tree_view.collapse_all (); @@ -32,7 +30,7 @@ public class Monitor.Search : Gtk.SearchEntry { // focus on child row to avoid the app crashes by clicking "Kill/End Process" buttons in headerbar process_tree_view.focus_on_child_row (); - this.grab_focus (); + search_entry.grab_focus (); // if (this.text != "") { // this.insert_at_cursor (""); @@ -45,7 +43,7 @@ public class Monitor.Search : Gtk.SearchEntry { int pid_haystack; string cmd_haystack; bool found = false; - var needle = this.text; + var needle = search_entry.text; // should help with assertion errors, donno // if (needle == null) return true; @@ -85,8 +83,8 @@ public class Monitor.Search : Gtk.SearchEntry { // reset filter, grab focus and insert the character public void activate_entry (string search_text = "") { - this.text = ""; - this.search_changed (); + search_entry.text = ""; + search_entry.search_changed (); // this.insert_at_cursor (search_text); } diff --git a/src/meson.build b/src/meson.build index 4da3ab5a..73a5f30e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -34,8 +34,8 @@ source_app_files = [ 'Views/ProcessView/ProcessInfoView/OpenFilesTreeView.vala', # Widgets - # 'Widgets/Headerbar/HeaderbarContent.vala', - # 'Widgets/Headerbar/Search.vala', + 'Widgets/Headerbar/Headerbar.vala', + 'Widgets/Headerbar/Search.vala', 'Widgets/Statusbar/Statusbar.vala', 'Widgets/Labels/LabelVertical.vala', 'Widgets/Labels/LabelRoundy.vala',