[gnome-builder] editor: only use Gtk templates for GtkWidgets
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: only use Gtk templates for GtkWidgets
- Date: Sun, 12 Oct 2014 23:48:08 +0000 (UTC)
commit a4c6742e462db2c5e37e6968bb46f8858555c140
Author: Christian Hergert <christian hergert me>
Date: Sun Oct 12 19:48:02 2014 -0400
editor: only use Gtk templates for GtkWidgets
We don't own the reference to various objects if they are created in the
GtkBuilder template. We are much better off just managing these ourselves
in the constructed vfunc.
This all still needs a ton of cleanup though (and making gb-editor-commands
suck less).
src/editor/gb-editor-tab.c | 91 +++++++++++++++++++-------------
src/editor/gb-source-change-monitor.c | 8 +++
src/resources/ui/gb-editor-tab.ui | 25 ---------
3 files changed, 62 insertions(+), 62 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 91f1794..cdf0909 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -1159,13 +1159,54 @@ gb_editor_tab_constructed (GObject *object)
ENTRY;
g_return_if_fail (GB_IS_EDITOR_TAB (tab));
- g_return_if_fail (GB_IS_EDITOR_DOCUMENT (tab->priv->document));
priv = tab->priv;
+ if (!priv->document)
+ priv->document = gb_editor_document_new ();
+
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->source_view),
+ GTK_TEXT_BUFFER (priv->document));
+
+ priv->snippets_provider =
+ g_object_new (GB_TYPE_SOURCE_SNIPPET_COMPLETION_PROVIDER,
+ "source-view", priv->source_view,
+ NULL);
+
if (!priv->settings)
gb_editor_tab_set_settings (tab, NULL);
+ if (!priv->file)
+ priv->file = gtk_source_file_new ();
+
+ if (!priv->change_monitor)
+ priv->change_monitor = gb_source_change_monitor_new (GTK_TEXT_BUFFER (priv->document));
+
+ priv->search_settings =
+ g_object_new (GTK_SOURCE_TYPE_SEARCH_SETTINGS,
+ NULL);
+
+ priv->search_context =
+ g_object_new (GTK_SOURCE_TYPE_SEARCH_CONTEXT,
+ "buffer", priv->document,
+ "settings", priv->search_settings,
+ "highlight", TRUE,
+ NULL);
+
+ priv->search_highlighter =
+ g_object_new (GB_TYPE_SOURCE_SEARCH_HIGHLIGHTER,
+ "search-context", priv->search_context,
+ "search-settings", priv->search_settings,
+ NULL);
+ g_object_set (priv->source_view,
+ "search-highlighter", priv->search_highlighter,
+ NULL);
+
+ priv->words_provider =
+ g_object_new (GTK_SOURCE_TYPE_COMPLETION_WORDS,
+ NULL);
+
+
g_signal_connect_swapped (priv->document,
"modified-changed",
G_CALLBACK (gb_editor_tab_modified_changed),
@@ -1414,6 +1455,7 @@ gb_editor_tab_dispose (GObject *object)
gb_editor_tab_disconnect_settings (tab);
+ g_clear_object (&tab->priv->change_monitor);
g_clear_object (&tab->priv->document);
g_clear_object (&tab->priv->search_entry_tag);
g_clear_object (&tab->priv->file);
@@ -1422,6 +1464,7 @@ gb_editor_tab_dispose (GObject *object)
g_clear_object (&tab->priv->search_settings);
g_clear_object (&tab->priv->search_context);
g_clear_object (&tab->priv->settings);
+ g_clear_object (&tab->priv->words_provider);
G_OBJECT_CLASS (gb_editor_tab_parent_class)->dispose (object);
@@ -1568,42 +1611,16 @@ gb_editor_tab_class_init (GbEditorTabClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
GB_EDITOR_TAB_UI_RESOURCE);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- floating_bar);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- document);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- change_monitor);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- file);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- go_down_button);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- go_up_button);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- overlay);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- preview_container);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- progress_bar);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- revealer);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- scroller);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- search_entry);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- search_context);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- search_highlighter);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- search_settings);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- snippets_provider);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- source_view);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- words_provider);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, floating_bar);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, go_down_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, go_up_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, overlay);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, preview_container);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, progress_bar);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, scroller);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, search_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab, source_view);
g_type_ensure (GB_TYPE_EDITOR_DOCUMENT);
g_type_ensure (GB_TYPE_SOURCE_CHANGE_MONITOR);
diff --git a/src/editor/gb-source-change-monitor.c b/src/editor/gb-source-change-monitor.c
index 6ffe7a1..5e63c82 100644
--- a/src/editor/gb-source-change-monitor.c
+++ b/src/editor/gb-source-change-monitor.c
@@ -62,6 +62,14 @@ G_DEFINE_TYPE_WITH_PRIVATE (GbSourceChangeMonitor,
static GParamSpec *gParamSpecs [LAST_PROP];
static guint gSignals [LAST_SIGNAL];
+GbSourceChangeMonitor *
+gb_source_change_monitor_new (GtkTextBuffer *buffer)
+{
+ return g_object_new (GB_TYPE_SOURCE_CHANGE_MONITOR,
+ "buffer", buffer,
+ NULL);
+}
+
GbSourceChangeFlags
gb_source_change_monitor_get_line (GbSourceChangeMonitor *monitor,
guint lineno)
diff --git a/src/resources/ui/gb-editor-tab.ui b/src/resources/ui/gb-editor-tab.ui
index 9f981a4..9ce46db 100644
--- a/src/resources/ui/gb-editor-tab.ui
+++ b/src/resources/ui/gb-editor-tab.ui
@@ -15,13 +15,11 @@
<property name="expand">True</property>
<child>
<object class="GbSourceView" id="source_view">
- <property name="buffer">document</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="show_line_numbers">True</property>
<property name="show_right_margin">True</property>
<property name="right_margin_position">80</property>
- <property name="search-highlighter">search_highlighter</property>
</object>
</child>
</object>
@@ -120,27 +118,4 @@
</object>
</child>
</template>
- <object class="GtkSourceFile" id="file">
- </object>
- <object class="GbEditorDocument" id="document">
- </object>
- <object class="GbSourceChangeMonitor" id="change_monitor">
- <property name="buffer">document</property>
- </object>
- <object class="GbSourceSnippetCompletionProvider" id="snippets_provider">
- <property name="source-view">source_view</property>
- </object>
- <object class="GtkSourceCompletionWords" id="words_provider">
- </object>
- <object class="GtkSourceSearchSettings" id="search_settings">
- </object>
- <object class="GtkSourceSearchContext" id="search_context">
- <property name="buffer">document</property>
- <property name="settings">search_settings</property>
- <property name="highlight">True</property>
- </object>
- <object class="GbSourceSearchHighlighter" id="search_highlighter">
- <property name="search-context">search_context</property>
- <property name="search-settings">search_settings</property>
- </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]