[gnome-builder/editor-layout: 16/21] start abstracting single editor into GbEditorFrame.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/editor-layout: 16/21] start abstracting single editor into GbEditorFrame.
- Date: Sat, 29 Nov 2014 05:11:48 +0000 (UTC)
commit b135ebda28961eaa398f2a18565231f9fe409091
Author: Christian Hergert <christian hergert me>
Date: Thu Nov 27 03:47:06 2014 -0800
start abstracting single editor into GbEditorFrame.
src/editor/gb-editor-document.c | 81 ++++-
src/editor/gb-editor-document.h | 3 +
src/editor/gb-editor-frame.c | 587 +++++++++++++++++++++++++++++
src/editor/gb-editor-frame.h | 63 +++
src/gnome-builder.mk | 2 +
src/resources/gnome-builder.gresource.xml | 1 +
src/resources/ui/gb-editor-frame.ui | 106 ++++++
7 files changed, 840 insertions(+), 3 deletions(-)
---
diff --git a/src/editor/gb-editor-document.c b/src/editor/gb-editor-document.c
index f7956fa..9d61dbb 100644
--- a/src/editor/gb-editor-document.c
+++ b/src/editor/gb-editor-document.c
@@ -23,8 +23,14 @@
#include "gb-editor-document.h"
+struct _GbEditorDocumentPrivate
+{
+ GtkSourceFile *file;
+};
+
enum {
PROP_0,
+ PROP_FILE,
PROP_STYLE_SCHEME_NAME,
LAST_PROP
};
@@ -34,7 +40,7 @@ enum {
LAST_SIGNAL
};
-G_DEFINE_TYPE (GbEditorDocument, gb_editor_document, GTK_SOURCE_TYPE_BUFFER)
+G_DEFINE_TYPE_WITH_PRIVATE (GbEditorDocument, gb_editor_document, GTK_SOURCE_TYPE_BUFFER)
static GParamSpec *gParamSpecs [LAST_PROP];
static guint gSignals [LAST_SIGNAL];
@@ -45,6 +51,29 @@ gb_editor_document_new (void)
return g_object_new (GB_TYPE_EDITOR_DOCUMENT, NULL);
}
+GtkSourceFile *
+gb_editor_document_get_file (GbEditorDocument *document)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_DOCUMENT (document), NULL);
+
+ return document->priv->file;
+}
+
+void
+gb_editor_document_set_file (GbEditorDocument *document,
+ GtkSourceFile *file)
+{
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+ g_return_if_fail (!file || GTK_SOURCE_IS_FILE (file));
+
+ if (file != document->priv->file)
+ {
+ g_clear_object (&document->priv->file);
+ document->priv->file = file ? g_object_ref (file) : NULL;
+ g_object_notify_by_pspec (G_OBJECT (document), gParamSpecs [PROP_FILE]);
+ }
+}
+
static void
gb_editor_document_set_style_scheme_name (GbEditorDocument *document,
const gchar *style_scheme_name)
@@ -69,7 +98,7 @@ gb_editor_document_mark_set (GtkTextBuffer *buffer,
GTK_TEXT_BUFFER_CLASS (gb_editor_document_parent_class)->mark_set (buffer, iter, mark);
if (mark == gtk_text_buffer_get_insert (buffer))
- g_signal_emit (buffer, gSignals[CURSOR_MOVED], 0);
+ g_signal_emit (buffer, gSignals [CURSOR_MOVED], 0);
}
static void
@@ -77,12 +106,41 @@ gb_editor_document_changed (GtkTextBuffer *buffer)
{
g_assert (GB_IS_EDITOR_DOCUMENT (buffer));
- g_signal_emit (buffer, gSignals[CURSOR_MOVED], 0);
+ g_signal_emit (buffer, gSignals [CURSOR_MOVED], 0);
GTK_TEXT_BUFFER_CLASS (gb_editor_document_parent_class)->changed (buffer);
}
static void
+gb_editor_document_finalize (GObject *object)
+{
+ GbEditorDocumentPrivate *priv = GB_EDITOR_DOCUMENT (object)->priv;
+
+ g_clear_object (&priv->file);
+
+ G_OBJECT_CLASS(gb_editor_document_parent_class)->finalize (object);
+}
+
+static void
+gb_editor_document_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbEditorDocument *self = (GbEditorDocument *)object;
+
+ switch (prop_id)
+ {
+ case PROP_FILE:
+ g_value_set_object (value, gb_editor_document_get_file (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+static void
gb_editor_document_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -92,6 +150,10 @@ gb_editor_document_set_property (GObject *object,
switch (prop_id)
{
+ case PROP_FILE:
+ gb_editor_document_set_file (self, g_value_get_object (value));
+ break;
+
case PROP_STYLE_SCHEME_NAME:
gb_editor_document_set_style_scheme_name (self,
g_value_get_string (value));
@@ -109,11 +171,22 @@ gb_editor_document_class_init (GbEditorDocumentClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkTextBufferClass *text_buffer_class = GTK_TEXT_BUFFER_CLASS (klass);
+ object_class->finalize = gb_editor_document_finalize;
+ object_class->get_property = gb_editor_document_get_property;
object_class->set_property = gb_editor_document_set_property;
text_buffer_class->mark_set = gb_editor_document_mark_set;
text_buffer_class->changed = gb_editor_document_changed;
+ gParamSpecs [PROP_FILE] =
+ g_param_spec_object ("file",
+ _("File"),
+ _("The backing file for the document."),
+ GTK_SOURCE_TYPE_FILE,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_FILE,
+ gParamSpecs [PROP_FILE]);
+
gParamSpecs [PROP_STYLE_SCHEME_NAME] =
g_param_spec_string ("style-scheme-name",
_("Style Scheme Name"),
@@ -139,4 +212,6 @@ static void
gb_editor_document_init (GbEditorDocument *document)
{
document->priv = gb_editor_document_get_instance_private (document);
+
+ document->priv->file = gtk_source_file_new ();
}
diff --git a/src/editor/gb-editor-document.h b/src/editor/gb-editor-document.h
index 2ba022a..a03ad1d 100644
--- a/src/editor/gb-editor-document.h
+++ b/src/editor/gb-editor-document.h
@@ -52,6 +52,9 @@ struct _GbEditorDocumentClass
GbEditorDocument *gb_editor_document_new (void);
GType gb_editor_document_get_type (void) G_GNUC_CONST;
+GtkSourceFile *gb_editor_document_get_file (GbEditorDocument *document);
+void gb_editor_document_set_file (GbEditorDocument *document,
+ GtkSourceFile *file);
G_END_DECLS
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
new file mode 100644
index 0000000..8a4c880
--- /dev/null
+++ b/src/editor/gb-editor-frame.c
@@ -0,0 +1,587 @@
+/* gb-editor-frame.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "editor-frame"
+
+#include <glib/gi18n.h>
+
+#include "gb-editor-frame.h"
+#include "gb-log.h"
+#include "gb-source-search-highlighter.h"
+#include "gb-source-view.h"
+#include "gd-tagged-entry.h"
+#include "nautilus-floating-bar.h"
+
+struct _GbEditorFramePrivate
+{
+ /* Widgets owned by GtkBuilder */
+ GtkSpinner *busy_spinner;
+ NautilusFloatingBar *floating_bar;
+ GtkButton *forward_search;
+ GtkButton *backward_search;
+ GtkScrolledWindow *scrolled_window;
+ GtkRevealer *search_revealer;
+ GdTaggedEntry *search_entry;
+ GdTaggedEntryTag *search_entry_tag;
+ GbSourceView *source_view;
+
+ /* Objects owned by GbEditorFrame */
+ GbEditorDocument *document;
+ GtkSourceSearchContext *search_context;
+ GtkSourceSearchSettings *search_settings;
+ GbSourceSearchHighlighter *search_highlighter;
+
+ /* Signal handler identifiers */
+ gulong cursor_moved_handler;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbEditorFrame, gb_editor_frame, GTK_TYPE_OVERLAY)
+
+enum {
+ PROP_0,
+ PROP_DOCUMENT,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+GtkWidget *
+gb_editor_frame_new (void)
+{
+ return g_object_new (GB_TYPE_EDITOR_FRAME, NULL);
+}
+
+/**
+ * gb_editor_frame_link:
+ * @src: (in): The source frame.
+ * @dst: (in): The destination frame.
+ *
+ * This function is intended to link two #GbEditorFrame instances to use the
+ * same backend buffer. This is useful when you want two separate views of the
+ * same content.
+ */
+void
+gb_editor_frame_link (GbEditorFrame *src,
+ GbEditorFrame *dst)
+{
+ g_return_if_fail (GB_IS_EDITOR_FRAME (src));
+ g_return_if_fail (GB_IS_EDITOR_FRAME (dst));
+
+ g_object_bind_property (src, "document", dst, "document",
+ G_BINDING_SYNC_CREATE);
+}
+
+/**
+ * gb_editor_frame_move_next_match:
+ *
+ * Move to the next search match after the cursor position.
+ */
+static void
+gb_editor_frame_move_next_match (GbEditorFrame *frame)
+{
+ GbEditorFramePrivate *priv;
+ GtkTextBuffer *buffer;
+ GtkTextIter select_begin;
+ GtkTextIter select_end;
+ GtkTextIter match_begin;
+ GtkTextIter match_end;
+ gboolean has_selection;
+
+ ENTRY;
+
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+
+ priv = frame->priv;
+
+ buffer = GTK_TEXT_BUFFER (priv->document);
+
+ /*
+ * Start by trying from our current location.
+ */
+ has_selection = gtk_text_buffer_get_selection_bounds (buffer, &select_begin,
+ &select_end);
+ if (!has_selection)
+ if (!gtk_text_iter_forward_char (&select_end))
+ gtk_text_buffer_get_end_iter (buffer, &select_end);
+
+ if (gtk_source_search_context_forward (priv->search_context, &select_end,
+ &match_begin, &match_end))
+ GOTO (found_match);
+
+ /*
+ * Didn't find anything, let's try from the beginning of the buffer.
+ */
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (priv->document),
+ &select_begin, &select_end);
+
+ if (gtk_source_search_context_forward (priv->search_context, &select_begin,
+ &match_begin, &match_end))
+ GOTO (found_match);
+
+ EXIT;
+
+found_match:
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (priv->document),
+ &match_begin, &match_end);
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (priv->source_view),
+ &match_begin, 0.0, TRUE, 0.5, 0.5);
+
+ EXIT;
+}
+
+/**
+ * gb_editor_frame_move_previous_match:
+ *
+ * Move to the first match before the cursor position.
+ */
+static void
+gb_editor_frame_move_previous_match (GbEditorFrame *frame)
+{
+ GbEditorFramePrivate *priv;
+ GtkTextIter select_begin;
+ GtkTextIter select_end;
+ GtkTextIter match_begin;
+ GtkTextIter match_end;
+
+ ENTRY;
+
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+
+ priv = frame->priv;
+
+ gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (priv->document),
+ &select_begin, &select_end);
+
+ if (gtk_source_search_context_backward (priv->search_context, &select_begin,
+ &match_begin, &match_end))
+ GOTO (found_match);
+ else
+ {
+ /*
+ * We need to wrap around from the end to find the last search result.
+ */
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (priv->document),
+ &select_begin);
+ if (gtk_source_search_context_backward (priv->search_context,
+ &select_begin, &match_begin,
+ &match_end))
+ GOTO (found_match);
+ }
+
+ EXIT;
+
+found_match:
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (priv->document),
+ &match_begin, &match_end);
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (priv->source_view),
+ &match_begin, 0.0, TRUE, 0.5, 0.5);
+
+ EXIT;
+}
+
+/**
+ * gb_editor_frame_on_cursor_moved:
+ *
+ * Update cursor ruler in the floating bar upon changing of insert text mark.
+ */
+static void
+gb_editor_frame_on_cursor_moved (GbEditorFrame *frame,
+ GbEditorDocument *document)
+{
+ GtkSourceView *source_view;
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ GtkTextMark *mark;
+ gchar *text;
+ guint ln;
+ guint col;
+
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+ source_view = GTK_SOURCE_VIEW (frame->priv->source_view);
+ buffer = GTK_TEXT_BUFFER (document);
+
+ mark = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+
+ ln = gtk_text_iter_get_line (&iter);
+ col = gtk_source_view_get_visual_column (source_view, &iter);
+
+ text = g_strdup_printf (_("Line %u, Column %u"), ln + 1, col + 1);
+ nautilus_floating_bar_set_primary_label (frame->priv->floating_bar, text);
+ g_free (text);
+}
+
+/**
+ * gb_editor_frame_connect:
+ *
+ * Attach to dynamic signals for the #GtkTextBuffer. Create any objects that
+ * are dependent on the buffer.
+ */
+static void
+gb_editor_frame_connect (GbEditorFrame *frame,
+ GbEditorDocument *document)
+{
+ GbEditorFramePrivate *priv;
+
+ ENTRY;
+
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+ g_return_if_fail (!frame->priv->document);
+
+ priv = frame->priv;
+
+ priv->document = g_object_ref (document);
+
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->source_view),
+ 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);
+
+ if (GB_IS_EDITOR_DOCUMENT (priv->document))
+ {
+ priv->cursor_moved_handler =
+ g_signal_connect_swapped (priv->document,
+ "cursor-moved",
+ G_CALLBACK (gb_editor_frame_on_cursor_moved),
+ frame);
+ }
+
+ EXIT;
+}
+
+/**
+ * gb_editor_frame_disconnect:
+ *
+ * Cleanup any signals or objects that are related to the #GtkTextBuffer.
+ */
+static void
+gb_editor_frame_disconnect (GbEditorFrame *frame)
+{
+ GbEditorFramePrivate *priv;
+
+ ENTRY;
+
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+
+ priv = frame->priv;
+
+ if (priv->document)
+ {
+ g_signal_handler_disconnect (priv->document, priv->cursor_moved_handler);
+ priv->cursor_moved_handler = 0;
+ }
+
+ g_clear_object (&priv->document);
+ g_clear_object (&priv->search_settings);
+ g_clear_object (&priv->search_context);
+ g_clear_object (&priv->search_highlighter);
+
+ EXIT;
+}
+
+/**
+ * gb_editor_frame_get_document:
+ *
+ * Gets the #GbEditorDocument associated with the #GbEditorFrame.
+ *
+ * Returns: (transfer none): A #GbEditorDocument.
+ */
+GbEditorDocument *
+gb_editor_frame_get_document (GbEditorFrame *frame)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_FRAME (frame), NULL);
+
+ return frame->priv->document;
+}
+
+/**
+ * gb_editor_frame_set_document:
+ *
+ * Set the #GbEditorDocument to be displayed by the #GbEditorFrame.
+ */
+void
+gb_editor_frame_set_document (GbEditorFrame *frame,
+ GbEditorDocument *document)
+{
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+ if (document != frame->priv->document)
+ {
+ gb_editor_frame_disconnect (frame);
+ if (document)
+ gb_editor_frame_connect (frame, document);
+ g_object_notify_by_pspec (G_OBJECT (frame), gParamSpecs [PROP_DOCUMENT]);
+ }
+}
+
+/**
+ * gb_editor_frame_on_focus_in_event:
+ *
+ * Handle the "focus-in-event" on the #GbSourceView. Ensure the search entry
+ * is hidden and we are no longer highlighting search results.
+ */
+static gboolean
+gb_editor_frame_on_focus_in_event (GbEditorFrame *frame,
+ GdkEvent *event,
+ GbSourceView *source_view)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_FRAME (frame), FALSE);
+ g_return_val_if_fail (GB_IS_SOURCE_VIEW (source_view), FALSE);
+
+ gtk_revealer_set_reveal_child (frame->priv->search_revealer, FALSE);
+ gtk_source_search_context_set_highlight (frame->priv->search_context, FALSE);
+
+ return GDK_EVENT_PROPAGATE;
+}
+
+/**
+ * gb_editor_frame_on_populate_popup:
+ *
+ * Update the popup menu to include choices for language highlight.
+ */
+static void
+gb_editor_frame_on_populate_popup (GbEditorFrame *frame,
+ GtkWidget *popup,
+ GtkTextView *text_view)
+{
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+ g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
+ g_return_if_fail (GTK_IS_WIDGET (popup));
+
+ /* TODO: Highlight Language Widget */
+}
+
+/**
+ * gb_editor_frame_on_push_snippet:
+ *
+ * Update snippet context with the filename of the current document.
+ */
+static void
+gb_editor_frame_on_push_snippet (GbSourceView *source_view,
+ GbSourceSnippet *snippet,
+ GbSourceSnippetContext *context,
+ GtkTextIter *iter,
+ GbEditorFrame *frame)
+{
+ GtkSourceFile *source_file;
+ GFile *file;
+
+ g_return_if_fail (GB_IS_SOURCE_VIEW (source_view));
+ g_return_if_fail (GB_IS_SOURCE_SNIPPET (snippet));
+ g_return_if_fail (GB_IS_SOURCE_SNIPPET_CONTEXT (context));
+ g_return_if_fail (iter);
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+
+ source_file = gb_editor_document_get_file (frame->priv->document);
+ file = gtk_source_file_get_location (source_file);
+ g_assert (!file || G_IS_FILE (file));
+
+ if (file)
+ {
+ gchar *name;
+
+ name = g_file_get_basename (file);
+ gb_source_snippet_context_add_variable (context, "filename", name);
+ g_free (name);
+ }
+}
+
+/**
+ * gb_editor_frame_on_begin_search:
+ *
+ * Show the search machinery when a request to begin a search has occurred.
+ */
+static void
+gb_editor_frame_on_begin_search (GbEditorFrame *frame,
+ GtkDirectionType direction,
+ const gchar *search_text,
+ GbSourceView *source_view)
+{
+ GbEditorFramePrivate *priv;
+
+ g_return_if_fail (GB_IS_EDITOR_FRAME (frame));
+ g_return_if_fail (GB_IS_SOURCE_VIEW (source_view));
+
+ priv = frame->priv;
+
+ if (search_text)
+ gtk_entry_set_text (GTK_ENTRY (priv->search_entry), search_text);
+
+ gtk_revealer_set_reveal_child (priv->search_revealer, TRUE);
+ gtk_source_search_context_set_highlight (priv->search_context, TRUE);
+ gtk_widget_grab_focus (GTK_WIDGET (priv->search_entry));
+
+ if (search_text)
+ {
+ if (direction == GTK_DIR_DOWN)
+ gb_editor_frame_move_next_match (frame);
+ else if (direction == GTK_DIR_UP)
+ gb_editor_frame_move_previous_match (frame);
+ }
+ else
+ {
+ const gchar *text;
+ guint len;
+
+ text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
+ len = g_utf8_strlen (text, -1);
+ gtk_editable_select_region (GTK_EDITABLE (priv->search_entry), 0, len);
+ }
+}
+
+static void
+gb_editor_frame_finalize (GObject *object)
+{
+ GbEditorFrame *frame = GB_EDITOR_FRAME (object);
+
+ gb_editor_frame_disconnect (frame);
+
+ G_OBJECT_CLASS (gb_editor_frame_parent_class)->finalize (object);
+}
+
+static void
+gb_editor_frame_constructed (GObject *object)
+{
+ GbEditorFramePrivate *priv = GB_EDITOR_FRAME (object)->priv;
+ GbEditorFrame *frame = GB_EDITOR_FRAME (object);
+
+ G_OBJECT_CLASS (gb_editor_frame_parent_class)->constructed (object);
+
+ g_signal_connect_object (priv->source_view,
+ "focus-in-event",
+ G_CALLBACK (gb_editor_frame_on_focus_in_event),
+ frame,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (priv->source_view,
+ "populate-popup",
+ G_CALLBACK (gb_editor_frame_on_populate_popup),
+ frame,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (priv->source_view,
+ "push-snippet",
+ G_CALLBACK (gb_editor_frame_on_push_snippet),
+ frame,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (priv->source_view,
+ "begin-search",
+ G_CALLBACK (gb_editor_frame_on_begin_search),
+ frame,
+ G_CONNECT_SWAPPED);
+}
+
+static void
+gb_editor_frame_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbEditorFrame *self = GB_EDITOR_FRAME (object);
+
+ switch (prop_id)
+ {
+ case PROP_DOCUMENT:
+ g_value_set_object (value, gb_editor_frame_get_document (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_editor_frame_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbEditorFrame *self = GB_EDITOR_FRAME (object);
+
+ switch (prop_id)
+ {
+ case PROP_DOCUMENT:
+ gb_editor_frame_set_document (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_editor_frame_class_init (GbEditorFrameClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->constructed = gb_editor_frame_constructed;
+ object_class->finalize = gb_editor_frame_finalize;
+ object_class->get_property = gb_editor_frame_get_property;
+ object_class->set_property = gb_editor_frame_set_property;
+
+ gParamSpecs [PROP_DOCUMENT] =
+ g_param_spec_object ("document",
+ _("Document"),
+ _("The document for the editor."),
+ GB_TYPE_EDITOR_DOCUMENT,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_DOCUMENT,
+ gParamSpecs [PROP_DOCUMENT]);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/builder/ui/gb-editor-frame.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, busy_spinner);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, floating_bar);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, forward_search);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, backward_search);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, scrolled_window);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, search_revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, search_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorFrame, source_view);
+
+ g_type_ensure (GB_TYPE_SOURCE_VIEW);
+ g_type_ensure (GD_TYPE_TAGGED_ENTRY);
+ g_type_ensure (NAUTILUS_TYPE_FLOATING_BAR);
+}
+
+static void
+gb_editor_frame_init (GbEditorFrame *self)
+{
+ self->priv = gb_editor_frame_get_instance_private (self);
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/src/editor/gb-editor-frame.h b/src/editor/gb-editor-frame.h
new file mode 100644
index 0000000..37ddaf1
--- /dev/null
+++ b/src/editor/gb-editor-frame.h
@@ -0,0 +1,63 @@
+/* gb-editor-frame.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_EDITOR_FRAME_H
+#define GB_EDITOR_FRAME_H
+
+#include <gtk/gtk.h>
+
+#include "gb-editor-document.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_EDITOR_FRAME (gb_editor_frame_get_type())
+#define GB_EDITOR_FRAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_EDITOR_FRAME,
GbEditorFrame))
+#define GB_EDITOR_FRAME_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_EDITOR_FRAME,
GbEditorFrame const))
+#define GB_EDITOR_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GB_TYPE_EDITOR_FRAME,
GbEditorFrameClass))
+#define GB_IS_EDITOR_FRAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GB_TYPE_EDITOR_FRAME))
+#define GB_IS_EDITOR_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GB_TYPE_EDITOR_FRAME))
+#define GB_EDITOR_FRAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GB_TYPE_EDITOR_FRAME,
GbEditorFrameClass))
+
+typedef struct _GbEditorFrame GbEditorFrame;
+typedef struct _GbEditorFrameClass GbEditorFrameClass;
+typedef struct _GbEditorFramePrivate GbEditorFramePrivate;
+
+struct _GbEditorFrame
+{
+ GtkOverlay parent;
+
+ /*< private >*/
+ GbEditorFramePrivate *priv;
+};
+
+struct _GbEditorFrameClass
+{
+ GtkOverlayClass parent;
+};
+
+GType gb_editor_frame_get_type (void);
+GtkWidget *gb_editor_frame_new (void);
+void gb_editor_frame_link (GbEditorFrame *src,
+ GbEditorFrame *dst);
+GbEditorDocument *gb_editor_frame_get_document (GbEditorFrame *frame);
+void gb_editor_frame_set_document (GbEditorFrame *frame,
+ GbEditorDocument *document);
+
+G_END_DECLS
+
+#endif /* GB_EDITOR_FRAME_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index e68d797..dd469b8 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -55,6 +55,8 @@ libgnome_builder_la_SOURCES = \
src/editor/gb-editor-file-mark.h \
src/editor/gb-editor-file-marks.c \
src/editor/gb-editor-file-marks.h \
+ src/editor/gb-editor-frame.c \
+ src/editor/gb-editor-frame.h \
src/editor/gb-editor-navigation-item.c \
src/editor/gb-editor-navigation-item.h \
src/editor/gb-editor-settings-widget.c \
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 96516db..07ad845 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -23,6 +23,7 @@
<file>ui/gb-credits-widget.ui</file>
<file>ui/gb-devhelp-tab.ui</file>
<file>ui/gb-editor-settings-widget.ui</file>
+ <file>ui/gb-editor-frame.ui</file>
<file>ui/gb-editor-tab.ui</file>
<file>ui/gb-editor-workspace.ui</file>
<file>ui/gb-preferences-window.ui</file>
diff --git a/src/resources/ui/gb-editor-frame.ui b/src/resources/ui/gb-editor-frame.ui
new file mode 100644
index 0000000..07d06e0
--- /dev/null
+++ b/src/resources/ui/gb-editor-frame.ui
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <template class="GbEditorFrame" parent="GtkOverlay">
+ <child type="overlay">
+ <object class="NautilusFloatingBar" id="floating_bar">
+ <property name="halign">end</property>
+ <property name="valign">end</property>
+ <property name="visible">true</property>
+ <property name="primary_label" translatable="yes">Line 1, Column 1</property>
+ <child>
+ <object class="GtkSpinner" id="busy_spinner">
+ <property name="active">false</property>
+ <property name="margin_start">6</property>
+ <property name="tooltip_text" translatable="yes">Currently parsing document</property>
+ <property name="visible">false</property>
+ </object>
+ <packing>
+ <property name="pack_type">start</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkRevealer" id="search_revealer">
+ <property name="halign">end</property>
+ <property name="valign">start</property>
+ <property name="visible">true</property>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">true</property>
+ <property name="margin_end">12</property>
+ <style>
+ <class name="gb-search-slider"/>
+ </style>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="visible">true</property>
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <object class="GdTaggedEntry" id="search_entry">
+ <property name="visible">True</property>
+ <property name="tag_close_visible">False</property>
+ <property name="can_focus">True</property>
+ <property name="width_request">260</property>
+ <property name="primary_icon_activatable">True</property>
+ <property name="primary_icon_sensitive">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="backward_search">
+ <property name="visible">true</property>
+ <property name="can_focus">false</property>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="icon_name">go-up-symbolic</property>
+ <property name="icon_size">1</property>
+ <property name="visible">true</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="forward_search">
+ <property name="visible">true</property>
+ <property name="can_focus">false</property>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="icon_name">go-down-symbolic</property>
+ <property name="icon_size">1</property>
+ <property name="visible">true</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolled_window">
+ <property name="visible">true</property>
+ <child>
+ <object class="GbSourceView" id="source_view">
+ <property name="visible">true</property>
+ <property name="show-line-numbers">true</property>
+ <property name="show-right-margin">true</property>
+ <property name="right-margin-position">80</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]