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

to delete account.
This commit is contained in:
John Ralls 2017-12-29 14:32:21 -08:00
commit 7951d4259e
5 changed files with 142 additions and 3 deletions

View File

@ -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);
}

View File

@ -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 );
/** @} */
/** @} */

View File

@ -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;
}
/** @} */
/** @} */

View File

@ -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);
/** @} */
/** @} */

View File

@ -626,6 +626,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)
{
@ -681,6 +703,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",