[gedit] Move the show-tabs-mode property to MultiNotebook
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Move the show-tabs-mode property to MultiNotebook
- Date: Mon, 3 Feb 2014 22:13:39 +0000 (UTC)
commit 81b4cfc45417ac4e6110773631516981468da645
Author: Paolo Borelli <pborelli gnome org>
Date: Mon Feb 3 22:46:27 2014 +0100
Move the show-tabs-mode property to MultiNotebook
This is needed to make sure we always show the tabs when we have
more than one notebook
gedit/gedit-multi-notebook.c | 152 ++++++++++++++++++++++++++++++++++++++++-
gedit/gedit-multi-notebook.h | 11 ++-
gedit/gedit-notebook.c | 132 ------------------------------------
gedit/gedit-notebook.h | 5 +-
gedit/gedit-window.c | 40 +-----------
5 files changed, 162 insertions(+), 178 deletions(-)
---
diff --git a/gedit/gedit-multi-notebook.c b/gedit/gedit-multi-notebook.c
index 2010db2..178787d 100644
--- a/gedit/gedit-multi-notebook.c
+++ b/gedit/gedit-multi-notebook.c
@@ -21,7 +21,9 @@
*/
#include "gedit-multi-notebook.h"
+#include "gedit-enum-types.h"
#include "gedit-marshal.h"
+#include "gedit-settings.h"
struct _GeditMultiNotebookPrivate
{
@@ -31,6 +33,10 @@ struct _GeditMultiNotebookPrivate
GeditTab *active_tab;
+ GeditNotebookShowTabsModeType show_tabs_mode;
+ GSettings *ui_settings;
+
+ guint show_tabs : 1;
guint removing_notebook : 1;
};
@@ -38,7 +44,8 @@ enum
{
PROP_0,
PROP_ACTIVE_NOTEBOOK,
- PROP_ACTIVE_TAB
+ PROP_ACTIVE_TAB,
+ PROP_SHOW_TABS_MODE
};
/* Signals */
@@ -63,6 +70,8 @@ G_DEFINE_TYPE_WITH_PRIVATE (GeditMultiNotebook, gedit_multi_notebook, GTK_TYPE_G
static void remove_notebook (GeditMultiNotebook *mnb,
GtkWidget *notebook);
+static void update_tabs_visibility (GeditMultiNotebook *mnb);
+
static void
gedit_multi_notebook_get_property (GObject *object,
guint prop_id,
@@ -81,6 +90,30 @@ gedit_multi_notebook_get_property (GObject *object,
g_value_set_object (value,
mnb->priv->active_tab);
break;
+ case PROP_SHOW_TABS_MODE:
+ g_value_set_enum (value,
+ mnb->priv->show_tabs_mode);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_multi_notebook_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GeditMultiNotebook *mnb = GEDIT_MULTI_NOTEBOOK (object);
+
+ switch (prop_id)
+ {
+ case PROP_SHOW_TABS_MODE:
+ mnb->priv->show_tabs_mode = g_value_get_enum (value);
+ update_tabs_visibility (mnb);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -88,6 +121,16 @@ gedit_multi_notebook_get_property (GObject *object,
}
static void
+gedit_multi_notebook_dispose (GObject *object)
+{
+ GeditMultiNotebook *mnb = GEDIT_MULTI_NOTEBOOK (object);
+
+ g_clear_object (&mnb->priv->ui_settings);
+
+ G_OBJECT_CLASS (gedit_multi_notebook_parent_class)->dispose (object);
+}
+
+static void
gedit_multi_notebook_finalize (GObject *object)
{
GeditMultiNotebook *mnb = GEDIT_MULTI_NOTEBOOK (object);
@@ -102,8 +145,10 @@ gedit_multi_notebook_class_init (GeditMultiNotebookClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = gedit_multi_notebook_dispose;
object_class->finalize = gedit_multi_notebook_finalize;
object_class->get_property = gedit_multi_notebook_get_property;
+ object_class->set_property = gedit_multi_notebook_set_property;
signals[NOTEBOOK_ADDED] =
g_signal_new ("notebook-added",
@@ -220,6 +265,14 @@ gedit_multi_notebook_class_init (GeditMultiNotebookClass *klass)
GEDIT_TYPE_TAB,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_SHOW_TABS_MODE,
+ g_param_spec_enum ("show-tabs-mode",
+ "Show Tabs Mode",
+ "When tabs should be shown",
+ GEDIT_TYPE_NOTEBOOK_SHOW_TABS_MODE_TYPE,
+ GEDIT_NOTEBOOK_SHOW_TABS_ALWAYS,
+ G_PARAM_READWRITE));
}
static void
@@ -295,6 +348,8 @@ notebook_page_removed (GtkNotebook *notebook,
{
remove_notebook (mnb, GTK_WIDGET (notebook));
}
+
+ update_tabs_visibility (mnb);
}
static void
@@ -307,6 +362,8 @@ notebook_page_added (GtkNotebook *notebook,
++mnb->priv->total_tabs;
+ update_tabs_visibility (mnb);
+
g_signal_emit (G_OBJECT (mnb), signals[TAB_ADDED], 0, notebook, tab);
}
@@ -367,6 +424,58 @@ notebook_set_focus (GtkContainer *container,
}
static void
+show_tabs_changed (GObject *object,
+ GParamSpec *pspec,
+ gpointer *data)
+{
+ update_tabs_visibility (GEDIT_MULTI_NOTEBOOK (data));
+}
+
+static void
+update_tabs_visibility (GeditMultiNotebook *mnb)
+{
+ gboolean show_tabs;
+ GList *l;
+
+ if (mnb->priv->notebooks == NULL)
+ return;
+
+ if (!mnb->priv->show_tabs)
+ {
+ show_tabs = FALSE;
+ }
+ else if (mnb->priv->notebooks->next == NULL) /* only one notebook */
+ {
+ switch (mnb->priv->show_tabs_mode)
+ {
+ case GEDIT_NOTEBOOK_SHOW_TABS_NEVER:
+ show_tabs = FALSE;
+ break;
+ case GEDIT_NOTEBOOK_SHOW_TABS_AUTO:
+ show_tabs = gtk_notebook_get_n_pages (GTK_NOTEBOOK
(mnb->priv->notebooks->data)) > 1;
+ break;
+ case GEDIT_NOTEBOOK_SHOW_TABS_ALWAYS:
+ default:
+ show_tabs = TRUE;
+ break;
+ }
+ }
+ else
+ {
+ show_tabs = (mnb->priv->show_tabs_mode != GEDIT_NOTEBOOK_SHOW_TABS_NEVER);
+ }
+
+ g_signal_handlers_block_by_func (mnb, show_tabs_changed, NULL);
+
+ for (l = mnb->priv->notebooks; l != NULL; l = l->next)
+ {
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (l->data), show_tabs);
+ }
+
+ g_signal_handlers_unblock_by_func (mnb, show_tabs_changed, NULL);
+}
+
+static void
connect_notebook_signals (GeditMultiNotebook *mnb,
GtkWidget *notebook)
{
@@ -402,6 +511,10 @@ connect_notebook_signals (GeditMultiNotebook *mnb,
"show-popup-menu",
G_CALLBACK (notebook_show_popup_menu),
mnb);
+ g_signal_connect (notebook,
+ "notify::show-tabs",
+ G_CALLBACK (show_tabs_changed),
+ mnb);
}
static void
@@ -424,6 +537,8 @@ disconnect_notebook_signals (GeditMultiNotebook *mnb,
mnb);
g_signal_handlers_disconnect_by_func (notebook, notebook_show_popup_menu,
mnb);
+ g_signal_handlers_disconnect_by_func (notebook, show_tabs_changed,
+ mnb);
}
static void
@@ -556,15 +671,28 @@ remove_notebook (GeditMultiNotebook *mnb,
static void
gedit_multi_notebook_init (GeditMultiNotebook *mnb)
{
+ GeditMultiNotebookPrivate *priv;
+
mnb->priv = gedit_multi_notebook_get_instance_private (mnb);
+ priv = mnb->priv;
- mnb->priv->removing_notebook = FALSE;
+ priv->removing_notebook = FALSE;
gtk_orientable_set_orientation (GTK_ORIENTABLE (mnb),
GTK_ORIENTATION_VERTICAL);
- mnb->priv->active_notebook = gedit_notebook_new ();
- add_notebook (mnb, mnb->priv->active_notebook, TRUE);
+ priv->show_tabs_mode = GEDIT_NOTEBOOK_SHOW_TABS_ALWAYS;
+ priv->show_tabs = TRUE;
+
+ priv->ui_settings = g_settings_new ("org.gnome.gedit.preferences.ui");
+ g_settings_bind (priv->ui_settings,
+ GEDIT_SETTINGS_SHOW_TABS_MODE,
+ mnb,
+ "show-tabs-mode",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
+ priv->active_notebook = gedit_notebook_new ();
+ add_notebook (mnb, priv->active_notebook, TRUE);
}
GeditMultiNotebook *
@@ -977,3 +1105,19 @@ gedit_multi_notebook_foreach_tab (GeditMultiNotebook *mnb,
g_list_free (children);
}
}
+
+/* We only use this to hide tabs in fullscreen mode so for now
+ * we do not have a real property etc.
+ */
+void
+_gedit_multi_notebook_set_show_tabs (GeditMultiNotebook *mnb,
+ gboolean show)
+{
+ g_return_if_fail (GEDIT_IS_MULTI_NOTEBOOK (mnb));
+
+ mnb->priv->show_tabs = show != FALSE;
+
+ update_tabs_visibility (mnb);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-multi-notebook.h b/gedit/gedit-multi-notebook.h
index 6d09169..c21f740 100644
--- a/gedit/gedit-multi-notebook.h
+++ b/gedit/gedit-multi-notebook.h
@@ -95,8 +95,8 @@ gint gedit_multi_notebook_get_n_notebooks (GeditMultiNotebook
*mnb);
GeditNotebook *gedit_multi_notebook_get_nth_notebook (GeditMultiNotebook *mnb,
gint notebook_num);
-GeditNotebook *gedit_multi_notebook_get_notebook_for_tab (GeditMultiNotebook *mnb,
- GeditTab *tab);
+GeditNotebook *gedit_multi_notebook_get_notebook_for_tab (GeditMultiNotebook *mnb,
+ GeditTab *tab);
gint gedit_multi_notebook_get_notebook_num (GeditMultiNotebook *mnb,
GeditNotebook *notebook);
@@ -123,7 +123,7 @@ void gedit_multi_notebook_close_all_tabs
(GeditMultiNotebook *mnb);
void gedit_multi_notebook_add_new_notebook (GeditMultiNotebook *mnb);
void gedit_multi_notebook_add_new_notebook_with_tab (GeditMultiNotebook *mnb,
- GeditTab *tab);
+ GeditTab *tab);
void gedit_multi_notebook_remove_active_notebook (GeditMultiNotebook *mnb);
@@ -138,6 +138,11 @@ void gedit_multi_notebook_foreach_tab
(GeditMultiNotebook *mnb,
GtkCallback callback,
gpointer callback_data);
+void _gedit_multi_notebook_set_show_tabs (GeditMultiNotebook *mnb,
+ gboolean show);
+
G_END_DECLS
#endif /* __GEDIT_MULTI_NOTEBOOK_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index a912ec3..103e81d 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -39,33 +39,20 @@
#include "gedit-tab.h"
#include "gedit-tab-label.h"
#include "gedit-window.h"
-#include "gedit-enum-types.h"
-#include "gedit-settings.h"
#include "gedit-marshal.h"
#define GEDIT_NOTEBOOK_GROUP_NAME "GeditNotebookGroup"
struct _GeditNotebookPrivate
{
- GSettings *ui_settings;
-
GList *focused_pages;
- GeditNotebookShowTabsModeType show_tabs_mode;
-
guint close_buttons_sensitive : 1;
guint ignore_focused_page_update : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (GeditNotebook, gedit_notebook, GTK_TYPE_NOTEBOOK)
-/* Properties */
-enum
-{
- PROP_0,
- PROP_SHOW_TABS_MODE
-};
-
/* Signals */
enum
{
@@ -77,95 +64,6 @@ enum
static guint signals[LAST_SIGNAL] = { 0 };
-static void update_tabs_visibility (GeditNotebook *notebook);
-
-static void
-show_tabs_changed (GObject *object,
- GParamSpec *pspec,
- gpointer *data)
-{
- GeditNotebook *notebook = GEDIT_NOTEBOOK (object);
-
- if (gtk_notebook_get_show_tabs (GTK_NOTEBOOK (notebook)))
- {
- update_tabs_visibility (notebook);
- }
-}
-
-static void
-update_tabs_visibility (GeditNotebook *notebook)
-{
- gboolean show_tabs;
-
- switch (notebook->priv->show_tabs_mode)
- {
- case GEDIT_NOTEBOOK_SHOW_TABS_NEVER:
- show_tabs = FALSE;
- break;
- case GEDIT_NOTEBOOK_SHOW_TABS_AUTO:
- show_tabs = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 1;
- break;
- case GEDIT_NOTEBOOK_SHOW_TABS_ALWAYS:
- default:
- show_tabs = TRUE;
- break;
- }
-
- g_signal_handlers_block_by_func (notebook, show_tabs_changed, NULL);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), show_tabs);
- g_signal_handlers_unblock_by_func (notebook, show_tabs_changed, NULL);
-}
-
-static void
-gedit_notebook_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GeditNotebook *notebook = GEDIT_NOTEBOOK (object);
-
- switch (prop_id)
- {
- case PROP_SHOW_TABS_MODE:
- g_value_set_enum (value,
- notebook->priv->show_tabs_mode);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gedit_notebook_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GeditNotebook *notebook = GEDIT_NOTEBOOK (object);
-
- switch (prop_id)
- {
- case PROP_SHOW_TABS_MODE:
- notebook->priv->show_tabs_mode = g_value_get_enum (value);
- update_tabs_visibility (notebook);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gedit_notebook_dispose (GObject *object)
-{
- GeditNotebook *notebook = GEDIT_NOTEBOOK (object);
-
- g_clear_object (¬ebook->priv->ui_settings);
-
- G_OBJECT_CLASS (gedit_notebook_parent_class)->dispose (object);
-}
-
static void
gedit_notebook_finalize (GObject *object)
{
@@ -421,8 +319,6 @@ gedit_notebook_page_removed (GtkNotebook *notebook,
{
smart_tab_switching_on_closure (nb, GEDIT_TAB (page));
}
-
- update_tabs_visibility (nb);
}
static void
@@ -444,8 +340,6 @@ gedit_notebook_page_added (GtkNotebook *notebook,
"close-clicked",
G_CALLBACK (close_button_clicked_cb),
nb);
-
- update_tabs_visibility (GEDIT_NOTEBOOK (notebook));
}
static void
@@ -497,10 +391,7 @@ gedit_notebook_class_init (GeditNotebookClass *klass)
GtkBindingSet *binding_set;
gint i;
- object_class->dispose = gedit_notebook_dispose;
object_class->finalize = gedit_notebook_finalize;
- object_class->get_property = gedit_notebook_get_property;
- object_class->set_property = gedit_notebook_set_property;
gtkwidget_class->grab_focus = gedit_notebook_grab_focus;
gtkwidget_class->button_press_event = gedit_notebook_button_press;
@@ -514,14 +405,6 @@ gedit_notebook_class_init (GeditNotebookClass *klass)
klass->change_to_page = gedit_notebook_change_to_page;
- g_object_class_install_property (object_class, PROP_SHOW_TABS_MODE,
- g_param_spec_enum ("show-tabs-mode",
- "Show Tabs Mode",
- "When tabs should be shown",
- GEDIT_TYPE_NOTEBOOK_SHOW_TABS_MODE_TYPE,
- GEDIT_NOTEBOOK_SHOW_TABS_ALWAYS,
- G_PARAM_READWRITE));
-
signals[TAB_CLOSE_REQUEST] =
g_signal_new ("tab-close-request",
G_OBJECT_CLASS_TYPE (object_class),
@@ -585,10 +468,6 @@ gedit_notebook_init (GeditNotebook *notebook)
notebook->priv = gedit_notebook_get_instance_private (notebook);
priv = notebook->priv;
- priv->ui_settings = g_settings_new ("org.gnome.gedit.preferences.ui");
-
- priv->show_tabs_mode = GEDIT_NOTEBOOK_SHOW_TABS_ALWAYS;
-
priv->close_buttons_sensitive = TRUE;
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
@@ -597,17 +476,6 @@ gedit_notebook_init (GeditNotebook *notebook)
gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook),
GEDIT_NOTEBOOK_GROUP_NAME);
gtk_container_set_border_width (GTK_CONTAINER (notebook), 0);
-
- g_settings_bind (priv->ui_settings,
- GEDIT_SETTINGS_SHOW_TABS_MODE,
- notebook,
- "show-tabs-mode",
- G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
-
- g_signal_connect (notebook,
- "notify::show-tabs",
- G_CALLBACK (show_tabs_changed),
- NULL);
}
static GtkWidget *
diff --git a/gedit/gedit-notebook.h b/gedit/gedit-notebook.h
index 0220738..e3617ec 100644
--- a/gedit/gedit-notebook.h
+++ b/gedit/gedit-notebook.h
@@ -53,7 +53,10 @@ G_BEGIN_DECLS
#define GEDIT_IS_NOTEBOOK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_NOTEBOOK))
#define GEDIT_NOTEBOOK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_NOTEBOOK,
GeditNotebookClass))
-typedef enum {
+/* This is now used in multi-notebook but we keep the same enum for
+ * backward compatibility since it is used in the gsettings schema */
+typedef enum
+{
GEDIT_NOTEBOOK_SHOW_TABS_NEVER,
GEDIT_NOTEBOOK_SHOW_TABS_AUTO,
GEDIT_NOTEBOOK_SHOW_TABS_ALWAYS
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index a28fb67..c21f593 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -3727,24 +3727,6 @@ _gedit_window_get_all_tabs (GeditWindow *window)
return gedit_multi_notebook_get_all_tabs (window->priv->multi_notebook);
}
-static void
-hide_notebook_tabs_on_fullscreen (GtkNotebook *notebook,
- GParamSpec *pspec,
- GeditWindow *window)
-{
- gtk_notebook_set_show_tabs (notebook, FALSE);
-}
-
-static void
-hide_notebook_tabs (GtkNotebook *notebook,
- GeditWindow *window)
-{
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
- g_signal_connect (notebook, "notify::show-tabs",
- G_CALLBACK (hide_notebook_tabs_on_fullscreen),
- window);
-}
-
void
_gedit_window_fullscreen (GeditWindow *window)
{
@@ -3755,27 +3737,12 @@ _gedit_window_fullscreen (GeditWindow *window)
/* Go to fullscreen mode and hide bars */
gtk_window_fullscreen (GTK_WINDOW (&window->window));
-
- gedit_multi_notebook_foreach_notebook (window->priv->multi_notebook,
- (GtkCallback)hide_notebook_tabs,
- window);
-
+ _gedit_multi_notebook_set_show_tabs (window->priv->multi_notebook, FALSE);
gtk_widget_hide (window->priv->statusbar);
-
fullscreen_controls_setup (window);
fullscreen_controls_show (window);
}
-static void
-show_notebook_tabs (GtkNotebook *notebook,
- GeditWindow *window)
-{
- g_signal_handlers_disconnect_by_func (notebook,
- hide_notebook_tabs_on_fullscreen,
- window);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), TRUE);
-}
-
void
_gedit_window_unfullscreen (GeditWindow *window)
{
@@ -3786,10 +3753,7 @@ _gedit_window_unfullscreen (GeditWindow *window)
/* Unfullscreen and show bars */
gtk_window_unfullscreen (GTK_WINDOW (&window->window));
-
- gedit_multi_notebook_foreach_notebook (window->priv->multi_notebook,
- (GtkCallback)show_notebook_tabs,
- window);
+ _gedit_multi_notebook_set_show_tabs (window->priv->multi_notebook, TRUE);
if (g_settings_get_boolean (window->priv->ui_settings, "statusbar-visible"))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]