gnucash unstable: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Fri Dec 29 17:43:49 EST 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/7951d425 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/965685cc (commit)
	from  https://github.com/Gnucash/gnucash/commit/47a42207 (commit)



commit 7951d4259e45b2632f26ab03dbb7d9603ec2a3c2
Merge: 47a4220 965685c
Author: John Ralls <jralls at ceridwen.us>
Date:   Fri Dec 29 14:32:21 2017 -0800

    Bug 616709 - Pressing delete key while editing account name offers...
    
    to delete account.


commit 965685cc7f24975b41a476f3abeb87af074f3860
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Fri Dec 29 12:29:57 2017 +0000

    Bug 616709 - Stop the delete button on the Account page
    
    When editing editable text fields on the Account page, if you press the
    delete key a 'delete account popup' would pop so these changes prevent
    that by disabling / enabling the delete key binding.

diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c
index 75aeee3..c1cac82 100644
--- a/gnucash/gnome-utils/gnc-tree-view-account.c
+++ b/gnucash/gnome-utils/gnc-tree-view-account.c
@@ -659,7 +659,7 @@ gnc_tree_view_account_color_update (gpointer gsettings, gchar *key, gpointer use
         priv->show_account_color = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, key);
 }
 
-/** Add the account color background data function to the GncTreeViewAccount column to 
+/** Add the account color background data function to the GncTreeViewAccount column to
  *  show or not the column background in the account color.
  */
 void
@@ -1521,7 +1521,7 @@ gnc_tree_view_account_set_selected_accounts (GncTreeViewAccount *view,
              */
             continue;
         }
-        
+
         path = gnc_tree_model_account_get_path_from_account (GNC_TREE_MODEL_ACCOUNT(model), account);
         if (path == NULL)
         {
@@ -2671,3 +2671,15 @@ static gboolean gnc_tree_view_search_compare (GtkTreeModel *model, gint column,
     // inverted return (FALSE means a match)
     return !match;
 }
+
+void gnc_tree_view_account_set_editing_started_cb(GncTreeViewAccount *view,
+    GFunc editing_started_cb, gpointer editing_cb_data)
+{
+    gnc_tree_view_set_editing_started_cb (GNC_TREE_VIEW(view), editing_started_cb, editing_cb_data);
+}
+
+void gnc_tree_view_account_set_editing_finished_cb(GncTreeViewAccount *view,
+    GFunc editing_finished_cb, gpointer editing_cb_data)
+{
+    gnc_tree_view_set_editing_finished_cb (GNC_TREE_VIEW(view), editing_finished_cb, editing_cb_data);
+}
diff --git a/gnucash/gnome-utils/gnc-tree-view-account.h b/gnucash/gnome-utils/gnc-tree-view-account.h
index b6381f2..072fd96 100644
--- a/gnucash/gnome-utils/gnc-tree-view-account.h
+++ b/gnucash/gnome-utils/gnc-tree-view-account.h
@@ -471,11 +471,24 @@ void gnc_tree_view_account_select_subaccounts (GncTreeViewAccount *view,
  */
 void gnc_tree_view_account_expand_to_account (GncTreeViewAccount *view, Account *account);
 
-/** Add the account color background data function to the GncTreeViewAccount column to 
+/** Add the account color background data function to the GncTreeViewAccount column to
  *  show or not the column background in the account color.
  */
 void gnc_tree_view_account_column_add_color (GncTreeViewAccount *view, GtkTreeViewColumn *col);
 
+/** Setup the callback for when the user starts editing the account tree so actions can be disabled
+ *  like the delete menu option as required.
+ */
+void gnc_tree_view_account_set_editing_started_cb
+    (GncTreeViewAccount *view, GFunc editing_started_cb, gpointer editing_cb_data );
+
+/** Setup the callback for when the user finishes editing the account tree so actions can be enabled
+ *  like the delete menu option as required.
+ */
+void gnc_tree_view_account_set_editing_finished_cb
+    (GncTreeViewAccount *view, GFunc editing_finished_cb, gpointer editing_cb_data );
+
+
 /** @} */
 
 /** @} */
diff --git a/gnucash/gnome-utils/gnc-tree-view.c b/gnucash/gnome-utils/gnc-tree-view.c
index 015e2fd..a5ea1ac 100644
--- a/gnucash/gnome-utils/gnc-tree-view.c
+++ b/gnucash/gnome-utils/gnc-tree-view.c
@@ -116,6 +116,11 @@ typedef struct GncTreeViewPrivate
     /* Sort callback model */
     GtkTreeModel      *sort_model;
 
+    /* Editing callback functions */
+    GFunc editing_started_cb;
+    GFunc editing_finished_cb;
+    gpointer editing_cb_data;
+
     /* State related values */
     gchar             *state_section;
     gboolean           seen_state_visibility;
@@ -1756,6 +1761,35 @@ gnc_tree_view_add_toggle_column (GncTreeView *view,
     return column;
 }
 
+static void
+renderer_editing_canceled_cb (GtkCellRenderer *renderer, gpointer user_data)
+{
+    GncTreeView *view = user_data;
+    GncTreeViewPrivate *priv = GNC_TREE_VIEW_GET_PRIVATE(view);
+    if (priv->editing_finished_cb)
+        (priv->editing_finished_cb)(view, priv->editing_cb_data);
+}
+
+static void
+renderer_editing_started_cb (GtkCellRenderer *renderer,
+               GtkCellEditable *editable, gchar *path, gpointer user_data)
+{
+    GncTreeView *view = user_data;
+    GncTreeViewPrivate *priv = GNC_TREE_VIEW_GET_PRIVATE(view);
+    if (priv->editing_started_cb)
+        (priv->editing_started_cb)(view, priv->editing_cb_data);
+}
+
+static void
+renderer_edited_cb (GtkCellRendererText *renderer, gchar *path,
+                    gchar *new_text, gpointer user_data)
+{
+    GncTreeView *view = user_data;
+    GncTreeViewPrivate *priv = GNC_TREE_VIEW_GET_PRIVATE(view);
+    if (priv->editing_finished_cb)
+        (priv->editing_finished_cb)(view, priv->editing_cb_data);
+}
+
 /** This function adds a new text column to a GncTreeView base view.
  *  It takes all the parameters necessary to hook a GtkTreeModel
  *  column to a GtkTreeViewColumn.  If the tree has a state section
@@ -1796,6 +1830,16 @@ gnc_tree_view_add_text_column (GncTreeView *view,
     renderer = gtk_cell_renderer_text_new ();
     gtk_tree_view_column_pack_start (column, renderer, TRUE);
 
+    /* Set up the callbacks for when editing */
+    g_signal_connect(G_OBJECT(renderer), "editing-canceled",
+                         (GCallback) renderer_editing_canceled_cb, view);
+
+    g_signal_connect(G_OBJECT(renderer), "editing-started",
+                         (GCallback) renderer_editing_started_cb, view);
+
+    g_signal_connect(G_OBJECT(renderer), "edited",
+                         (GCallback) renderer_edited_cb, view);
+
     /* Set renderer attributes controlled by the model */
     if (model_data_column != GNC_TREE_VIEW_COLUMN_DATA_NONE)
         gtk_tree_view_column_add_attribute (column, renderer,
@@ -2149,5 +2193,33 @@ gnc_tree_view_keynav(GncTreeView *view, GtkTreeViewColumn **col,
     return;
 }
 
+void
+gnc_tree_view_set_editing_started_cb(GncTreeView *view, GFunc editing_started_cb, gpointer editing_cb_data)
+{
+    GncTreeViewPrivate *priv;
+
+    if (!view && !editing_started_cb)
+        return;
+
+    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
+
+    priv->editing_started_cb = editing_started_cb;
+    priv->editing_cb_data = editing_cb_data;
+}
+
+void
+gnc_tree_view_set_editing_finished_cb(GncTreeView *view, GFunc editing_finished_cb, gpointer editing_cb_data)
+{
+    GncTreeViewPrivate *priv;
+
+    if (!view && !editing_finished_cb)
+        return;
+
+    priv = GNC_TREE_VIEW_GET_PRIVATE(view);
+
+    priv->editing_finished_cb = editing_finished_cb;
+    priv->editing_cb_data = editing_cb_data;
+}
+
 /** @} */
 /** @} */
diff --git a/gnucash/gnome-utils/gnc-tree-view.h b/gnucash/gnome-utils/gnc-tree-view.h
index 27f01f6..9b379a4 100644
--- a/gnucash/gnome-utils/gnc-tree-view.h
+++ b/gnucash/gnome-utils/gnc-tree-view.h
@@ -453,6 +453,20 @@ gnc_tree_view_keynav(GncTreeView *view, GtkTreeViewColumn **col,
 gboolean
 gnc_tree_view_path_is_valid(GncTreeView *view, GtkTreePath *path);
 
+/** Setup a callback for when the user starts editing so appropiate actions can be taken
+ *  like disable the actions delete menu option.
+ */
+void
+gnc_tree_view_set_editing_started_cb(GncTreeView *view,
+                    GFunc editing_started_cb, gpointer editing_cb_data);
+
+/** Setup a callback for when the user finishes editing so appropiate actions can be taken
+ *  like enable the actions delete menu option.
+ */
+void
+gnc_tree_view_set_editing_finished_cb(GncTreeView *view,
+                   GFunc editing_finished_cb, gpointer editing_cb_data);
+
 /** @} */
 
 /** @} */
diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c
index 1630dfe..aeee963 100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.c
@@ -613,6 +613,28 @@ gnc_plugin_page_account_tree_close_cb (gpointer user_data)
     gnc_main_window_close_page(plugin_page);
 }
 
+static void
+gnc_plugin_page_account_editing_started_cd (gpointer various, GncPluginPageRegister *page)
+{
+    GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(page);
+    GtkAction *action = gnc_main_window_find_action (GNC_MAIN_WINDOW(plugin_page->window),
+                                                     "EditDeleteAccountAction");
+
+    if (action != NULL)
+        gtk_action_set_sensitive (action, FALSE);
+}
+
+static void
+gnc_plugin_page_account_editing_finished_cb (gpointer various, GncPluginPageRegister *page)
+{
+    GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(page);
+    GtkAction *action = gnc_main_window_find_action (GNC_MAIN_WINDOW(plugin_page->window),
+                                                     "EditDeleteAccountAction");
+
+    if (action != NULL)
+        gtk_action_set_sensitive (action, TRUE);
+}
+
 static GtkWidget *
 gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
 {
@@ -668,6 +690,12 @@ gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
     gnc_tree_view_account_set_notes_edited(GNC_TREE_VIEW_ACCOUNT(tree_view),
                                            gnc_tree_view_account_notes_edited_cb);
 
+    // Setup some callbacks so menu actions can be disabled/enabled
+    gnc_tree_view_account_set_editing_started_cb(GNC_TREE_VIEW_ACCOUNT(tree_view),
+        (GFunc)gnc_plugin_page_account_editing_started_cd, page);
+    gnc_tree_view_account_set_editing_finished_cb(GNC_TREE_VIEW_ACCOUNT(tree_view),
+        (GFunc)gnc_plugin_page_account_editing_finished_cb, page);
+
     priv->tree_view = tree_view;
     selection = gtk_tree_view_get_selection(tree_view);
     g_signal_connect (G_OBJECT (selection), "changed",



Summary of changes:
 gnucash/gnome-utils/gnc-tree-view-account.c  | 16 ++++++-
 gnucash/gnome-utils/gnc-tree-view-account.h  | 15 +++++-
 gnucash/gnome-utils/gnc-tree-view.c          | 72 ++++++++++++++++++++++++++++
 gnucash/gnome-utils/gnc-tree-view.h          | 14 ++++++
 gnucash/gnome/gnc-plugin-page-account-tree.c | 28 +++++++++++
 5 files changed, 142 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list