[Xfce4-commits] [apps/mousepad] 02/06: Re-factor languages code into two new files
noreply at xfce.org
noreply at xfce.org
Mon Jul 14 13:35:46 CEST 2014
This is an automated email from the git hooks/post-receive script.
mbrush pushed a commit to branch master
in repository apps/mousepad.
commit 0d73a7eac32856cb4d4a16dc185d7e3e7699a690
Author: Matthew Brush <mbrush at codebrainz.ca>
Date: Mon Jul 14 02:05:53 2014 -0700
Re-factor languages code into two new files
Add a GtkActionGroup subclass that knows about languages and a GtkAction
subclass that can have a related language. This way all the actions are
in the same action group and will be useful for moving the colour
scheme code out of mousepad-window.c in the future.
---
mousepad/Makefile.am | 6 +-
mousepad/mousepad-action-group.c | 462 +++++++++++++++++++++++++++++++
mousepad/mousepad-action-group.h | 32 +++
mousepad/mousepad-language-action.c | 250 +++++++++++++++++
mousepad/mousepad-language-action.h | 27 ++
mousepad/mousepad-languages.c | 512 -----------------------------------
mousepad/mousepad-languages.h | 28 --
mousepad/mousepad-util.c | 17 ++
mousepad/mousepad-util.h | 2 +
mousepad/mousepad-window.c | 57 ++--
10 files changed, 828 insertions(+), 565 deletions(-)
diff --git a/mousepad/Makefile.am b/mousepad/Makefile.am
index 15a8b7b..e87ef4a 100644
--- a/mousepad/Makefile.am
+++ b/mousepad/Makefile.am
@@ -21,6 +21,8 @@ mousepad_SOURCES = \
$(mousepad_built_sources) \
$(mousepad_dbus_sources) \
main.c \
+ mousepad-action-group.c \
+ mousepad-action-group.h \
mousepad-application.c \
mousepad-application.h \
mousepad-dialogs.c \
@@ -33,8 +35,8 @@ mousepad_SOURCES = \
mousepad-encoding-dialog.h \
mousepad-file.c \
mousepad-file.h \
- mousepad-languages.c \
- mousepad-languages.h \
+ mousepad-language-action.c \
+ mousepad-language-action.h \
mousepad-prefs-dialog.c \
mousepad-prefs-dialog.h \
mousepad-prefs-dialog-ui.h \
diff --git a/mousepad/mousepad-action-group.c b/mousepad/mousepad-action-group.c
new file mode 100644
index 0000000..e5f7744
--- /dev/null
+++ b/mousepad/mousepad-action-group.c
@@ -0,0 +1,462 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <mousepad/mousepad-action-group.h>
+#include <mousepad/mousepad-language-action.h>
+#include <glib/gi18n.h>
+#include <gtksourceview/gtksourcelanguagemanager.h>
+
+
+
+enum
+{
+ PROP_0,
+ PROP_ACTIVE_LANGUAGE,
+ NUM_PROPERTIES
+};
+
+
+
+struct MousepadActionGroup_
+{
+ GtkActionGroup parent;
+ GtkSourceLanguage *active_language;
+ gboolean locked;
+};
+
+
+
+struct MousepadActionGroupClass_
+{
+ GtkActionGroupClass parent_class;
+};
+
+
+
+static void mousepad_action_group_finalize (GObject *object);
+static void mousepad_action_group_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void mousepad_action_group_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static GtkWidget *mousepad_action_group_create_language_submenu (MousepadActionGroup *self,
+ const gchar *section);
+static void mousepad_action_group_action_activate (MousepadActionGroup *self,
+ MousepadLanguageAction *action);
+static void mousepad_action_group_add_language_actions (MousepadActionGroup *self);
+static GtkAction *mousepad_action_group_get_language_action (MousepadActionGroup *group,
+ GtkSourceLanguage *language);
+static gint mousepad_action_group_languages_name_compare (gconstpointer a,
+ gconstpointer b);
+static GSList *mousepad_action_group_get_sorted_languages_for_section (const gchar *section);
+static GSList *mousepad_action_group_get_sorted_section_names (void);
+
+
+G_DEFINE_TYPE (MousepadActionGroup, mousepad_action_group, GTK_TYPE_ACTION_GROUP)
+
+
+
+static void
+mousepad_action_group_class_init (MousepadActionGroupClass *klass)
+{
+ GObjectClass *g_object_class;
+
+ g_object_class = G_OBJECT_CLASS (klass);
+
+ g_object_class->finalize = mousepad_action_group_finalize;
+ g_object_class->set_property = mousepad_action_group_set_property;
+ g_object_class->get_property = mousepad_action_group_get_property;
+
+ g_object_class_install_property (
+ g_object_class,
+ PROP_ACTIVE_LANGUAGE,
+ g_param_spec_object ("active-language",
+ "ActiveLanguage",
+ "The currently active language action",
+ MOUSEPAD_TYPE_LANGUAGE_ACTION,
+ G_PARAM_READWRITE));
+}
+
+
+
+static void
+mousepad_action_group_finalize (GObject *object)
+{
+ MousepadActionGroup *self;
+
+ g_return_if_fail (MOUSEPAD_IS_ACTION_GROUP (object));
+
+ self = MOUSEPAD_ACTION_GROUP (object);
+
+ if (GTK_IS_SOURCE_LANGUAGE (self->active_language))
+ g_object_unref (self->active_language);
+
+ G_OBJECT_CLASS (mousepad_action_group_parent_class)->finalize (object);
+}
+
+
+
+static void
+mousepad_action_group_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MousepadActionGroup *self = MOUSEPAD_ACTION_GROUP (object);
+
+ switch (prop_id)
+ {
+ case PROP_ACTIVE_LANGUAGE:
+ mousepad_action_group_set_active_language (self, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+mousepad_action_group_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MousepadActionGroup *self = MOUSEPAD_ACTION_GROUP (object);
+
+ switch (prop_id)
+ {
+ case PROP_ACTIVE_LANGUAGE:
+ g_value_set_object (value, mousepad_action_group_get_active_language (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+mousepad_action_group_init (MousepadActionGroup *self)
+{
+ self->active_language = NULL;
+ mousepad_action_group_add_language_actions (self);
+ mousepad_action_group_set_active_language (self, NULL);
+}
+
+
+
+GtkActionGroup *
+mousepad_action_group_new (void)
+{
+ return g_object_new (MOUSEPAD_TYPE_ACTION_GROUP, "name", "MousepadWindow", NULL);
+}
+
+
+
+/**
+ * Property accessors
+ **/
+
+
+
+void
+mousepad_action_group_set_active_language (MousepadActionGroup *self,
+ GtkSourceLanguage *language)
+{
+ GtkAction *action;
+
+ g_return_if_fail (MOUSEPAD_IS_ACTION_GROUP (self));
+
+ if (GTK_IS_SOURCE_LANGUAGE (self->active_language))
+ g_object_unref (self->active_language);
+
+ if (GTK_IS_SOURCE_LANGUAGE (language))
+ self->active_language = g_object_ref (language);
+ else
+ self->active_language = NULL;
+
+ action = mousepad_action_group_get_language_action (self, language);
+
+ /* prevent recursion since we watch the action's 'activate' signal */
+ self->locked = TRUE;
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+ self->locked = FALSE;
+
+ g_object_notify (G_OBJECT (self), "active-language");
+}
+
+
+
+GtkSourceLanguage *
+mousepad_action_group_get_active_language (MousepadActionGroup *self)
+{
+ g_return_val_if_fail (MOUSEPAD_IS_ACTION_GROUP (self), NULL);
+
+ return self->active_language;
+}
+
+
+
+/**
+ * GUI proxy creation
+ **/
+
+
+
+static GtkWidget *
+mousepad_action_group_create_language_submenu (MousepadActionGroup *self,
+ const gchar *section)
+{
+ GtkWidget *menu, *item;
+ GSList *language_ids, *iter;
+
+ menu = gtk_menu_new ();
+
+ language_ids = mousepad_action_group_get_sorted_languages_for_section (section);
+
+ for (iter = language_ids; iter != NULL; iter = g_slist_next (iter))
+ {
+ GtkAction *action;
+ GtkSourceLanguage *language = iter->data;
+
+ action = mousepad_action_group_get_language_action (self, language);
+ item = gtk_action_create_menu_item (action);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ }
+
+ g_slist_free (language_ids);
+
+ return menu;
+}
+
+
+
+GtkWidget *
+mousepad_action_group_create_language_menu (MousepadActionGroup *self)
+{
+ GtkWidget *menu;
+ GtkWidget *item;
+ GSList *sections, *iter;
+ GtkAction *action;
+
+ menu = gtk_menu_new ();
+
+ /* add the 'none' language first */
+ action = gtk_action_group_get_action (GTK_ACTION_GROUP (self), "mousepad-language-none");
+ item = gtk_action_create_menu_item (action);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ /* separate the 'none' language from the section submenus */
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ sections = mousepad_action_group_get_sorted_section_names ();
+
+ for (iter = sections; iter != NULL; iter = g_slist_next (iter))
+ {
+ const gchar *section = iter->data;
+ GtkWidget *submenu;
+
+ /* create a menu item for the section */
+ item = gtk_menu_item_new_with_label (section);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ /* create a submenu for the section and it to the item */
+ submenu = mousepad_action_group_create_language_submenu (self, section);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+
+ }
+
+ g_slist_free (sections);
+
+ return menu;
+}
+
+
+
+/**
+ * Signal handlers
+ **/
+
+
+
+static void
+mousepad_action_group_action_activate (MousepadActionGroup *self,
+ MousepadLanguageAction *action)
+{
+ /* only update the active action if we're not already in the process of
+ * setting it and the sender action is actually active */
+ if (! self->locked &&
+ gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+ {
+ GtkSourceLanguage *language;
+
+ language = mousepad_language_action_get_language (action);
+ mousepad_action_group_set_active_language (self, language);
+ }
+}
+
+
+
+/**
+ * Helper functions
+ **/
+
+
+
+static void
+mousepad_action_group_add_language_actions (MousepadActionGroup *self)
+{
+ GtkSourceLanguageManager *manager;
+ const gchar *const *lang_ids;
+ const gchar *const *lang_id_ptr;
+ GSList *group = NULL;
+ GtkAccelGroup *accel_group;
+ GtkAction *action;
+
+ accel_group = gtk_accel_group_new ();
+
+ /* add an action for the 'none' (non-)language */
+ action = mousepad_language_action_new (NULL);
+ gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);
+ group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
+ gtk_action_set_accel_group (action, accel_group);
+ gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (self), action, NULL);
+ g_signal_connect_object (action, "activate", G_CALLBACK (mousepad_action_group_action_activate), self, G_CONNECT_SWAPPED);
+
+ manager = gtk_source_language_manager_get_default ();
+ lang_ids = gtk_source_language_manager_get_language_ids (manager);
+
+ for (lang_id_ptr = lang_ids; lang_id_ptr && *lang_id_ptr; lang_id_ptr++)
+ {
+ GtkSourceLanguage *language;
+
+ /* add an action for each GSV language */
+ language = gtk_source_language_manager_get_language (manager, *lang_id_ptr);
+ action = mousepad_language_action_new (language);
+ gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);
+ group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
+ gtk_action_set_accel_group (action, accel_group);
+ gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (self), action, NULL);
+ g_signal_connect_object (action, "activate", G_CALLBACK (mousepad_action_group_action_activate), self, G_CONNECT_SWAPPED);
+ }
+
+ g_object_unref (accel_group);
+}
+
+
+
+GtkAction *
+mousepad_action_group_get_language_action (MousepadActionGroup *self,
+ GtkSourceLanguage *language)
+{
+ const gchar *language_id;
+ gchar *action_name;
+ GtkAction *action;
+
+ g_return_val_if_fail (MOUSEPAD_IS_ACTION_GROUP (self), NULL);
+
+ if (GTK_IS_SOURCE_LANGUAGE (language))
+ language_id = gtk_source_language_get_id (language);
+ else
+ language_id = "none";
+
+ action_name = g_strdup_printf ("mousepad-language-%s", language_id);
+ action = gtk_action_group_get_action (GTK_ACTION_GROUP (self), action_name);
+ g_free (action_name);
+
+ return action;
+}
+
+
+
+static gint
+mousepad_action_group_languages_name_compare (gconstpointer a,
+ gconstpointer b)
+{
+ const gchar *name_a, *name_b;
+
+ if (G_UNLIKELY (!GTK_IS_SOURCE_LANGUAGE (a)))
+ return -(a != b);
+ if (G_UNLIKELY (!GTK_IS_SOURCE_LANGUAGE (b)))
+ return a != b;
+
+ name_a = gtk_source_language_get_name (GTK_SOURCE_LANGUAGE (a));
+ name_b = gtk_source_language_get_name (GTK_SOURCE_LANGUAGE (b));
+
+ return g_utf8_collate (name_a, name_b);
+}
+
+
+
+static GSList *
+mousepad_action_group_get_sorted_section_names (void)
+{
+ GSList *list = NULL;
+ const gchar *const *languages;
+ GtkSourceLanguage *language;
+ GtkSourceLanguageManager *manager;
+
+ manager = gtk_source_language_manager_get_default ();
+ languages = gtk_source_language_manager_get_language_ids (manager);
+
+ while (*languages)
+ {
+ language = gtk_source_language_manager_get_language (manager, *languages);
+ if (G_LIKELY (GTK_IS_SOURCE_LANGUAGE (language)))
+ {
+ /* ensure no duplicates in list */
+ if (!g_slist_find_custom (list,
+ gtk_source_language_get_section (language),
+ (GCompareFunc)g_strcmp0))
+ {
+ list = g_slist_prepend (list, (gchar *)gtk_source_language_get_section (language));
+ }
+ }
+ languages++;
+ }
+
+ return g_slist_sort (list, (GCompareFunc) g_utf8_collate);
+}
+
+
+
+static GSList *
+mousepad_action_group_get_sorted_languages_for_section (const gchar *section)
+{
+ GSList *list = NULL;
+ const gchar *const *languages;
+ GtkSourceLanguage *language;
+ GtkSourceLanguageManager *manager;
+
+ g_return_val_if_fail (section != NULL, NULL);
+
+ manager = gtk_source_language_manager_get_default ();
+ languages = gtk_source_language_manager_get_language_ids (manager);
+
+ while (*languages)
+ {
+ language = gtk_source_language_manager_get_language (manager, *languages);
+ if (G_LIKELY (GTK_IS_SOURCE_LANGUAGE (language)))
+ {
+ /* only get languages in the specified section */
+ if (g_strcmp0 (gtk_source_language_get_section (language), section) == 0)
+ list = g_slist_prepend (list, language);
+ }
+ languages++;
+ }
+
+ return g_slist_sort(list, (GCompareFunc) mousepad_action_group_languages_name_compare);
+}
diff --git a/mousepad/mousepad-action-group.h b/mousepad/mousepad-action-group.h
new file mode 100644
index 0000000..bc067e9
--- /dev/null
+++ b/mousepad/mousepad-action-group.h
@@ -0,0 +1,32 @@
+#ifndef MOUSEPADACTIONGROUP_H_
+#define MOUSEPADACTIONGROUP_H_ 1
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourcelanguage.h>
+
+G_BEGIN_DECLS
+
+#define MOUSEPAD_TYPE_ACTION_GROUP (mousepad_action_group_get_type ())
+#define MOUSEPAD_ACTION_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOUSEPAD_TYPE_ACTION_GROUP, MousepadActionGroup))
+#define MOUSEPAD_ACTION_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOUSEPAD_TYPE_ACTION_GROUP, MousepadActionGroupClass))
+#define MOUSEPAD_IS_ACTION_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOUSEPAD_TYPE_ACTION_GROUP))
+#define MOUSEPAD_IS_ACTION_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_ACTION_GROUP))
+#define MOUSEPAD_ACTION_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_ACTION_GROUP, MousepadActionGroupClass))
+
+typedef struct MousepadActionGroup_ MousepadActionGroup;
+typedef struct MousepadActionGroupClass_ MousepadActionGroupClass;
+
+GType mousepad_action_group_get_type (void);
+
+GtkActionGroup *mousepad_action_group_new (void);
+
+void mousepad_action_group_set_active_language (MousepadActionGroup *group,
+ GtkSourceLanguage *language);
+
+GtkSourceLanguage *mousepad_action_group_get_active_language (MousepadActionGroup *group);
+
+GtkWidget *mousepad_action_group_create_language_menu (MousepadActionGroup *group);
+
+G_END_DECLS
+
+#endif /* MOUSEPADACTIONGROUP_H_ */
diff --git a/mousepad/mousepad-language-action.c b/mousepad/mousepad-language-action.c
new file mode 100644
index 0000000..5ab85ff
--- /dev/null
+++ b/mousepad/mousepad-language-action.c
@@ -0,0 +1,250 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <mousepad/mousepad-language-action.h>
+#include <mousepad/mousepad-util.h>
+#include <glib/gi18n.h>
+
+
+
+enum
+{
+ PROP_0,
+ PROP_LANGUAGE,
+ NUM_PROPERTIES
+};
+
+
+
+struct MousepadLanguageAction_
+{
+ GtkRadioAction parent;
+ GtkSourceLanguage *language;
+};
+
+
+
+struct MousepadLanguageActionClass_
+{
+ GtkRadioActionClass parent_class;
+};
+
+
+
+static void mousepad_language_action_finalize (GObject *object);
+static void mousepad_language_action_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void mousepad_language_action_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void mousepad_language_action_update_language (MousepadLanguageAction *action,
+ GtkSourceLanguage *language);
+
+
+static void mousepad_language_action_set_language (MousepadLanguageAction *action,
+ GtkSourceLanguage *language);
+
+
+G_DEFINE_TYPE (MousepadLanguageAction, mousepad_language_action, GTK_TYPE_RADIO_ACTION)
+
+
+
+static void
+mousepad_language_action_class_init (MousepadLanguageActionClass *klass)
+{
+ GObjectClass *g_object_class;
+
+ g_object_class = G_OBJECT_CLASS (klass);
+
+ g_object_class->finalize = mousepad_language_action_finalize;
+ g_object_class->set_property = mousepad_language_action_set_property;
+ g_object_class->get_property = mousepad_language_action_get_property;
+
+ g_object_class_install_property (
+ g_object_class,
+ PROP_LANGUAGE,
+ g_param_spec_object (
+ "language",
+ "Language",
+ "The GtkSourceLanguage associated with the action",
+ GTK_TYPE_SOURCE_LANGUAGE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+}
+
+
+
+static void
+mousepad_language_action_finalize (GObject *object)
+{
+ MousepadLanguageAction *self;
+
+ g_return_if_fail (MOUSEPAD_IS_LANGUAGE_ACTION (object));
+
+ self = MOUSEPAD_LANGUAGE_ACTION (object);
+
+ if (GTK_IS_SOURCE_LANGUAGE (self->language))
+ g_object_unref (self->language);
+
+ G_OBJECT_CLASS (mousepad_language_action_parent_class)->finalize (object);
+}
+
+
+
+static void
+mousepad_language_action_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MousepadLanguageAction *self = MOUSEPAD_LANGUAGE_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_LANGUAGE:
+ mousepad_language_action_set_language (self, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+mousepad_language_action_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MousepadLanguageAction *self = MOUSEPAD_LANGUAGE_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_LANGUAGE:
+ g_value_set_object (value, mousepad_language_action_get_language (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+mousepad_language_action_init (MousepadLanguageAction *self)
+{
+ self->language = NULL;
+}
+
+
+
+GtkAction *
+mousepad_language_action_new (GtkSourceLanguage *language)
+{
+ gchar *name;
+ const gchar *language_id;
+ GtkAction *action;
+
+ if (GTK_IS_SOURCE_LANGUAGE (language))
+ language_id = gtk_source_language_get_id (language);
+ else
+ language_id = "none";
+
+ name = g_strdup_printf ("mousepad-language-%s", language_id);
+ action = g_object_new (MOUSEPAD_TYPE_LANGUAGE_ACTION,
+ "name", name,
+ "language", language, NULL);
+ g_free (name);
+
+ return action;
+}
+
+
+
+GtkSourceLanguage *
+mousepad_language_action_get_language (MousepadLanguageAction *self)
+{
+ g_return_val_if_fail (MOUSEPAD_IS_LANGUAGE_ACTION (self), NULL);
+
+ return self->language;
+}
+
+
+
+static GIcon *
+mousepad_language_action_get_icon (MousepadLanguageAction *self)
+{
+ gchar **mime_types;
+ GIcon *mime_icon = NULL;
+
+ g_return_val_if_fail (MOUSEPAD_IS_LANGUAGE_ACTION (self), NULL);
+
+ if (self->language != NULL)
+ {
+ mime_types = gtk_source_language_get_mime_types (self->language);
+ if (G_LIKELY (mime_types != NULL && g_strv_length (mime_types)) > 0)
+ mime_icon = mousepad_util_icon_for_mime_type (mime_types[0]);
+ g_strfreev (mime_types);
+ }
+ else
+ mime_icon = mousepad_util_icon_for_mime_type ("text/plain");
+
+ return mime_icon;
+}
+
+
+
+static void
+mousepad_language_action_set_language (MousepadLanguageAction *self,
+ GtkSourceLanguage *language)
+{
+ GQuark value_quark;
+ GIcon *icon = NULL;
+
+ g_return_if_fail (MOUSEPAD_IS_LANGUAGE_ACTION (self));
+ g_return_if_fail (language == NULL || GTK_IS_SOURCE_LANGUAGE (language));
+
+ if (G_UNLIKELY (self->language != NULL))
+ g_object_unref (self->language);
+
+ if (G_UNLIKELY (language == NULL))
+ {
+ self->language = NULL;
+ value_quark = g_quark_from_static_string ("none");
+ gtk_action_set_label (GTK_ACTION (self), _("Plain Text"));
+ gtk_action_set_tooltip (GTK_ACTION (self), _("No filetype"));
+ }
+ else
+ {
+ const gchar *language_id, *name, *section;
+ gchar *tooltip;
+
+ self->language = g_object_ref (language);
+ value_quark = g_quark_from_string (language_id);
+ language_id = gtk_source_language_get_id (language);
+ name = gtk_source_language_get_name (language);
+ section = gtk_source_language_get_section (language);
+ tooltip = g_strdup_printf ("%s/%s", section, name);
+ gtk_action_set_label (GTK_ACTION (self), name);
+ gtk_action_set_tooltip (GTK_ACTION (self), tooltip);
+ g_free (tooltip);
+ }
+
+ g_object_set (G_OBJECT (self), "value", value_quark, NULL);
+
+ icon = mousepad_language_action_get_icon (self);
+ if (G_IS_ICON (icon))
+ {
+ gtk_action_set_gicon (GTK_ACTION (self), icon);
+ g_object_unref (icon);
+ }
+
+ g_object_notify (G_OBJECT (self), "language");
+}
diff --git a/mousepad/mousepad-language-action.h b/mousepad/mousepad-language-action.h
new file mode 100644
index 0000000..ebcc618
--- /dev/null
+++ b/mousepad/mousepad-language-action.h
@@ -0,0 +1,27 @@
+#ifndef MOUSEPAD_LANGUAGE_ACTION_H_
+#define MOUSEPAD_LANGUAGE_ACTION_H_ 1
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourcelanguage.h>
+
+G_BEGIN_DECLS
+
+#define MOUSEPAD_TYPE_LANGUAGE_ACTION (mousepad_language_action_get_type ())
+#define MOUSEPAD_LANGUAGE_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOUSEPAD_TYPE_LANGUAGE_ACTION, MousepadLanguageAction))
+#define MOUSEPAD_LANGUAGE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOUSEPAD_TYPE_LANGUAGE_ACTION, MousepadLanguageActionClass))
+#define MOUSEPAD_IS_LANGUAGE_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOUSEPAD_TYPE_LANGUAGE_ACTION))
+#define MOUSEPAD_IS_LANGUAGE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_LANGUAGE_ACTION))
+#define MOUSEPAD_LANGUAGE_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_LANGUAGE_ACTION, MousepadLanguageActionClass))
+
+typedef struct MousepadLanguageAction_ MousepadLanguageAction;
+typedef struct MousepadLanguageActionClass_ MousepadLanguageActionClass;
+
+GType mousepad_language_action_get_type (void);
+
+GtkAction *mousepad_language_action_new (GtkSourceLanguage *language);
+
+GtkSourceLanguage *mousepad_language_action_get_language (MousepadLanguageAction *action);
+
+G_END_DECLS
+
+#endif /* MOUSEPAD_LANGUAGE_ACTION_H_ */
diff --git a/mousepad/mousepad-languages.c b/mousepad/mousepad-languages.c
deleted file mode 100644
index 650bea4..0000000
--- a/mousepad/mousepad-languages.c
+++ /dev/null
@@ -1,512 +0,0 @@
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <mousepad/mousepad-languages.h>
-#include <mousepad/mousepad-util.h>
-#include <glib/gi18n.h>
-#include <gtksourceview/gtksourcelanguagemanager.h>
-
-
-
-static inline void
-mousepad_action_set_language (GtkAction *action,
- GtkSourceLanguage *language)
-{
- g_return_if_fail (GTK_IS_ACTION (action));
-
- if (GTK_IS_SOURCE_LANGUAGE (language))
- {
- g_object_set_data_full (G_OBJECT (action),
- "mousepad-language",
- g_object_ref (language),
- g_object_unref);
- }
- else
- g_object_set_data (G_OBJECT (action), "mousepad-language", NULL);
-}
-
-
-
-static inline GtkSourceLanguage *
-mousepad_action_get_language (GtkAction *action)
-{
- g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
-
- return g_object_get_data (G_OBJECT (action), "mousepad-language");
-}
-
-
-
-static inline void
-mousepad_action_group_set_active_language (GtkActionGroup *group,
- GtkSourceLanguage *language)
-{
- g_return_if_fail (GTK_IS_ACTION_GROUP (group));
-
- if (GTK_IS_SOURCE_LANGUAGE (language))
- {
- g_object_set_data_full (G_OBJECT (group),
- "mousepad-active-language",
- g_object_ref (language),
- g_object_unref);
- }
- else
- g_object_set_data (G_OBJECT (group), "mousepad-active-language", NULL);
-}
-
-
-
-static inline GtkSourceLanguage *
-mousepad_action_group_get_active_language (GtkActionGroup *group)
-{
- g_return_val_if_fail (GTK_IS_ACTION_GROUP (group), NULL);
-
- return g_object_get_data (G_OBJECT (group), "mousepad-active-language");
-}
-
-
-
-static GIcon *
-mousepad_languages_get_icon_for_mime_type (const gchar *mime_type)
-{
- gchar *content_type;
- GIcon *icon = NULL;
-
- content_type = g_content_type_from_mime_type (mime_type);
- if (content_type != NULL)
- {
- icon = g_content_type_get_icon (content_type);
- g_free (content_type);
- }
-
- return icon;
-}
-
-
-
-static GIcon *
-mousepad_languages_get_icon_for_language (GtkSourceLanguage *language)
-{
- gchar **mime_types;
- GIcon *mime_icon = NULL;
-
- g_return_val_if_fail (GTK_IS_SOURCE_LANGUAGE (language), NULL);
-
- mime_types = gtk_source_language_get_mime_types (language);
- if (G_LIKELY (mime_types != NULL && g_strv_length (mime_types)) > 0)
- mime_icon = mousepad_languages_get_icon_for_mime_type (mime_types[0]);
- g_strfreev (mime_types);
-
- return mime_icon;
-}
-
-
-
-static void
-mousepad_languages_active_language_changed (GtkActionGroup *group,
- GtkToggleAction *action)
-{
- GtkSourceLanguage *language;
-
- if (gtk_toggle_action_get_active (action))
- {
- language = mousepad_action_get_language (GTK_ACTION (action));
- mousepad_action_group_set_active_language (group, language);
- g_signal_emit_by_name (group, "language-changed", language);
- }
-}
-
-
-
-static GtkRadioAction *
-mousepad_languages_create_action (GtkActionGroup *group,
- GtkSourceLanguage *language,
- GSList **radio_action_group,
- GtkAccelGroup *accel_group)
-{
- GtkRadioAction *action;
- GQuark value_quark;
- GIcon *icon = NULL;
-
- g_return_val_if_fail (GTK_IS_ACTION_GROUP (group), NULL);
- g_return_val_if_fail (language == NULL || GTK_IS_SOURCE_LANGUAGE (language), NULL);
- g_return_val_if_fail (radio_action_group != NULL, NULL);
-
- if (G_UNLIKELY (language == NULL))
- {
- /* NULL/'none' language is treated as plain text */
- value_quark = g_quark_from_static_string ("mousepad-language-none");
- action = gtk_radio_action_new ("mousepad-language-none", _("Plain Text"), _("No language"), NULL, value_quark);
- gtk_action_set_accel_group (GTK_ACTION (action), accel_group);
- mousepad_action_set_language (GTK_ACTION (action), NULL);
- icon = mousepad_languages_get_icon_for_mime_type ("text/plain");
- }
- else
- {
- const gchar *language_id, *name;
- gchar *label, *tooltip;
-
- language_id = gtk_source_language_get_id (language);
- value_quark = g_quark_from_string (language_id);
-
- /* the proper name of the language for user display */
- name = gtk_source_language_get_name (language);
-
- /* a label for the action in the action group */
- label = g_strdup_printf ("mousepad-language-%s", language_id);
-
- /* a tooltip to the section and name, ex. 'Scripts/Python' */
- tooltip = g_strdup_printf ("%s/%s",
- gtk_source_language_get_section (language),
- gtk_source_language_get_name (language));
-
- /* a unique id of the language, for the radio action's value */
- value_quark = g_quark_from_string (language_id);
-
- /* create the new action */
- action = gtk_radio_action_new (label, name, tooltip, NULL, value_quark);
- g_free (label);
- g_free (tooltip);
-
- gtk_action_set_accel_group (GTK_ACTION (action), accel_group);
-
- /* update the action's related language */
- mousepad_action_set_language (GTK_ACTION (action), language);
-
- /* try and get an icon for the language's first mime-type if possible */
- icon = mousepad_languages_get_icon_for_language (language);
- }
-
- /* set an icon for the action if we have one */
- if (G_IS_ICON (icon))
- {
- gtk_action_set_gicon (GTK_ACTION (action), icon);
- g_object_unref (icon);
- }
-
- /* watch for the 'none' language activation */
- g_signal_connect_object (action,
- "activate",
- G_CALLBACK (mousepad_languages_active_language_changed),
- group,
- G_CONNECT_SWAPPED);
-
- /* add it to the provided radio action group */
- gtk_radio_action_set_group (action, *radio_action_group);
- *radio_action_group = gtk_radio_action_get_group (action);
-
- gtk_action_group_add_action_with_accel (group, GTK_ACTION (action), NULL);
- g_object_unref (action);
-
- return action;
-}
-
-
-
-GtkActionGroup *
-mousepad_languages_action_group_new (void)
-{
- GtkSourceLanguageManager *manager;
- const gchar *const *language_ids;
- const gchar *const *language_id_ptr;
- GSList *radio_action_group = NULL;
- GtkActionGroup *group;
- GtkAccelGroup *accel_group;
- static gsize installed_signal = 0;
-
- /* one-time, add our 'language-changed' signal to the action group class */
- if (g_once_init_enter (&installed_signal))
- {
- g_signal_new ("language-changed",
- GTK_TYPE_ACTION_GROUP,
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1,
- GTK_TYPE_SOURCE_LANGUAGE);
- g_once_init_leave (&installed_signal, 1);
- }
-
- accel_group = gtk_accel_group_new ();
- group = gtk_action_group_new ("mousepad-languages");
-
- /* add an action for the 'none' language */
- mousepad_languages_create_action (group, NULL, &radio_action_group, accel_group);
-
- /* the default is the 'none' language */
- mousepad_action_group_set_active_language (group, NULL);
-
- manager = gtk_source_language_manager_get_default ();
- language_ids = gtk_source_language_manager_get_language_ids (manager);
-
- for (language_id_ptr = language_ids; language_id_ptr && *language_id_ptr; language_id_ptr++)
- {
- GtkSourceLanguage *language;
-
- /* lookup the language for the id */
- language = gtk_source_language_manager_get_language (manager, *language_id_ptr);
-
- /* create an action for the language */
- mousepad_languages_create_action (group, language, &radio_action_group, accel_group);
- }
-
- g_object_unref (accel_group);
-
- return group;
-}
-
-
-
-static GtkWidget *
-mousepad_languages_create_submenu (GtkActionGroup *group,
- const gchar *section)
-{
- GtkWidget *menu;
- GtkWidget *item;
- GSList *language_ids, *iter;
-
- menu = gtk_menu_new ();
-
- language_ids = mousepad_languages_get_sorted_for_section (section);
-
- for (iter = language_ids; iter != NULL; iter = g_slist_next (iter))
- {
- GtkAction *action;
- GtkSourceLanguage *language = iter->data;
-
- action = mousepad_languages_get_action (group, language);
- item = gtk_action_create_menu_item (action);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
- }
- g_slist_free (language_ids);
-
- return menu;
-}
-
-
-
-GtkWidget *
-mousepad_languages_create_menu (GtkActionGroup *group)
-{
- GtkWidget *menu;
- GtkWidget *item;
- GSList *sections, *iter;
- GtkAction *action;
-
- menu = gtk_menu_new ();
-
- /* add the 'none' language first */
- action = gtk_action_group_get_action (group, "mousepad-language-none");
- item = gtk_action_create_menu_item (action);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
-
- /* separator the 'none' language from the section submenus */
- item = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
-
- sections = mousepad_languages_get_sorted_sections ();
- for (iter = sections; iter != NULL; iter = g_slist_next (iter))
- {
- const gchar *section = iter->data;
- GtkWidget *submenu;
-
- /* create a menu item for the section */
- item = gtk_menu_item_new_with_label (section);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
-
- /* create a submenu for the section and it to the item */
- submenu = mousepad_languages_create_submenu (group, section);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
-
- }
- g_slist_free (sections);
-
- return menu;
-}
-
-
-
-static GtkSourceLanguage *
-mousepad_languages_get_radio_action_group_active (GSList *actions)
-{
- GSList *iter;
-
- for (iter = actions; iter != NULL; iter = g_slist_next (iter))
- {
- if (gtk_toggle_action_get_active (iter->data))
- return mousepad_action_get_language (iter->data);
- }
-
- return NULL;
-}
-
-
-
-GtkSourceLanguage *
-mousepad_languages_get_active (GtkActionGroup *group)
-{
- GList *actions, *action_iter;
- GtkSourceLanguage *language = NULL;
-
- /* scan for the first radio action in case there's other stuff in the group */
- actions = gtk_action_group_list_actions (group);
- for (action_iter = actions; action_iter != NULL; action_iter = g_list_next (action_iter))
- {
- /* make sure it's one of our language radio actions */
- if (GTK_IS_RADIO_ACTION (action_iter->data) &&
- GTK_IS_SOURCE_LANGUAGE (mousepad_action_get_language (action_iter->data)))
- {
- GSList *radio_actions;
- /* get the active language from its group */
- radio_actions = gtk_radio_action_get_group (action_iter->data);
- language = mousepad_languages_get_radio_action_group_active (radio_actions);
- break;
- }
- }
- g_list_free (actions);
-
- return language;
-}
-
-
-
-void
-mousepad_languages_set_active (GtkActionGroup *group,
- GtkSourceLanguage *language)
-{
- GtkAction *action;
-
- g_return_if_fail (GTK_IS_ACTION_GROUP (group));
-
- action = mousepad_languages_get_action (group, language);
- if (G_UNLIKELY (action == NULL))
- {
- g_critical ("failed to find action for language '%s'",
- language ? gtk_source_language_get_id (language) : "none");
- return;
- }
-
- /* the "language-changed" signal is emitted by the action groups handler
- * for actions activating when we do this */
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
-}
-
-
-
-GtkAction *
-mousepad_languages_get_action (GtkActionGroup *group,
- GtkSourceLanguage *language)
-{
- gchar *action_name;
- GtkAction *action;
- const gchar *language_id;
-
- g_return_val_if_fail (GTK_IS_ACTION_GROUP (group), NULL);
-
- if (GTK_IS_SOURCE_LANGUAGE (language))
- language_id = gtk_source_language_get_id (language);
- else
- language_id = "none";
-
- action_name = g_strdup_printf ("mousepad-language-%s", language_id);
- action = gtk_action_group_get_action (group, action_name);
- g_free (action_name);
-
- return action;
-}
-
-
-
-GtkSourceLanguage *
-mousepad_languages_get_action_language (GtkAction *action)
-{
- g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
-
- return mousepad_action_get_language (action);
-}
-
-
-static gint
-mousepad_util_languages_name_compare (gconstpointer a,
- gconstpointer b)
-{
- const gchar *name_a, *name_b;
-
- if (G_UNLIKELY (!GTK_IS_SOURCE_LANGUAGE (a)))
- return -(a != b);
- if (G_UNLIKELY (!GTK_IS_SOURCE_LANGUAGE (b)))
- return a != b;
-
- name_a = gtk_source_language_get_name (GTK_SOURCE_LANGUAGE (a));
- name_b = gtk_source_language_get_name (GTK_SOURCE_LANGUAGE (b));
-
- return g_utf8_collate (name_a, name_b);
-}
-
-
-
-GSList *
-mousepad_languages_get_sorted_sections (void)
-{
- GSList *list = NULL;
- const gchar *const *languages;
- GtkSourceLanguage *language;
- GtkSourceLanguageManager *manager;
-
- manager = gtk_source_language_manager_get_default ();
- languages = gtk_source_language_manager_get_language_ids (manager);
-
- while (*languages)
- {
- language = gtk_source_language_manager_get_language (manager, *languages);
- if (G_LIKELY (GTK_IS_SOURCE_LANGUAGE (language)))
- {
- /* ensure no duplicates in list */
- if (!g_slist_find_custom (list,
- gtk_source_language_get_section (language),
- (GCompareFunc)g_strcmp0))
- {
- list = g_slist_prepend (list, (gchar *)gtk_source_language_get_section (language));
- }
- }
- languages++;
- }
-
- return g_slist_sort (list, (GCompareFunc) g_utf8_collate);
-}
-
-
-
-GSList *
-mousepad_languages_get_sorted_for_section (const gchar *section)
-{
- GSList *list = NULL;
- const gchar *const *languages;
- GtkSourceLanguage *language;
- GtkSourceLanguageManager *manager;
-
- g_return_val_if_fail (section != NULL, NULL);
-
- manager = gtk_source_language_manager_get_default ();
- languages = gtk_source_language_manager_get_language_ids (manager);
-
- while (*languages)
- {
- language = gtk_source_language_manager_get_language (manager, *languages);
- if (G_LIKELY (GTK_IS_SOURCE_LANGUAGE (language)))
- {
- /* only get languages in the specified section */
- if (g_strcmp0 (gtk_source_language_get_section (language), section) == 0)
- list = g_slist_prepend (list, language);
- }
- languages++;
- }
-
- return g_slist_sort(list, (GCompareFunc)mousepad_util_languages_name_compare);
-}
diff --git a/mousepad/mousepad-languages.h b/mousepad/mousepad-languages.h
deleted file mode 100644
index fc801b0..0000000
--- a/mousepad/mousepad-languages.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef MOUSEPAD_LANGUAGES_H_
-#define MOUSEPAD_LANGUAGES_H_ 1
-
-#include <gtksourceview/gtksourcelanguage.h>
-
-G_BEGIN_DECLS
-
-GtkActionGroup *mousepad_languages_action_group_new (void);
-
-GtkWidget *mousepad_languages_create_menu (GtkActionGroup *group);
-
-GtkSourceLanguage *mousepad_languages_get_active (GtkActionGroup *group);
-
-void mousepad_languages_set_active (GtkActionGroup *group,
- GtkSourceLanguage *language);
-
-GtkAction *mousepad_languages_get_action (GtkActionGroup *group,
- GtkSourceLanguage *language);
-
-GtkSourceLanguage *mousepad_languages_get_action_language (GtkAction *action);
-
-GSList *mousepad_languages_get_sorted_sections (void);
-
-GSList *mousepad_languages_get_sorted_for_section (const gchar *section);
-
-G_END_DECLS
-
-#endif /* MOUSEPAD_LANGUAGES_H_ */
diff --git a/mousepad/mousepad-util.c b/mousepad/mousepad-util.c
index 929d322..c2c81ad 100644
--- a/mousepad/mousepad-util.c
+++ b/mousepad/mousepad-util.c
@@ -1160,3 +1160,20 @@ mousepad_util_find_related_action (GtkWidget *widget)
return action;
}
+
+
+
+GIcon *
+mousepad_util_icon_for_mime_type (const gchar *mime_type)
+{
+ gchar *content_type;
+ GIcon *icon = NULL;
+
+ g_return_val_if_fail (mime_type != NULL, NULL);
+
+ content_type = g_content_type_from_mime_type (mime_type);
+ if (content_type != NULL)
+ icon = g_content_type_get_icon (content_type);
+
+ return icon;
+}
diff --git a/mousepad/mousepad-util.h b/mousepad/mousepad-util.h
index 2cfc9d6..f2d2d7f 100644
--- a/mousepad/mousepad-util.h
+++ b/mousepad/mousepad-util.h
@@ -128,6 +128,8 @@ GSList *mousepad_util_color_schemes_get_sorted (void);
GtkAction *mousepad_util_find_related_action (GtkWidget *widget);
+GIcon *mousepad_util_icon_for_mime_type (const gchar *mime_type);
+
G_END_DECLS
#endif /* !__MOUSEPAD_UTIL_H__ */
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 0903515..e9f561c 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -35,6 +35,7 @@
#include <mousepad/mousepad-private.h>
#include <mousepad/mousepad-settings.h>
+#include <mousepad/mousepad-action-group.h>
#include <mousepad/mousepad-application.h>
#include <mousepad/mousepad-marshal.h>
#include <mousepad/mousepad-document.h>
@@ -44,7 +45,6 @@
#include <mousepad/mousepad-search-bar.h>
#include <mousepad/mousepad-statusbar.h>
#include <mousepad/mousepad-print.h>
-#include <mousepad/mousepad-languages.h>
#include <mousepad/mousepad-window.h>
#include <mousepad/mousepad-window-ui.h>
@@ -105,7 +105,7 @@ static gboolean mousepad_window_open_file (MousepadW
static gboolean mousepad_window_close_document (MousepadWindow *window,
MousepadDocument *document);
static void mousepad_window_set_title (MousepadWindow *window);
-static GtkMenu *mousepad_window_provide_languages_menu (MousepadWindow *window,
+static GtkWidget *mousepad_window_provide_languages_menu (MousepadWindow *window,
MousepadStatusbar *statusbar);
static void mousepad_window_create_statusbar (MousepadWindow *window);
static gboolean mousepad_window_get_in_fullscreen (MousepadWindow *window);
@@ -380,7 +380,6 @@ struct _MousepadWindow
/* action groups */
GtkActionGroup *action_group;
- GtkActionGroup *language_actions;
/* recent manager */
GtkRecentManager *recent_manager;
@@ -681,10 +680,15 @@ mousepad_window_restore (MousepadWindow *window)
static void
-mousepad_window_language_changed (MousepadWindow *window,
- GtkSourceLanguage *language,
- GtkActionGroup *group)
+mousepad_window_action_group_language_changed (MousepadWindow *window,
+ GParamSpec *pspec,
+ MousepadActionGroup *group)
{
+ GtkSourceLanguage *language;
+
+ /* get the new active language */
+ language = mousepad_action_group_get_active_language (group);
+
/* update the language on the active file */
mousepad_file_set_language (window->active->file, language);
@@ -697,19 +701,22 @@ mousepad_window_language_changed (MousepadWindow *window,
static void
mousepad_window_create_languages_menu (MousepadWindow *window)
{
- GtkWidget *menu, *item;
+ GtkWidget *menu, *item;
+ MousepadActionGroup *group;
+ static const gchar *menu_path = "/main-menu/document-menu/language-menu";
/* create the languages menu and add it to the placeholder */
- menu = mousepad_languages_create_menu (window->language_actions);
- item = gtk_ui_manager_get_widget (window->ui_manager, "/main-menu/document-menu/language-menu");
+ group = MOUSEPAD_ACTION_GROUP (window->action_group);
+ menu = mousepad_action_group_create_language_menu (group);
+ item = gtk_ui_manager_get_widget (window->ui_manager, menu_path);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
gtk_widget_show_all (menu);
gtk_widget_show (item);
/* watch for activations of the language actions */
- g_signal_connect_object (window->language_actions,
- "language-changed",
- G_CALLBACK (mousepad_window_language_changed),
+ g_signal_connect_object (window->action_group,
+ "notify::active-language",
+ G_CALLBACK (mousepad_window_action_group_language_changed),
window,
G_CONNECT_SWAPPED);
}
@@ -968,21 +975,17 @@ mousepad_window_init (MousepadWindow *window)
mousepad_window_restore (window);
/* the action group for this window */
- window->action_group = gtk_action_group_new ("MousepadWindow");
+ window->action_group = mousepad_action_group_new ();
gtk_action_group_set_translation_domain (window->action_group, GETTEXT_PACKAGE);
gtk_action_group_add_actions (window->action_group, action_entries, G_N_ELEMENTS (action_entries), GTK_WIDGET (window));
gtk_action_group_add_toggle_actions (window->action_group, toggle_action_entries, G_N_ELEMENTS (toggle_action_entries), GTK_WIDGET (window));
gtk_action_group_add_radio_actions (window->action_group, radio_action_entries, G_N_ELEMENTS (radio_action_entries), -1, G_CALLBACK (mousepad_window_action_line_ending), GTK_WIDGET (window));
- /* the action group for the languages/filetypes actions */
- window->language_actions = mousepad_languages_action_group_new ();
-
/* create the ui manager and connect proxy signals for the statusbar */
window->ui_manager = gtk_ui_manager_new ();
g_signal_connect (G_OBJECT (window->ui_manager), "connect-proxy", G_CALLBACK (mousepad_window_connect_proxy), window);
g_signal_connect (G_OBJECT (window->ui_manager), "disconnect-proxy", G_CALLBACK (mousepad_window_disconnect_proxy), window);
gtk_ui_manager_insert_action_group (window->ui_manager, window->action_group, 0);
- gtk_ui_manager_insert_action_group (window->ui_manager, window->language_actions, 1);
gtk_ui_manager_add_ui_from_string (window->ui_manager, mousepad_window_ui, mousepad_window_ui_length, NULL);
/* build the templates menu when the item is shown for the first time */
@@ -1095,7 +1098,6 @@ mousepad_window_finalize (GObject *object)
/* release the action groups */
g_object_unref (G_OBJECT (window->action_group));
- g_object_unref (G_OBJECT (window->language_actions));
/* free clipboard history if needed */
if (clipboard_history_ref_count == 0 && clipboard_history != NULL)
@@ -1694,11 +1696,14 @@ mousepad_window_set_title (MousepadWindow *window)
/* give the statusbar a languages menu created from our action group */
-static GtkMenu *
+static GtkWidget *
mousepad_window_provide_languages_menu (MousepadWindow *window,
MousepadStatusbar *statusbar)
{
- return GTK_MENU (mousepad_languages_create_menu (window->language_actions));
+ MousepadActionGroup *group;
+
+ group = MOUSEPAD_ACTION_GROUP (window->action_group);
+ return mousepad_action_group_create_language_menu (group);
}
@@ -1819,7 +1824,7 @@ mousepad_window_notebook_removed (GtkNotebook *notebook,
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_cursor_changed, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_selection_changed, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_overwrite_changed, window);
- g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_language_changed, window);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_buffer_language_changed, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_drag_data_received, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_undo, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_redo, window);
@@ -2091,8 +2096,11 @@ mousepad_window_buffer_language_changed (MousepadDocument *document,
GtkSourceLanguage *language,
MousepadWindow *window)
{
+ MousepadActionGroup *group;
+
/* activate the action for the new buffer language */
- mousepad_languages_set_active (window->language_actions, language);
+ group = MOUSEPAD_ACTION_GROUP (window->action_group);
+ mousepad_action_group_set_active_language (group, language);
}
@@ -2497,6 +2505,8 @@ mousepad_window_update_actions (MousepadWindow *window)
/* update the actions for the active document */
if (G_LIKELY (document))
{
+ MousepadActionGroup *group;
+
/* avoid menu actions */
lock_menu_updates++;
@@ -2573,7 +2583,8 @@ mousepad_window_update_actions (MousepadWindow *window)
/* update the currently active language */
language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (window->active->buffer));
- mousepad_languages_set_active (window->language_actions, language);
+ group = MOUSEPAD_ACTION_GROUP (window->action_group);
+ mousepad_action_group_set_active_language (group, language);
/* allow menu actions again */
lock_menu_updates--;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list