pspp-dev
[Top][All Lists]
Advanced

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

[PATCH 07/17] pspp-sheet-view: Edit cells on the first click by default.


From: Ben Pfaff
Subject: [PATCH 07/17] pspp-sheet-view: Edit cells on the first click by default.
Date: Sun, 22 Apr 2012 11:12:25 -0700

With GtkTreeView it takes two clicks to edit a cell.  The first click
selects the row and the second click starts editing.  This isn't a
great user experience for a spreadsheet, so this commit enables
single-click editing.
---
 src/ui/gui/pspp-sheet-view-column.c |   65 +++++++++++++++++++++++++++++++++--
 src/ui/gui/pspp-sheet-view-column.h |    5 +++
 src/ui/gui/pspp-sheet-view.c        |   17 ++++++++-
 3 files changed, 82 insertions(+), 5 deletions(-)

diff --git a/src/ui/gui/pspp-sheet-view-column.c 
b/src/ui/gui/pspp-sheet-view-column.c
index 1677953..a59a14e 100644
--- a/src/ui/gui/pspp-sheet-view-column.c
+++ b/src/ui/gui/pspp-sheet-view-column.c
@@ -67,7 +67,8 @@ enum
   PROP_REORDERABLE,
   PROP_SORT_INDICATOR,
   PROP_SORT_ORDER,
-  PROP_SORT_COLUMN_ID
+  PROP_SORT_COLUMN_ID,
+  PROP_QUICK_EDIT
 };
 
 enum
@@ -362,6 +363,14 @@ pspp_sheet_view_column_class_init 
(PsppSheetViewColumnClass *class)
                                                      G_MAXINT,
                                                      -1,
                                                      GTK_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_QUICK_EDIT,
+                                   g_param_spec_boolean ("quick-edit",
+                                                         P_("Quick edit"),
+                                                         P_("If true, editing 
starts upon the first click in the column.  If false, the first click selects 
the column and a second click is needed to begin editing.  This has no effect 
on cells that are not editable."),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE));
 }
 
 static void
@@ -412,6 +421,7 @@ pspp_sheet_view_column_init (PsppSheetViewColumn 
*tree_column)
   tree_column->fixed_width = 1;
   tree_column->use_resized_width = FALSE;
   tree_column->title = g_strdup ("");
+  tree_column->quick_edit = TRUE;
 }
 
 static void
@@ -531,7 +541,12 @@ pspp_sheet_view_column_set_property (GObject         
*object,
       pspp_sheet_view_column_set_sort_column_id (tree_column,
                                                g_value_get_int (value));
       break;
-      
+
+    case PROP_QUICK_EDIT:
+      pspp_sheet_view_column_set_quick_edit (tree_column,
+                                             g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -629,7 +644,12 @@ pspp_sheet_view_column_get_property (GObject         
*object,
       g_value_set_int (value,
                        pspp_sheet_view_column_get_sort_column_id 
(tree_column));
       break;
-      
+
+    case PROP_QUICK_EDIT:
+      g_value_set_boolean (value,
+                           pspp_sheet_view_column_get_quick_edit 
(tree_column));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2328,6 +2348,45 @@ pspp_sheet_view_column_get_reorderable 
(PsppSheetViewColumn *tree_column)
   return tree_column->reorderable;
 }
 
+/**
+ * pspp_sheet_view_column_set_quick_edit:
+ * @tree_column: A #PsppSheetViewColumn
+ * @quick_edit: If true, editing starts upon the first click in the column.  If
+ * false, the first click selects the column and a second click is needed to
+ * begin editing.  This has no effect on cells that are not editable.
+ **/
+void
+pspp_sheet_view_column_set_quick_edit (PsppSheetViewColumn *tree_column,
+                                     gboolean           quick_edit)
+{
+  g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
+
+  quick_edit = !!quick_edit;
+  if (tree_column->quick_edit != quick_edit)
+    {
+      tree_column->quick_edit = (quick_edit?TRUE:FALSE);
+      g_object_notify (G_OBJECT (tree_column), "quick-edit");
+    }
+}
+
+/**
+ * pspp_sheet_view_column_get_quick_edit:
+ * @tree_column: A #PsppSheetViewColumn
+ *
+ * Returns %TRUE if editing starts upon the first click in the column.  Returns
+ * %FALSE, the first click selects the column and a second click is needed to
+ * begin editing.  This is not meaningful for cells that are not editable.
+ *
+ * Return value: %TRUE if editing starts upon the first click.
+ **/
+gboolean
+pspp_sheet_view_column_get_quick_edit (PsppSheetViewColumn *tree_column)
+{
+  g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
+
+  return tree_column->quick_edit;
+}
+
 
 /**
  * pspp_sheet_view_column_set_sort_column_id:
diff --git a/src/ui/gui/pspp-sheet-view-column.h 
b/src/ui/gui/pspp-sheet-view-column.h
index 4e640e4..419a326 100644
--- a/src/ui/gui/pspp-sheet-view-column.h
+++ b/src/ui/gui/pspp-sheet-view-column.h
@@ -106,6 +106,7 @@ struct _PsppSheetViewColumn
   guint GSEAL (reorderable)         : 1;
   guint GSEAL (use_resized_width)   : 1;
   guint GSEAL (expand)              : 1;
+  guint GSEAL (quick_edit)          : 1;
 };
 
 struct _PsppSheetViewColumnClass
@@ -194,6 +195,10 @@ void                    
pspp_sheet_view_column_set_reorderable     (PsppSheetVie
                                                                  gboolean      
           reorderable);
 gboolean                pspp_sheet_view_column_get_reorderable     
(PsppSheetViewColumn       *tree_column);
 
+void                    pspp_sheet_view_column_set_quick_edit     
(PsppSheetViewColumn       *tree_column,
+                                                                 gboolean      
           quick_edit);
+gboolean                pspp_sheet_view_column_get_quick_edit     
(PsppSheetViewColumn       *tree_column);
+
 
 
 /* You probably only want to use pspp_sheet_view_column_set_sort_column_id.  
The
diff --git a/src/ui/gui/pspp-sheet-view.c b/src/ui/gui/pspp-sheet-view.c
index a145dd3..fc38eb8 100644
--- a/src/ui/gui/pspp-sheet-view.c
+++ b/src/ui/gui/pspp-sheet-view.c
@@ -2159,8 +2159,9 @@ pspp_sheet_view_button_press (GtkWidget      *widget,
          else
            anchor = NULL;
 
-         if ((anchor && !gtk_tree_path_compare (anchor, path))
-             || !_pspp_sheet_view_column_has_editable_cell (column))
+         if (pspp_sheet_view_column_get_quick_edit (column)
+              || (anchor && !gtk_tree_path_compare (anchor, path))
+              || !_pspp_sheet_view_column_has_editable_cell (column))
            {
              GtkCellEditable *cell_editable = NULL;
 
@@ -2475,6 +2476,18 @@ pspp_sheet_view_button_release (GtkWidget      *widget,
 {
   PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
 
+  if (tree_view->priv->edited_column &&
+      tree_view->priv->edited_column->editable_widget)
+    {
+      /* When a column is in quick-edit mode, the initial button press that
+       * starts editing implicitly grabs the pointer, so that the corresponding
+       * release doesn't get passed along to the GtkWidget created by the
+       * press.  Pass the release along explicitly. */
+      gtk_widget_event (GTK_WIDGET 
(tree_view->priv->edited_column->editable_widget),
+                        (GdkEvent *) event);
+      return FALSE;
+    }
+
   if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
     return pspp_sheet_view_button_release_drag_column (widget, event);
 
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]