[gnome-builder/wip/libide-merge] show docs with "help keyword" in the command bar



commit 6b1455ac26eb3d1f7725f607412bdc865bd32404
Author: Christian Hergert <christian hergert me>
Date:   Sat Mar 21 19:31:22 2015 -0700

    show docs with "help keyword" in the command bar

 src/editor/gb-editor-workspace.c     |   45 ++++++++++++++++++++++++++++++++++
 src/editor/gb-editor-workspace.h     |    6 +++-
 src/vim/gb-vim.c                     |   14 ++++++++++
 src/workbench/gb-workbench-actions.c |   15 +++++++++++
 4 files changed, 78 insertions(+), 2 deletions(-)
---
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 0e4ec59..1222a01 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -26,6 +26,7 @@
 #include "gb-editor-workspace.h"
 #include "gb-editor-workspace-actions.h"
 #include "gb-editor-workspace-private.h"
+#include "gb-string.h"
 #include "gb-view-grid.h"
 #include "gb-widget.h"
 
@@ -208,3 +209,47 @@ gb_editor_workspace_show_help (GbEditorWorkspace *self,
 
   g_clear_object (&document);
 }
+
+void
+gb_editor_workspace_search_help (GbEditorWorkspace *self,
+                                 const gchar       *keywords)
+{
+  GbDocument *document;
+  GtkWidget *last_focus;
+  GtkWidget *after;
+
+  g_return_if_fail (GB_IS_EDITOR_WORKSPACE (self));
+
+  if (gb_str_empty0 (keywords))
+    return;
+
+  document = gb_view_grid_find_document_typed (self->view_grid, GB_TYPE_DEVHELP_DOCUMENT);
+
+  if (document != NULL)
+    {
+      gb_devhelp_document_set_search (GB_DEVHELP_DOCUMENT (document), keywords);
+      gb_view_grid_focus_document (self->view_grid, document);
+      return;
+    }
+
+  document = g_object_new (GB_TYPE_DEVHELP_DOCUMENT,
+                           NULL);
+  gb_devhelp_document_set_search (GB_DEVHELP_DOCUMENT (document), keywords);
+
+  last_focus = gb_view_grid_get_last_focus (self->view_grid);
+
+  if (last_focus == NULL)
+    {
+      gb_view_grid_focus_document (self->view_grid, document);
+      return;
+    }
+
+  after = gb_view_grid_get_stack_after (self->view_grid, GB_VIEW_STACK (last_focus));
+
+  if (after == NULL)
+    after = gb_view_grid_add_stack_after (self->view_grid, GB_VIEW_STACK (last_focus));
+
+  gb_view_stack_focus_document (GB_VIEW_STACK (after), document);
+
+  g_clear_object (&document);
+}
diff --git a/src/editor/gb-editor-workspace.h b/src/editor/gb-editor-workspace.h
index 04657cd..fb7ed0d 100644
--- a/src/editor/gb-editor-workspace.h
+++ b/src/editor/gb-editor-workspace.h
@@ -27,8 +27,10 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbEditorWorkspace, gb_editor_workspace, GB, EDITOR_WORKSPACE, GbWorkspace)
 
-void gb_editor_workspace_show_help (GbEditorWorkspace *self,
-                                    const gchar       *uri);
+void gb_editor_workspace_search_help (GbEditorWorkspace *self,
+                                      const gchar       *keyword);
+void gb_editor_workspace_show_help   (GbEditorWorkspace *self,
+                                      const gchar       *uri);
 
 G_END_DECLS
 
diff --git a/src/vim/gb-vim.c b/src/vim/gb-vim.c
index 0b07846..e7d67dc 100644
--- a/src/vim/gb-vim.c
+++ b/src/vim/gb-vim.c
@@ -592,11 +592,25 @@ gb_vim_jump_to_line (GtkSourceView  *source_view,
   return TRUE;
 }
 
+static gboolean
+gb_vim_command_help (GtkSourceView  *source_view,
+                     const gchar    *command,
+                     const gchar    *options,
+                     GError        **error)
+{
+  GVariant *param;
+
+  param = g_variant_new_string (options);
+  gb_widget_activate_action (GTK_WIDGET (source_view), "workbench", "search-docs", param);
+  return TRUE;
+}
+
 static const GbVimCommand vim_commands[] = {
   { "cnext",       gb_vim_command_cnext },
   { "colorscheme", gb_vim_command_colorscheme },
   { "cprevious",   gb_vim_command_cprevious },
   { "edit",        gb_vim_command_edit },
+  { "help",        gb_vim_command_help },
   { "nohl",        gb_vim_command_nohl },
   { "quit",        gb_vim_command_quit },
   { "set",         gb_vim_command_set },
diff --git a/src/workbench/gb-workbench-actions.c b/src/workbench/gb-workbench-actions.c
index e233bf5..e2f42e9 100644
--- a/src/workbench/gb-workbench-actions.c
+++ b/src/workbench/gb-workbench-actions.c
@@ -281,6 +281,20 @@ gb_workbench_actions_dayhack (GSimpleAction *action,
   g_settings_set_string (settings, "style-scheme-name", "builder");
 }
 
+static void
+gb_workbench_actions_search_docs (GSimpleAction *action,
+                                  GVariant      *parameter,
+                                  gpointer       user_data)
+{
+  GbWorkbench *self = user_data;
+  const gchar *str;
+
+  g_return_if_fail (GB_IS_WORKBENCH (self));
+
+  str = g_variant_get_string (parameter, NULL);
+  gb_editor_workspace_search_help (self->editor_workspace, str);
+}
+
 static const GActionEntry GbWorkbenchActions[] = {
   { "build",            gb_workbench_actions_build },
   { "dayhack",          gb_workbench_actions_dayhack },
@@ -289,6 +303,7 @@ static const GActionEntry GbWorkbenchActions[] = {
   { "open",             gb_workbench_actions_open },
   { "open-uri-list",    gb_workbench_actions_open_uri_list, "as" },
   { "save-all",         gb_workbench_actions_save_all },
+  { "search-docs",        gb_workbench_actions_search_docs, "s" },
   { "show-command-bar", gb_workbench_actions_show_command_bar },
 };
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]