[gnome-control-center/wip/feborges/new-search-panel: 2/4] search: Place "Move" button in each row



commit f61e12b8ecfc91a2dfb97d2f6b24b05544aa79e5
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jul 2 16:53:36 2019 +0200

    search: Place "Move" button in each row
    
    This is based on the mockups available at
    https://gitlab.gnome.org/Teams/Design/settings-mockups/raw/master/search/search.png
    
    Fixes #591

 panels/search/cc-search-panel-row.c  | 36 ++++++++++++++++++
 panels/search/cc-search-panel-row.ui | 56 ++++++++++++++++++++++++++++
 panels/search/cc-search-panel.c      | 49 -------------------------
 panels/search/cc-search-panel.ui     | 71 ------------------------------------
 4 files changed, 92 insertions(+), 120 deletions(-)
---
diff --git a/panels/search/cc-search-panel-row.c b/panels/search/cc-search-panel-row.c
index 40ef86ea0..f05f20001 100644
--- a/panels/search/cc-search-panel-row.c
+++ b/panels/search/cc-search-panel-row.c
@@ -45,6 +45,40 @@ enum
 
 static guint signals[SIGNAL_LAST] = { 0, };
 
+static void
+move_up_button_clicked (GtkButton        *button,
+                        CcSearchPanelRow *self)
+{
+  GtkListBox *list_box = GTK_LIST_BOX (gtk_widget_get_parent (GTK_WIDGET (self)));
+  gint previous_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self)) - 1;
+  GtkListBoxRow *previous_row = gtk_list_box_get_row_at_index (list_box, previous_idx);
+
+  if (previous_row == NULL)
+    return;
+
+  g_signal_emit (self,
+                 signals[SIGNAL_MOVE_ROW],
+                 0,
+                 previous_row);
+}
+
+static void
+move_down_button_clicked (GtkButton    *button,
+                          CcSearchPanelRow *self)
+{
+  GtkListBox *list_box = GTK_LIST_BOX (gtk_widget_get_parent (GTK_WIDGET (self)));
+  gint next_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self)) + 1;
+  GtkListBoxRow *next_row = gtk_list_box_get_row_at_index (list_box, next_idx);
+
+  if (next_row == NULL)
+    return;
+
+  g_signal_emit (next_row,
+                 signals[SIGNAL_MOVE_ROW],
+                 0,
+                 self);
+}
+
 static void
 drag_begin_cb (CcSearchPanelRow *self,
                GdkDragContext   *drag_context)
@@ -134,6 +168,8 @@ cc_search_panel_row_class_init (CcSearchPanelRowClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, drag_end_cb);
   gtk_widget_class_bind_template_callback (widget_class, drag_data_get_cb);
   gtk_widget_class_bind_template_callback (widget_class, drag_data_received_cb);
+  gtk_widget_class_bind_template_callback (widget_class, move_up_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, move_down_button_clicked);
 
   signals[SIGNAL_MOVE_ROW] =
     g_signal_new ("move-row",
diff --git a/panels/search/cc-search-panel-row.ui b/panels/search/cc-search-panel-row.ui
index 5e8ce221f..b147fb8f2 100644
--- a/panels/search/cc-search-panel-row.ui
+++ b/panels/search/cc-search-panel-row.ui
@@ -47,9 +47,65 @@
                 <property name="valign">center</property>
               </object>
             </child>
+            <child>
+              <object class="GtkSeparator">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuButton">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="popover">move_row_menu</property>
+                <style>
+                  <class name="flat"/>
+                </style>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="icon-name">view-more-symbolic</property>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
       </object>
     </child>
   </template>
+
+  <!-- Move Row Menu -->
+  <object class="GtkPopoverMenu" id="move_row_menu">
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="margin">12</property>
+        <property name="spacing">6</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkModelButton">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Move Up</property>
+            <property name="can-focus">True</property>
+            <property name="receives-default">True</property>
+            <property name="xalign">0.0</property>
+            <signal name="clicked" handler="move_up_button_clicked"/>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Move Down</property>
+            <property name="can-focus">True</property>
+            <property name="receives-default">True</property>
+            <property name="xalign">0.0</property>
+            <signal name="clicked" handler="move_down_button_clicked"/>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/panels/search/cc-search-panel.c b/panels/search/cc-search-panel.c
index 86049636a..34cb66170 100644
--- a/panels/search/cc-search-panel.c
+++ b/panels/search/cc-search-panel.c
@@ -32,8 +32,6 @@ struct _CcSearchPanel
   CcPanel     parent_instance;
 
   GtkWidget  *list_box;
-  GtkWidget  *up_button;
-  GtkWidget  *down_button;
   GtkWidget  *search_vbox;
   GtkWidget  *search_frame;
   GtkWidget  *settings_button;
@@ -94,26 +92,6 @@ list_sort_func (gconstpointer a,
   return (idx_a - idx_b);
 }
 
-static void
-search_panel_invalidate_button_state (CcSearchPanel *self)
-{
-  g_autoptr(GList) children = NULL;
-  gboolean is_first, is_last;
-  GtkListBoxRow *row;
-
-  row = gtk_list_box_get_selected_row (GTK_LIST_BOX (self->list_box));
-  children = gtk_container_get_children (GTK_CONTAINER (self->list_box));
-
-  if (!row || !children)
-    return;
-
-  is_first = (row == g_list_first (children)->data);
-  is_last = (row == g_list_last (children)->data);
-
-  gtk_widget_set_sensitive (self->up_button, !is_first);
-  gtk_widget_set_sensitive (self->down_button, !is_last);
-}
-
 static void
 search_panel_invalidate_sort_order (CcSearchPanel *self)
 {
@@ -127,8 +105,6 @@ search_panel_invalidate_sort_order (CcSearchPanel *self)
     g_hash_table_insert (self->sort_order, g_strdup (sort_order[idx]), GINT_TO_POINTER (idx + 1));
 
   gtk_list_box_invalidate_sort (GTK_LIST_BOX (self->list_box));
-
-  search_panel_invalidate_button_state (self);
 }
 
 static gint
@@ -303,20 +279,6 @@ row_moved_cb (CcSearchPanel    *self,
     search_panel_move_selected (self, down);
 }
 
-static void
-down_button_clicked (GtkWidget *widget,
-                     CcSearchPanel *self)
-{
-  search_panel_move_selected (self, TRUE);
-}
-
-static void
-up_button_clicked (GtkWidget *widget,
-                   CcSearchPanel *self)
-{
-  search_panel_move_selected (self, FALSE);
-}
-
 static void
 settings_button_clicked (GtkWidget *widget,
                          gpointer user_data)
@@ -718,14 +680,6 @@ cc_search_panel_init (CcSearchPanel *self)
                               (GtkListBoxSortFunc)list_sort_func, self, NULL);
   gtk_list_box_set_header_func (GTK_LIST_BOX (self->list_box), cc_list_box_update_header_func, NULL, NULL);
 
-  g_signal_connect (self->up_button, "clicked",
-                    G_CALLBACK (up_button_clicked), self);
-  gtk_widget_set_sensitive (self->up_button, FALSE);
-
-  g_signal_connect (self->down_button, "clicked",
-                    G_CALLBACK (down_button_clicked), self);
-  gtk_widget_set_sensitive (self->down_button, FALSE);
-
   gtk_widget_set_sensitive (self->settings_button, cc_search_locations_dialog_is_available ());
 
   self->search_settings = g_settings_new ("org.gnome.desktop.search-providers");
@@ -752,12 +706,9 @@ cc_search_panel_class_init (CcSearchPanelClass *klass)
                                                "/org/gnome/control-center/search/cc-search-panel.ui");
 
   gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, list_box);
-  gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, up_button);
-  gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, down_button);
   gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, search_vbox);
   gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, search_frame);
   gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, settings_button);
 
-  gtk_widget_class_bind_template_callback (widget_class, search_panel_invalidate_button_state);
   gtk_widget_class_bind_template_callback (widget_class, settings_button_clicked);
 }
diff --git a/panels/search/cc-search-panel.ui b/panels/search/cc-search-panel.ui
index ffff72042..ac303e7ab 100644
--- a/panels/search/cc-search-panel.ui
+++ b/panels/search/cc-search-panel.ui
@@ -29,81 +29,10 @@
                     <child>
                       <object class="GtkListBox" id="list_box">
                         <property name="visible">True</property>
-                        <signal name="row-selected" handler="search_panel_invalidate_button_state" 
swapped="yes"/>
                       </object>
                     </child>
                   </object>
                 </child>
-                <child>
-                  <object class="GtkToolbar" id="search_toolbar">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="toolbar_style">icons</property>
-                    <property name="show_arrow">False</property>
-                    <property name="icon_size">1</property>
-                    <style>
-                      <class name="inline-toolbar"/>
-                    </style>
-                    <child>
-                      <object class="GtkToolItem" id="up_down_item">
-                        <property name="visible">True</property>
-                        <child>
-                          <object class="GtkBox" id="up_down_box">
-                            <property name="visible">True</property>
-                            <child>
-                               <object class="GtkButton" id="up_button">
-                                 <property name="visible">True</property>
-                                 <child internal-child="accessible">
-                                   <object class="AtkObject" id="up_button_a11y">
-                                     <property name="accessible-name" translatable="yes">Move Up</property>
-                                   </object>
-                                 </child>
-                                 <child>
-                                    <object class="GtkImage" id="up_image">
-                                      <property name="visible">True</property>
-                                      <property name="icon-name">go-up-symbolic</property>
-                                      <property name="icon-size">1</property>
-                                    </object>
-                                 </child>
-                               </object>
-                            </child>
-                            <child>
-                               <object class="GtkButton" id="down_button">
-                                 <property name="visible">True</property>
-                                 <child internal-child="accessible">
-                                   <object class="AtkObject" id="down_button_a11y">
-                                     <property name="accessible-name" translatable="yes">Move Down</property>
-                                   </object>
-                                 </child>
-                                 <child>
-                                    <object class="GtkImage" id="down_image">
-                                      <property name="visible">True</property>
-                                      <property name="icon-name">go-down-symbolic</property>
-                                      <property name="icon-size">1</property>
-                                    </object>
-                                 </child>
-                               </object>
-                            </child>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorToolItem" id="sep1">
-                        <property name="visible">True</property>
-                        <property name="draw">False</property>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
               </object>
            </child>
           </object>


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