[gnome-photos] organize-collection: Special case OK clicks when typing a collection



commit 21bd8bf15cd933dbe21b40f2a56fcb05a11562cc
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Jul 14 16:52:20 2012 +0200

    organize-collection: Special case OK clicks when typing a collection
    
    See the comment in the code for why this is necessary, but in a
    nutshell, GtkCellRenderer will emit editing-canceled as soon as any
    button is clicked (since we focus out of the editable in order to
    click the button), and we don't want "focus-out" to mean "cancel" if
    we clicked on the OK button.
    
    Original patch from Cosimo Cecchi for gnome-documents.

 src/photos-organize-collection-dialog.c |   28 +++++++++++++++++++++++++++-
 src/photos-organize-collection-model.c  |   18 ++++++++++++------
 src/photos-organize-collection-model.h  |    3 ++-
 src/photos-organize-collection-view.c   |    8 ++++++++
 src/photos-organize-collection-view.h   |    2 ++
 5 files changed, 51 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-organize-collection-dialog.c b/src/photos-organize-collection-dialog.c
index 69c8182..991f8f2 100644
--- a/src/photos-organize-collection-dialog.c
+++ b/src/photos-organize-collection-dialog.c
@@ -34,6 +34,16 @@ struct _PhotosOrganizeCollectionDialogPrivate
 G_DEFINE_TYPE (PhotosOrganizeCollectionDialog, photos_organize_collection_dialog, GTK_TYPE_DIALOG);
 
 
+static gboolean
+photos_organize_collection_dialog_button_press_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+  PhotosOrganizeCollectionDialog *self = PHOTOS_ORGANIZE_COLLECTION_DIALOG (widget);
+
+  photos_organize_collection_view_confirmed_choice (PHOTOS_ORGANIZE_COLLECTION_VIEW (self->priv->coll_view));
+  return FALSE;
+}
+
+
 static void
 photos_organize_collection_dialog_response (GtkDialog *dialog, gint response_id)
 {
@@ -51,6 +61,7 @@ photos_organize_collection_dialog_init (PhotosOrganizeCollectionDialog *self)
 {
   PhotosOrganizeCollectionDialogPrivate *priv;
   GtkWidget *content_area;
+  GtkWidget *ok_button;
   GtkWidget *sw;
 
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
@@ -58,7 +69,7 @@ photos_organize_collection_dialog_init (PhotosOrganizeCollectionDialog *self)
                                             PhotosOrganizeCollectionDialogPrivate);
   priv = self->priv;
 
-  gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT);
+  ok_button = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT);
   gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
   gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
 
@@ -73,6 +84,21 @@ photos_organize_collection_dialog_init (PhotosOrganizeCollectionDialog *self)
   gtk_container_add (GTK_CONTAINER (sw), priv->coll_view);
   gtk_container_add (GTK_CONTAINER (content_area), sw);
 
+  /* HACK:
+   * - We want clicking on "OK" to add the typed-in collection if
+   *   we're editing.
+   * - Unfortunately, since we focus out of the editable entry in
+   *   order to click the button, we'll get an editing-canceled signal
+   *   on the renderer from GTK+. As this handler will run before
+   *   focus-out, we here signal the view to ignore the next
+   *   editing-canceled signal and add the collection in that case
+   *   instead.
+   */
+  g_signal_connect (ok_button,
+                    "button-press-event",
+                    G_CALLBACK (photos_organize_collection_dialog_button_press_event),
+                    self);
+
   gtk_widget_show_all (GTK_WIDGET (self));
 }
 
diff --git a/src/photos-organize-collection-model.c b/src/photos-organize-collection-model.c
index b146080..b1b5154 100644
--- a/src/photos-organize-collection-model.c
+++ b/src/photos-organize-collection-model.c
@@ -169,15 +169,21 @@ photos_organize_collection_model_destroy (PhotosOrganizeCollectionModel *self)
 
 
 GtkTreePath *
-photos_organize_collection_model_forget_placeholder (PhotosOrganizeCollectionModel *self)
+photos_organize_collection_model_get_placeholder (PhotosOrganizeCollectionModel *self, gboolean forget)
 {
   PhotosOrganizeCollectionModelPrivate *priv = self->priv;
-  GtkTreePath *path;
+  GtkTreePath *ret_val = NULL;
 
-  path = gtk_tree_row_reference_get_path (priv->placeholder_ref);
-  gtk_tree_row_reference_free (priv->placeholder_ref);
-  priv->placeholder_ref = NULL;
-  return path;
+  if (priv->placeholder_ref != NULL)
+    ret_val = gtk_tree_row_reference_get_path (priv->placeholder_ref);
+
+  if (forget)
+    {
+      gtk_tree_row_reference_free (priv->placeholder_ref);
+      priv->placeholder_ref = NULL;
+    }
+
+  return ret_val;
 }
 
 
diff --git a/src/photos-organize-collection-model.h b/src/photos-organize-collection-model.h
index 5635d9d..2ebd761 100644
--- a/src/photos-organize-collection-model.h
+++ b/src/photos-organize-collection-model.h
@@ -87,7 +87,8 @@ GtkTreePath      *photos_organize_collection_model_add_placeholder        (Photo
 
 void              photos_organize_collection_model_destroy                (PhotosOrganizeCollectionModel *self);
 
-GtkTreePath      *photos_organize_collection_model_forget_placeholder     (PhotosOrganizeCollectionModel *self);
+GtkTreePath      *photos_organize_collection_model_get_placeholder        (PhotosOrganizeCollectionModel *self,
+                                                                           gboolean                       forget);
 
 void              photos_organize_collection_model_remove_placeholder     (PhotosOrganizeCollectionModel *self);
 
diff --git a/src/photos-organize-collection-view.c b/src/photos-organize-collection-view.c
index d9da603..a2522f1 100644
--- a/src/photos-organize-collection-view.c
+++ b/src/photos-organize-collection-view.c
@@ -35,6 +35,7 @@ struct _PhotosOrganizeCollectionViewPrivate
   GtkCellRenderer *renderer_text;
   GtkListStore *model;
   GtkTreeViewColumn *view_col;
+  gboolean choice_confirmed;
 };
 
 
@@ -208,3 +209,10 @@ photos_organize_collection_view_add_collection (PhotosOrganizeCollectionView *se
   g_object_set (priv->renderer_text, "editable", TRUE, NULL);
   gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (self), path, priv->view_col, priv->renderer_text, TRUE);
 }
+
+
+void
+photos_organize_collection_view_confirmed_choice (PhotosOrganizeCollectionView *self)
+{
+  self->priv->choice_confirmed = TRUE;
+}
diff --git a/src/photos-organize-collection-view.h b/src/photos-organize-collection-view.h
index b041301..b541084 100644
--- a/src/photos-organize-collection-view.h
+++ b/src/photos-organize-collection-view.h
@@ -68,6 +68,8 @@ GtkWidget        *photos_organize_collection_view_new                    (void);
 
 void              photos_organize_collection_view_add_collection         (PhotosOrganizeCollectionView *self);
 
+void              photos_organize_collection_view_confirmed_choice       (PhotosOrganizeCollectionView *self);
+
 G_END_DECLS
 
 #endif /* PHOTOS_ORGANIZE_COLLECTION_VIEW_H */



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