ensure gtk scaffolding destruction does not create memory errors

This commit is contained in:
Vincent Sanders 2019-10-13 01:52:22 +01:00
parent c82049eb84
commit 6e31dcaec4
4 changed files with 21 additions and 17 deletions

View File

@ -611,7 +611,6 @@ nserror nsgtk_menu_bar_destroy(struct nsgtk_bar_submenu *menu)
free(menu->view_submenu->scaleview_submenu); free(menu->view_submenu->scaleview_submenu);
free(menu->view_submenu); free(menu->view_submenu);
free(menu->nav_submenu); free(menu->nav_submenu);
free(menu->tabs_submenu);
free(menu->tools_submenu->developer_submenu); free(menu->tools_submenu->developer_submenu);
free(menu->tools_submenu); free(menu->tools_submenu);
free(menu->help_submenu); free(menu->help_submenu);
@ -633,7 +632,6 @@ nserror nsgtk_burger_menu_destroy(struct nsgtk_burger_menu *menu)
free(menu->view_submenu->scaleview_submenu); free(menu->view_submenu->scaleview_submenu);
free(menu->view_submenu); free(menu->view_submenu);
free(menu->nav_submenu); free(menu->nav_submenu);
free(menu->tabs_submenu);
free(menu->tools_submenu->developer_submenu); free(menu->tools_submenu->developer_submenu);
free(menu->tools_submenu); free(menu->tools_submenu);
free(menu->help_submenu); free(menu->help_submenu);

View File

@ -145,7 +145,6 @@ struct nsgtk_bar_submenu {
struct nsgtk_edit_menu *edit_submenu; struct nsgtk_edit_menu *edit_submenu;
struct nsgtk_view_menu *view_submenu; struct nsgtk_view_menu *view_submenu;
struct nsgtk_nav_menu *nav_submenu; struct nsgtk_nav_menu *nav_submenu;
struct nsgtk_tabs_submenu *tabs_submenu;
struct nsgtk_tools_menu *tools_submenu; struct nsgtk_tools_menu *tools_submenu;
struct nsgtk_help_menu *help_submenu; struct nsgtk_help_menu *help_submenu;
}; };
@ -165,9 +164,6 @@ struct nsgtk_burger_menu {
GtkWidget *nav_menuitem; GtkWidget *nav_menuitem;
struct nsgtk_nav_menu *nav_submenu; struct nsgtk_nav_menu *nav_submenu;
GtkWidget *tabs_menuitem;
struct nsgtk_tabs_submenu *tabs_submenu;
GtkWidget *tools_menuitem; GtkWidget *tools_menuitem;
struct nsgtk_tools_menu *tools_submenu; struct nsgtk_tools_menu *tools_submenu;

View File

@ -75,6 +75,9 @@ struct nsgtk_scaffolding {
/** tab widget holding displayed pages */ /** tab widget holding displayed pages */
GtkNotebook *notebook; GtkNotebook *notebook;
/** handler id for tabs remove callback */
gulong tabs_remove_handler_id;
/** menu bar hierarchy */ /** menu bar hierarchy */
struct nsgtk_bar_submenu *menu_bar; struct nsgtk_bar_submenu *menu_bar;
@ -171,8 +174,6 @@ popup_menu_show(struct nsgtk_popup_menu *menu, bool nav, bool cnp)
} }
/* event handlers and support functions for them */
/** /**
* resource cleanup function for window destruction. * resource cleanup function for window destruction.
* *
@ -207,6 +208,8 @@ static void scaffolding_window_destroy(GtkWidget *widget, gpointer data)
nsgtk_popup_menu_destroy(gs->popup_menu); nsgtk_popup_menu_destroy(gs->popup_menu);
nsgtk_link_menu_destroy(gs->link_menu); nsgtk_link_menu_destroy(gs->link_menu);
g_signal_handler_disconnect(gs->notebook, gs->tabs_remove_handler_id);
free(gs); free(gs);
if (scaf_list == NULL) { if (scaf_list == NULL) {
@ -425,6 +428,8 @@ nsgtk_window_tabs_remove(GtkNotebook *notebook,
guint page_num, guint page_num,
struct nsgtk_scaffolding *gs) struct nsgtk_scaffolding *gs)
{ {
gboolean visible;
/* if the scaffold is being destroyed it is not useful to /* if the scaffold is being destroyed it is not useful to
* update the state, further many of the widgets may have * update the state, further many of the widgets may have
* already been destroyed. * already been destroyed.
@ -439,7 +444,7 @@ nsgtk_window_tabs_remove(GtkNotebook *notebook,
return; return;
} }
gboolean visible = gtk_notebook_get_show_tabs(gs->notebook); visible = gtk_notebook_get_show_tabs(gs->notebook);
g_object_set(gs->menu_bar->view_submenu->tabs_menuitem, g_object_set(gs->menu_bar->view_submenu->tabs_menuitem,
"visible", visible, NULL); "visible", visible, NULL);
g_object_set(gs->burger_menu->view_submenu->tabs_menuitem, g_object_set(gs->burger_menu->view_submenu->tabs_menuitem,
@ -1548,7 +1553,7 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
"page-added", "page-added",
G_CALLBACK(nsgtk_window_tabs_add), G_CALLBACK(nsgtk_window_tabs_add),
gs); gs);
g_signal_connect_after(gs->notebook, gs->tabs_remove_handler_id = g_signal_connect_after(gs->notebook,
"page-removed", "page-removed",
G_CALLBACK(nsgtk_window_tabs_remove), G_CALLBACK(nsgtk_window_tabs_remove),
gs); gs);

View File

@ -312,14 +312,19 @@ nsgtk_tab_add_newtab(GtkNotebook *notebook)
static void static void
nsgtk_tab_visibility_update(GtkNotebook *notebook, GtkWidget *child, guint page) nsgtk_tab_visibility_update(GtkNotebook *notebook, GtkWidget *child, guint page)
{ {
gint pagec = gtk_notebook_get_n_pages(notebook); gint pagec;
GtkWidget *addpage = g_object_get_data(G_OBJECT(notebook), "addtab"); GtkWidget *addpage;
if (addpage != NULL) { pagec = gtk_notebook_get_n_pages(notebook);
pagec--; /* skip the add tab */ if (pagec > 1) {
if ((gint)page == pagec) { addpage = g_object_get_data(G_OBJECT(notebook), "addtab");
/* ensure the add new tab cannot be current */ if (addpage != NULL) {
gtk_notebook_set_current_page(notebook, page - 1); pagec--; /* skip the add tab */
if ((gint)page == pagec) {
/* ensure the add new tab cannot be current */
gtk_notebook_set_current_page(notebook,
page - 1);
}
} }
} }