[gspell/wip/entry] entry: add a GtkEntry to test-spell
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/entry] entry: add a GtkEntry to test-spell
- Date: Fri, 28 Oct 2016 05:29:22 +0000 (UTC)
commit 620c5cc74d3edf70cb0b4052ad1690fe0f27d5b8
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Oct 28 07:19:28 2016 +0200
entry: add a GtkEntry to test-spell
tests/test-spell.c | 87 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 63 insertions(+), 24 deletions(-)
---
diff --git a/tests/test-spell.c b/tests/test-spell.c
index 64d18a6..2e821d3 100644
--- a/tests/test-spell.c
+++ b/tests/test-spell.c
@@ -28,7 +28,7 @@ struct _TestSpell
{
GtkGrid parent;
- GtkTextView *view;
+ GtkTextView *text_view;
};
G_DEFINE_TYPE (TestSpell, test_spell, GTK_TYPE_GRID)
@@ -39,7 +39,7 @@ get_spell_checker (TestSpell *spell)
GtkTextBuffer *gtk_buffer;
GspellTextBuffer *gspell_buffer;
- gtk_buffer = gtk_text_view_get_buffer (spell->view);
+ gtk_buffer = gtk_text_view_get_buffer (spell->text_view);
gspell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (gtk_buffer);
return gspell_text_buffer_get_spell_checker (gspell_buffer);
@@ -64,7 +64,7 @@ checker_button_clicked_cb (GtkButton *checker_button,
g_return_if_reached ();
}
- navigator = gspell_navigator_text_view_new (spell->view);
+ navigator = gspell_navigator_text_view_new (spell->text_view);
checker_dialog = gspell_checker_dialog_new (GTK_WINDOW (window), navigator);
gtk_widget_show (checker_dialog);
@@ -80,7 +80,7 @@ change_buffer_button_clicked_cb (GtkButton *change_buffer_button,
GspellTextBuffer *new_gspell_buffer;
GspellChecker *checker;
- old_gtk_buffer = gtk_text_view_get_buffer (spell->view);
+ old_gtk_buffer = gtk_text_view_get_buffer (spell->text_view);
old_gspell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (old_gtk_buffer);
checker = gspell_text_buffer_get_spell_checker (old_gspell_buffer);
@@ -88,12 +88,12 @@ change_buffer_button_clicked_cb (GtkButton *change_buffer_button,
new_gspell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (new_gtk_buffer);
gspell_text_buffer_set_spell_checker (new_gspell_buffer, checker);
- gtk_text_view_set_buffer (spell->view, new_gtk_buffer);
+ gtk_text_view_set_buffer (spell->text_view, new_gtk_buffer);
g_object_unref (new_gtk_buffer);
}
static GtkWidget *
-get_sidebar (TestSpell *spell)
+create_sidebar (TestSpell *spell)
{
GtkWidget *sidebar;
GtkWidget *checker_button;
@@ -105,16 +105,10 @@ get_sidebar (TestSpell *spell)
GspellTextView *gspell_view;
sidebar = gtk_grid_new ();
-
- g_object_set (sidebar,
- "margin", 6,
- NULL);
-
+ gtk_grid_set_row_spacing (GTK_GRID (sidebar), 6);
gtk_orientable_set_orientation (GTK_ORIENTABLE (sidebar),
GTK_ORIENTATION_VERTICAL);
- gtk_grid_set_row_spacing (GTK_GRID (sidebar), 6);
-
/* Button to launch a spell checker dialog */
checker_button = gtk_button_new_with_mnemonic ("_Check Spelling…");
gtk_container_add (GTK_CONTAINER (sidebar),
@@ -141,7 +135,7 @@ get_sidebar (TestSpell *spell)
gtk_container_add (GTK_CONTAINER (sidebar),
highlight_checkbutton);
- gspell_view = gspell_text_view_get_from_gtk_text_view (spell->view);
+ gspell_view = gspell_text_view_get_from_gtk_text_view (spell->text_view);
gspell_text_view_set_enable_language_menu (gspell_view, TRUE);
g_object_bind_property (highlight_checkbutton, "active",
@@ -163,27 +157,69 @@ get_sidebar (TestSpell *spell)
return sidebar;
}
-static void
-test_spell_init (TestSpell *spell)
+static GtkEntry *
+create_entry (GspellChecker *checker)
{
- GtkWidget *scrolled_window;
+ GtkEntry *entry;
+ GtkEntryBuffer *gtk_buffer;
+ GspellEntryBuffer *gspell_buffer;
+
+ entry = GTK_ENTRY (gtk_entry_new ());
+ gtk_buffer = gtk_entry_get_buffer (entry);
+
+ gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
+ gspell_entry_buffer_set_spell_checker (gspell_buffer, checker);
+
+ return entry;
+}
+
+static GtkTextView *
+create_text_view (GspellChecker *checker)
+{
+ GtkTextView *view;
GtkTextBuffer *gtk_buffer;
GspellTextBuffer *gspell_buffer;
- GspellChecker *checker;
- spell->view = GTK_TEXT_VIEW (gtk_text_view_new ());
- gtk_buffer = gtk_text_view_get_buffer (spell->view);
+ view = GTK_TEXT_VIEW (gtk_text_view_new ());
+ gtk_buffer = gtk_text_view_get_buffer (view);
- checker = gspell_checker_new (NULL);
gspell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (gtk_buffer);
gspell_text_buffer_set_spell_checker (gspell_buffer, checker);
+
+ return view;
+}
+
+static void
+test_spell_init (TestSpell *spell)
+{
+ GspellChecker *checker;
+ GtkEntry *entry;
+ GtkWidget *vgrid;
+ GtkWidget *scrolled_window;
+
+ checker = gspell_checker_new (NULL);
+ entry = create_entry (checker);
+ spell->text_view = create_text_view (checker);
g_object_unref (checker);
+ g_object_set (spell,
+ "margin", 6,
+ NULL);
+
+ gtk_grid_set_column_spacing (GTK_GRID (spell), 6);
gtk_orientable_set_orientation (GTK_ORIENTABLE (spell),
GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (spell),
- get_sidebar (spell));
+ create_sidebar (spell));
+
+ vgrid = gtk_grid_new ();
+ gtk_grid_set_row_spacing (GTK_GRID (vgrid), 6);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (vgrid),
+ GTK_ORIENTATION_VERTICAL);
+
+ gtk_container_add (GTK_CONTAINER (vgrid),
+ GTK_WIDGET (entry));
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
@@ -192,10 +228,13 @@ test_spell_init (TestSpell *spell)
NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window),
- GTK_WIDGET (spell->view));
- gtk_container_add (GTK_CONTAINER (spell),
+ GTK_WIDGET (spell->text_view));
+ gtk_container_add (GTK_CONTAINER (vgrid),
scrolled_window);
+ gtk_container_add (GTK_CONTAINER (spell),
+ vgrid);
+
gtk_widget_show_all (GTK_WIDGET (spell));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]