[gtranslator] Destroy tab instead of removing it.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Destroy tab instead of removing it.
- Date: Wed, 18 May 2011 09:22:07 +0000 (UTC)
commit 67b1038053a3845fb100bdc5a065a851845e8d26
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed May 18 11:22:10 2011 +0200
Destroy tab instead of removing it.
We break circular references doing this. Fixes a bug where the tab
was not finalized.
src/gtr-actions-file.c | 10 +---------
src/gtr-notebook.c | 38 ++++++++++++++++++++++++++++++--------
src/gtr-notebook.h | 14 ++++++--------
src/gtr-tab-activatable.c | 21 ---------------------
src/gtr-tab-activatable.h | 3 ---
src/gtr-window.c | 1 +
6 files changed, 38 insertions(+), 49 deletions(-)
---
diff --git a/src/gtr-actions-file.c b/src/gtr-actions-file.c
index fdbab3a..27efcc7 100644
--- a/src/gtr-actions-file.c
+++ b/src/gtr-actions-file.c
@@ -510,17 +510,9 @@ static void
close_all_tabs (GtrWindow * window)
{
GtrNotebook *nb;
- gint pages;
nb = gtr_window_get_notebook (window);
- pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb));
-
- while (pages >= 0)
- {
- gtk_notebook_remove_page (GTK_NOTEBOOK (nb), pages);
-
- pages--;
- }
+ gtr_notebook_remove_all_pages (nb);
//FIXME: This has to change once we add the close all documents menuitem
gtk_widget_destroy (GTK_WIDGET (window));
diff --git a/src/gtr-notebook.c b/src/gtr-notebook.c
index 4487b93..26b9ae3 100644
--- a/src/gtr-notebook.c
+++ b/src/gtr-notebook.c
@@ -164,6 +164,18 @@ gtr_notebook_add_page (GtrNotebook * notebook, GtrTab * tab)
update_tabs_visibility (notebook);
}
+static void
+remove_tab (GtrTab *tab,
+ GtrNotebook *notebook)
+{
+ remove_tab_label (notebook, tab);
+
+ /* Destroy the tab to break circular refs */
+ gtk_widget_destroy (GTK_WIDGET (tab));
+
+ update_tabs_visibility (notebook);
+}
+
/**
* gtr_notebook_remove_page:
* @notebook: a #GtrNotebook
@@ -174,19 +186,29 @@ gtr_notebook_add_page (GtrNotebook * notebook, GtrTab * tab)
void
gtr_notebook_remove_page (GtrNotebook * notebook, gint page_num)
{
- GtkWidget *tab;
+ GtrTab *tab;
g_return_if_fail (GTR_IS_NOTEBOOK (notebook));
- tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page_num);
+ tab = GTR_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page_num));
+
+ remove_tab (tab, notebook);
+}
- if (page_num != -1)
- {
- remove_tab_label (notebook, GTR_TAB (tab));
- gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num);
- }
+/**
+ * gtr_notebook_remove_all_pages:
+ * @notebook: a #GtrNotebook
+ *
+ * Removes all tabs from from @notebook
+ */
+void
+gtr_notebook_remove_all_pages (GtrNotebook *notebook)
+{
+ g_return_if_fail (GTR_IS_NOTEBOOK (notebook));
- update_tabs_visibility (notebook);
+ gtk_container_foreach (GTK_CONTAINER (notebook),
+ (GtkCallback)remove_tab,
+ notebook);
}
/**
diff --git a/src/gtr-notebook.h b/src/gtr-notebook.h
index 51ad720..4359f79 100644
--- a/src/gtr-notebook.h
+++ b/src/gtr-notebook.h
@@ -61,19 +61,17 @@ struct _GtrNotebookClass
/*
* Public methods
*/
-GType
-gtr_notebook_get_type (void)
- G_GNUC_CONST;
+GType gtr_notebook_get_type (void) G_GNUC_CONST;
- GType gtr_notebook_register_type (GTypeModule * module);
+GtkWidget *gtr_notebook_new (void);
- GtkWidget *gtr_notebook_new (void);
+void gtr_notebook_add_page (GtrNotebook * notebook, GtrTab * tab);
- void gtr_notebook_add_page (GtrNotebook * notebook, GtrTab * tab);
+void gtr_notebook_remove_page (GtrNotebook * notebook, gint page_num);
- void gtr_notebook_remove_page (GtrNotebook * notebook, gint page_num);
+void gtr_notebook_remove_all_pages (GtrNotebook *notebook);
- GtrTab *gtr_notebook_get_page (GtrNotebook * notebook);
+GtrTab *gtr_notebook_get_page (GtrNotebook * notebook);
G_END_DECLS
#endif /* __NOTEBOOK_H__ */
diff --git a/src/gtr-tab-activatable.c b/src/gtr-tab-activatable.c
index ec476c3..e35ace6 100644
--- a/src/gtr-tab-activatable.c
+++ b/src/gtr-tab-activatable.c
@@ -102,24 +102,3 @@ gtr_tab_activatable_deactivate (GtrTabActivatable * activatable)
iface->deactivate (activatable);
}
}
-
-/**
- * gtr_tab_activatable_update_state:
- * @activatable: A #GtrTabActivatable.
- *
- * Triggers an update of the extension internal state to take into account
- * state changes in the tab, due to some event or user action.
- */
-void
-gtr_tab_activatable_update_state (GtrTabActivatable * activatable)
-{
- GtrTabActivatableInterface *iface;
-
- g_return_if_fail (GTR_IS_TAB_ACTIVATABLE (activatable));
-
- iface = GTR_TAB_ACTIVATABLE_GET_IFACE (activatable);
- if (iface->update_state != NULL)
- {
- iface->update_state (activatable);
- }
-}
diff --git a/src/gtr-tab-activatable.h b/src/gtr-tab-activatable.h
index ee01228..562096b 100644
--- a/src/gtr-tab-activatable.h
+++ b/src/gtr-tab-activatable.h
@@ -43,7 +43,6 @@ struct _GtrTabActivatableInterface
/* Virtual public methods */
void (*activate) (GtrTabActivatable * activatable);
void (*deactivate) (GtrTabActivatable * activatable);
- void (*update_state) (GtrTabActivatable * activatable);
};
/*
@@ -57,8 +56,6 @@ gtr_tab_activatable_get_type (void)
activatable);
void gtr_tab_activatable_deactivate (GtrTabActivatable *
activatable);
- void gtr_tab_activatable_update_state (GtrTabActivatable *
- activatable);
G_END_DECLS
#endif /* __GTR_TAB_ACTIVATABLE_H__ */
diff --git a/src/gtr-window.c b/src/gtr-window.c
index be3d6f8..81e92a8 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -1990,6 +1990,7 @@ _gtr_window_close_tab (GtrWindow * window, GtrTab * tab)
gtr_statusbar_clear_progress_bar (GTR_STATUSBAR
(window->priv->statusbar));
}
+
set_sensitive_according_to_window (window);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]