[gnome-builder] source-view: add request-documentation and display-documentation signals
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] source-view: add request-documentation and display-documentation signals
- Date: Thu, 11 Dec 2014 00:14:18 +0000 (UTC)
commit 2991453e471adfcb07dc299787e0c9df506a0c0c
Author: Christian Hergert <christian hergert me>
Date: Tue Dec 9 20:44:50 2014 -0800
source-view: add request-documentation and display-documentation signals
request-documentation is a G_SIGNAL_ACTION that can be activated from
a GtkBindingSet. The attached keybinding is <Control><Shift>k.
We also wire up the <Shift>k accelerator from VIM to use the same
infrastructure.
src/editor/gb-source-view.c | 88 +++++++++++++++++++++++++++++++++++++++++-
src/editor/gb-source-view.h | 3 +
2 files changed, 88 insertions(+), 3 deletions(-)
---
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index 6512213..6a6787e 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -88,9 +88,11 @@ enum {
enum {
BEGIN_SEARCH,
+ DISPLAY_DOCUMENTATION,
DRAW_LAYER,
POP_SNIPPET,
PUSH_SNIPPET,
+ REQUEST_DOCUMENTATION,
LAST_SIGNAL
};
@@ -271,6 +273,18 @@ gb_source_view_vim_begin_search (GbSourceView *view,
}
static void
+gb_source_view_vim_jump_to_doc (GbSourceView *view,
+ const gchar *text,
+ GbSourceVim *vim)
+{
+ g_return_if_fail (GB_IS_SOURCE_VIEW (view));
+ g_return_if_fail (GB_IS_SOURCE_VIM (vim));
+
+ if (text)
+ g_signal_emit (view, gSignals [DISPLAY_DOCUMENTATION], 0, text);
+}
+
+static void
on_search_highlighter_changed (GbSourceSearchHighlighter *highlighter,
GbSourceView *view)
{
@@ -1646,6 +1660,37 @@ gb_source_view_real_draw_layer (GbSourceView *view,
}
static void
+gb_source_view_display_documentation (GbSourceView *view,
+ const gchar *search_text)
+{
+ g_return_if_fail (GB_IS_SOURCE_VIEW (view));
+ g_return_if_fail (search_text);
+
+}
+
+static void
+gb_source_view_request_documentation (GbSourceView *view)
+{
+ GtkTextIter begin;
+ GtkTextIter end;
+ gchar *word;
+
+ ENTRY;
+
+ g_return_if_fail (GB_IS_SOURCE_VIEW (view));
+
+ word = gb_source_vim_get_current_word (view->priv->vim, &begin, &end);
+
+ if (word)
+ {
+ g_signal_emit (view, gSignals [DISPLAY_DOCUMENTATION], 0, word);
+ g_free (word);
+ }
+
+ EXIT;
+}
+
+static void
gb_source_view_grab_focus (GtkWidget *widget)
{
invalidate_window (GB_SOURCE_VIEW (widget));
@@ -1835,6 +1880,7 @@ gb_source_view_class_init (GbSourceViewClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass);
+ GtkBindingSet *binding_set;
object_class->constructed = gb_source_view_constructed;
object_class->finalize = gb_source_view_finalize;
@@ -1849,6 +1895,8 @@ gb_source_view_class_init (GbSourceViewClass *klass)
text_view_class->draw_layer = gb_source_view_draw_layer;
klass->draw_layer = gb_source_view_real_draw_layer;
+ klass->display_documentation = gb_source_view_display_documentation;
+ klass->request_documentation = gb_source_view_request_documentation;
gParamSpecs [PROP_ENABLE_WORD_COMPLETION] =
g_param_spec_boolean ("enable-word-completion",
@@ -1930,14 +1978,25 @@ gb_source_view_class_init (GbSourceViewClass *klass)
GB_TYPE_SOURCE_VIEW,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GbSourceViewClass, begin_search),
- NULL,
- NULL,
- NULL,
+ NULL, NULL,
+ g_cclosure_marshal_generic,
G_TYPE_NONE,
2,
GTK_TYPE_DIRECTION_TYPE,
G_TYPE_STRING);
+ gSignals [DISPLAY_DOCUMENTATION] =
+ g_signal_new ("display-documentation",
+ GB_TYPE_SOURCE_VIEW,
+ G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GbSourceViewClass,
+ display_documentation),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_STRING);
+
gSignals [DRAW_LAYER] =
g_signal_new ("draw-layer",
GB_TYPE_SOURCE_VIEW,
@@ -1950,6 +2009,24 @@ gb_source_view_class_init (GbSourceViewClass *klass)
2,
GTK_TYPE_TEXT_VIEW_LAYER,
G_TYPE_POINTER);
+
+ gSignals [REQUEST_DOCUMENTATION] =
+ g_signal_new ("request-documentation",
+ GB_TYPE_SOURCE_VIEW,
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GbSourceViewClass,
+ request_documentation),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 0);
+
+ binding_set = gtk_binding_set_by_class (klass);
+ gtk_binding_entry_add_signal (binding_set,
+ GDK_KEY_k,
+ GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+ "request-documentation",
+ 0);
}
static void
@@ -1985,6 +2062,11 @@ gb_source_view_init (GbSourceView *view)
G_CALLBACK (gb_source_view_vim_begin_search),
view,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (view->priv->vim,
+ "jump-to-doc",
+ G_CALLBACK (gb_source_view_vim_jump_to_doc),
+ view,
+ G_CONNECT_SWAPPED);
completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (view));
gtk_source_completion_block_interactive (completion);
diff --git a/src/editor/gb-source-view.h b/src/editor/gb-source-view.h
index 8905ea8..3e79211 100644
--- a/src/editor/gb-source-view.h
+++ b/src/editor/gb-source-view.h
@@ -63,6 +63,9 @@ struct _GbSourceViewClass
void (*draw_layer) (GbSourceView *view,
GtkTextViewLayer layer,
cairo_t *cr);
+ void (*request_documentation) (GbSourceView *view);
+ void (*display_documentation) (GbSourceView *view,
+ const gchar *search_text);
};
void gb_source_view_begin_search (GbSourceView *view,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]