[gtksourceview] Add actions to toggle syntax hl.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Add actions to toggle syntax hl.
- Date: Sat, 3 Jul 2010 10:43:40 +0000 (UTC)
commit 15ad9a65755cb4a6cee3063c21f0998d7c70416a
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jul 3 12:43:28 2010 +0200
Add actions to toggle syntax hl.
Based on a patch by Jose Aliste
tests/test-widget.c | 25 +++++++++++++++++++++++++
tests/test-widget.py | 9 ++++++++-
2 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 2fa996d..0b0d93f 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -72,6 +72,8 @@ static void marks_toggled_cb (GtkAction *action,
gpointer user_data);
static void margin_toggled_cb (GtkAction *action,
gpointer user_data);
+static void hl_syntax_toggled_cb (GtkAction *action,
+ gpointer user_data);
static void hl_bracket_toggled_cb (GtkAction *action,
gpointer user_data);
static void hl_line_toggled_cb (GtkAction *action,
@@ -132,6 +134,9 @@ static GtkActionEntry view_action_entries[] = {
};
static GtkToggleActionEntry toggle_entries[] = {
+ { "HlSyntax", NULL, "Highlight _Syntax", NULL,
+ "Toggle syntax highlighting",
+ G_CALLBACK (hl_syntax_toggled_cb), FALSE },
{ "HlBracket", NULL, "Highlight Matching _Bracket", NULL,
"Toggle highlighting of matching bracket",
G_CALLBACK (hl_bracket_toggled_cb), FALSE },
@@ -200,6 +205,7 @@ static const gchar *view_ui_description =
" <menu action=\"ViewMenu\">"
" <menuitem action=\"NewView\"/>"
" <separator/>"
+" <menuitem action=\"HlSyntax\"/>"
" <menuitem action=\"HlBracket\"/>"
" <menuitem action=\"ShowNumbers\"/>"
" <menuitem action=\"ShowMarks\"/>"
@@ -518,6 +524,17 @@ margin_toggled_cb (GtkAction *action, gpointer user_data)
}
static void
+hl_syntax_toggled_cb (GtkAction *action, gpointer user_data)
+{
+ GtkTextBuffer *buffer;
+ g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_IS_SOURCE_VIEW (user_data));
+ buffer = gtk_text_view_get_buffer (user_data);
+ gtk_source_buffer_set_highlight_syntax (
+ GTK_SOURCE_BUFFER (buffer),
+ gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+}
+
+static void
hl_bracket_toggled_cb (GtkAction *action, gpointer user_data)
{
GtkTextBuffer *buffer;
@@ -1458,6 +1475,10 @@ create_main_window (GtkSourceBuffer *buffer)
/* retrieve the view action group at position 0 in the list */
action_group = g_list_nth_data (groups, 0);
+ action = gtk_action_group_get_action (action_group, "HlSyntax");
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
+ gtk_source_buffer_get_highlight_syntax (buffer));
+
action = gtk_action_group_get_action (action_group, "HlBracket");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
@@ -1574,6 +1595,7 @@ main (int argc, char *argv[])
GtkSourceStyleSchemeManager *sm;
GtkSourceBuffer *buffer;
+ gboolean no_syntax = FALSE;
gchar *builtin_lang_dirs[] = {TOP_SRCDIR "/data/language-specs", NULL};
gchar *builtin_sm_dirs[] = {TOP_SRCDIR "/data/styles", NULL};
gchar **dirs;
@@ -1584,6 +1606,7 @@ main (int argc, char *argv[])
GOptionContext *context;
GOptionEntry entries[] = {
+ { "no-syntax", 'n', 0, G_OPTION_ARG_NONE, &no_syntax, "Disable syntax highlighting", NULL},
{ "style-scheme", 's', 0, G_OPTION_ARG_STRING, &style_scheme_id, "Style scheme name to use", "SCHEME"},
{ "default-paths", 'd', 0, G_OPTION_ARG_NONE, &use_default_paths, "Use default search paths", NULL},
{ NULL }
@@ -1649,6 +1672,8 @@ main (int argc, char *argv[])
/* create buffer */
buffer = gtk_source_buffer_new (NULL);
+ gtk_source_buffer_set_highlight_syntax (buffer, !no_syntax);
+
if (argc > 1)
open_file (buffer, argv [1]);
else
diff --git a/tests/test-widget.py b/tests/test-widget.py
index ba1bb9d..6914b46 100644
--- a/tests/test-widget.py
+++ b/tests/test-widget.py
@@ -22,6 +22,7 @@ ui_description = """
<menu action=\"ViewMenu\">
<menuitem action=\"NewView\"/>
<separator/>
+ <menuitem action=\"HlSyntax\"/>
<menuitem action=\"HlBracket\"/>
<menuitem action=\"ShowNumbers\"/>
<menuitem action=\"ShowMarks\"/>
@@ -197,7 +198,9 @@ class Window(Gtk.Window):
("About", Gtk.STOCK_ABOUT, "_About...", None,
"About GtkSourceView Test Widget", self.about_cb)])
- action_group.add_toggle_actions([("HlBracket", None, "Highlight Matching _Bracket", None,
+ action_group.add_toggle_actions([("HlSyntax", None, "Highlight _Syntax", None,
+ "Toggle syntax highlighting", self.hl_syntax_toggled_cb),
+ ("HlBracket", None, "Highlight Matching _Bracket", None,
"Toggle highlighting of matching bracket", self.hl_bracket_toggled_cb),
("ShowNumbers", None, "Show _Line Numbers", None,
"Toggle visibility of line numbers in the left margin", self.numbers_toggled_cb),
@@ -268,6 +271,7 @@ class Window(Gtk.Window):
self.add_accel_group (accel_group)
# Add default values
+ action_group.get_action("HlSyntax").set_active(True)
action_group.get_action("HlBracket").set_active(True)
action_group.get_action("ShowNumbers").set_active(True)
action_group.get_action("ShowMarks").set_active(True)
@@ -412,6 +416,9 @@ class Window(Gtk.Window):
window = Window()
window.show_all()
+ def hl_syntax_toggled_cb(self, action):
+ self._buf.set_highlight_syntax(action.get_active())
+
def hl_bracket_toggled_cb(self, action):
self._buf.set_highlight_matching_brackets(action.get_active())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]