[gtksourceview/wip/renovate-test-widget: 7/7] Renovate test-widget (not finished)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/renovate-test-widget: 7/7] Renovate test-widget (not finished)
- Date: Sat, 22 Mar 2014 17:26:42 +0000 (UTC)
commit cdd58ec7e49de251be0bcf0d1886edefae0f3b31
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Mar 9 15:19:07 2014 +0100
Renovate test-widget (not finished)
- use a composite widget template
- replaces the menu with a sidebar, like in test-completion.
- fixes lots of warnings due to deprecated functions (GtkStock,
GtkUIManager, etc.).
tests/Makefile.am | 10 +-
tests/test-widget.c | 450 ++++++++++++++++++---------------------
tests/test-widget.gresource.xml | 6 +
tests/test-widget.ui | 407 +++++++++++++++++++++++++++++++++++
4 files changed, 623 insertions(+), 250 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8d0a4e6..94dd3f3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,7 +14,8 @@ noinst_PROGRAMS = $(TEST_PROGS) $(UNIT_TEST_PROGS)
BUILT_SOURCES = \
test-completion-resources.c \
- test-search-resources.c
+ test-search-resources.c \
+ test-widget-resources.c
test-completion-resources.c: test-completion.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES)
--generate-dependencies $(srcdir)/test-completion.gresource.xml)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source
$(srcdir)/test-completion.gresource.xml
@@ -22,6 +23,9 @@ test-completion-resources.c: test-completion.gresource.xml $(shell $(GLIB_COMPIL
test-search-resources.c: test-search.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies
$(srcdir)/test-search.gresource.xml)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source
$(srcdir)/test-search.gresource.xml
+test-widget-resources.c: test-widget.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies
$(srcdir)/test-widget.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source
$(srcdir)/test-widget.gresource.xml
+
TEST_PROGS = test-completion
test_completion_SOURCES = \
test-completion.c \
@@ -49,7 +53,9 @@ test_search_performances_LDADD = \
$(TESTS_LIBS)
TEST_PROGS += test-widget
-test_widget_SOURCES = test-widget.c
+test_widget_SOURCES = \
+ test-widget.c \
+ test-widget-resources.c
test_widget_LDADD = \
$(top_builddir)/gtksourceview/libgtksourceview-3.0.la \
$(DEP_LIBS) \
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 319fd5b..74f9c27 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -4,6 +4,7 @@
*
* Copyright (C) 2001 - Mikael Hermansson <tyan linux se>
* Copyright (C) 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
*
* GtkSourceView is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -25,6 +26,42 @@
#include <gio/gio.h>
#include <gtksourceview/gtksource.h>
+#define TEST_TYPE_WIDGET (test_widget_get_type ())
+#define TEST_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_WIDGET, TestWidget))
+#define TEST_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_WIDGET, TestWidgetClass))
+#define TEST_IS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_WIDGET))
+#define TEST_IS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_WIDGET))
+#define TEST_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_WIDGET, TestWidgetClass))
+
+typedef struct _TestWidget TestWidget;
+typedef struct _TestWidgetClass TestWidgetClass;
+typedef struct _TestWidgetPrivate TestWidgetPrivate;
+
+struct _TestWidget
+{
+ GtkGrid parent;
+
+ TestWidgetPrivate *priv;
+};
+
+struct _TestWidgetClass
+{
+ GtkGridClass parent_class;
+};
+
+struct _TestWidgetPrivate
+{
+ GtkSourceView *source_view;
+ GtkSourceBuffer *source_buffer;
+
+ GtkCheckButton *indent_width_checkbutton;
+ GtkSpinButton *indent_width_spinbutton;
+};
+
+GType test_widget_get_type (void);
+
+G_DEFINE_TYPE_WITH_PRIVATE (TestWidget, test_widget, GTK_TYPE_GRID)
+
static GtkSourceStyleScheme *style_scheme = NULL;
#define MARK_TYPE_1 "one"
@@ -32,38 +69,6 @@ static GtkSourceStyleScheme *style_scheme = NULL;
/* Private prototypes */
-static void open_file_cb (GtkAction *action,
- gpointer user_data);
-static void print_file_cb (GtkAction *action,
- gpointer user_data);
-
-static void numbers_toggled_cb (GtkAction *action,
- gpointer user_data);
-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,
- gpointer user_data);
-static void draw_spaces_toggled_cb (GtkAction *action,
- gpointer user_data);
-static void wrap_lines_toggled_cb (GtkAction *action,
- gpointer user_data);
-static void auto_indent_toggled_cb (GtkAction *action,
- gpointer user_data);
-static void insert_spaces_toggled_cb (GtkAction *action,
- gpointer user_data);
-static void tabs_toggled_cb (GtkAction *action,
- GtkAction *current,
- gpointer user_data);
-static void indent_toggled_cb (GtkAction *action,
- GtkAction *current,
- gpointer user_data);
-
static void forward_string_cb (GtkAction *action,
gpointer user_data);
@@ -72,17 +77,8 @@ static void backward_string_cb (GtkAction *action,
/* Actions & UI definition */
-static GtkActionEntry buffer_action_entries[] = {
- { "Open", GTK_STOCK_OPEN, "_Open", "<control>O",
- "Open a file", G_CALLBACK (open_file_cb) },
- { "Quit", GTK_STOCK_QUIT, "_Quit", "<control>Q",
- "Exit the application", G_CALLBACK (gtk_main_quit) }
-};
-
static GtkActionEntry view_action_entries[] = {
{ "FileMenu", NULL, "_File", NULL, NULL, NULL },
- { "Print", GTK_STOCK_PRINT, "_Print", "<control>P",
- "Print the current file", G_CALLBACK (print_file_cb) },
{ "ViewMenu", NULL, "_View", NULL, NULL, NULL },
{ "TabWidth", NULL, "_Tab Width", NULL, NULL, NULL },
{ "IndentWidth", NULL, "I_ndent Width", NULL, NULL, NULL },
@@ -93,56 +89,6 @@ static GtkActionEntry view_action_entries[] = {
"Backward to the start or end of the next string", G_CALLBACK (backward_string_cb) }
};
-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 },
- { "ShowNumbers", NULL, "Show _Line Numbers", NULL,
- "Toggle visibility of line numbers in the left margin",
- G_CALLBACK (numbers_toggled_cb), FALSE },
- { "ShowMarks", NULL, "Show Line _Marks", NULL,
- "Toggle visibility of marks in the left margin",
- G_CALLBACK (marks_toggled_cb), FALSE },
- { "ShowMargin", NULL, "Show Right M_argin", NULL,
- "Toggle visibility of right margin indicator",
- G_CALLBACK (margin_toggled_cb), FALSE },
- { "HlLine", NULL, "_Highlight Current Line", NULL,
- "Toggle highlighting of current line",
- G_CALLBACK (hl_line_toggled_cb), FALSE },
- { "DrawSpaces", NULL, "_Draw Spaces", NULL,
- "Draw Spaces",
- G_CALLBACK (draw_spaces_toggled_cb), FALSE },
- { "WrapLines", NULL, "_Wrap Lines", NULL,
- "Toggle line wrapping",
- G_CALLBACK (wrap_lines_toggled_cb), FALSE },
- { "AutoIndent", NULL, "Enable _Auto Indent", NULL,
- "Toggle automatic auto indentation of text",
- G_CALLBACK (auto_indent_toggled_cb), FALSE },
- { "InsertSpaces", NULL, "Insert _Spaces Instead of Tabs", NULL,
- "Whether to insert space characters when inserting tabulations",
- G_CALLBACK (insert_spaces_toggled_cb), FALSE }
-};
-
-static GtkRadioActionEntry tabs_radio_entries[] = {
- { "TabWidth4", NULL, "4", NULL, "Set tabulation width to 4 spaces", 4 },
- { "TabWidth6", NULL, "6", NULL, "Set tabulation width to 6 spaces", 6 },
- { "TabWidth8", NULL, "8", NULL, "Set tabulation width to 8 spaces", 8 },
- { "TabWidth10", NULL, "10", NULL, "Set tabulation width to 10 spaces", 10 },
- { "TabWidth12", NULL, "12", NULL, "Set tabulation width to 12 spaces", 12 }
-};
-
-static GtkRadioActionEntry indent_radio_entries[] = {
- { "IndentWidthUnset", NULL, "Use Tab Width", NULL, "Set indent width same as tab width", -1 },
- { "IndentWidth4", NULL, "4", NULL, "Set indent width to 4 spaces", 4 },
- { "IndentWidth6", NULL, "6", NULL, "Set indent width to 6 spaces", 6 },
- { "IndentWidth8", NULL, "8", NULL, "Set indent width to 8 spaces", 8 },
- { "IndentWidth10", NULL, "10", NULL, "Set indent width to 10 spaces", 10 },
- { "IndentWidth12", NULL, "12", NULL, "Set indent width to 12 spaces", 12 }
-};
-
static GtkRadioActionEntry smart_home_end_entries[] = {
{ "SmartHomeEndDisabled", NULL, "Disabled", NULL,
"Smart Home/End disabled", GTK_SOURCE_SMART_HOME_END_DISABLED },
@@ -401,8 +347,8 @@ print_language_style_ids (GtkSourceLanguage *language)
}
static void
-open_file (GtkSourceBuffer *buffer,
- const gchar *filename)
+open_file (TestWidget *self,
+ const gchar *filename)
{
GtkSourceLanguage *language = NULL;
gchar *absolute_filename;
@@ -418,20 +364,21 @@ open_file (GtkSourceBuffer *buffer,
g_free (curdir);
}
- remove_all_marks (buffer);
+ remove_all_marks (self->priv->source_buffer);
- if (!gtk_source_buffer_load_file (buffer, absolute_filename))
+ if (!gtk_source_buffer_load_file (self->priv->source_buffer, absolute_filename))
{
g_free (absolute_filename);
return;
}
- g_object_set_data_full (G_OBJECT (buffer),
+ /* TODO have a GFile class attribute */
+ g_object_set_data_full (G_OBJECT (self->priv->source_buffer),
"filename", absolute_filename,
(GDestroyNotify) g_free);
- language = get_language (GTK_TEXT_BUFFER (buffer), absolute_filename);
- gtk_source_buffer_set_language (buffer, language);
+ language = get_language (GTK_TEXT_BUFFER (self->priv->source_buffer), absolute_filename);
+ gtk_source_buffer_set_language (self->priv->source_buffer, language);
if (language != NULL)
{
@@ -446,140 +393,114 @@ open_file (GtkSourceBuffer *buffer,
/* View action callbacks */
static void
-numbers_toggled_cb (GtkAction *action,
- gpointer user_data)
+show_line_numbers_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_show_line_numbers (
- GTK_SOURCE_VIEW (user_data),
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_view_set_show_line_numbers (self->priv->source_view, enabled);
}
static void
-marks_toggled_cb (GtkAction *action,
- gpointer user_data)
+show_line_marks_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_show_line_marks (
- GTK_SOURCE_VIEW (user_data),
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_view_set_show_line_marks (self->priv->source_view, enabled);
}
static void
-margin_toggled_cb (GtkAction *action,
- gpointer user_data)
+show_right_margin_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_show_right_margin (
- GTK_SOURCE_VIEW (user_data),
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_view_set_show_right_margin (self->priv->source_view, enabled);
}
static void
-hl_syntax_toggled_cb (GtkAction *action,
- gpointer user_data)
+highlight_syntax_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- GtkTextBuffer *buffer;
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_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)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_buffer_set_highlight_syntax (self->priv->source_buffer, enabled);
}
static void
-hl_bracket_toggled_cb (GtkAction *action,
- gpointer user_data)
+highlight_matching_bracket_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- GtkTextBuffer *buffer;
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- buffer = gtk_text_view_get_buffer (user_data);
- gtk_source_buffer_set_highlight_matching_brackets (
- GTK_SOURCE_BUFFER (buffer),
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_buffer_set_highlight_matching_brackets (self->priv->source_buffer, enabled);
}
static void
-hl_line_toggled_cb (GtkAction *action,
- gpointer user_data)
+highlight_current_line_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_highlight_current_line (
- GTK_SOURCE_VIEW (user_data),
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_view_set_highlight_current_line (self->priv->source_view, enabled);
}
static void
-draw_spaces_toggled_cb (GtkAction *action,
- gpointer user_data)
+draw_spaces_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- gboolean draw_spaces;
-
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- draw_spaces = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+ gboolean draw_spaces = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
if (draw_spaces)
{
- gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (user_data),
+ gtk_source_view_set_draw_spaces (self->priv->source_view,
GTK_SOURCE_DRAW_SPACES_ALL);
}
else
{
- gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (user_data),
- 0);
+ gtk_source_view_set_draw_spaces (self->priv->source_view, 0);
}
}
static void
-wrap_lines_toggled_cb (GtkAction *action,
- gpointer user_data)
+wrap_lines_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_text_view_set_wrap_mode (user_data,
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) ?
- GTK_WRAP_WORD : GTK_WRAP_NONE);
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (self->priv->source_view),
+ enabled ? GTK_WRAP_WORD : GTK_WRAP_NONE);
}
static void
-auto_indent_toggled_cb (GtkAction *action,
- gpointer user_data)
+auto_indent_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_auto_indent (
- GTK_SOURCE_VIEW (user_data),
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_view_set_auto_indent (self->priv->source_view, enabled);
}
static void
-insert_spaces_toggled_cb (GtkAction *action,
- gpointer user_data)
+indent_spaces_toggled_cb (TestWidget *self,
+ GtkCheckButton *button)
{
- g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_insert_spaces_instead_of_tabs (
- GTK_SOURCE_VIEW (user_data),
- gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+ gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_source_view_set_insert_spaces_instead_of_tabs (self->priv->source_view, enabled);
}
static void
-tabs_toggled_cb (GtkAction *action,
- GtkAction *current,
- gpointer user_data)
+tab_width_value_changed_cb (TestWidget *self,
+ GtkSpinButton *button)
{
- g_return_if_fail (GTK_IS_RADIO_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_tab_width (
- GTK_SOURCE_VIEW (user_data),
- gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)));
+ gint tab_width = gtk_spin_button_get_value_as_int (button);
+ gtk_source_view_set_tab_width (self->priv->source_view, tab_width);
}
static void
-indent_toggled_cb (GtkAction *action,
- GtkAction *current,
- gpointer user_data)
+update_indent_width (TestWidget *self)
{
- g_return_if_fail (GTK_IS_RADIO_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
- gtk_source_view_set_indent_width (
- GTK_SOURCE_VIEW (user_data),
- gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)));
+ gint indent_width = -1;
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->indent_width_checkbutton)))
+ {
+ indent_width = gtk_spin_button_get_value_as_int (self->priv->indent_width_spinbutton);
+ }
+
+ gtk_source_view_set_indent_width (self->priv->source_view, indent_width);
}
static void
@@ -652,15 +573,12 @@ backward_string_cb (GtkAction *action,
/* Buffer action callbacks */
static void
-open_file_cb (GtkAction *action,
- gpointer user_data)
+open_button_clicked_cb (TestWidget *self)
{
GtkWidget *chooser;
gint response;
static gchar *last_dir;
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (user_data));
-
chooser = gtk_file_chooser_dialog_new ("Open file...",
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
@@ -691,7 +609,7 @@ open_file_cb (GtkAction *action,
{
g_free (last_dir);
last_dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (chooser));
- open_file (GTK_SOURCE_BUFFER (user_data), filename);
+ open_file (self, filename);
g_free (filename);
}
}
@@ -821,36 +739,26 @@ end_print (GtkPrintOperation *operation,
#undef SETUP_FROM_VIEW
static void
-print_file_cb (GtkAction *action,
- gpointer user_data)
+print_button_clicked_cb (TestWidget *self)
{
- GtkSourceView *view;
- GtkSourceBuffer *buffer;
GtkSourcePrintCompositor *compositor;
GtkPrintOperation *operation;
const gchar *filename;
gchar *basename;
- g_return_if_fail (GTK_SOURCE_IS_VIEW (user_data));
-
- view = GTK_SOURCE_VIEW (user_data);
-
- buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
-
- filename = g_object_get_data (G_OBJECT (buffer), "filename");
+ filename = g_object_get_data (G_OBJECT (self->priv->source_buffer), "filename");
basename = g_filename_display_basename (filename);
#ifdef SETUP_FROM_VIEW
- compositor = gtk_source_print_compositor_new_from_view (view);
+ compositor = gtk_source_print_compositor_new_from_view (self->priv->source_view);
#else
-
- compositor = gtk_source_print_compositor_new (buffer);
+ compositor = gtk_source_print_compositor_new (self->priv->source_buffer);
gtk_source_print_compositor_set_tab_width (compositor,
- gtk_source_view_get_tab_width (view));
+ gtk_source_view_get_tab_width (self->priv->source_view));
gtk_source_print_compositor_set_wrap_mode (compositor,
- gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW (view)));
+ gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW
(self->priv->source_view)));
gtk_source_print_compositor_set_print_line_numbers (compositor, 1);
@@ -1175,14 +1083,6 @@ create_view_window (GtkSourceBuffer *buffer,
action_group = gtk_action_group_new ("ViewActions");
gtk_action_group_add_actions (action_group, view_action_entries,
G_N_ELEMENTS (view_action_entries), view);
- gtk_action_group_add_toggle_actions (action_group, toggle_entries,
- G_N_ELEMENTS (toggle_entries), view);
- gtk_action_group_add_radio_actions (action_group, tabs_radio_entries,
- G_N_ELEMENTS (tabs_radio_entries),
- -1, G_CALLBACK (tabs_toggled_cb), view);
- gtk_action_group_add_radio_actions (action_group, indent_radio_entries,
- G_N_ELEMENTS (indent_radio_entries),
- -1, G_CALLBACK (indent_toggled_cb), view);
gtk_action_group_add_radio_actions (action_group, smart_home_end_entries,
G_N_ELEMENTS (smart_home_end_entries),
-1, G_CALLBACK (smart_home_end_toggled_cb), view);
@@ -1297,13 +1197,6 @@ create_main_window (GtkSourceBuffer *buffer)
window = create_view_window (buffer, NULL);
ui_manager = g_object_get_data (G_OBJECT (window), "ui_manager");
- /* buffer action group */
- action_group = gtk_action_group_new ("BufferActions");
- gtk_action_group_add_actions (action_group, buffer_action_entries,
- G_N_ELEMENTS (buffer_action_entries), buffer);
- gtk_ui_manager_insert_action_group (ui_manager, action_group, 1);
- g_object_unref (action_group);
-
/* merge buffer ui */
if (!gtk_ui_manager_add_ui_from_string (ui_manager, buffer_ui_description, -1, &error))
{
@@ -1346,19 +1239,91 @@ create_main_window (GtkSourceBuffer *buffer)
return window;
}
+/* Class init, dispose, etc. */
+
+static void
+test_widget_dispose (GObject *object)
+{
+ TestWidget *self = TEST_WIDGET (object);
+
+ g_clear_object (&self->priv->source_buffer);
+
+ G_OBJECT_CLASS (test_widget_parent_class)->dispose (object);
+}
+
+static void
+test_widget_class_init (TestWidgetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->dispose = test_widget_dispose;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/gtksourceview/tests/ui/test-widget.ui");
+
+ gtk_widget_class_bind_template_callback (widget_class, open_button_clicked_cb);
+ gtk_widget_class_bind_template_callback (widget_class, print_button_clicked_cb);
+ gtk_widget_class_bind_template_callback (widget_class, highlight_syntax_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, highlight_matching_bracket_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, show_line_numbers_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, show_line_marks_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, show_right_margin_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, highlight_current_line_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, draw_spaces_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, wrap_lines_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, auto_indent_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, indent_spaces_toggled_cb);
+ gtk_widget_class_bind_template_callback (widget_class, tab_width_value_changed_cb);
+
+ gtk_widget_class_bind_template_child_private (widget_class, TestWidget, source_view);
+ gtk_widget_class_bind_template_child_private (widget_class, TestWidget, indent_width_checkbutton);
+ gtk_widget_class_bind_template_child_private (widget_class, TestWidget, indent_width_spinbutton);
+}
+
+static void
+test_widget_init (TestWidget *self)
+{
+ self->priv = test_widget_get_instance_private (self);
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ self->priv->source_buffer = GTK_SOURCE_BUFFER (
+ gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->priv->source_view)));
+
+ g_object_ref (self->priv->source_buffer);
+
+ g_signal_connect_swapped (self->priv->indent_width_checkbutton,
+ "toggled",
+ G_CALLBACK (update_indent_width),
+ self);
+
+ g_signal_connect_swapped (self->priv->indent_width_spinbutton,
+ "value-changed",
+ G_CALLBACK (update_indent_width),
+ self);
+
+ open_file (self, TOP_SRCDIR "/gtksourceview/gtksourcebuffer.c");
+}
+
+static TestWidget *
+test_widget_new (void)
+{
+ return g_object_new (test_widget_get_type (), NULL);
+}
+
/* Program entry point */
int
main (int argc, char *argv[])
{
+ GtkSourceLanguageManager *language_manager;
+ GtkSourceStyleSchemeManager *style_scheme_manager;
GtkWidget *window;
- GtkSourceLanguageManager *lm;
- GtkSourceStyleSchemeManager *sm;
- GtkSourceBuffer *buffer;
+ TestWidget *test_widget;
- gboolean no_syntax = FALSE;
gchar *builtin_lang_dirs[] = {TOP_SRCDIR "/data/language-specs", NULL};
- gchar *builtin_sm_dirs[] = {TOP_SRCDIR "/data/styles", NULL};
+ gchar *builtin_styles_dirs[] = {TOP_SRCDIR "/data/styles", NULL};
gchar **dirs;
const gchar * const * schemes;
gboolean use_default_paths = FALSE;
@@ -1367,7 +1332,6 @@ 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 }
@@ -1378,29 +1342,32 @@ main (int argc, char *argv[])
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_parse (context, &argc, &argv, NULL);
+ gtk_init (&argc, &argv);
+
/* we do not use defaults so we don't need to install the library */
dirs = use_default_paths ? NULL : builtin_lang_dirs;
- lm = gtk_source_language_manager_get_default ();
- gtk_source_language_manager_set_search_path (lm, dirs);
+ language_manager = gtk_source_language_manager_get_default ();
+ gtk_source_language_manager_set_search_path (language_manager, dirs);
- dirs = use_default_paths ? NULL : builtin_sm_dirs;
+ dirs = use_default_paths ? NULL : builtin_styles_dirs;
- sm = gtk_source_style_scheme_manager_get_default ();
- gtk_source_style_scheme_manager_set_search_path (sm, dirs);
+ style_scheme_manager = gtk_source_style_scheme_manager_get_default ();
+ gtk_source_style_scheme_manager_set_search_path (style_scheme_manager, dirs);
if (!use_default_paths)
{
- gtk_source_style_scheme_manager_append_search_path (sm, TOP_SRCDIR "/tests/test-scheme.xml");
+ gtk_source_style_scheme_manager_append_search_path (style_scheme_manager,
+ TOP_SRCDIR "/tests/test-scheme.xml");
}
- schemes = gtk_source_style_scheme_manager_get_scheme_ids (sm);
+ schemes = gtk_source_style_scheme_manager_get_scheme_ids (style_scheme_manager);
g_print ("Available style schemes:\n");
while (*schemes != NULL)
{
const gchar* const *authors;
gchar *authors_str = NULL;
- style_scheme = gtk_source_style_scheme_manager_get_scheme (sm, *schemes);
+ style_scheme = gtk_source_style_scheme_manager_get_scheme (style_scheme_manager, *schemes);
authors = gtk_source_style_scheme_get_authors (style_scheme);
if (authors != NULL)
@@ -1426,38 +1393,25 @@ main (int argc, char *argv[])
if (style_scheme_id != NULL)
{
- style_scheme = gtk_source_style_scheme_manager_get_scheme (sm, style_scheme_id);
+ style_scheme = gtk_source_style_scheme_manager_get_scheme (style_scheme_manager,
style_scheme_id);
}
else
{
style_scheme = NULL;
}
- /* create buffer */
- buffer = gtk_source_buffer_new (NULL);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
- gtk_source_buffer_set_highlight_syntax (buffer, !no_syntax);
+ g_signal_connect (window, "destroy", gtk_main_quit, NULL);
- if (argc > 1)
- {
- open_file (buffer, argv [1]);
- }
- else
- {
- open_file (buffer, TOP_SRCDIR "/gtksourceview/gtksourcebuffer.c");
- }
+ test_widget = test_widget_new ();
+ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (test_widget));
- /* create first window */
- window = create_main_window (buffer);
- gtk_window_set_default_size (GTK_WINDOW (window), 500, 500);
gtk_widget_show (window);
- /* ... and action! */
gtk_main ();
- /* cleanup */
- g_object_unref (buffer);
-
g_free (style_scheme_id);
return 0;
diff --git a/tests/test-widget.gresource.xml b/tests/test-widget.gresource.xml
new file mode 100644
index 0000000..7568a08
--- /dev/null
+++ b/tests/test-widget.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/gtksourceview/tests/ui">
+ <file preprocess="xml-stripblanks">test-widget.ui</file>
+ </gresource>
+</gresources>
diff --git a/tests/test-widget.ui b/tests/test-widget.ui
new file mode 100644
index 0000000..7576425
--- /dev/null
+++ b/tests/test-widget.ui
@@ -0,0 +1,407 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.0 -->
+<interface>
+ <requires lib="gtk+" version="3.10"/>
+ <requires lib="gtksourceview" version="3.0"/>
+ <object class="GtkAdjustment" id="adjustment_indent_width">
+ <property name="lower">1</property>
+ <property name="upper">16</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkAdjustment" id="adjustment_tab_width">
+ <property name="lower">1</property>
+ <property name="upper">16</property>
+ <property name="value">8</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <template class="TestWidget" parent="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">6</property>
+ <property name="column_spacing">4</property>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="width_request">400</property>
+ <property name="height_request">400</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkSourceView" id="source_view">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="left_margin">2</property>
+ <property name="right_margin">2</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">2</property>
+ <child>
+ <object class="GtkButton" id="open_button">
+ <property name="label">Open File</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="open_button_clicked_cb" object="TestWidget" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="print_button">
+ <property name="label">Print</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="print_button_clicked_cb" object="TestWidget" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label">General options</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkCheckButton" id="highlight_syntax">
+ <property name="label">Highlight syntax</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="highlight_syntax_toggled_cb" object="TestWidget"
swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="highlight_matching_bracket">
+ <property name="label">Highlight matching bracket</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="highlight_matching_bracket_toggled_cb" object="TestWidget"
swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="show_line_numbers">
+ <property name="label">Show line numbers</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="show_line_numbers_toggled_cb" object="TestWidget"
swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="show_line_marks">
+ <property name="label">Show line marks</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="show_line_marks_toggled_cb" object="TestWidget"
swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="show_right_margin">
+ <property name="label">Show right margin</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="show_right_margin_toggled_cb" object="TestWidget"
swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="highlight_current_line">
+ <property name="label">Highlight current line</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="highlight_current_line_toggled_cb" object="TestWidget"
swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="draw_spaces">
+ <property name="label">Draw spaces</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="draw_spaces_toggled_cb" object="TestWidget" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">6</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="wrap_lines">
+ <property name="label">Wrap lines</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="wrap_lines_toggled_cb" object="TestWidget" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">7</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label">Indentation</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkCheckButton" id="auto_indent">
+ <property name="label">Auto indent</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="auto_indent_toggled_cb" object="TestWidget" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="indent_spaces">
+ <property name="label">Insert spaces instead of tabs</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="indent_spaces_toggled_cb" object="TestWidget" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid5">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="column_spacing">4</property>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">Tab width:</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="tab_width">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">adjustment_tab_width</property>
+ <property name="value">8</property>
+ <signal name="value-changed" handler="tab_width_value_changed_cb" object="TestWidget"
swapped="yes"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid6">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="column_spacing">4</property>
+ <child>
+ <object class="GtkSpinButton" id="indent_width_spinbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">adjustment_indent_width</property>
+ <property name="value">8</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="indent_width_checkbutton">
+ <property name="label">Different indent width:</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]