[gnome-control-center/wip/gbsneto/new-keyboard-panel: 10/19] keyboard: remove the shortcuts treeview



commit e27cdca19891ac38d9f73e637fe0db9374a232bf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jun 21 15:45:38 2016 -0300

    keyboard: remove the shortcuts treeview
    
    After porting the shortcuts management entirely to
    GtkListBox, the current treeview is not necessary
    anymore.
    
    This patch removes the shortcuts treeview and all
    the related functions.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769063

 panels/keyboard/cc-keyboard-panel.c     |  162 ++++-----------------------
 panels/keyboard/gnome-keyboard-panel.ui |  184 ++++++------------------------
 2 files changed, 61 insertions(+), 285 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-panel.c b/panels/keyboard/cc-keyboard-panel.c
index 204b931..3515d4a 100644
--- a/panels/keyboard/cc-keyboard-panel.c
+++ b/panels/keyboard/cc-keyboard-panel.c
@@ -48,19 +48,14 @@ struct _CcKeyboardPanel
 {
   CcPanel             parent;
 
-  /* Treeviews */
+  /* Shortcut view */
+  GtkListStore       *shortcuts_model;
   GtkListStore       *sections_store;
   GtkTreeModel       *sections_model;
-  GtkWidget          *shortcut_treeview;
   GtkWidget          *listbox;
   GtkListBoxRow      *add_shortcut_row;
   GtkSizeGroup       *accelerator_sizegroup;
 
-  /* Toolbar widgets */
-  GtkWidget          *add_toolbutton;
-  GtkWidget          *remove_toolbutton;
-  GtkWidget          *shortcut_toolbar;
-
   /* Custom shortcut dialog */
   GtkWidget          *custom_shortcut_command_entry;
   GtkWidget          *custom_shortcut_dialog;
@@ -466,7 +461,7 @@ append_section (CcKeyboardPanel    *self,
   if (!hash)
     return;
 
-  shortcut_model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->shortcut_treeview));
+  shortcut_model = GTK_TREE_MODEL (self->shortcuts_model);
 
   /* Add all CcKeyboardItems for this section */
   is_new = FALSE;
@@ -728,7 +723,7 @@ reload_sections (CcKeyboardPanel *self)
   const gchar * const * data_dirs;
   guint i;
 
-  shortcut_model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->shortcut_treeview));
+  shortcut_model = GTK_TREE_MODEL (self->shortcuts_model);
   /* FIXME: get current selection and keep it after refreshing */
 
   /* Clear previous models and hash tables */
@@ -842,11 +837,9 @@ section_sort_item  (GtkTreeModel *model,
 static void
 add_shortcuts (CcKeyboardPanel *self)
 {
-  GtkTreeModel *shortcuts;
   GtkTreeIter sections_iter;
   gboolean can_continue;
 
-  shortcuts = gtk_tree_view_get_model (GTK_TREE_VIEW (self->shortcut_treeview));
   can_continue = gtk_tree_model_get_iter_first (self->sections_model, &sections_iter);
 
   while (can_continue)
@@ -880,8 +873,8 @@ add_shortcuts (CcKeyboardPanel *self)
             {
               GtkTreeIter new_row;
 
-              gtk_list_store_append (GTK_LIST_STORE (shortcuts), &new_row);
-              gtk_list_store_set (GTK_LIST_STORE (shortcuts),
+              gtk_list_store_append (self->shortcuts_model, &new_row);
+              gtk_list_store_set (self->shortcuts_model,
                                   &new_row,
                                   DETAIL_DESCRIPTION_COLUMN, item->description,
                                   DETAIL_KEYENTRY_COLUMN, item,
@@ -1124,9 +1117,7 @@ remove_custom_shortcut (CcKeyboardPanel *self,
 }
 
 static void
-add_custom_shortcut (CcKeyboardPanel *self,
-                     GtkTreeView     *tree_view,
-                     GtkTreeModel    *model)
+add_custom_shortcut (CcKeyboardPanel *self)
 {
   CcKeyboardItem *item;
   GtkTreePath *path;
@@ -1138,7 +1129,7 @@ add_custom_shortcut (CcKeyboardPanel *self,
   cc_keyboard_item_load_from_gsettings_path (item, settings_path, TRUE);
   g_free (settings_path);
 
-  item->model = model;
+  item->model = GTK_TREE_MODEL (self->shortcuts_model);
   item->group = BINDING_GROUP_USER;
 
   if (edit_custom_shortcut (self, item) && item->command && item->command[0])
@@ -1160,8 +1151,8 @@ add_custom_shortcut (CcKeyboardPanel *self,
 
       g_ptr_array_add (keys_array, item);
 
-      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-      gtk_list_store_set (GTK_LIST_STORE (model), &iter, DETAIL_KEYENTRY_COLUMN, item, -1);
+      gtk_list_store_append (self->shortcuts_model, &iter);
+      gtk_list_store_set (self->shortcuts_model, &iter, DETAIL_KEYENTRY_COLUMN, item, -1);
 
       settings_paths = g_settings_get_strv (self->binding_settings, "custom-keybindings");
       g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
@@ -1172,9 +1163,7 @@ add_custom_shortcut (CcKeyboardPanel *self,
                             g_variant_builder_end (&builder));
 
       /* make the new shortcut visible */
-      path = gtk_tree_model_get_path (model, &iter);
-      gtk_tree_view_expand_to_path (tree_view, path);
-      gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0, 0);
+      path = gtk_tree_model_get_path (GTK_TREE_MODEL (self->shortcuts_model), &iter);
       gtk_tree_path_free (path);
 
       add_item (self, item, CUSTOM_SHORTCUTS_ID, _("Custom Shortcuts"));
@@ -1619,7 +1608,7 @@ accel_edited_callback (GtkCellRendererText   *cell,
   CcKeyboardItem *reverse_item;
   char *str;
 
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->shortcut_treeview));
+  model = GTK_TREE_MODEL (self->shortcuts_model);
   gtk_tree_model_get_iter (model, &iter, path);
   gtk_tree_path_free (path);
   gtk_tree_model_get (model, &iter,
@@ -1736,36 +1725,12 @@ shortcut_entry_changed (GtkEntry        *entry,
 }
 
 static void
-add_button_clicked (GtkWidget       *button,
-                    CcKeyboardPanel *self)
-{
-  GtkTreeView *treeview;
-  GtkTreeModel *model;
-
-  treeview = GTK_TREE_VIEW (self->shortcut_treeview);
-  model = gtk_tree_view_get_model (treeview);
-
-  /* And add the shortcut */
-  add_custom_shortcut (self, treeview, model);
-}
-
-static void
-remove_button_clicked (GtkWidget       *button,
-                       CcKeyboardPanel *self)
+shortcut_row_activated (GtkWidget       *button,
+                        GtkListBoxRow   *row,
+                        CcKeyboardPanel *self)
 {
-  GtkTreeView *treeview;
-  GtkTreeModel *model;
-  GtkTreeSelection *selection;
-  GtkTreeIter iter;
-
-  treeview = GTK_TREE_VIEW (self->shortcut_treeview);
-  model = gtk_tree_view_get_model (treeview);
-  selection = gtk_tree_view_get_selection (treeview);
-
-  if (gtk_tree_selection_get_selected (selection, NULL, &iter))
-    {
-      remove_custom_shortcut (self, model, &iter);
-    }
+  if (row == self->add_shortcut_row)
+    add_custom_shortcut (self);
 }
 
 static void
@@ -1774,19 +1739,11 @@ xkb_options_combo_changed (GtkCellRendererCombo *combo,
                            GtkTreeIter          *model_iter,
                            CcKeyboardPanel      *self)
 {
-  GtkTreeView *shortcut_treeview;
   GtkTreeModel *shortcut_model;
   GtkTreeIter shortcut_iter;
-  GtkTreeSelection *selection;
   CcKeyboardOption *option;
   ShortcutType type;
 
-  shortcut_treeview = GTK_TREE_VIEW (self->shortcut_treeview);
-  selection = gtk_tree_view_get_selection (shortcut_treeview);
-
-  if (!gtk_tree_selection_get_selected (selection, &shortcut_model, &shortcut_iter))
-    return;
-
   gtk_tree_model_get (shortcut_model, &shortcut_iter,
                       DETAIL_KEYENTRY_COLUMN, &option,
                       DETAIL_TYPE_COLUMN, &type,
@@ -1801,12 +1758,8 @@ xkb_options_combo_changed (GtkCellRendererCombo *combo,
 static void
 setup_tree_views (CcKeyboardPanel *self)
 {
-  GtkTreeViewColumn *column;
-  GtkCellRenderer *renderer;
-  GtkListStore *model;
   GtkWidget *widget;
   CcShell *shell;
-  GList *focus_chain;
 
   /* Setup the section treeview */
   self->sections_store = gtk_list_store_new (SECTION_N_COLUMNS,
@@ -1825,74 +1778,12 @@ setup_tree_views (CcKeyboardPanel *self)
                                         SECTION_DESCRIPTION_COLUMN,
                                         GTK_SORT_ASCENDING);
 
-  /* Setup the shortcut treeview */
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
-
-  column = gtk_tree_view_column_new_with_attributes (NULL, renderer, NULL);
-  gtk_tree_view_column_set_cell_data_func (column, renderer, description_set_func, NULL, NULL);
-  gtk_tree_view_column_set_resizable (column, FALSE);
-  gtk_tree_view_column_set_expand (column, TRUE);
-
-  gtk_tree_view_append_column (GTK_TREE_VIEW (self->shortcut_treeview), column);
-
-  renderer = (GtkCellRenderer *) g_object_new (GTK_TYPE_CELL_RENDERER_ACCEL,
-                                               "accel-mode", GTK_CELL_RENDERER_ACCEL_MODE_OTHER,
-                                               NULL);
-
-  g_signal_connect (self->shortcut_treeview,
-                    "button_press_event",
-                    G_CALLBACK (start_editing_cb),
-                    renderer);
-  g_signal_connect (self->shortcut_treeview,
-                    "row-activated",
-                    G_CALLBACK (start_editing_kb_cb),
-                    renderer);
-
-  g_signal_connect (renderer,
-                    "accel_edited",
-                    G_CALLBACK (accel_edited_callback),
-                    self);
-  g_signal_connect (renderer,
-                    "accel_cleared",
-                    G_CALLBACK (accel_cleared_callback),
-                    self->shortcut_treeview);
-
-  column = gtk_tree_view_column_new_with_attributes (NULL, renderer, NULL);
-  gtk_tree_view_column_set_cell_data_func (column, renderer, accel_set_func, NULL, NULL);
-  gtk_tree_view_column_set_resizable (column, FALSE);
-  gtk_tree_view_column_set_expand (column, FALSE);
-
-  renderer = (GtkCellRenderer *) g_object_new (GTK_TYPE_CELL_RENDERER_COMBO,
-                                               "has-entry", FALSE,
-                                               "text-column", XKB_OPTION_DESCRIPTION_COLUMN,
-                                               "editable", TRUE,
-                                               "ellipsize", PANGO_ELLIPSIZE_END,
-                                               "width-chars", 25,
-                                               NULL);
-  g_signal_connect (renderer,
-                    "changed",
-                    G_CALLBACK (xkb_options_combo_changed),
-                    self);
-
-  gtk_tree_view_column_pack_end (column, renderer, FALSE);
-
-  gtk_tree_view_column_set_cell_data_func (column, renderer, accel_set_func, NULL, NULL);
-
-  gtk_tree_view_append_column (GTK_TREE_VIEW (self->shortcut_treeview), column);
-
-  model = gtk_list_store_new (DETAIL_N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT);
-  gtk_tree_view_set_model (GTK_TREE_VIEW (self->shortcut_treeview), GTK_TREE_MODEL (model));
-  g_object_unref (model);
-
-  setup_keyboard_options (model);
-
-  /* set up the focus chain */
-  focus_chain = g_list_append (NULL, self->shortcut_treeview);
-  focus_chain = g_list_append (focus_chain, self->shortcut_toolbar);
-
-  gtk_container_set_focus_chain (GTK_CONTAINER (self), focus_chain);
-  g_list_free (focus_chain);
+  self->shortcuts_model = gtk_list_store_new (DETAIL_N_COLUMNS,
+                                              G_TYPE_STRING,
+                                              G_TYPE_POINTER,
+                                              G_TYPE_INT);
+
+  setup_keyboard_options (self->shortcuts_model);
 
   /* set up the dialog */
   shell = cc_panel_get_shell (CC_PANEL (self));
@@ -1988,19 +1879,14 @@ cc_keyboard_panel_class_init (CcKeyboardPanelClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/keyboard/gnome-keyboard-panel.ui");
 
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, add_shortcut_row);
-  gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, add_toolbutton);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, custom_shortcut_command_entry);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, custom_shortcut_dialog);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, custom_shortcut_name_entry);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, custom_shortcut_ok_button);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, listbox);
-  gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, remove_toolbutton);
-  gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, shortcut_toolbar);
-  gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, shortcut_treeview);
 
-  gtk_widget_class_bind_template_callback (widget_class, add_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, remove_button_clicked);
   gtk_widget_class_bind_template_callback (widget_class, shortcut_entry_changed);
+  gtk_widget_class_bind_template_callback (widget_class, shortcut_row_activated);
   gtk_widget_class_bind_template_callback (widget_class, shortcut_selection_changed);
 }
 
diff --git a/panels/keyboard/gnome-keyboard-panel.ui b/panels/keyboard/gnome-keyboard-panel.ui
index 192b3a3..a7cf1af 100644
--- a/panels/keyboard/gnome-keyboard-panel.ui
+++ b/panels/keyboard/gnome-keyboard-panel.ui
@@ -155,182 +155,72 @@
   <template class="CcKeyboardPanel" parent="CcPanel">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="border_width">12</property>
+    <property name="expand">True</property>
+    <property name="border_width">18</property>
     <child>
-      <object class="GtkBox" id="shortcuts_page">
+      <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
-        <property name="border_width">5</property>
+        <property name="halign">center</property>
         <property name="spacing">12</property>
         <child>
-          <object class="GtkBox" id="shortcuts_vbox">
+          <object class="GtkScrolledWindow">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">6</property>
+            <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="hscrollbar_policy">never</property>
+            <property name="shadow_type">in</property>
             <child>
-              <object class="GtkGrid" id="shortcuts_grid">
+              <object class="GtkListBox" id="listbox">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="column_spacing">5</property>
-                <child>
-                  <object class="GtkScrolledWindow">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
-                    <property name="hscrollbar_policy">never</property>
-                    <property name="shadow_type">in</property>
-                    <child>
-                      <object class="GtkTreeView" id="shortcut_treeview">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="headers_visible">False</property>
-                        <property name="rules_hint">True</property>
-                        <child internal-child="selection">
-                          <object class="GtkTreeSelection" id="treeview-selection2">
-                            <signal name="changed" handler="shortcut_selection_changed" 
object="remove_toolbutton" swapped="no" />
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">0</property>
-                  </packing>
-                </child>
+                <property name="can_focus">True</property>
+                <property name="selection-mode">none</property>
+                <property name="width-request">250</property>
+                <signal name="row-activated" handler="shortcut_row_activated" object="CcKeyboardPanel" 
swapped="no" />
                 <child>
-                  <object class="GtkScrolledWindow">
+                  <object class="GtkListBoxRow" id="add_shortcut_row">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
-                    <property name="hscrollbar_policy">never</property>
-                    <property name="shadow_type">in</property>
                     <child>
-                      <object class="GtkListBox" id="listbox">
+                      <object class="GtkBox">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="selection-mode">none</property>
-                        <property name="width-request">100</property>
-                        <child>
-                          <object class="GtkListBoxRow" id="add_shortcut_row">
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="border_width">6</property>
+                        <child type="center">
+                          <object class="GtkImage">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <child>
-                              <object class="GtkBox">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="hexpand">True</property>
-                                <property name="border_width">6</property>
-                                <child type="center">
-                                  <object class="GtkImage">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="icon_name">list-add-symbolic</property>
-                                  </object>
-                                </child>
-                              </object>
-                            </child>
+                            <property name="can_focus">False</property>
+                            <property name="icon_name">list-add-symbolic</property>
                           </object>
                         </child>
                       </object>
                     </child>
                   </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkToolbar" id="shortcut_toolbar">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="icon_size">1</property>
-                    <property name="toolbar-style">icons</property>
-                    <style>
-                      <class name="inline-toolbar"/>
-                    </style>
-                    <child>
-                      <object class="GtkToolButton" id="add_toolbutton">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="icon_name">list-add-symbolic</property>
-                        <property name="label" translatable="yes">Add Shortcut</property>
-                        <signal name="clicked" handler="add_button_clicked" object="CcKeyboardPanel" 
swapped="no" />
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="homogeneous">True</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkToolButton" id="remove_toolbutton">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="icon_name">list-remove-symbolic</property>
-                        <property name="label" translatable="yes">Remove Shortcut</property>
-                        <signal name="clicked" handler="remove_button_clicked" object="CcKeyboardPanel" 
swapped="no" />
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="homogeneous">True</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">1</property>
-                  </packing>
                 </child>
               </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
             </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">6</property>
             <child>
-              <object class="GtkBox" id="hbox1">
+              <object class="GtkLabel">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">5</property>
-                <property name="spacing">12</property>
-                <child>
-                  <object class="GtkLabel" id="label12">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes">To edit a shortcut, click the row and hold 
down the new keys or press Backspace to clear.</property>
-                    <property name="justify">fill</property>
-                    <property name="wrap">True</property>
-                    <property name="max_width_chars">70</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">To edit a shortcut, click the row and hold down 
the new keys or press Backspace to clear.</property>
+                <property name="justify">fill</property>
+                <property name="wrap">True</property>
+                <property name="max_width_chars">60</property>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
         </child>
       </object>
     </child>


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