talkatu/talkatu

Parents f3a71aa833cd
Children c523a909b8ac
Add a new TalkatuInput which subclasses TalkatuView and move the GSpell setup to it. Fixes TALKATU-60
--- a/talkatu/meson.build Sat Jan 25 15:35:26 2020 -0600
+++ b/talkatu/meson.build Sat Jan 25 15:54:23 2020 -0600
@@ -14,6 +14,7 @@
'talkatuhistory.h',
'talkatuhistorybuffer.h',
'talkatuhtmlbuffer.h',
+ 'talkatuinput.h',
'talkatulinkdialog.h',
'talkatumarkdownbuffer.h',
'talkatumarkup.h',
@@ -40,6 +41,7 @@
'talkatuhistory.c',
'talkatuhistorybuffer.c',
'talkatuhtmlbuffer.c',
+ 'talkatuinput.c',
'talkatulinkdialog.c',
'talkatumarkdownbuffer.c',
'talkatumarkup.c',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatuinput.c Sat Jan 25 15:54:23 2020 -0600
@@ -0,0 +1,70 @@
+/*
+ * talkatu
+ * Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gspell/gspell.h>
+
+#include "talkatu/talkatuinput.h"
+
+struct _TalkatuInput {
+ TalkatuView parent;
+
+ GspellTextView *gspell_view;
+};
+
+/******************************************************************************
+ * Callbacks
+ *****************************************************************************/
+static void
+talkatu_input_buffer_set_cb(GObject *view, GParamSpec *pspec, gpointer data) {
+ TalkatuInput *input = TALKATU_INPUT(view);
+
+ gspell_text_view_basic_setup(input->gspell_view);
+}
+
+/******************************************************************************
+ * GObject Implementation
+ *****************************************************************************/
+G_DEFINE_TYPE(TalkatuInput, talkatu_input, TALKATU_TYPE_VIEW)
+
+static void
+talkatu_input_init(TalkatuInput *input) {
+ /* we need to know when the buffer is changed in our parent so we can
+ * update our actions and other stuff.
+ */
+ g_signal_connect(
+ G_OBJECT(input),
+ "notify::buffer",
+ G_CALLBACK(talkatu_input_buffer_set_cb),
+ NULL
+ );
+
+ /* setup GSpell */
+ input->gspell_view = gspell_text_view_get_from_gtk_text_view(GTK_TEXT_VIEW(input));
+}
+
+static void
+talkatu_input_class_init(TalkatuInputClass *klass) {
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+GtkWidget *
+talkatu_input_new(void) {
+ return NULL;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatuinput.h Sat Jan 25 15:54:23 2020 -0600
@@ -0,0 +1,42 @@
+/*
+ * talkatu
+ * Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if !defined(TALKATU_GLOBAL_HEADER_INSIDE) && !defined(TALKATU_COMPILATION)
+#error "only <talkatu.h> may be included directly"
+#endif
+
+#ifndef TALKATU_INPUT_H
+#define TALKATU_INPUT_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+#include <talkatu/talkatuview.h>
+
+G_BEGIN_DECLS
+
+#define TALKATU_TYPE_INPUT (talkatu_input_get_type())
+G_DECLARE_FINAL_TYPE(TalkatuInput, talkatu_input, TALKATU, INPUT, TalkatuView)
+
+GtkWidget *talkatu_input_new(void);
+
+G_END_DECLS
+
+#endif /* TALKATU_INPUT_H */
--- a/talkatu/talkatuview.c Sat Jan 25 15:35:26 2020 -0600
+++ b/talkatu/talkatuview.c Sat Jan 25 15:54:23 2020 -0600
@@ -18,7 +18,6 @@
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
-#include <gspell/gspell.h>
#include <gumbo.h>
#include <stdio.h>
@@ -78,7 +77,6 @@
typedef struct {
GSimpleActionGroup *action_group;
TalkatuViewSendBinding send_binding;
- GspellTextView *gspell_view;
/* this mark is used to keep track of our context for the context menu. It
* is updated via cursor-moved and button-press callbacks.
@@ -273,8 +271,6 @@
NULL
);
}
-
- gspell_text_view_basic_setup(priv->gspell_view);
}
static void
@@ -589,9 +585,6 @@
NULL
);
- /* setup GSpell */
- priv->gspell_view = gspell_text_view_get_from_gtk_text_view(GTK_TEXT_VIEW(view));
-
/* we need to connect this signal *AFTER* everything to make sure our items
* end up in the correct place.
*/