[seahorse/wip/nielsdg/cleanup-empty-state: 2/3] KeyManager: use the UI template more



commit 31311a9afe346e1a586ebd5ddba18f0dfd2acd1c
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Jan 12 17:59:40 2019 +0100

    KeyManager: use the UI template more
    
    * Add signals to the UI file and connect them automatically using
    `[GtkCallback]` in the Vala code.
    * Set some properties in the UI file rather than doing it manually

 common/key-manager-store.vala |  4 ----
 src/key-manager.vala          | 29 +++++++++++------------------
 src/seahorse-key-manager.ui   | 15 ++++++++++++++-
 3 files changed, 25 insertions(+), 23 deletions(-)
---
diff --git a/common/key-manager-store.vala b/common/key-manager-store.vala
index 0db3d06b..cb937823 100644
--- a/common/key-manager-store.vala
+++ b/common/key-manager-store.vala
@@ -171,10 +171,6 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
         if (sort_by != null)
             set_sort_to(sort_by);
 
-        view.set_enable_search(false);
-        view.set_show_expanders(false);
-        view.set_headers_visible(false);
-
         set_sort_column_id (Column.LABEL, Gtk.SortType.ASCENDING);
 
         // Tree drag
diff --git a/src/key-manager.vala b/src/key-manager.vala
index c6b51a0f..90ea95fd 100644
--- a/src/key-manager.vala
+++ b/src/key-manager.vala
@@ -66,7 +66,6 @@ public class Seahorse.KeyManager : Catalog {
         );
         this.settings = new GLib.Settings("org.gnome.seahorse.manager");
 
-        set_default_size(640, 476);
         set_events(Gdk.EventMask.POINTER_MOTION_MASK
                    | Gdk.EventMask.POINTER_MOTION_HINT_MASK
                    | Gdk.EventMask.BUTTON_PRESS_MASK
@@ -76,12 +75,6 @@ public class Seahorse.KeyManager : Catalog {
 
         load_css();
 
-        // Init key list & selection settings
-        Gtk.TreeSelection selection = this.key_list.get_selection();
-        selection.set_mode(Gtk.SelectionMode.MULTIPLE);
-        selection.changed.connect(on_view_selection_changed);
-        this.key_list.realize();
-
         // Add new key store and associate it
         this.store = new KeyManagerStore(this.collection, this.key_list, this.settings);
 
@@ -93,7 +86,6 @@ public class Seahorse.KeyManager : Catalog {
 
         // For the filtering
         on_filter_changed(this.filter_entry);
-        this.filter_entry.search_changed.connect(on_filter_changed);
         this.key_list.start_interactive_search.connect(() => {
             this.filter_entry.grab_focus();
             return false;
@@ -109,11 +101,6 @@ public class Seahorse.KeyManager : Catalog {
         targets.add_uri_targets(DndTarget.URIS);
         targets.add_text_targets(DndTarget.PLAIN);
         Gtk.drag_dest_set_target_list(this, targets);
-
-        this.drag_data_received.connect(on_target_drag_data_received);
-        this.key_list.button_press_event.connect(on_keymanager_key_list_button_pressed);
-        this.key_list.row_activated.connect(on_keymanager_row_activated);
-        this.key_list.popup_menu.connect(on_keymanager_key_list_popup_menu);
     }
 
     private void init_actions() {
@@ -138,6 +125,7 @@ public class Seahorse.KeyManager : Catalog {
         provider.load_from_resource("/org/gnome/Seahorse/seahorse.css");
     }
 
+    [GtkCallback]
     private void on_view_selection_changed(Gtk.TreeSelection selection) {
         Idle.add(() => {
             // Fire the signal
@@ -155,7 +143,8 @@ public class Seahorse.KeyManager : Catalog {
             backend.actions.set_actions_for_selected_objects(objects);
     }
 
-    private void on_keymanager_row_activated(Gtk.TreeView key_list, Gtk.TreePath? path, Gtk.TreeViewColumn 
column) {
+    [GtkCallback]
+    private void on_key_list_row_activated(Gtk.TreeView key_list, Gtk.TreePath? path, Gtk.TreeViewColumn 
column) {
         if (path == null)
             return;
 
@@ -164,7 +153,8 @@ public class Seahorse.KeyManager : Catalog {
             show_properties(obj);
     }
 
-    private bool on_keymanager_key_list_button_pressed(Gdk.EventButton event) {
+    [GtkCallback]
+    private bool on_key_list_button_pressed(Gdk.EventButton event) {
         if (event.button == 3) {
             show_context_menu(event);
             GLib.List<GLib.Object> objects = get_selected_objects();
@@ -176,7 +166,8 @@ public class Seahorse.KeyManager : Catalog {
         return false;
     }
 
-    private bool on_keymanager_key_list_popup_menu() {
+    [GtkCallback]
+    private bool on_key_list_popup_menu() {
         GLib.List<GLib.Object> objects = get_selected_objects();
         if (objects != null)
             show_context_menu(null);
@@ -202,6 +193,7 @@ public class Seahorse.KeyManager : Catalog {
         this.settings.set_boolean("sidebar-visible", !combined);
     }
 
+    [GtkCallback]
     private void on_filter_changed(Gtk.Editable entry) {
         this.store.filter = this.filter_entry.text;
     }
@@ -283,8 +275,9 @@ public class Seahorse.KeyManager : Catalog {
         dialog.destroy();
     }
 
-    private void on_target_drag_data_received(Gdk.DragContext context, int x, int y,
-                                              Gtk.SelectionData? selection_data, uint info, uint time) {
+    [GtkCallback]
+    private void on_drag_data_received(Gdk.DragContext context, int x, int y,
+                                       Gtk.SelectionData? selection_data, uint info, uint time) {
         if (selection_data == null)
             return;
 
diff --git a/src/seahorse-key-manager.ui b/src/seahorse-key-manager.ui
index 1d1ccdc3..9b84a07b 100644
--- a/src/seahorse-key-manager.ui
+++ b/src/seahorse-key-manager.ui
@@ -266,6 +266,9 @@
     </child>
   </object>
   <template class="SeahorseKeyManager" parent="SeahorseCatalog">
+    <property name="default-width">600</property>
+    <property name="default-height">476</property>
+    <signal name="drag-data-received" handler="on_drag_data_received" />
     <child type="titlebar">
       <object class="GtkHeaderBar">
         <property name="visible">True</property>
@@ -355,6 +358,7 @@
                     <property name="visible">True</property>
                     <property name="width_chars">30</property>
                     <property name="placeholder_text" translatable="yes">Filter</property>
+                    <signal name="search-changed" handler="on_filter_changed" />
                   </object>
                 </child>
               </object>
@@ -397,10 +401,19 @@
                         <child>
                           <object class="GtkTreeView" id="key_list">
                             <property name="visible">True</property>
+                            <property name="enable-search">False</property>
+                            <property name="show-expanders">False</property>
+                            <property name="headers-visible">False</property>
                             <property name="can_focus">True</property>
                             <property name="enable-grid-lines">horizontal</property>
+                            <signal name="row-activated" handler="on_key_list_row_activated"/>
+                            <signal name="button-press-event" handler="on_key_list_button_pressed" />
+                            <signal name="popup-menu" handler="on_key_list_popup_menu" />
                             <child internal-child="selection">
-                              <object class="GtkTreeSelection" id="treeview-selection"/>
+                              <object class="GtkTreeSelection" id="treeview-selection">
+                                <property name="mode">multiple</property>
+                                <signal name="changed" handler="on_view_selection_changed" />
+                              </object>
                             </child>
                           </object>
                         </child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]