qulogic/talkatu

Parents 77ecd92fa219
Children a4cc51141378
Created a composite widget named TalkatuEditor that contains a toolbar and view with everything hooked up for you
--- a/demo/data/demo.ui Mon Aug 27 23:15:17 2018 -0500
+++ b/demo/data/demo.ui Mon Sep 03 15:55:45 2018 -0500
@@ -3,6 +3,22 @@
<interface>
<requires lib="Talkatu" version="0.0"/>
<requires lib="gtk+" version="3.10"/>
+ <object class="TalkatuTagTable" id="table_history"/>
+ <object class="TalkatuHistoryBuffer" id="buffer_history">
+ <property name="tag_table">table_history</property>
+ </object>
+ <object class="TalkatuTagTable" id="table_html"/>
+ <object class="TalkatuHtmlBuffer" id="buffer_html">
+ <property name="tag_table">table_html</property>
+ </object>
+ <object class="TalkatuTagTable" id="table_markdown"/>
+ <object class="TalkatuMarkdownBuffer" id="buffer_markdown">
+ <property name="tag_table">table_markdown</property>
+ </object>
+ <object class="TalkatuTagTable" id="table_plain"/>
+ <object class="TalkatuBuffer" id="buffer_plain">
+ <property name="tag_table">table_plain</property>
+ </object>
<template class="TalkatuDemo" parent="GtkWindow">
<property name="can_focus">False</property>
<property name="border_width">12</property>
@@ -137,9 +153,26 @@
</packing>
</child>
<child>
- <object class="TalkatuToolbar" id="toolbar">
+ <object class="TalkatuEditor" id="editor">
+ <property name="orientation">vertical</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <child internal-child="toolbar">
+ <object class="TalkatuToolbar"/>
+ <packing>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ <child internal-child="view">
+ <object class="TalkatuView">
+ <property name="buffer">buffer_plain</property>
+ <signal name="open-url" handler="talkatu_demo_view_open_url_cb" object="TalkatuDemo" swapped="no"/>
+ <signal name="send-message" handler="talkatu_demo_view_send_message_cb" object="TalkatuDemo" swapped="no"/>
+ </object>
+ <packing>
+ <property name="fill">False</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -147,30 +180,6 @@
<property name="position">2</property>
</packing>
</child>
- <child>
- <object class="GtkScrolledWindow">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="shadow_type">in</property>
- <child>
- <object class="TalkatuView" id="view_input">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="has_focus">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="wrap_mode">word</property>
- <signal name="notify::buffer" handler="talkatu_demo_view_buffer_changed_cb" object="TalkatuDemo" swapped="no"/>
- <signal name="open-url" handler="talkatu_demo_view_open_url_cb" object="TalkatuDemo" swapped="no"/>
- <signal name="send-message" handler="talkatu_demo_view_send_message_cb" object="TalkatuDemo" swapped="no"/>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">3</property>
- </packing>
- </child>
</object>
</child>
</template>
--- a/demo/talkatudemo.c Mon Aug 27 23:15:17 2018 -0500
+++ b/demo/talkatudemo.c Mon Sep 03 15:55:45 2018 -0500
@@ -36,13 +36,12 @@
GtkWindow parent;
GtkWidget *view_history;
- GtkWidget *view_input;
+ GtkWidget *editor;
+
GtkRadioToolButton *toggle_plain;
GtkRadioToolButton *toggle_html;
GtkRadioToolButton *toggle_markdown;
- GtkWidget *toolbar;
-
GtkTextBuffer *buffer_plain;
GtkTextBuffer *buffer_html;
GtkTextBuffer *buffer_markdown;
@@ -144,37 +143,23 @@
}
static void
-talkatu_demo_change_buffer(TalkatuDemo *demo, GtkTextBuffer *buffer) {
- if(TALKATU_IS_BUFFER(buffer)) {
- GSimpleActionGroup *action_group = talkatu_buffer_get_action_group(TALKATU_BUFFER(buffer));
- gtk_widget_insert_action_group(demo->toolbar, "talkatutext", G_ACTION_GROUP(action_group));
- } else {
- gtk_widget_insert_action_group(demo->toolbar, "talkatutext", NULL);
- }
-}
-
-static void
talkatu_demo_buffer_changed_cb(GtkToggleButton *toggle, gpointer data) {
TalkatuDemo *demo = (TalkatuDemo *)data;
+ GtkWidget *view = talkatu_editor_get_view(TALKATU_EDITOR(demo->editor));
if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(demo->toggle_plain))) {
g_message("switching to plain buffer");
- gtk_text_view_set_buffer(GTK_TEXT_VIEW(demo->view_input), demo->buffer_plain);
+ gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), demo->buffer_plain);
} else if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(demo->toggle_html))) {
g_message("switching to html buffer");
- gtk_text_view_set_buffer(GTK_TEXT_VIEW(demo->view_input), demo->buffer_html);
+ gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), demo->buffer_html);
} else if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(demo->toggle_markdown))) {
g_message("switch to markdown buffer");
- gtk_text_view_set_buffer(GTK_TEXT_VIEW(demo->view_input), demo->buffer_markdown);
+ gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), demo->buffer_markdown);
}
}
static void
-talkatu_demo_view_buffer_changed_cb(GObject *obj, GParamSpec *pspec, gpointer data) {
- talkatu_demo_change_buffer(TALKATU_DEMO(data), gtk_text_view_get_buffer(GTK_TEXT_VIEW(obj)));
-}
-
-static void
talkatu_demo_view_open_url_cb(TalkatuView *view, const gchar *url, gpointer data) {
GError *error = NULL;
gboolean success = FALSE;
@@ -211,7 +196,7 @@
TalkatuDemo *demo = TALKATU_DEMO(data);
TalkatuContentType content_type = TALKATU_CONTENT_TYPE_PLAIN;
TalkatuMessage *message = NULL;
- GtkTextBuffer *input = gtk_text_view_get_buffer(GTK_TEXT_VIEW(demo->view_input));
+ GtkTextBuffer *input = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
static guint64 id = 0;
if(TALKATU_IS_HTML_BUFFER(input)) {
@@ -247,11 +232,6 @@
talkatu_demo_init(TalkatuDemo *demo) {
gtk_widget_init_template(GTK_WIDGET(demo));
- demo->buffer_plain = talkatu_buffer_new(NULL);
- demo->buffer_html = talkatu_html_buffer_new();
- demo->buffer_markdown = talkatu_markdown_buffer_new();
-
- demo->buffer_history = talkatu_history_buffer_new();
gtk_text_view_set_buffer(GTK_TEXT_VIEW(demo->view_history), demo->buffer_history);
}
@@ -265,15 +245,19 @@
);
gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, view_history);
- gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, view_input);
+ gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, editor);
+
+ gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, buffer_plain);
+ gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, buffer_html);
+ gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, buffer_markdown);
+ gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, buffer_history);
+
gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, toggle_plain);
gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, toggle_html);
gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, toggle_markdown);
- gtk_widget_class_bind_template_child(widget_class, TalkatuDemo, toolbar);
gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_closed_cb);
gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_buffer_changed_cb);
- gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_view_buffer_changed_cb);
gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_view_open_url_cb);
gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_view_send_message_cb);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/data/editor.ui Mon Sep 03 15:55:45 2018 -0500
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+ <requires lib="Talkatu" version="0.0"/>
+ <requires lib="gtk+" version="3.20"/>
+ <object class="TalkatuTagTable" id="table"/>
+ <object class="TalkatuBuffer" id="buffer">
+ <property name="tag_table">table</property>
+ </object>
+ <template class="TalkatuEditor" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="TalkatuToolbar" id="toolbar">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">never</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="TalkatuView" id="view">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="buffer">buffer</property>
+ <signal name="notify::buffer" handler="talkatu_editor_view_buffer_changed_handler" object="TalkatuEditor" swapped="no"/>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </template>
+</interface>
--- a/talkatu/data/tagtable.ui Mon Aug 27 23:15:17 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.1 -->
-<interface>
- <requires lib="gtk+" version="3.10"/>
- <object class="GtkTextTagTable" id="format_tag_table">
- <child type="tag">
- <object class="GtkTextTag" id="bold">
- <property name="name">bold</property>
- <property name="weight">700</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="italic">
- <property name="name">italic</property>
- <property name="style">italic</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="underline">
- <property name="name">underline</property>
- <property name="underline">single</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="strikethrough">
- <property name="name">strikethrough</property>
- <property name="strikethrough">True</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="subscript">
- <property name="name">subscript</property>
- <property name="rise">-5000</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="superscript">
- <property name="name">superscript</property>
- <property name="rise">5000</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="pre">
- <property name="name">pre</property>
- <property name="family">Monospace</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="search">
- <property name="name">search</property>
- <property name="background_rgba">rgb(34,255,0)</property>
- <property name="weight">700</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="code">
- <property name="name">code</property>
- <property name="background_rgba">rgb(186,189,182)</property>
- <property name="family">Monospace</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="h1">
- <property name="name">h1</property>
- <property name="weight">700</property>
- <property name="scale">2</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="h2">
- <property name="name">h2</property>
- <property name="font">Normal</property>
- <property name="weight">700</property>
- <property name="scale">1.5</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="h3">
- <property name="name">h3</property>
- <property name="font">Normal</property>
- <property name="weight">700</property>
- <property name="scale">1.1699999999999999</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="h4">
- <property name="name">h4</property>
- <property name="font">Normal</property>
- <property name="weight">700</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="h5">
- <property name="name">h5</property>
- <property name="font">Normal</property>
- <property name="weight">700</property>
- <property name="scale">0.82999999999999996</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="h6">
- <property name="name">h6</property>
- <property name="font">Normal</property>
- <property name="weight">700</property>
- <property name="scale">0.67000000000000004</property>
- </object>
- </child>
- <child type="tag">
- <object class="GtkTextTag" id="a">
- <property name="name">a</property>
- <property name="foreground_rgba">rgb(0,0,255)</property>
- <property name="underline">single</property>
- <property name="underline_rgba">rgb(0,0,255)</property>
- </object>
- </child>
- </object>
-</interface>
--- a/talkatu/data/talkatu.gresource.xml Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/data/talkatu.gresource.xml Mon Sep 03 15:55:45 2018 -0500
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/bitbucket/rw_grim/talkatu/ui">
+ <file compressed="true">editor.ui</file>
<file compressed="true">linkdialog.ui</file>
<file compressed="true">messageactions.ui</file>
- <file compressed="true">tagtable.ui</file>
<file compressed="true">toolbar.ui</file>
</gresource>
</gresources>
--- a/talkatu/data/toolbar.ui Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/data/toolbar.ui Mon Sep 03 15:55:45 2018 -0500
@@ -9,7 +9,7 @@
<object class="GtkToggleToolButton" id="format_bold">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.format-bold</property>
+ <property name="action_name">talkatu.format-bold</property>
<property name="label" translatable="yes">Bold</property>
<property name="icon_name">format-text-bold</property>
</object>
@@ -22,7 +22,7 @@
<object class="GtkToggleToolButton" id="format_italic">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.format-italic</property>
+ <property name="action_name">talkatu.format-italic</property>
<property name="label" translatable="yes">Italic</property>
<property name="icon_name">format-text-italic</property>
</object>
@@ -35,7 +35,7 @@
<object class="GtkToggleToolButton" id="format_underline">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.format-underline</property>
+ <property name="action_name">talkatu.format-underline</property>
<property name="label" translatable="yes">Underline</property>
<property name="icon_name">format-text-underline</property>
</object>
@@ -48,7 +48,7 @@
<object class="GtkToggleToolButton" id="format_strikethrough">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.format-strikethrough</property>
+ <property name="action_name">talkatu.format-strikethrough</property>
<property name="label" translatable="yes">Strikethrough</property>
<property name="icon_name">format-text-strikethrough</property>
</object>
@@ -71,7 +71,7 @@
<object class="GtkToolButton" id="format_larger">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.format-grow</property>
+ <property name="action_name">talkatu.format-grow</property>
<property name="label" translatable="yes">Increase Font Size</property>
<property name="icon_name">zoom-in</property>
</object>
@@ -84,7 +84,7 @@
<object class="GtkToolButton" id="format_smaller">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.format-shrink</property>
+ <property name="action_name">talkatu.format-shrink</property>
<property name="label" translatable="yes">Decrease Font Size</property>
<property name="icon_name">zoom-out</property>
</object>
@@ -107,7 +107,7 @@
<object class="GtkToolButton" id="format_reset">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.format-reset</property>
+ <property name="action_name">talkatu.format-reset</property>
<property name="label" translatable="yes">Clear Formatting</property>
<property name="icon_name">edit-clear</property>
</object>
@@ -130,7 +130,7 @@
<object class="GtkToolButton" id="insert_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.insert-image</property>
+ <property name="action_name">talkatu.insert-image</property>
<property name="label" translatable="yes">Insert Image</property>
<property name="use_underline">True</property>
<property name="icon_name">insert-image</property>
@@ -144,7 +144,7 @@
<object class="GtkToggleToolButton" id="insert_link">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.insert-link</property>
+ <property name="action_name">talkatu.insert-link</property>
<property name="label" translatable="yes">Insert Link</property>
<property name="use_underline">True</property>
<property name="icon_name">insert-link</property>
@@ -158,7 +158,7 @@
<object class="GtkToolButton" id="insert_file">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.insert-file</property>
+ <property name="action_name">talkatu.insert-file</property>
<property name="label" translatable="yes">Insert File</property>
<property name="icon_name">insert-object</property>
</object>
@@ -171,7 +171,7 @@
<object class="GtkToolButton" id="insert_code">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.insert-code</property>
+ <property name="action_name">talkatu.insert-code</property>
<property name="label" translatable="yes">Insert Code</property>
<property name="use_underline">True</property>
<property name="icon_name">insert-text</property>
@@ -185,7 +185,7 @@
<object class="GtkToolButton" id="insert_emoji">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.insert-emoji</property>
+ <property name="action_name">talkatu.insert-emoji</property>
<property name="label" translatable="yes">Insert Emoji</property>
<property name="use_underline">True</property>
<property name="icon_name">face-smile-big</property>
@@ -209,7 +209,7 @@
<object class="GtkToolButton" id="get_attention">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatutext.attention</property>
+ <property name="action_name">talkatu.attention</property>
<property name="label" translatable="yes">Get Attention</property>
<property name="use_underline">True</property>
<property name="icon_name">emblem-important</property>
--- a/talkatu/meson.build Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/meson.build Mon Sep 03 15:55:45 2018 -0500
@@ -8,6 +8,7 @@
'talkatubuffer.h',
'talkatucodeset.h',
'talkatucore.h',
+ 'talkatueditor.h',
'talkatuhistory.h',
'talkatuhistorybuffer.h',
'talkatuhtmlbuffer.h',
@@ -18,6 +19,7 @@
'talkatumessage.h',
'talkatumessageactions.h',
'talkatutag.h',
+ 'talkatutagtable.h',
'talkatutoolbar.h',
'talkatutooldrawer.h',
'talkatuview.h',
@@ -28,6 +30,7 @@
'talkatubuffer.c',
'talkatucodeset.c',
'talkatucore.c',
+ 'talkatueditor.c',
'talkatuhistory.c',
'talkatuhistorybuffer.c',
'talkatuhtmlbuffer.c',
@@ -38,6 +41,7 @@
'talkatumessage.c',
'talkatumessageactions.c',
'talkatutag.c',
+ 'talkatutagtable.c',
'talkatutoolbar.c',
'talkatutooldrawer.c',
'talkatuview.c',
--- a/talkatu/talkatu.xml Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/talkatu.xml Mon Sep 03 15:55:45 2018 -0500
@@ -1,12 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<glade-catalog name="Talkatu" version="0.0" library="talkatu">
<glade-widget-classes>
+ <glade-widget-class name="TalkatuEditor" generic-name="editor" title="Editor">
+ <internal-children>
+ <object name="toolbar"/>
+ <object name="view"/>
+ </internal-children>
+ </glade-widget-class>
+
+ <glade-widget-class name="TalkatuHistory" generic-name="history" title="History"/>
<glade-widget-class name="TalkatuLinkDialog" generic-name="link_dialog" title="LinkDialog"/>
<glade-widget-class name="TalkatuMenuToolButton" generic-name="menu_tool_button" title="MenuToolButton"/>
<glade-widget-class name="TalkatuToolDrawer" generic-name="tool_drawer" title="ToolDrawer"/>
<glade-widget-class name="TalkatuToolbar" generic-name="toolbar" title="Toolbar"/>
<glade-widget-class name="TalkatuView" generic-name="view" title="View"/>
- <glade-widget-class name="TalkatuHistory" generic-name="history" title="History"/>
+
+ <glade-widget-class name="TalkatuTagTable" generic-name="tag-table" title="Tag Table" toplevel="True"/>
<glade-widget-class name="TalkatuBuffer" generic-name="buffer" title="Buffer" toplevel="True">
<properties>
@@ -14,7 +23,7 @@
</properties>
</glade-widget-class>
- <glade-widget-class name="TalkatuHTMLBuffer" generic-name="buffer" title="HTML Buffer" toplevel="True">
+ <glade-widget-class name="TalkatuHtmlBuffer" generic-name="buffer" title="HTML Buffer" toplevel="True">
<properties>
<property translatable="True" multiline="True" id="text"/>
</properties>
@@ -25,17 +34,25 @@
<property translatable="True" multiline="True" id="text"/>
</properties>
</glade-widget-class>
+
+ <glade-widget-class name="TalkatuHistoryBuffer" generic-name="buffer" title="History Buffer" toplevel="True">
+ <properties>
+ <property translatable="True" multiline="True" id="text"/>
+ </properties>
+ </glade-widget-class>
</glade-widget-classes>
<glade-widget-group name="Talkatu" title="Talkatu">
+ <glade-widget-class-ref name="TalkatuBuffer"/>
+ <glade-widget-class-ref name="TalkatuEditor"/>
+ <glade-widget-class-ref name="TalkatuHistory"/>
+ <glade-widget-class-ref name="TalkatuHistoryBuffer"/>
+ <glade-widget-class-ref name="TalkatuHtmlBuffer"/>
<glade-widget-class-ref name="TalkatuLinkDialog"/>
+ <glade-widget-class-ref name="TalkatuMarkdownBuffer"/>
<glade-widget-class-ref name="TalkatuMenuToolButton"/>
<glade-widget-class-ref name="TalkatuToolDrawer"/>
<glade-widget-class-ref name="TalkatuToolbar"/>
<glade-widget-class-ref name="TalkatuView"/>
- <glade-widget-class-ref name="TalkatuHistory"/>
-
- <glade-widget-class-ref name="TalkatuBuffer"/>
- <glade-widget-class-ref name="TalkatuHTMLBuffer"/>
- <glade-widget-class-ref name="TalkatuMarkdownBuffer"/>
+ <glade-widget-class-ref name="TalkatuTagTable"/>
</glade-widget-group>
</glade-catalog>
--- a/talkatu/talkatubuffer.c Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/talkatubuffer.c Mon Sep 03 15:55:45 2018 -0500
@@ -100,6 +100,11 @@
);
}
+static GSimpleActionGroup *
+talkatu_buffer_default_creation_action_group(TalkatuBuffer *buffer) {
+ return g_simple_action_group_new();
+}
+
/******************************************************************************
* GtkTextBuffer Stuff
*****************************************************************************/
@@ -164,7 +169,7 @@
new_text_length
);
- /* no apply the tags as necessary. pos has been revalidated */
+ /* now apply the tags as necessary. pos has been revalidated */
start = gtk_text_iter_copy(pos);
gtk_text_iter_backward_chars(start, new_text_length);
@@ -332,6 +337,7 @@
text_buffer_class->mark_set = talkatu_buffer_mark_set;
klass->insert_markup = talkatu_buffer_real_insert_markup;
+ klass->create_action_group = talkatu_buffer_default_creation_action_group;
properties[PROP_ACTION_GROUP] = g_param_spec_object(
"action-group", "action-group", "The action group for this buffer",
@@ -383,6 +389,12 @@
priv = talkatu_buffer_get_instance_private(buffer);
+ if(priv->action_group == NULL) {
+ GSimpleActionGroup *action_group = TALKATU_BUFFER_GET_CLASS(buffer)->create_action_group(buffer);
+ talkatu_buffer_set_action_group(buffer, action_group);
+ g_object_unref(G_OBJECT(action_group));
+ }
+
return priv->action_group;
}
--- a/talkatu/talkatubuffer.h Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/talkatubuffer.h Mon Sep 03 15:55:45 2018 -0500
@@ -53,6 +53,8 @@
void (*insert_markup)(TalkatuBuffer *buffer, GtkTextIter *pos, const gchar *new_text, gint new_text_length);
+ GSimpleActionGroup *(*create_action_group)(TalkatuBuffer *buffer);
+
void (*_talkatu_reserved1)(void);
void (*_talkatu_reserved2)(void);
void (*_talkatu_reserved3)(void);
@@ -75,7 +77,6 @@
gchar *talkatu_buffer_get_plain_text(TalkatuBuffer *buffer);
-
G_END_DECLS
#endif /* TALKATU_BUFFER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatueditor.c Mon Sep 03 15:55:45 2018 -0500
@@ -0,0 +1,141 @@
+/*
+ * talkatu
+ * Copyright (C) 2017-2018 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 <gtk/gtk.h>
+
+#include <talkatu/talkatubuffer.h>
+#include <talkatu/talkatueditor.h>
+#include <talkatu/talkatutoolbar.h>
+#include <talkatu/talkatuview.h>
+
+/**
+ * SECTION:talkatueditor
+ * @Title: Editor
+ * @Short_description: A simple editor composed of other Talkatu Widgets
+ *
+ * TalkatuEditor is a composite widget of #TalkatuToolbar and #TalkatuView to
+ * help make them easier to use.
+ */
+
+typedef struct {
+ GtkWidget *view;
+ GtkWidget *toolbar;
+} TalkatuEditorPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE(TalkatuEditor, talkatu_editor, GTK_TYPE_BOX)
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+talkatu_editor_buffer_changed(TalkatuEditor *editor) {
+ GActionGroup *action_group = NULL;
+ TalkatuEditorPrivate *priv = talkatu_editor_get_instance_private(editor);
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(priv->view));
+
+ if(TALKATU_IS_BUFFER(buffer)) {
+ action_group = G_ACTION_GROUP(talkatu_buffer_get_action_group(TALKATU_BUFFER(buffer)));
+ }
+
+ gtk_widget_insert_action_group(priv->toolbar, "talkatu", action_group);
+}
+
+/******************************************************************************
+ * Callbacks
+ *****************************************************************************/
+static void
+talkatu_editor_view_buffer_changed_handler(GObject *obj, GParamSpec *pspec, gpointer data) {
+ talkatu_editor_buffer_changed(TALKATU_EDITOR(data));
+}
+
+/******************************************************************************
+ * GObject Stuff
+ *****************************************************************************/
+static void
+talkatu_editor_init(TalkatuEditor *editor) {
+ gtk_widget_init_template(GTK_WIDGET(editor));
+}
+
+static void
+talkatu_editor_class_init(TalkatuEditorClass *klass) {
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+
+ /* load our template */
+ gtk_widget_class_set_template_from_resource(
+ GTK_WIDGET_CLASS(klass),
+ "/org/bitbucket/rw_grim/talkatu/ui/editor.ui"
+ );
+
+ gtk_widget_class_bind_template_child_internal_private(widget_class, TalkatuEditor, view);
+ gtk_widget_class_bind_template_child_internal_private(widget_class, TalkatuEditor, toolbar);
+
+ gtk_widget_class_bind_template_callback(widget_class, talkatu_editor_view_buffer_changed_handler);
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+
+/**
+ * talkatu_editor_new:
+ *
+ * Creates a new #TalkatuEditor with a normal #GtkTextBuffer.
+ *
+ * Returns: (transfer full): The new #TalkatuEditor instance.
+ */
+GtkWidget *
+talkatu_editor_new(void) {
+ return GTK_WIDGET(g_object_new(TALKATU_TYPE_EDITOR, NULL));
+}
+
+/**
+ * talkatu_editor_get_view:
+ * @editor: The #TalkatuEditor instance.
+ *
+ * Gets the #TalkatuView that @editor is using.
+ *
+ * Returns: (transfer none): The #TalkatuTextView that @editor is using.
+ */
+GtkWidget *
+talkatu_editor_get_view(TalkatuEditor *editor) {
+ TalkatuEditorPrivate *priv = NULL;
+
+ g_return_val_if_fail(TALKATU_IS_EDITOR(editor), NULL);
+
+ priv = talkatu_editor_get_instance_private(editor);
+
+ return priv->view;
+}
+
+/**
+ * talkatu_editor_get_toolbar:
+ * @editor: The #TalkatuEditor instance.
+ *
+ * Gets the #TalkatuToolbar that @editor is using.
+ *
+ * Returns: (transfer none): The #TalkatuToolbar that @editor is using.
+ */
+GtkWidget *
+talkatu_editor_get_toolbar(TalkatuEditor *editor) {
+ TalkatuEditorPrivate *priv = NULL;
+
+ g_return_val_if_fail(TALKATU_IS_EDITOR(editor), NULL);
+
+ priv = talkatu_editor_get_instance_private(editor);
+
+ return priv->toolbar;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatueditor.h Mon Sep 03 15:55:45 2018 -0500
@@ -0,0 +1,72 @@
+/*
+ * talkatu
+ * Copyright (C) 2017-2018 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/>.
+ */
+
+#ifndef __GI_SCANNER__ /* hide this bit from g-ir-scanner */
+#if !defined(TALKATU_GLOBAL_HEADER_INSIDE) && !defined(TALKATU_COMPILATION)
+#error "only <talkatu.h> may be included directly"
+#endif
+#endif /* __GI_SCANNER__ */
+
+#ifndef TALKATU_EDITOR_H
+#define TALKATU_EDITOR_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+#define TALKATU_TYPE_EDITOR (talkatu_editor_get_type())
+#define TALKATU_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TALKATU_TYPE_EDITOR, TalkatuEditor))
+#define TALKATU_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TALKATU_TYPE_EDITOR, TalkatuEditorClass))
+#define TALKATU_IS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), TALKATU_TYPE_EDITOR))
+#define TALKATU_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TALKATU_TYPE_EDITOR))
+#define TALKATU_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TALKATU_TYPE_EDITOR, TalkatuEditorClass))
+
+typedef struct _TalkatuEditor TalkatuEditor;
+typedef struct _TalkatuEditorClass TalkatuEditorClass;
+
+struct _TalkatuEditor {
+ GtkBox parent;
+
+ void (*_talkatu_reserved1)(void);
+ void (*_talkatu_reserved2)(void);
+ void (*_talkatu_reserved3)(void);
+ void (*_talkatu_reserved4)(void);
+};
+
+struct _TalkatuEditorClass {
+ GtkBoxClass parent;
+
+ void (*_talkatu_reserved1)(void);
+ void (*_talkatu_reserved2)(void);
+ void (*_talkatu_reserved3)(void);
+ void (*_talkatu_reserved4)(void);
+};
+
+G_BEGIN_DECLS
+
+GType talkatu_editor_get_type(void);
+
+GtkWidget *talkatu_editor_new(void);
+
+GtkWidget *talkatu_editor_get_view(TalkatuEditor *editor);
+GtkWidget *talkatu_editor_get_toolbar(TalkatuEditor *editor);
+
+G_END_DECLS
+
+#endif /* TALKATU_EDITOR_H */
--- a/talkatu/talkatuhistorybuffer.c Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/talkatuhistorybuffer.c Mon Sep 03 15:55:45 2018 -0500
@@ -109,22 +109,10 @@
*/
GtkTextBuffer *
talkatu_history_buffer_new(void) {
- GtkBuilder *builder = NULL;
- GtkTextTagTable *table = NULL;
- GtkTextBuffer *buffer = NULL;
-
- builder = gtk_builder_new_from_resource("/org/bitbucket/rw_grim/talkatu/ui/tagtable.ui");
- table = GTK_TEXT_TAG_TABLE(gtk_builder_get_object(builder, "format_tag_table"));
-
- buffer = GTK_TEXT_BUFFER(g_object_new(
+ return GTK_TEXT_BUFFER(g_object_new(
TALKATU_TYPE_HISTORY_BUFFER,
- "tag-table", table,
NULL
));
-
- g_object_unref(G_OBJECT(builder));
-
- return buffer;
}
void
--- a/talkatu/talkatuhtmlbuffer.c Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/talkatuhtmlbuffer.c Mon Sep 03 15:55:45 2018 -0500
@@ -32,60 +32,14 @@
* to render it properly.
*/
-G_DEFINE_TYPE(TalkatuHTMLBuffer, talkatu_html_buffer, TALKATU_TYPE_BUFFER);
-
-/******************************************************************************
- * GObject Stuff
- *****************************************************************************/
-static void
-talkatu_html_buffer_init(TalkatuHTMLBuffer *buffer) {
- gtk_text_buffer_register_deserialize_format(
- GTK_TEXT_BUFFER(buffer),
- "text/html",
- talkatu_markup_deserialize_html,
- NULL,
- NULL
- );
-}
-
-static void
-talkatu_html_buffer_class_init(TalkatuHTMLBufferClass *klass) {
-}
+G_DEFINE_TYPE(TalkatuHtmlBuffer, talkatu_html_buffer, TALKATU_TYPE_BUFFER);
/******************************************************************************
- * Public API
+ * TalkatuBuffer Stuff
*****************************************************************************/
-
-/**
- * talkatu_html_buffer_new:
- *
- * Creates a new #TalkatuHTMLBuffer. A #TalkatuHTMLBuffer supports HTML
- * formatting as well as pasting rendered HTML.
- *
- * Returns: (transfer full): The new #TalkatuHTMLBuffer instance.
- */
-GtkTextBuffer *talkatu_html_buffer_new(void) {
- GtkTextBuffer *buffer = NULL;
- GtkBuilder *builder = NULL;
- GtkTextTagTable *table = NULL;
- GSimpleActionGroup *action_group = NULL;
-
- builder = gtk_builder_new_from_resource("/org/bitbucket/rw_grim/talkatu/ui/tagtable.ui");
- table = GTK_TEXT_TAG_TABLE(gtk_builder_get_object(builder, "format_tag_table"));
-
- action_group = g_simple_action_group_new();
-
- buffer = g_object_new(
- TALKATU_TYPE_HTML_BUFFER,
- "tag-table", table,
- "action-group", action_group,
- NULL
- );
-
- /* we can't free the builder until the table has been refed by the
- * constructor.
- */
- g_object_unref(G_OBJECT(builder));
+static GSimpleActionGroup *
+talkatu_html_buffer_create_action_group(TalkatuBuffer *buffer) {
+ GSimpleActionGroup *action_group = g_simple_action_group_new();
/* order of operation sucks, we need the buffer for the callbacks, but we
* need the group to create the buffer.
@@ -98,14 +52,53 @@
talkatu_action_add_shrink(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
talkatu_action_add_reset(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
talkatu_action_add_link(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
- g_object_unref(G_OBJECT(action_group));
+
+ return action_group;
+}
+
+/******************************************************************************
+ * GObject Stuff
+ *****************************************************************************/
+static void
+talkatu_html_buffer_init(TalkatuHtmlBuffer *buffer) {
+ gtk_text_buffer_register_deserialize_format(
+ GTK_TEXT_BUFFER(buffer),
+ "text/html",
+ talkatu_markup_deserialize_html,
+ NULL,
+ NULL
+ );
+}
- return buffer;
+static void
+talkatu_html_buffer_class_init(TalkatuHtmlBufferClass *klass) {
+ TalkatuBufferClass *buffer_class = TALKATU_BUFFER_CLASS(klass);
+
+ buffer_class->create_action_group = talkatu_html_buffer_create_action_group;
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+
+/**
+ * talkatu_html_buffer_new:
+ *
+ * Creates a new #TalkatuHtmlBuffer. A #TalkatuHtmlBuffer supports HTML
+ * formatting as well as pasting rendered HTML.
+ *
+ * Returns: (transfer full): The new #TalkatuHtmlBuffer instance.
+ */
+GtkTextBuffer *talkatu_html_buffer_new(void) {
+ return GTK_TEXT_BUFFER(g_object_new(
+ TALKATU_TYPE_HTML_BUFFER,
+ NULL
+ ));
}
/**
* talkatu_html_buffer_insert_html:
- * @buffer: The #TalkatuHTMLBuffer instance.
+ * @buffer: The #TalkatuHtmlBuffer instance.
* @iter: The #GtkTextIter where to insert the HTML.
* @text: The HTML text to insert.
* @len: The length of @text or -1
@@ -113,7 +106,7 @@
* Inserts and renders @text as HTML into @buffer.
*/
void
-talkatu_html_buffer_insert_html(TalkatuHTMLBuffer *buffer,
+talkatu_html_buffer_insert_html(TalkatuHtmlBuffer *buffer,
GtkTextIter *iter,
const gchar *text,
gint len)
--- a/talkatu/talkatuhtmlbuffer.h Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/talkatuhtmlbuffer.h Mon Sep 03 15:55:45 2018 -0500
@@ -31,18 +31,18 @@
#include <gtk/gtk.h>
#define TALKATU_TYPE_HTML_BUFFER (talkatu_html_buffer_get_type())
-#define TALKATU_HTML_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TALKATU_TYPE_HTML_BUFFER, TalkatuHTMLBuffer))
-#define TALKATU_HTML_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TALKATU_TYPE_HTML_BUFFER, TalkatuHTMLBufferClass))
+#define TALKATU_HTML_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TALKATU_TYPE_HTML_BUFFER, TalkatuHtmlBuffer))
+#define TALKATU_HTML_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TALKATU_TYPE_HTML_BUFFER, TalkatuHtmlBufferClass))
#define TALKATU_IS_HTML_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), TALKATU_TYPE_HTML_BUFFER))
#define TALKATU_IS_HTML_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TALKATU_TYPE_HTML_BUFFER))
-#define TALKATU_HTML_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TALKATU_TYPE_HTML_BUFFER, TalkatuHTMLBufferClass))
+#define TALKATU_HTML_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TALKATU_TYPE_HTML_BUFFER, TalkatuHtmlBufferClass))
-typedef struct _TalkatuHTMLBuffer TalkatuHTMLBuffer;
-typedef struct _TalkatuHTMLBufferClass TalkatuHTMLBufferClass;
+typedef struct _TalkatuHtmlBuffer TalkatuHtmlBuffer;
+typedef struct _TalkatuHtmlBufferClass TalkatuHtmlBufferClass;
#include "talkatu/talkatubuffer.h"
-struct _TalkatuHTMLBuffer {
+struct _TalkatuHtmlBuffer {
TalkatuBuffer parent;
void (*_talkatu_reserved1)(void);
@@ -51,10 +51,10 @@
void (*_talkatu_reserved4)(void);
};
-struct _TalkatuHTMLBufferClass {
+struct _TalkatuHtmlBufferClass {
TalkatuBufferClass parent;
- void (*insert_html)(TalkatuHTMLBuffer *buffer, GtkTextIter *iter, const gchar *text, gint len);
+ void (*insert_html)(TalkatuHtmlBuffer *buffer, GtkTextIter *iter, const gchar *text, gint len);
void (*_talkatu_reserved1)(void);
void (*_talkatu_reserved2)(void);
@@ -68,7 +68,7 @@
GtkTextBuffer *talkatu_html_buffer_new(void);
-void talkatu_html_buffer_insert_html(TalkatuHTMLBuffer *buffer, GtkTextIter *iter, const gchar *text, gint len);
+void talkatu_html_buffer_insert_html(TalkatuHtmlBuffer *buffer, GtkTextIter *iter, const gchar *text, gint len);
G_END_DECLS
--- a/talkatu/talkatumarkdownbuffer.c Mon Aug 27 23:15:17 2018 -0500
+++ b/talkatu/talkatumarkdownbuffer.c Mon Sep 03 15:55:45 2018 -0500
@@ -235,6 +235,23 @@
}
/******************************************************************************
+ * TalkatuBuffer Stuff
+ *****************************************************************************/
+static GSimpleActionGroup *
+talkatu_markdown_buffer_create_action_group(TalkatuBuffer *buffer) {
+ GSimpleActionGroup *action_group = g_simple_action_group_new();
+
+ talkatu_action_add_bold(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
+ talkatu_action_add_italic(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
+ talkatu_action_add_underline(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
+ talkatu_action_add_strikethrough(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
+ talkatu_action_add_reset(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
+ talkatu_action_add_link(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
+
+ return action_group;
+}
+
+/******************************************************************************
* GObject Stuff
*****************************************************************************/
static void
@@ -250,6 +267,10 @@
static void
talkatu_markdown_buffer_class_init(TalkatuMarkdownBufferClass *klass) {
+ TalkatuBufferClass *buffer_class = TALKATU_BUFFER_CLASS(klass);
+
+ buffer_class->create_action_group = talkatu_markdown_buffer_create_action_group;
+
klass->insert_markdown = talkatu_markdown_buffer_real_insert_markdown;
}
@@ -265,40 +286,10 @@
* Returns: (transfer full): The new #TalkatuMarkdownBuffer.
*/
GtkTextBuffer *talkatu_markdown_buffer_new(void) {
- GtkTextBuffer *buffer = NULL;
- GtkBuilder *builder = NULL;
- GtkTextTagTable *table = NULL;
- GSimpleActionGroup *action_group = NULL;
-
- builder = gtk_builder_new_from_resource("/org/bitbucket/rw_grim/talkatu/ui/tagtable.ui");
- table = GTK_TEXT_TAG_TABLE(gtk_builder_get_object(builder, "format_tag_table"));
-
- action_group = g_simple_action_group_new();
-
- buffer = g_object_new(
+ return GTK_TEXT_BUFFER(g_object_new(
TALKATU_TYPE_MARKDOWN_BUFFER,
- "tag-table", table,
- "action-group", action_group,
NULL
- );
-
- /* we can't free the builder until the table has been refed by the
- * constructor.
- */
- g_object_unref(G_OBJECT(builder));
-
- /* order of operation sucks, we need the buffer for the callbacks, but we
- * need the group to create the buffer.
- */
- talkatu_action_add_bold(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
- talkatu_action_add_italic(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
- talkatu_action_add_underline(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
- talkatu_action_add_strikethrough(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
- talkatu_action_add_reset(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
- talkatu_action_add_link(G_ACTION_MAP(action_group), GTK_TEXT_BUFFER(buffer));
- g_object_unref(G_OBJECT(action_group));
-
- return buffer;
+ ));
}
/**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatutagtable.c Mon Sep 03 15:55:45 2018 -0500
@@ -0,0 +1,193 @@
+/*
+ * talkatu
+ * Copyright (C) 2017-2018 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 <stdarg.h>
+
+#include <gtk/gtk.h>
+#include <pango/pango.h>
+
+#include <talkatu/talkatutag.h>
+#include <talkatu/talkatutagtable.h>
+
+/**
+ * SECTION:talkatutag_table
+ * @Title: TagTable
+ * @Short_description: A simple formatting tag_table
+ *
+ * Talkatu provides a simple formatting tag_table that gives the user the ability
+ * to format any #TalkatuBuffer via the formatting actions.
+ */
+
+G_DEFINE_TYPE(TalkatuTagTable, talkatu_tag_table, GTK_TYPE_TEXT_TAG_TABLE)
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+talkatu_tag_table_add_tag(TalkatuTagTable *table,
+ const gchar *name,
+ const gchar *first_property,
+ ...)
+{
+ GtkTextTag *tag = gtk_text_tag_new(name);
+ va_list vargs;
+
+ va_start(vargs, first_property);
+ g_object_set_valist(G_OBJECT(tag), first_property, vargs);
+ va_end(vargs);
+
+ gtk_text_tag_table_add(GTK_TEXT_TAG_TABLE(table), tag);
+}
+
+/******************************************************************************
+ * GObject Stuff
+ *****************************************************************************/
+static void
+talkatu_tag_table_init(TalkatuTagTable *table) {
+ GdkRGBA color;
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_BOLD,
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_ITALIC,
+ "style", PANGO_STYLE_ITALIC,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_UNDERLINE,
+ "underline", PANGO_UNDERLINE_SINGLE,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_STRIKETHROUGH,
+ "strikethrough", TRUE,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_SUBSCRIPT,
+ "rise", -5000,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_SUPERSCRIPT,
+ "rise", 5000,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_PRE,
+ "family", "Monospace",
+ NULL
+ );
+
+ gdk_rgba_parse(&color, "#C0C0C0FF");
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_CODE,
+ "family", "Monospace",
+ "background-rgba", &color,
+ NULL
+ );
+
+ gdk_rgba_parse(&color, "#22FF00FF");
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_SEARCH,
+ "background-rgba", &color,
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_H1,
+ "weight", PANGO_WEIGHT_BOLD,
+ "scale", 2.0,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_H2,
+ "weight", PANGO_WEIGHT_BOLD,
+ "scale", 1.5,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_H3,
+ "weight", PANGO_WEIGHT_BOLD,
+ "scale", 1.1699,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_H4,
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_H5,
+ "weight", PANGO_WEIGHT_BOLD,
+ "scale", 0.8299,
+ NULL
+ );
+
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_H6,
+ "weight", PANGO_WEIGHT_BOLD,
+ "scale", 0.67,
+ NULL
+ );
+
+ gdk_rgba_parse(&color, "#0000FFFF");
+ talkatu_tag_table_add_tag(
+ table, TALKATU_TAG_ANCHOR,
+ "foreground-rgba", &color,
+ "underline", PANGO_UNDERLINE_SINGLE,
+ "underline-rgba", &color,
+ NULL
+ );
+}
+
+static void
+talkatu_tag_table_class_init(TalkatuTagTableClass *klass) {
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+
+/**
+ * talkatu_tag_table_new:
+ *
+ * Creates a new #TalkatuTagTable that provides the user with an interface to
+ * control the formatting of a #TalkatuBuffer.
+ *
+ * Returns: (transfer full): The new #TalkatuTagTable instance.
+ */
+GtkWidget *talkatu_tag_table_new(void) {
+ return GTK_WIDGET(g_object_new(
+ TALKATU_TYPE_TAG_TABLE,
+ NULL
+ ));
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatutagtable.h Mon Sep 03 15:55:45 2018 -0500
@@ -0,0 +1,71 @@
+/*
+ * talkatu
+ * Copyright (C) 2017-2018 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/>.
+ */
+
+#ifndef __GI_SCANNER__ /* hide this bit from g-ir-scanner */
+#if !defined(TALKATU_GLOBAL_HEADER_INSIDE) && !defined(TALKATU_COMPILATION)
+#error "only <talkatu.h> may be included directly"
+#endif
+#endif /* __GI_SCANNER__ */
+
+#ifndef TALKATU_TAG_TABLE_H
+#define TALKATU_TAG_TABLE_H
+
+#include <gtk/gtk.h>
+
+#define TALKATU_TYPE_TAG_TABLE (talkatu_tag_table_get_type())
+#define TALKATU_TAG_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TALKATU_TYPE_TAG_TABLE, TalkatuTagTable))
+#define TALKATU_TAG_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TALKATU_TYPE_TAG_TABLE, TalkatuTagTableClass))
+#define TALKATU_IS_TAG_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), TALKATU_TYPE_TAG_TABLE))
+#define TALKATU_IS_TAG_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TALKATU_TYPE_TAG_TABLE))
+#define TALKATU_TAG_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TALKATU_TYPE_TAG_TABLE, TalkatuTagTableClass))
+
+typedef struct _TalkatuTagTable TalkatuTagTable;
+typedef struct _TalkatuTagTableClass TalkatuTagTableClass;
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+struct _TalkatuTagTable {
+ GtkTextTagTable parent;
+
+ void (*_talkatu_reserved1)(void);
+ void (*_talkatu_reserved2)(void);
+ void (*_talkatu_reserved3)(void);
+ void (*_talkatu_reserved4)(void);
+};
+
+struct _TalkatuTagTableClass {
+ GtkTextTagTableClass parent;
+
+ void (*_talkatu_reserved1)(void);
+ void (*_talkatu_reserved2)(void);
+ void (*_talkatu_reserved3)(void);
+ void (*_talkatu_reserved4)(void);
+};
+
+G_BEGIN_DECLS
+
+GType talkatu_tag_table_get_type(void);
+
+GtkWidget *talkatu_tag_table_new(void);
+
+G_END_DECLS
+
+#endif /* TALKATU_TAG_TABLE_H */