gnucash stable: Bug 799048 - Hover on tab not correct
Robert Fewell
bobit at code.gnucash.org
Sat Aug 5 09:52:38 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/84db7916 (commit)
from https://github.com/Gnucash/gnucash/commit/d8954456 (commit)
commit 84db7916a0c943c5874643d42387580578841757
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Sat Aug 5 14:46:08 2023 +0100
Bug 799048 - Hover on tab not correct
When the account name is changed, an event is used to update the tool
tip on the register tab. If the account is moved, the same event is
triggered but as the name is the same, the tool tip is not updated.
Add a new function 'main_window_update_page_long_name' to only update
the long name and the tool tip and call it from the register event
after setting the name. Also remove the setting of the long name from
'main_window_update_page_name'.
diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp
index 5dd830edf8..d7e19473e1 100644
--- a/gnucash/gnome-utils/gnc-main-window.cpp
+++ b/gnucash/gnome-utils/gnc-main-window.cpp
@@ -2292,6 +2292,48 @@ main_window_find_tab_widget (GncMainWindow *window,
return TRUE;
}
+void
+main_window_update_page_long_name (GncPluginPage *page,
+ const gchar *long_name_in)
+{
+ GtkWidget *tab_widget;
+
+ ENTER(" ");
+
+ if ((long_name_in == nullptr) || (*long_name_in == '\0'))
+ {
+ LEAVE("no string");
+ return;
+ }
+ gchar *long_name = g_strstrip (g_strdup (long_name_in));
+ const gchar *old_long_name = gnc_plugin_page_get_page_long_name (page);
+
+ /* Optimization, if the long_name hasn't changed, don't update X. */
+ if (*long_name == '\0' || strcmp (long_name, old_long_name) == 0)
+ {
+ g_free (long_name);
+ LEAVE("empty string or name unchanged");
+ return;
+ }
+
+ gnc_plugin_page_set_page_long_name (page, long_name);
+
+ GncMainWindow *window = GNC_MAIN_WINDOW(page->window);
+ if (!window)
+ {
+ g_free (long_name);
+ LEAVE("no window widget available");
+ return;
+ }
+
+ /* Update the notebook tab tooltip */
+ if (main_window_find_tab_widget (window, page, &tab_widget))
+ gtk_widget_set_tooltip_text (tab_widget, long_name);
+
+ g_free (long_name);
+ LEAVE("");
+}
+
void
main_window_update_page_name (GncPluginPage *page,
const gchar *name_in)
@@ -2344,25 +2386,6 @@ main_window_update_page_name (GncPluginPage *page,
gnc_main_window_update_tab_width_one_page (page, tw);
g_free (tw);
- /* Update Tooltip on notebook Tab */
- if (old_page_long_name && old_page_name
- && g_strrstr(old_page_long_name, old_page_name) != nullptr)
- {
- gchar *new_page_long_name;
- gint string_position;
- GtkWidget *tab_widget;
-
- string_position = strlen(old_page_long_name) - strlen(old_page_name);
- new_page_long_name = g_strconcat(g_strndup(old_page_long_name, string_position), name, nullptr);
-
- gnc_plugin_page_set_page_long_name(page, new_page_long_name);
-
- if (main_window_find_tab_widget(window, page, &tab_widget))
- gtk_widget_set_tooltip_text(tab_widget, new_page_long_name);
-
- g_free(new_page_long_name);
- }
-
/* Update the notebook menu */
if (page->notebook_page)
{
diff --git a/gnucash/gnome-utils/gnc-main-window.h b/gnucash/gnome-utils/gnc-main-window.h
index 7216fc3e08..63bd933d6d 100644
--- a/gnucash/gnome-utils/gnc-main-window.h
+++ b/gnucash/gnome-utils/gnc-main-window.h
@@ -179,6 +179,15 @@ void
main_window_update_page_name (GncPluginPage *page,
const gchar *name_in);
+/** Update the long name of the page in the main window.
+ *
+ * @param page The page to be updated.
+ * @param long_name_in The new long name for the page.
+*/
+void
+main_window_update_page_long_name (GncPluginPage *page,
+ const gchar *long_name_in);
+
/** Update the color on the page tabs in the main window.
*
* @param page The page to be updated.
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 8683bcd78a..c9bee2493e 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -5287,7 +5287,6 @@ gnc_plugin_page_register_event_handler (QofInstance* entity,
QofBook* book;
GncPluginPage* visible_page;
GtkWidget* window;
- gchar* label, *color;
g_return_if_fail (page); /* Required */
if (!GNC_IS_TRANS (entity) && !GNC_IS_ACCOUNT (entity))
@@ -5302,15 +5301,20 @@ gnc_plugin_page_register_event_handler (QofInstance* entity,
{
if (GNC_IS_MAIN_WINDOW (window))
{
- label = gnc_plugin_page_register_get_tab_name (GNC_PLUGIN_PAGE (page));
- main_window_update_page_name (GNC_PLUGIN_PAGE (page), label);
- color = gnc_plugin_page_register_get_tab_color (GNC_PLUGIN_PAGE (page));
+ gchar *name = gnc_plugin_page_register_get_tab_name (GNC_PLUGIN_PAGE (page));
+ main_window_update_page_name (GNC_PLUGIN_PAGE (page), name);
+
+ gchar *long_name = gnc_plugin_page_register_get_long_name (GNC_PLUGIN_PAGE (page));
+ main_window_update_page_long_name (GNC_PLUGIN_PAGE (page), long_name);
+
+ gchar *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);
+ g_free (name);
+ g_free (long_name);
}
LEAVE ("tab name updated");
return;
Summary of changes:
gnucash/gnome-utils/gnc-main-window.cpp | 61 ++++++++++++++++++++++----------
gnucash/gnome-utils/gnc-main-window.h | 9 +++++
gnucash/gnome/gnc-plugin-page-register.c | 14 +++++---
3 files changed, 60 insertions(+), 24 deletions(-)
More information about the gnucash-changes
mailing list