[Xfce4-commits] [apps/mousepad] 03/06: Move colour scheme code out of mousepad-window.c
noreply at xfce.org
noreply at xfce.org
Mon Jul 14 13:35:47 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 971e77b6c5775b3e640f5e879e1b7ec48197c267
Author: Matthew Brush <mbrush at codebrainz.ca>
Date: Mon Jul 14 03:45:28 2014 -0700
Move colour scheme code out of mousepad-window.c
Treated like the languages code, there's a GtkAction subclass for
style scheme actions and the MousepadActionGroup knows about them.
---
mousepad/Makefile.am | 2 +
mousepad/mousepad-action-group.c | 256 ++++++++++++++++++++++++++++++-
mousepad/mousepad-action-group.h | 20 ++-
mousepad/mousepad-style-scheme-action.c | 221 ++++++++++++++++++++++++++
mousepad/mousepad-style-scheme-action.h | 27 ++++
mousepad/mousepad-util.c | 54 -------
mousepad/mousepad-util.h | 7 -
mousepad/mousepad-window.c | 192 +++++++----------------
8 files changed, 567 insertions(+), 212 deletions(-)
diff --git a/mousepad/Makefile.am b/mousepad/Makefile.am
index e87ef4a..d9cf129 100644
--- a/mousepad/Makefile.am
+++ b/mousepad/Makefile.am
@@ -53,6 +53,8 @@ mousepad_SOURCES = \
mousepad-settings-store.h \
mousepad-statusbar.c \
mousepad-statusbar.h \
+ mousepad-style-scheme-action.c \
+ mousepad-style-scheme-action.h \
mousepad-view.c \
mousepad-view.h \
mousepad-util.c \
diff --git a/mousepad/mousepad-action-group.c b/mousepad/mousepad-action-group.c
index e5f7744..e90c6c8 100644
--- a/mousepad/mousepad-action-group.c
+++ b/mousepad/mousepad-action-group.c
@@ -4,8 +4,10 @@
#include <mousepad/mousepad-action-group.h>
#include <mousepad/mousepad-language-action.h>
+#include <mousepad/mousepad-style-scheme-action.h>
#include <glib/gi18n.h>
#include <gtksourceview/gtksourcelanguagemanager.h>
+#include <gtksourceview/gtksourcestyleschememanager.h>
@@ -13,6 +15,7 @@ enum
{
PROP_0,
PROP_ACTIVE_LANGUAGE,
+ PROP_ACTIVE_STYLE_SCHEME,
NUM_PROPERTIES
};
@@ -20,9 +23,10 @@ enum
struct MousepadActionGroup_
{
- GtkActionGroup parent;
- GtkSourceLanguage *active_language;
- gboolean locked;
+ GtkActionGroup parent;
+ GtkSourceLanguage *active_language;
+ GtkSourceStyleScheme *active_scheme;
+ gboolean locked;
};
@@ -45,7 +49,7 @@ static void mousepad_action_group_get_property (GObjec
GParamSpec *pspec);
static GtkWidget *mousepad_action_group_create_language_submenu (MousepadActionGroup *self,
const gchar *section);
-static void mousepad_action_group_action_activate (MousepadActionGroup *self,
+static void mousepad_action_group_language_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,
@@ -54,6 +58,14 @@ static gint mousepad_action_group_languages_name_compare (gconst
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);
+static void mousepad_action_group_add_style_scheme_actions (MousepadActionGroup *self);
+static GtkAction *mousepad_action_group_get_style_scheme_action (MousepadActionGroup *self,
+ GtkSourceStyleScheme *scheme);
+static gint mousepad_action_group_style_schemes_name_compare (gconstpointer a,
+ gconstpointer b);
+static GSList *mousepad_action_group_get_style_schemes (void);
+static GSList *mousepad_action_group_style_schemes_get_sorted (void);
+
G_DEFINE_TYPE (MousepadActionGroup, mousepad_action_group, GTK_TYPE_ACTION_GROUP)
@@ -79,6 +91,15 @@ mousepad_action_group_class_init (MousepadActionGroupClass *klass)
"The currently active language action",
MOUSEPAD_TYPE_LANGUAGE_ACTION,
G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ g_object_class,
+ PROP_ACTIVE_STYLE_SCHEME,
+ g_param_spec_object ("active-style-scheme",
+ "ActiveStyleScheme",
+ "The currently active style scheme action",
+ MOUSEPAD_TYPE_STYLE_SCHEME_ACTION,
+ G_PARAM_READWRITE));
}
@@ -95,6 +116,9 @@ mousepad_action_group_finalize (GObject *object)
if (GTK_IS_SOURCE_LANGUAGE (self->active_language))
g_object_unref (self->active_language);
+ if (GTK_IS_SOURCE_STYLE_SCHEME (self->active_scheme))
+ g_object_unref (self->active_scheme);
+
G_OBJECT_CLASS (mousepad_action_group_parent_class)->finalize (object);
}
@@ -113,6 +137,9 @@ mousepad_action_group_set_property (GObject *object,
case PROP_ACTIVE_LANGUAGE:
mousepad_action_group_set_active_language (self, g_value_get_object (value));
break;
+ case PROP_ACTIVE_STYLE_SCHEME:
+ mousepad_action_group_set_active_style_scheme (self, g_value_get_object (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -134,6 +161,9 @@ mousepad_action_group_get_property (GObject *object,
case PROP_ACTIVE_LANGUAGE:
g_value_set_object (value, mousepad_action_group_get_active_language (self));
break;
+ case PROP_ACTIVE_STYLE_SCHEME:
+ g_value_set_object (value, mousepad_action_group_get_active_style_scheme (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -148,6 +178,10 @@ 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);
+
+ self->active_scheme = NULL;
+ mousepad_action_group_add_style_scheme_actions (self);
+ mousepad_action_group_set_active_style_scheme (self, NULL);
}
@@ -204,6 +238,44 @@ mousepad_action_group_get_active_language (MousepadActionGroup *self)
+void
+mousepad_action_group_set_active_style_scheme (MousepadActionGroup *self,
+ GtkSourceStyleScheme *scheme)
+{
+ GtkAction *action;
+
+ g_return_if_fail (MOUSEPAD_IS_ACTION_GROUP (self));
+
+ if (GTK_IS_SOURCE_STYLE_SCHEME (self->active_scheme))
+ g_object_unref (self->active_scheme);
+
+ if (GTK_IS_SOURCE_STYLE_SCHEME (scheme))
+ self->active_scheme = g_object_ref (scheme);
+ else
+ self->active_scheme = NULL;
+
+ action = mousepad_action_group_get_style_scheme_action (self, scheme);
+
+ /* 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-style-scheme");
+}
+
+
+
+GtkSourceStyleScheme *
+mousepad_action_group_get_active_style_scheme (MousepadActionGroup *self)
+{
+ g_return_val_if_fail (MOUSEPAD_IS_ACTION_GROUP (self), NULL);
+
+ return self->active_scheme;
+}
+
+
+
/**
* GUI proxy creation
**/
@@ -286,6 +358,44 @@ mousepad_action_group_create_language_menu (MousepadActionGroup *self)
+GtkWidget *
+mousepad_action_group_create_style_scheme_menu (MousepadActionGroup *self)
+{
+ GtkWidget *menu;
+ GtkWidget *item;
+ GtkAction *action;
+ GSList *schemes, *iter;
+
+ menu = gtk_menu_new ();
+
+ action = mousepad_action_group_get_style_scheme_action (self, NULL);
+ item = gtk_action_create_menu_item (action);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ schemes = mousepad_action_group_style_schemes_get_sorted ();
+
+ for (iter = schemes; iter != NULL; iter = g_slist_next (iter))
+ {
+ GtkSourceStyleScheme *scheme = iter->data;
+
+ action = mousepad_action_group_get_style_scheme_action (self, scheme);
+ item = gtk_action_create_menu_item (action);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ }
+
+ g_slist_free (schemes);
+
+ return menu;
+}
+
+
+
/**
* Signal handlers
**/
@@ -293,8 +403,8 @@ mousepad_action_group_create_language_menu (MousepadActionGroup *self)
static void
-mousepad_action_group_action_activate (MousepadActionGroup *self,
- MousepadLanguageAction *action)
+mousepad_action_group_language_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 */
@@ -310,6 +420,24 @@ mousepad_action_group_action_activate (MousepadActionGroup *self,
+static void
+mousepad_action_group_style_scheme_action_activate (MousepadActionGroup *self,
+ MousepadStyleSchemeAction *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)))
+ {
+ GtkSourceStyleScheme *scheme;
+
+ scheme = mousepad_style_scheme_action_get_style_scheme (action);
+ mousepad_action_group_set_active_style_scheme (self, scheme);
+ }
+}
+
+
+
/**
* Helper functions
**/
@@ -334,7 +462,7 @@ mousepad_action_group_add_language_actions (MousepadActionGroup *self)
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_signal_connect_object (action, "activate", G_CALLBACK (mousepad_action_group_language_action_activate), self, G_CONNECT_SWAPPED);
manager = gtk_source_language_manager_get_default ();
lang_ids = gtk_source_language_manager_get_language_ids (manager);
@@ -350,7 +478,7 @@ mousepad_action_group_add_language_actions (MousepadActionGroup *self)
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_signal_connect_object (action, "activate", G_CALLBACK (mousepad_action_group_language_action_activate), self, G_CONNECT_SWAPPED);
}
g_object_unref (accel_group);
@@ -460,3 +588,115 @@ mousepad_action_group_get_sorted_languages_for_section (const gchar *section)
return g_slist_sort(list, (GCompareFunc) mousepad_action_group_languages_name_compare);
}
+
+
+
+static void
+mousepad_action_group_add_style_scheme_actions (MousepadActionGroup *self)
+{
+ GSList *schemes, *iter;
+ GSList *group = NULL;
+ GtkAccelGroup *accel_group;
+ GtkAction *action;
+
+ accel_group = gtk_accel_group_new ();
+
+ /* add an action for the 'none' (non-)scheme */
+ action = mousepad_style_scheme_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_style_scheme_action_activate), self, G_CONNECT_SWAPPED);
+
+ schemes = mousepad_action_group_get_style_schemes ();
+
+ for (iter = schemes; iter != NULL; iter = g_slist_next (iter))
+ {
+ GtkSourceStyleScheme *scheme = iter->data;
+
+ /* add an action for each GSV style scheme */
+ action = mousepad_style_scheme_action_new (scheme);
+ 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_style_scheme_action_activate), self, G_CONNECT_SWAPPED);
+ }
+
+ g_slist_free (schemes);
+ g_object_unref (accel_group);
+}
+
+
+
+static GtkAction *
+mousepad_action_group_get_style_scheme_action (MousepadActionGroup *self,
+ GtkSourceStyleScheme *scheme)
+{
+ gchar *name;
+ const gchar *scheme_id;
+ GtkAction *action;
+
+ if (GTK_IS_SOURCE_STYLE_SCHEME (scheme))
+ scheme_id = gtk_source_style_scheme_get_id (scheme);
+ else
+ scheme_id = "none";
+
+ name = g_strdup_printf ("mousepad-style-scheme-%s", scheme_id);
+ action = gtk_action_group_get_action (GTK_ACTION_GROUP (self), name);
+ g_free (name);
+
+ return action;
+}
+
+
+
+static gint
+mousepad_action_group_style_schemes_name_compare (gconstpointer a,
+ gconstpointer b)
+{
+ const gchar *name_a, *name_b;
+
+ if (G_UNLIKELY (!GTK_IS_SOURCE_STYLE_SCHEME (a)))
+ return -(a != b);
+ if (G_UNLIKELY (!GTK_IS_SOURCE_STYLE_SCHEME (b)))
+ return a != b;
+
+ name_a = gtk_source_style_scheme_get_name (GTK_SOURCE_STYLE_SCHEME (a));
+ name_b = gtk_source_style_scheme_get_name (GTK_SOURCE_STYLE_SCHEME (b));
+
+ return g_utf8_collate (name_a, name_b);
+}
+
+
+
+static GSList *
+mousepad_action_group_get_style_schemes (void)
+{
+ GSList *list = NULL;
+ const gchar * const *schemes;
+ GtkSourceStyleScheme *scheme;
+
+ schemes = gtk_source_style_scheme_manager_get_scheme_ids (
+ gtk_source_style_scheme_manager_get_default ());
+
+ while (*schemes)
+ {
+ scheme = gtk_source_style_scheme_manager_get_scheme (
+ gtk_source_style_scheme_manager_get_default (), *schemes);
+ list = g_slist_prepend (list, scheme);
+ schemes++;
+ }
+
+ return list;
+}
+
+
+
+static GSList *
+mousepad_action_group_style_schemes_get_sorted (void)
+{
+ return g_slist_sort (mousepad_action_group_get_style_schemes (),
+ mousepad_action_group_style_schemes_name_compare);
+}
diff --git a/mousepad/mousepad-action-group.h b/mousepad/mousepad-action-group.h
index bc067e9..dcaba57 100644
--- a/mousepad/mousepad-action-group.h
+++ b/mousepad/mousepad-action-group.h
@@ -3,6 +3,7 @@
#include <gtk/gtk.h>
#include <gtksourceview/gtksourcelanguage.h>
+#include <gtksourceview/gtksourcestylescheme.h>
G_BEGIN_DECLS
@@ -16,16 +17,23 @@ G_BEGIN_DECLS
typedef struct MousepadActionGroup_ MousepadActionGroup;
typedef struct MousepadActionGroupClass_ MousepadActionGroupClass;
-GType mousepad_action_group_get_type (void);
+GType mousepad_action_group_get_type (void);
-GtkActionGroup *mousepad_action_group_new (void);
+GtkActionGroup *mousepad_action_group_new (void);
-void mousepad_action_group_set_active_language (MousepadActionGroup *group,
- GtkSourceLanguage *language);
+void mousepad_action_group_set_active_language (MousepadActionGroup *group,
+ GtkSourceLanguage *language);
-GtkSourceLanguage *mousepad_action_group_get_active_language (MousepadActionGroup *group);
+GtkSourceLanguage *mousepad_action_group_get_active_language (MousepadActionGroup *group);
-GtkWidget *mousepad_action_group_create_language_menu (MousepadActionGroup *group);
+GtkWidget *mousepad_action_group_create_language_menu (MousepadActionGroup *group);
+
+void mousepad_action_group_set_active_style_scheme (MousepadActionGroup *group,
+ GtkSourceStyleScheme *scheme);
+
+GtkSourceStyleScheme *mousepad_action_group_get_active_style_scheme (MousepadActionGroup *group);
+
+GtkWidget *mousepad_action_group_create_style_scheme_menu (MousepadActionGroup *group);
G_END_DECLS
diff --git a/mousepad/mousepad-style-scheme-action.c b/mousepad/mousepad-style-scheme-action.c
new file mode 100644
index 0000000..48f08a0
--- /dev/null
+++ b/mousepad/mousepad-style-scheme-action.c
@@ -0,0 +1,221 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <mousepad/mousepad-style-scheme-action.h>
+#include <glib/gi18n.h>
+#include <gtksourceview/gtksourcestyleschememanager.h>
+
+
+
+enum
+{
+ PROP_0,
+ PROP_STYLE_SCHEME,
+ NUM_PROPERTIES
+};
+
+
+
+struct MousepadStyleSchemeAction_
+{
+ GtkRadioAction parent;
+ GtkSourceStyleScheme *scheme;
+};
+
+
+
+struct MousepadStyleSchemeActionClass_
+{
+ GtkRadioActionClass parent_class;
+};
+
+
+
+static void mousepad_style_scheme_action_finalize (GObject *object);
+static void mousepad_style_scheme_action_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void mousepad_style_scheme_action_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void mousepad_style_scheme_action_set_style_scheme (MousepadStyleSchemeAction *action,
+ GtkSourceStyleScheme *scheme);
+
+
+
+G_DEFINE_TYPE (MousepadStyleSchemeAction, mousepad_style_scheme_action, GTK_TYPE_RADIO_ACTION)
+
+
+
+static void
+mousepad_style_scheme_action_class_init (MousepadStyleSchemeActionClass *klass)
+{
+ GObjectClass *g_object_class;
+
+ g_object_class = G_OBJECT_CLASS (klass);
+
+ g_object_class->finalize = mousepad_style_scheme_action_finalize;
+ g_object_class->set_property = mousepad_style_scheme_action_set_property;
+ g_object_class->get_property = mousepad_style_scheme_action_get_property;
+
+ g_object_class_install_property (
+ g_object_class,
+ PROP_STYLE_SCHEME,
+ g_param_spec_object ("style-scheme",
+ "StyleScheme",
+ "The style scheme related to the action",
+ GTK_TYPE_SOURCE_STYLE_SCHEME,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+}
+
+
+
+static void
+mousepad_style_scheme_action_finalize (GObject *object)
+{
+ MousepadStyleSchemeAction *self;
+
+ g_return_if_fail (MOUSEPAD_IS_STYLE_SCHEME_ACTION (object));
+
+ self = MOUSEPAD_STYLE_SCHEME_ACTION (object);
+
+ if (GTK_IS_SOURCE_STYLE_SCHEME (self->scheme))
+ g_object_unref (self->scheme);
+
+ G_OBJECT_CLASS (mousepad_style_scheme_action_parent_class)->finalize (object);
+}
+
+
+
+static void
+mousepad_style_scheme_action_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MousepadStyleSchemeAction *self = MOUSEPAD_STYLE_SCHEME_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_STYLE_SCHEME:
+ mousepad_style_scheme_action_set_style_scheme (self, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+mousepad_style_scheme_action_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MousepadStyleSchemeAction *self = MOUSEPAD_STYLE_SCHEME_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_STYLE_SCHEME:
+ g_value_set_object (value, mousepad_style_scheme_action_get_style_scheme (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+mousepad_style_scheme_action_init (MousepadStyleSchemeAction *self)
+{
+ self->scheme = NULL;
+}
+
+
+
+GtkAction *
+mousepad_style_scheme_action_new (GtkSourceStyleScheme *scheme)
+{
+ const gchar *scheme_id;
+ gchar *name;
+ GtkAction *action;
+
+ if (GTK_IS_SOURCE_STYLE_SCHEME (scheme))
+ scheme_id = gtk_source_style_scheme_get_id (scheme);
+ else
+ scheme_id = "none";
+
+ name = g_strdup_printf ("mousepad-style-scheme-%s", scheme_id);
+ action = g_object_new (MOUSEPAD_TYPE_STYLE_SCHEME_ACTION,
+ "name", name,
+ "style-scheme", scheme, NULL);
+ g_free (name);
+
+ return action;
+}
+
+
+
+static void
+mousepad_style_scheme_action_set_style_scheme (MousepadStyleSchemeAction *self,
+ GtkSourceStyleScheme *scheme)
+{
+ GQuark value_quark;
+
+ if (G_UNLIKELY (self->scheme != NULL))
+ g_object_unref (self->scheme);
+
+ if (G_UNLIKELY (scheme == NULL))
+ {
+ self->scheme = NULL;
+ gtk_action_set_label (GTK_ACTION (self), _("None"));
+ gtk_action_set_tooltip (GTK_ACTION (self), _("No style scheme"));
+ value_quark = g_quark_from_static_string ("none");
+ }
+ else
+ {
+ gchar *tooltip, *author;
+ gchar **authors;
+ const gchar *scheme_id;
+
+ self->scheme = g_object_ref (scheme);
+
+ authors = (gchar**) gtk_source_style_scheme_get_authors (scheme);
+ author = g_strjoinv (", ", authors);
+
+ tooltip = g_strdup_printf ("%s\n\nAuthors: %s\nFilename: %s",
+ gtk_source_style_scheme_get_description (scheme),
+ author,
+ gtk_source_style_scheme_get_filename (scheme));
+
+ gtk_action_set_label (GTK_ACTION (self), gtk_source_style_scheme_get_name (scheme));
+ gtk_action_set_tooltip (GTK_ACTION (self), tooltip);
+
+ g_free (author);
+ g_free (tooltip);
+
+ scheme_id = gtk_source_style_scheme_get_id (scheme);
+ value_quark = g_quark_from_string (scheme_id);
+ }
+
+ g_object_set (G_OBJECT (self), "value", value_quark, NULL);
+
+ g_object_notify (G_OBJECT (self), "style-scheme");
+}
+
+
+
+GtkSourceStyleScheme *
+mousepad_style_scheme_action_get_style_scheme (MousepadStyleSchemeAction *self)
+{
+ g_return_val_if_fail (MOUSEPAD_IS_STYLE_SCHEME_ACTION (self), NULL);
+
+ return self->scheme;
+}
diff --git a/mousepad/mousepad-style-scheme-action.h b/mousepad/mousepad-style-scheme-action.h
new file mode 100644
index 0000000..ca9f10f
--- /dev/null
+++ b/mousepad/mousepad-style-scheme-action.h
@@ -0,0 +1,27 @@
+#ifndef MOUSEPAD_STYLESCHEME_ACTION_H_
+#define MOUSEPAD_STYLESCHEME_ACTION_H_ 1
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourcestylescheme.h>
+
+G_BEGIN_DECLS
+
+#define MOUSEPAD_TYPE_STYLE_SCHEME_ACTION (mousepad_style_scheme_action_get_type ())
+#define MOUSEPAD_STYLE_SCHEME_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOUSEPAD_TYPE_STYLE_SCHEME_ACTION, MousepadStyleSchemeAction))
+#define MOUSEPAD_STYLE_SCHEME_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOUSEPAD_TYPE_STYLE_SCHEME_ACTION, MousepadStyleSchemeActionClass))
+#define MOUSEPAD_IS_STYLE_SCHEME_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOUSEPAD_TYPE_STYLE_SCHEME_ACTION))
+#define MOUSEPAD_IS_STYLE_SCHEME_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_STYLE_SCHEME_ACTION))
+#define MOUSEPAD_STYLE_SCHEME_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_STYLE_SCHEME_ACTION, MousepadStyleSchemeActionClass))
+
+typedef struct MousepadStyleSchemeAction_ MousepadStyleSchemeAction;
+typedef struct MousepadStyleSchemeActionClass_ MousepadStyleSchemeActionClass;
+
+GType mousepad_style_scheme_action_get_type (void);
+
+GtkAction *mousepad_style_scheme_action_new (GtkSourceStyleScheme *scheme);
+
+GtkSourceStyleScheme *mousepad_style_scheme_action_get_style_scheme (MousepadStyleSchemeAction *action);
+
+G_END_DECLS
+
+#endif /* MOUSEPAD_STYLESCHEME_ACTION_H_ */
diff --git a/mousepad/mousepad-util.c b/mousepad/mousepad-util.c
index c2c81ad..42d028c 100644
--- a/mousepad/mousepad-util.c
+++ b/mousepad/mousepad-util.c
@@ -1081,60 +1081,6 @@ mousepad_util_search (GtkTextBuffer *buffer,
-/**
- * Colour scheme functions
- */
-gint
-mousepad_util_color_schemes_name_compare (gconstpointer a,
- gconstpointer b)
-{
- const gchar *name_a, *name_b;
-
- if (G_UNLIKELY (!GTK_IS_SOURCE_STYLE_SCHEME (a)))
- return -(a != b);
- if (G_UNLIKELY (!GTK_IS_SOURCE_STYLE_SCHEME (b)))
- return a != b;
-
- name_a = gtk_source_style_scheme_get_name (GTK_SOURCE_STYLE_SCHEME (a));
- name_b = gtk_source_style_scheme_get_name (GTK_SOURCE_STYLE_SCHEME (b));
-
- return g_utf8_collate (name_a, name_b);
-}
-
-
-
-GSList *
-mousepad_util_color_schemes_get (void)
-{
- GSList *list = NULL;
- const gchar * const *schemes;
- GtkSourceStyleScheme *scheme;
-
- schemes = gtk_source_style_scheme_manager_get_scheme_ids (
- gtk_source_style_scheme_manager_get_default ());
-
- while (*schemes)
- {
- scheme = gtk_source_style_scheme_manager_get_scheme (
- gtk_source_style_scheme_manager_get_default (), *schemes);
- list = g_slist_prepend (list, scheme);
- schemes++;
- }
-
- return list;
-}
-
-
-
-GSList *
-mousepad_util_color_schemes_get_sorted (void)
-{
- return g_slist_sort (mousepad_util_color_schemes_get (),
- mousepad_util_color_schemes_name_compare);
-}
-
-
-
/* get the related action of the widget or walk up the parents to find one.
* useful for example to get the related action of a tool item from its child. */
GtkAction *
diff --git a/mousepad/mousepad-util.h b/mousepad/mousepad-util.h
index f2d2d7f..6e48ddf 100644
--- a/mousepad/mousepad-util.h
+++ b/mousepad/mousepad-util.h
@@ -119,13 +119,6 @@ gint mousepad_util_search (GtkTextBuffer *
const gchar *replace,
MousepadSearchFlags flags);
-gint mousepad_util_color_schemes_name_compare (gconstpointer a,
- gconstpointer b);
-
-GSList *mousepad_util_color_schemes_get (void);
-
-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);
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index e9f561c..b23ef1d 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -190,7 +190,6 @@ static void mousepad_window_update_gomenu (MousepadW
static void mousepad_window_update_tabs (MousepadWindow *window,
gchar *key,
GSettings *settings);
-static void mousepad_window_menu_color_schemes (MousepadWindow *window);
/* recent functions */
static void mousepad_window_recent_add (MousepadWindow *window,
@@ -326,8 +325,6 @@ static void mousepad_window_action_go_to_position (GtkAction
MousepadWindow *window);
static void mousepad_window_action_select_font (GtkAction *action,
MousepadWindow *window);
-static void mousepad_window_action_color_scheme (GtkToggleAction *action,
- MousepadWindow *window);
static void mousepad_window_action_line_numbers (GtkToggleAction *action,
MousepadWindow *window);
static void mousepad_window_action_menubar (GtkToggleAction *action,
@@ -724,6 +721,57 @@ mousepad_window_create_languages_menu (MousepadWindow *window)
static void
+mousepad_window_action_group_style_scheme_changed (MousepadWindow *window,
+ GParamSpec *pspec,
+ MousepadActionGroup *group)
+{
+ GtkSourceStyleScheme *scheme;
+ const gchar *scheme_id;
+ gint npages, i;
+
+ /* get the new active language */
+ scheme = mousepad_action_group_get_active_style_scheme (group);
+ scheme_id = gtk_source_style_scheme_get_id (scheme);
+
+ /* update the color scheme on all the documents */
+ npages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook));
+ for (i = 0; i < npages; i++)
+ {
+ MousepadDocument *document;
+
+ document = MOUSEPAD_DOCUMENT (gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), i));
+ mousepad_view_set_color_scheme (document->textview, scheme_id);
+ }
+}
+
+
+
+static void
+mousepad_window_create_style_schemes_menu (MousepadWindow *window)
+{
+ GtkWidget *menu, *item;
+ MousepadActionGroup *group;
+ static const gchar *menu_path = "/main-menu/view-menu/color-scheme-menu";
+
+ /* create the color schemes menu and add it to the placeholder */
+ group = MOUSEPAD_ACTION_GROUP (window->action_group);
+ menu = mousepad_action_group_create_style_scheme_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 style schemes actions */
+ g_signal_connect_object (window->action_group,
+ "notify::active-style-scheme",
+ G_CALLBACK (mousepad_window_action_group_style_scheme_changed),
+ window,
+ G_CONNECT_SWAPPED);
+}
+
+
+
+static void
mousepad_window_create_menubar (MousepadWindow *window)
{
GtkAction *action;
@@ -732,8 +780,12 @@ mousepad_window_create_menubar (MousepadWindow *window)
window->menubar = gtk_ui_manager_get_widget (window->ui_manager, "/main-menu");
gtk_box_pack_start (GTK_BOX (window->box), window->menubar, FALSE, FALSE, 0);
+ /* add the filetypes menu */
mousepad_window_create_languages_menu (window);
+ /* add the colour schemes menu */
+ mousepad_window_create_style_schemes_menu (window);
+
/* sync the menubar visibility and action state to the setting */
action = gtk_action_group_get_action (window->action_group, "menubar");
if (MOUSEPAD_SETTING_GET_BOOLEAN (WINDOW_FULLSCREEN))
@@ -996,9 +1048,6 @@ mousepad_window_init (MousepadWindow *window)
/* add tab size menu */
mousepad_window_menu_tab_sizes (window);
- /* add color schemes menu */
- mousepad_window_menu_color_schemes (window);
-
/* set accel group for the window */
accel_group = gtk_ui_manager_get_accel_group (window->ui_manager);
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
@@ -3492,94 +3541,6 @@ mousepad_window_delete_event (MousepadWindow *window,
-static void
-mousepad_window_menu_color_schemes (MousepadWindow *window)
-{
- GtkRadioAction *action;
- GSList *group = NULL, *schemes, *iter;
- gint merge_id;
- gchar *name, *selected_color_scheme = NULL;
-
- /* lock menu updates */
- lock_menu_updates++;
-
- /* get the previously saved colour scheme name */
- selected_color_scheme = MOUSEPAD_SETTING_GET_STRING (COLOR_SCHEME);
-
- /* get list of schemes */
- schemes = mousepad_util_color_schemes_get_sorted ();
-
- /* create merge id */
- merge_id = gtk_ui_manager_new_merge_id (window->ui_manager);
-
- /* create a "none" action */
- action = gtk_radio_action_new ("color-scheme-none",
- _("None"),
- _("Turn off color schemes"),
- NULL,
- g_str_hash ("none"));
- gtk_radio_action_set_group (action, group);
- group = gtk_radio_action_get_group (action);
- g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (mousepad_window_action_color_scheme), window);
- gtk_action_group_add_action_with_accel (window->action_group, GTK_ACTION (action), "");
-
- /* release the action */
- g_object_unref (G_OBJECT (action));
-
- /* add the action to the go menu */
- gtk_ui_manager_add_ui (window->ui_manager, merge_id,
- "/main-menu/view-menu/color-scheme-menu/placeholder-color-scheme-items",
- "color-scheme-none", "color-scheme-none", GTK_UI_MANAGER_MENUITEM, FALSE);
-
- /* add a separator */
- gtk_ui_manager_add_ui (window->ui_manager, merge_id,
- "/main-menu/view-menu/color-scheme-menu/placeholder-color-scheme-items",
- "color-scheme-separator", NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
-
- /* add the color schemes to the menu */
- for (iter = schemes; iter != NULL; iter = g_slist_next (iter))
- {
- /* create action name */
- name = g_strdup_printf ("color-scheme_%s", gtk_source_style_scheme_get_id (iter->data));
-
- /* create action for colour scheme */
- action = gtk_radio_action_new (name,
- gtk_source_style_scheme_get_name (iter->data),
- gtk_source_style_scheme_get_description (iter->data),
- NULL,
- g_str_hash (gtk_source_style_scheme_get_id (iter->data)));
- gtk_radio_action_set_group (action, group);
- group = gtk_radio_action_get_group (action);
- g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (mousepad_window_action_color_scheme), window);
- gtk_action_group_add_action_with_accel (window->action_group, GTK_ACTION (action), "");
-
- /* activate the radio button if it was the last saved colour scheme */
- if (g_strcmp0 (gtk_source_style_scheme_get_id (iter->data), selected_color_scheme) == 0)
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
-
- /* release the action */
- g_object_unref (G_OBJECT (action));
-
- /* add the action to the go menu */
- gtk_ui_manager_add_ui (window->ui_manager, merge_id,
- "/main-menu/view-menu/color-scheme-menu/placeholder-color-scheme-items",
- name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
-
- /* cleanup */
- g_free (name);
- }
-
- g_free (selected_color_scheme);
-
- /* cleanup the list */
- g_slist_free (schemes);
-
- /* unlock */
- lock_menu_updates--;
-}
-
-
-
/**
* Menu Actions
*
@@ -4845,49 +4806,6 @@ mousepad_window_action_select_font (GtkAction *action,
static void
-mousepad_window_action_color_scheme (GtkToggleAction *action,
- MousepadWindow *window)
-{
- guint scheme_id_hash;
- GtkSourceStyleScheme *scheme = NULL;
- GSList *schemes, *iter;
-
- mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
-
- /* leave when menu updates are locked */
- if (lock_menu_updates == 0 && gtk_toggle_action_get_active (action))
- {
- mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
-
- /* get the color scheme id hashed */
- scheme_id_hash = (guint) gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
-
- if (scheme_id_hash != g_str_hash ("none"))
- {
- /* lookup the scheme from the id hash */
- schemes = mousepad_util_color_schemes_get ();
- for (iter = schemes; iter != NULL; iter = g_slist_next (iter))
- {
- if (scheme_id_hash == g_str_hash (gtk_source_style_scheme_get_id (iter->data)))
- {
- scheme = iter->data;
- break;
- }
- }
- g_slist_free (schemes);
- }
-
- /* store as last used value */
- MOUSEPAD_SETTING_SET_STRING (COLOR_SCHEME,
- (scheme != NULL) ?
- gtk_source_style_scheme_get_id (scheme) :
- "none");
- }
-}
-
-
-
-static void
mousepad_window_action_line_numbers (GtkToggleAction *action,
MousepadWindow *window)
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list