[gedit] Split the Open tool item in a custom widget
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Split the Open tool item in a custom widget
- Date: Sun, 4 Nov 2012 22:33:18 +0000 (UTC)
commit ec918eb506a4b7536de4762064a80f2ff119e947
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Nov 4 23:09:17 2012 +0100
Split the Open tool item in a custom widget
gedit/Makefile.am | 2 +
gedit/gedit-open-tool-button.c | 126 ++++++++++++++++++++++++++++++++++++++++
gedit/gedit-open-tool-button.h | 60 +++++++++++++++++++
gedit/gedit-settings.c | 31 ----------
gedit/gedit-window-private.h | 1 -
gedit/gedit-window.c | 46 +++------------
po/POTFILES.in | 1 +
7 files changed, 197 insertions(+), 70 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 875e69f..8145bd6 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -121,6 +121,7 @@ NOINST_H_FILES = \
gedit-multi-notebook.h \
gedit-notebook.h \
gedit-notebook-popup-menu.h \
+ gedit-open-tool-button.h \
gedit-plugins-engine.h \
gedit-preferences-dialog.h \
gedit-print-job.h \
@@ -209,6 +210,7 @@ libgedit_c_files = \
gedit-multi-notebook.c \
gedit-notebook.c \
gedit-notebook-popup-menu.c \
+ gedit-open-tool-button.c \
gedit-panel.c \
gedit-plugins-engine.c \
gedit-preferences-dialog.c \
diff --git a/gedit/gedit-open-tool-button.c b/gedit/gedit-open-tool-button.c
new file mode 100644
index 0000000..6dc03b9
--- /dev/null
+++ b/gedit/gedit-open-tool-button.c
@@ -0,0 +1,126 @@
+/*
+ * gedit-open-tool-button.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2012 - Paolo Borelli
+ *
+ * gedit is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gedit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include "gedit-settings.h"
+#include "gedit-open-tool-button.h"
+
+struct _GeditOpenToolButtonPrivate
+{
+ GSettings *ui_settings;
+};
+
+G_DEFINE_TYPE (GeditOpenToolButton, gedit_open_tool_button, GTK_TYPE_MENU_TOOL_BUTTON)
+
+static void
+set_recent_menu (GeditOpenToolButton *button)
+{
+ GtkRecentManager *recent_manager;
+ GtkRecentFilter *filter;
+ GtkWidget *recent_menu;
+
+ recent_manager = gtk_recent_manager_get_default ();
+
+ recent_menu = gtk_recent_chooser_menu_new_for_manager (recent_manager);
+ gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu),
+ FALSE);
+ gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu),
+ GTK_RECENT_SORT_MRU);
+
+ g_settings_bind (button->priv->ui_settings,
+ GEDIT_SETTINGS_MAX_RECENTS,
+ GTK_RECENT_CHOOSER (recent_menu),
+ "limit",
+ G_SETTINGS_BIND_GET);
+
+ filter = gtk_recent_filter_new ();
+ gtk_recent_filter_add_group (filter, "gedit");
+ gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu),
+ filter);
+
+ gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (button),
+ recent_menu);
+}
+
+static void
+gedit_open_tool_button_dispose (GObject *object)
+{
+ GeditOpenToolButton *button = GEDIT_OPEN_TOOL_BUTTON (object);
+
+ g_clear_object (&button->priv->ui_settings);
+
+ G_OBJECT_CLASS (gedit_open_tool_button_parent_class)->dispose (object);
+}
+
+static void
+gedit_open_tool_button_constructed (GObject *object)
+{
+ GeditOpenToolButton *button = GEDIT_OPEN_TOOL_BUTTON (object);
+
+ set_recent_menu (button);
+
+ gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (button), _("Open a file"));
+ gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (button),
+ _("Open a recently used file"));
+
+ if (G_OBJECT_CLASS (gedit_open_tool_button_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (gedit_open_tool_button_parent_class)->constructed (object);
+}
+
+static void
+gedit_open_tool_button_init (GeditOpenToolButton *button)
+{
+ button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
+ GEDIT_TYPE_OPEN_TOOL_BUTTON,
+ GeditOpenToolButtonPrivate);
+
+ button->priv->ui_settings = g_settings_new ("org.gnome.gedit.preferences.ui");
+}
+
+static void
+gedit_open_tool_button_class_init (GeditOpenToolButtonClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gedit_open_tool_button_dispose;
+ object_class->constructed = gedit_open_tool_button_constructed;
+
+ g_type_class_add_private (object_class, sizeof (GeditOpenToolButtonPrivate));
+}
+
+GtkToolItem *
+gedit_open_tool_button_new ()
+{
+ GeditOpenToolButton *button;
+
+ button = g_object_new (GEDIT_TYPE_OPEN_TOOL_BUTTON,
+ "stock-id", GTK_STOCK_OPEN,
+ NULL);
+
+ return GTK_TOOL_ITEM (button);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-open-tool-button.h b/gedit/gedit-open-tool-button.h
new file mode 100644
index 0000000..7fee133
--- /dev/null
+++ b/gedit/gedit-open-tool-button.h
@@ -0,0 +1,60 @@
+/*
+ * gedit-open-tool-button.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2012 - Paolo Borelli
+ *
+ * gedit is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gedit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __GEDIT_OPEN_TOOL_BUTTON_H__
+#define __GEDIT_OPEN_TOOL_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_OPEN_TOOL_BUTTON (gedit_open_tool_button_get_type ())
+#define GEDIT_OPEN_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_OPEN_TOOL_BUTTON, GeditOpenToolButton))
+#define GEDIT_OPEN_TOOL_BUTTON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_OPEN_TOOL_BUTTON, GeditOpenToolButton const))
+#define GEDIT_OPEN_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_OPEN_TOOL_BUTTON, GeditOpenToolButtonClass))
+#define GEDIT_IS_OPEN_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_OPEN_TOOL_BUTTON))
+#define GEDIT_IS_OPEN_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_OPEN_TOOL_BUTTON))
+#define GEDIT_OPEN_TOOL_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_OPEN_TOOL_BUTTON, GeditOpenToolButtonClass))
+
+typedef struct _GeditOpenToolButton GeditOpenToolButton;
+typedef struct _GeditOpenToolButtonClass GeditOpenToolButtonClass;
+typedef struct _GeditOpenToolButtonPrivate GeditOpenToolButtonPrivate;
+
+struct _GeditOpenToolButton
+{
+ GtkMenuToolButton parent;
+
+ GeditOpenToolButtonPrivate *priv;
+};
+
+struct _GeditOpenToolButtonClass
+{
+ GtkMenuToolButtonClass parent_class;
+};
+
+GType gedit_open_tool_button_get_type (void) G_GNUC_CONST;
+
+GtkToolItem *gedit_open_tool_button_new (void);
+
+G_END_DECLS
+
+#endif /* __GEDIT_OPEN_TOOL_BUTTON_H__ */
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-settings.c b/gedit/gedit-settings.c
index a6bb603..410d216 100644
--- a/gedit/gedit-settings.c
+++ b/gedit/gedit-settings.c
@@ -597,31 +597,6 @@ on_search_highlighting_changed (GSettings *settings,
}
static void
-on_max_recents_changed (GSettings *settings,
- const gchar *key,
- GeditSettings *gs)
-{
- const GList *windows;
- gint max;
-
- g_settings_get (settings, key, "u", &max);
-
- windows = gedit_app_get_windows (gedit_app_get_default ());
- while (windows != NULL)
- {
- GeditWindow *w = GEDIT_WINDOW (windows->data);
-
- gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (w->priv->toolbar_recent_menu),
- max);
-
- windows = g_list_next (windows);
- }
-
- /* FIXME: we have no way at the moment to trigger the
- * update of the inline recents in the File menu */
-}
-
-static void
gedit_settings_init (GeditSettings *gs)
{
gs->priv = GEDIT_SETTINGS_GET_PRIVATE (gs);
@@ -718,12 +693,6 @@ gedit_settings_init (GeditSettings *gs)
"changed::search-highlighting",
G_CALLBACK (on_search_highlighting_changed),
gs);
-
- /* ui changes */
- g_signal_connect (gs->priv->ui,
- "changed::max-recents",
- G_CALLBACK (on_max_recents_changed),
- gs);
}
static void
diff --git a/gedit/gedit-window-private.h b/gedit/gedit-window-private.h
index a092495..8ea3b5c 100644
--- a/gedit/gedit-window-private.h
+++ b/gedit/gedit-window-private.h
@@ -93,7 +93,6 @@ struct _GeditWindowPrivate
GtkActionGroup *documents_list_action_group;
guint documents_list_menu_ui_id;
GtkWidget *toolbar;
- GtkWidget *toolbar_recent_menu;
GtkWidget *menubar;
/* recent files */
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 6deae63..9087695 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -52,6 +52,7 @@
#include "gedit-utils.h"
#include "gedit-commands.h"
#include "gedit-debug.h"
+#include "gedit-open-tool-button.h"
#include "gedit-panel.h"
#include "gedit-documents-panel.h"
#include "gedit-plugins-engine.h"
@@ -1442,50 +1443,22 @@ toolbar_visibility_changed (GtkWidget *toolbar,
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
}
-static GtkWidget *
+static void
setup_toolbar_open_button (GeditWindow *window,
GtkWidget *toolbar)
{
- GtkRecentManager *recent_manager;
- GtkRecentFilter *filter;
- GtkWidget *toolbar_recent_menu;
GtkToolItem *open_button;
+ GtkWidget *recent_menu;
GtkAction *action;
- gint max_recents;
-
- recent_manager = gtk_recent_manager_get_default ();
-
- g_settings_get (window->priv->ui_settings, GEDIT_SETTINGS_MAX_RECENTS,
- "u", &max_recents);
-
- /* recent files menu tool button */
- toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (recent_manager);
- gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu),
- FALSE);
- gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu),
- GTK_RECENT_SORT_MRU);
- gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (toolbar_recent_menu),
- max_recents);
+ open_button = gedit_open_tool_button_new ();
- filter = gtk_recent_filter_new ();
- gtk_recent_filter_add_group (filter, "gedit");
- gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu),
- filter);
+ recent_menu = gtk_menu_tool_button_get_menu (GTK_MENU_TOOL_BUTTON (open_button));
- g_signal_connect (toolbar_recent_menu,
- "item_activated",
+ g_signal_connect (recent_menu,
+ "item-activated",
G_CALLBACK (recent_chooser_item_activated),
window);
-
- /* add the custom Open button to the toolbar */
- open_button = gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN);
- gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (open_button),
- toolbar_recent_menu);
-
- gtk_tool_item_set_tooltip_text (open_button, _("Open a file"));
- gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (open_button),
- _("Open a recently used file"));
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
"FileOpen");
@@ -1499,8 +1472,6 @@ setup_toolbar_open_button (GeditWindow *window,
gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
open_button,
1);
-
- return toolbar_recent_menu;
}
static void
@@ -1671,8 +1642,7 @@ create_menu_bar_and_toolbar (GeditWindow *window,
#endif
set_toolbar_visibility (window, NULL);
- window->priv->toolbar_recent_menu = setup_toolbar_open_button (window,
- window->priv->toolbar);
+ setup_toolbar_open_button (window, window->priv->toolbar);
gtk_container_foreach (GTK_CONTAINER (window->priv->toolbar),
(GtkCallback)set_non_homogeneus,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f281c38..ca4fb01 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -23,6 +23,7 @@ gedit/gedit-file-chooser-dialog.c
gedit/gedit-io-error-info-bar.c
gedit/gedit-notebook.c
gedit/gedit-notebook-popup-menu.c
+gedit/gedit-open-tool-item.c
gedit/gedit-panel.c
gedit/gedit-plugins-engine.c
gedit/gedit-preferences-dialog.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]