Skip to content

Commit

Permalink
Change register page icon to a padlock if read only
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob-IT committed Dec 10, 2020
1 parent dced40c commit 0ee7ebb
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
70 changes: 70 additions & 0 deletions gnucash/gnome-utils/gnc-main-window.c
Expand Up @@ -2442,6 +2442,76 @@ main_window_update_page_color (GncPluginPage *page,
}


void
main_window_update_page_set_read_only_icon (GncPluginPage *page,
gboolean read_only)
{
GncMainWindow *window;
GncMainWindowPrivate *priv;
GtkWidget *tab_widget;
GtkWidget *image = NULL;
GList *children;
gchar *image_name = NULL;
const gchar *icon_name;

ENTER(" ");

window = GNC_MAIN_WINDOW(page->window);

/* Get the notebook tab widget */
main_window_find_tab_widget (window, page, &tab_widget);
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);

if (!tab_widget)
{
LEAVE("no tab widget");
return;
}

if (GTK_IS_EVENT_BOX(tab_widget))
tab_widget = gtk_bin_get_child (GTK_BIN(tab_widget));

/* For each, walk the list of container children to get image widget */
for (children = gtk_container_get_children (GTK_CONTAINER(tab_widget));
children; children = children->next)
{
GtkWidget *widget = children->data;
if (GTK_IS_IMAGE(widget))
image = widget;
}

if (!image)
{
LEAVE("no image to replace");
return;
}

g_object_get (image, "icon-name", &image_name, NULL);

if (read_only)
icon_name = "changes-prevent-symbolic";
else
icon_name = GNC_PLUGIN_PAGE_GET_CLASS(page)->tab_icon;

if (g_strcmp0 (icon_name, image_name) == 0)
{
LEAVE("page icon the same, no need to replace");
g_free (image_name);
return;
}
gtk_container_remove (GTK_CONTAINER(tab_widget), image);
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
gtk_widget_show (image);

gtk_container_add (GTK_CONTAINER(tab_widget), image);
gtk_widget_set_margin_start (GTK_WIDGET(image), 5);
gtk_box_reorder_child (GTK_BOX(tab_widget), image, 0);

g_free (image_name);
LEAVE("done");
}


static void
gnc_main_window_tab_entry_activate (GtkWidget *entry,
GncPluginPage *page)
Expand Down
9 changes: 9 additions & 0 deletions gnucash/gnome-utils/gnc-main-window.h
Expand Up @@ -185,6 +185,15 @@ void
main_window_update_page_color (GncPluginPage *page,
const gchar *color_in);

/** Update the icon on the page tabs in the main window.
*
* @param page The page to be updated.
* @param read_only If set a padlock icon will be displayed
* for the page tab icon if it had one.
*/
void
main_window_update_page_set_read_only_icon (GncPluginPage *page,
gboolean read_only);

/** Manually add a set of actions to the specified window. Plugins
* whose user interface is not hard coded (e.g. the menu-additions *
Expand Down
26 changes: 26 additions & 0 deletions gnucash/gnome/gnc-plugin-page-register.c
Expand Up @@ -1126,6 +1126,7 @@ gnc_plugin_page_register_ui_update (gpointer various,
GtkAction* action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), *iter);
gtk_action_set_sensitive (action, TRUE);
}
main_window_update_page_set_read_only_icon (GNC_PLUGIN_PAGE(page), FALSE);

if (trans)
read_only = xaccTransIsReadonlyByPostedDate (trans);
Expand Down Expand Up @@ -1209,6 +1210,7 @@ gnc_plugin_page_register_ui_update (gpointer various,
GtkAction* action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), *iter);
gtk_action_set_sensitive (action, FALSE);
}
main_window_update_page_set_read_only_icon (GNC_PLUGIN_PAGE(page), TRUE);
}

/* Modifying action descriptions based on cursor class */
Expand Down Expand Up @@ -3512,6 +3514,27 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page)
LEAVE (" ");
}


static void
gnc_plugin_page_register_update_page_icon (GncPluginPage* plugin_page)
{
GncPluginPageRegisterPrivate* priv;
gboolean read_only;

g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page));

priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);

if (qof_book_is_readonly (gnc_get_current_book()) ||
gnc_split_reg_get_read_only (priv->gsr))
read_only = TRUE;
else
read_only = FALSE;

main_window_update_page_set_read_only_icon (GNC_PLUGIN_PAGE(plugin_page),
read_only);
}

/************************************************************/
/* Report Helper Functions */
/************************************************************/
Expand Down Expand Up @@ -5393,6 +5416,9 @@ gnc_plugin_page_register_event_handler (QofInstance* entity,
main_window_update_page_name (GNC_PLUGIN_PAGE (page), label);
color = gnc_plugin_page_register_get_tab_color (GNC_PLUGIN_PAGE (page));
main_window_update_page_color (GNC_PLUGIN_PAGE (page), color);
// update page icon if read only registers
gnc_plugin_page_register_update_page_icon (GNC_PLUGIN_PAGE (page));

g_free (color);
g_free (label);
}
Expand Down

0 comments on commit 0ee7ebb

Please sign in to comment.