[gnome-control-center] online-accounts: Make the main listbox non-selectable



commit 4e197b491fd967639fc2fb56e9f870efc1542d8e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Nov 9 15:55:45 2016 -0200

    online-accounts: Make the main listbox non-selectable
    
    Instead of selecting an account, this commit makes the account
    editor dialog only visible through explicit activation of the
    account row.
    
    As a side effect, this commit temporarily makes removing an
    account non-functional.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774222

 panels/online-accounts/cc-online-accounts-panel.c |   76 +++++++--------------
 panels/online-accounts/online-accounts.ui         |    6 +-
 2 files changed, 28 insertions(+), 54 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-accounts-panel.c 
b/panels/online-accounts/cc-online-accounts-panel.c
index de6dceb..b628015 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -39,6 +39,7 @@ struct _CcGoaPanel
   CcPanel parent_instance;
 
   GoaClient *client;
+  GoaObject *active_object;
 
   GtkWidget *accounts_listbox;
   GtkWidget *accounts_notebook;
@@ -52,8 +53,10 @@ struct _CcGoaPanel
   GtkWidget *accounts_vbox;
 };
 
-static void on_listbox_selection_changed (CcGoaPanel    *self,
-                                          GtkListBoxRow *selected_row);
+static gboolean on_edit_account_dialog_delete_event (CcGoaPanel *self);
+
+static void on_listbox_row_activated (CcGoaPanel    *self,
+                                      GtkListBoxRow *activated_row);
 
 static void on_toolbar_add_button_clicked (GtkToolButton *button,
                                            gpointer       user_data);
@@ -195,20 +198,6 @@ cc_goa_panel_set_property (GObject *object,
 }
 
 static void
-cc_goa_panel_dispose (GObject *object)
-{
-  CcGoaPanel *panel = CC_GOA_PANEL (object);
-
-  if (panel->accounts_listbox != NULL)
-    {
-      g_signal_handlers_disconnect_by_func (panel->accounts_listbox, on_listbox_selection_changed, panel);
-      panel->accounts_listbox = NULL;
-    }
-
-  G_OBJECT_CLASS (cc_goa_panel_parent_class)->dispose (object);
-}
-
-static void
 cc_goa_panel_finalize (GObject *object)
 {
   CcGoaPanel *panel = CC_GOA_PANEL (object);
@@ -301,7 +290,6 @@ cc_goa_panel_class_init (CcGoaPanelClass *klass)
   panel_class->get_help_uri = cc_goa_panel_get_help_uri;
 
   object_class->set_property = cc_goa_panel_set_property;
-  object_class->dispose = cc_goa_panel_dispose;
   object_class->finalize = cc_goa_panel_finalize;
   object_class->constructed = cc_goa_panel_constructed;
 
@@ -320,7 +308,8 @@ cc_goa_panel_class_init (CcGoaPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, toolbar_add_button);
   gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, toolbar_remove_button);
 
-  gtk_widget_class_bind_template_callback (widget_class, on_listbox_selection_changed);
+  gtk_widget_class_bind_template_callback (widget_class, on_edit_account_dialog_delete_event);
+  gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
   gtk_widget_class_bind_template_callback (widget_class, on_toolbar_add_button_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_toolbar_remove_button_clicked);
 }
@@ -356,6 +345,8 @@ show_page_account (CcGoaPanel  *panel,
 
   provider = NULL;
 
+  panel->active_object = object;
+
   show_page (panel, 0);
   gtk_widget_set_sensitive (panel->accounts_tree_box, TRUE);
   gtk_widget_hide (panel->accounts_tree_label);
@@ -402,10 +393,8 @@ static void
 select_account_by_id (CcGoaPanel    *panel,
                       const gchar *account_id)
 {
-  GtkListBoxRow *account_row;
   GList *children, *l;
 
-  account_row = NULL;
   children = gtk_container_get_children (GTK_CONTAINER (panel->accounts_listbox));
 
   for (l = children; l != NULL; l = l->next)
@@ -418,39 +407,30 @@ select_account_by_id (CcGoaPanel    *panel,
 
       if (g_strcmp0 (goa_account_get_id (account), account_id) == 0)
         {
-          account_row = l->data;
+          show_page_account (panel, row_object);
           break;
         }
     }
 
-  gtk_list_box_select_row (GTK_LIST_BOX (panel->accounts_listbox), account_row);
-
   g_list_free (children);
 }
 
-static void
-on_listbox_selection_changed (CcGoaPanel    *self,
-                              GtkListBoxRow *selected_row)
+static gboolean
+on_edit_account_dialog_delete_event (CcGoaPanel *self)
 {
-  if (selected_row != NULL)
-    {
-      GoaObject *object;
-
-      object = g_object_get_data (G_OBJECT (selected_row), "goa-object");
-      show_page_account (self, object);
-    }
-  else
-    {
-      GList *children;
+  self->active_object = NULL;
+  gtk_widget_hide (self->edit_account_dialog);
+  return TRUE;
+}
 
-      children = gtk_container_get_children (GTK_CONTAINER (self->accounts_listbox));
-      if (children == NULL)
-        show_page_nothing_selected (self);
-      else
-        gtk_widget_set_sensitive (self->toolbar_remove_button, FALSE);
+static void
+on_listbox_row_activated (CcGoaPanel    *self,
+                          GtkListBoxRow *activated_row)
+{
+  GoaObject *object;
 
-      g_list_free (children);
-    }
+  object = g_object_get_data (G_OBJECT (activated_row), "goa-object");
+  show_page_account (self, object);
 }
 
 static void
@@ -555,17 +535,11 @@ on_account_changed (GoaClient  *client,
                     gpointer    user_data)
 {
   CcGoaPanel *panel = CC_GOA_PANEL (user_data);
-  GtkListBoxRow *selected_row;
-  GoaObject *selected_object;
 
-  selected_row = gtk_list_box_get_selected_row (GTK_LIST_BOX (panel->accounts_listbox));
-  if (selected_row == NULL)
+  if (panel->active_object != object)
     return;
 
-  selected_object = g_object_get_data (G_OBJECT (selected_row), "goa-object");
-
-  if (selected_object == object)
-    show_page_account (panel, selected_object);
+  show_page_account (panel, panel->active_object);
 }
 
 static void
diff --git a/panels/online-accounts/online-accounts.ui b/panels/online-accounts/online-accounts.ui
index 3316eec..9cbb82b 100644
--- a/panels/online-accounts/online-accounts.ui
+++ b/panels/online-accounts/online-accounts.ui
@@ -36,8 +36,8 @@
                         <property name="can_focus">True</property>
                         <property name="hexpand">False</property>
                         <property name="width_request">278</property>
-                        <property name="selection_mode">browse</property>
-                        <signal name="row-selected" handler="on_listbox_selection_changed" 
object="CcGoaPanel" swapped="yes" />
+                        <property name="selection_mode">none</property>
+                        <signal name="row-activated" handler="on_listbox_row_activated" object="CcGoaPanel" 
swapped="yes" />
                       </object>
                     </child>
                   </object>
@@ -114,7 +114,7 @@
     <property name="use_header_bar">1</property>
     <property name="resizable">False</property>
     <property name="modal">True</property>
-    <signal name="delete-event" handler="gtk_widget_hide_on_delete" swapped="no" />
+    <signal name="delete-event" handler="on_edit_account_dialog_delete_event" object="CcGoaPanel" 
swapped="yes" />
     <child type="titlebar">
       <object class="GtkHeaderBar" id="edit_account_headerbar">
         <property name="visible">True</property>


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