[gnome-builder/wip/chergert/layout: 64/118] source-view: add documentation-requested
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/layout: 64/118] source-view: add documentation-requested
- Date: Wed, 5 Jul 2017 11:53:26 +0000 (UTC)
commit e711e71babc90e664b72621e5b4598ef180f582c
Author: Christian Hergert <chergert redhat com>
Date: Sat Jul 1 15:41:42 2017 -0700
source-view: add documentation-requested
This allows request-documentation as a G_SIGNAL_ACTION to have
a default handler which grabs the current word and emits
documentation-requested with the word as an argument.
libide/sourceview/ide-source-view.c | 48 +++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/libide/sourceview/ide-source-view.c b/libide/sourceview/ide-source-view.c
index 29af108..ce54d6e 100644
--- a/libide/sourceview/ide-source-view.c
+++ b/libide/sourceview/ide-source-view.c
@@ -52,6 +52,7 @@
#include "sourceview/ide-indenter.h"
#include "sourceview/ide-line-change-gutter-renderer.h"
#include "sourceview/ide-line-diagnostics-gutter-renderer.h"
+#include "sourceview/ide-source-iter.h"
#include "sourceview/ide-source-view-capture.h"
#include "sourceview/ide-source-view-mode.h"
#include "sourceview/ide-source-view-movements.h"
@@ -259,6 +260,7 @@ enum {
CLEAR_SELECTION,
CLEAR_SNIPPETS,
CYCLE_COMPLETION,
+ DOCUMENTATION_REQUESTED,
DECREASE_FONT_SIZE,
DELETE_SELECTION,
DUPLICATE_ENTIRE_LINE,
@@ -6274,6 +6276,36 @@ ide_source_view_real_find_references (IdeSourceView *self)
}
static void
+ide_source_view_real_request_documentation (IdeSourceView *self)
+{
+ g_autofree gchar *word = NULL;
+ GtkTextBuffer *buffer;
+ GtkTextIter begin;
+ GtkTextIter end;
+
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
+
+ if (!gtk_text_buffer_get_selection_bounds (buffer, &begin, &end))
+ {
+ gtk_text_iter_order (&begin, &end);
+
+ if (!_ide_source_iter_starts_extra_natural_word (&begin))
+ {
+ _ide_source_iter_backward_extra_natural_word_start (&begin);
+ end = begin;
+ }
+
+ _ide_source_iter_forward_extra_natural_word_end (&end);
+ }
+
+ word = gtk_text_iter_get_slice (&begin, &end);
+
+ g_signal_emit (self, signals [DOCUMENTATION_REQUESTED], 0, word);
+}
+
+static void
ide_source_view_real_reset (IdeSourceView *self)
{
g_assert (IDE_IS_SOURCE_VIEW (self));
@@ -6631,6 +6663,7 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
klass->push_selection = ide_source_view_real_push_selection;
klass->rebuild_highlight = ide_source_view_real_rebuild_highlight;
klass->replay_macro = ide_source_view_real_replay_macro;
+ klass->request_documentation = ide_source_view_real_request_documentation;
klass->reset_font_size = ide_source_view_real_reset_font_size;
klass->restore_insert_mark = ide_source_view_real_restore_insert_mark;
klass->save_command = ide_source_view_real_save_command;
@@ -6997,6 +7030,21 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
1,
GTK_TYPE_DIRECTION_TYPE);
+ /**
+ * IdeSourceView:documentation-requested:
+ * @self: A #IdeSourceView
+ * @word: the word that was requested
+ *
+ * This is emitted by the default request-documentation handler to
+ * locate the documentation for the currently selected word.
+ */
+ signals [DOCUMENTATION_REQUESTED] =
+ g_signal_new ("documentation-requested",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
signals [DECREASE_FONT_SIZE] =
g_signal_new ("decrease-font-size",
G_TYPE_FROM_CLASS (klass),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]