[gnome-builder/wip/commands2] commands: use command-bar for VIM command entry.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/commands2] commands: use command-bar for VIM command entry.
- Date: Fri, 10 Oct 2014 22:31:10 +0000 (UTC)
commit 9f4ec7eb2c6d0ea29374688dac9384dc626abb67
Author: Christian Hergert <christian hergert me>
Date: Fri Oct 10 15:31:03 2014 -0700
commands: use command-bar for VIM command entry.
This finally unifies all the command-bar/vim-command-entry work.
Yay!
src/editor/gb-editor-tab-private.h | 2 -
src/editor/gb-editor-tab.c | 107 +++++-------------------------------
src/resources/ui/gb-editor-tab.ui | 26 ---------
src/workbench/gb-workbench.c | 49 ++++++++++++++++-
4 files changed, 62 insertions(+), 122 deletions(-)
---
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index 33da9c5..8850211 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -107,8 +107,6 @@ struct _GbEditorTabPrivate
GbSourceView *source_view;
GdTaggedEntry *search_entry;
GdTaggedEntryTag *search_entry_tag;
- GtkEntry *vim_command_entry;
- GtkRevealer *vim_command_entry_revealer;
/*
* Information about our target file and encoding.
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index beea4b5..99e3967 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -985,21 +985,27 @@ on_vim_command_visibility_toggled (GbEditorVim *vim,
gboolean visible,
GbEditorTab *tab)
{
+ GbWorkbench *workbench;
+ GAction *action;
+ GVariant *params;
+
ENTRY;
g_return_if_fail (GB_IS_EDITOR_VIM (vim));
g_return_if_fail (GB_IS_EDITOR_TAB (tab));
- gtk_revealer_set_reveal_child (tab->priv->vim_command_entry_revealer,
- visible);
+ workbench = gb_widget_get_workbench (GTK_WIDGET (tab));
+ if (!workbench)
+ return;
- if (visible)
- {
- gtk_entry_set_text (tab->priv->vim_command_entry, "");
- gtk_widget_grab_focus (GTK_WIDGET (tab->priv->vim_command_entry));
- }
- else
- gtk_widget_grab_focus (GTK_WIDGET (tab->priv->source_view));
+ action = g_action_map_lookup_action (G_ACTION_MAP (workbench),
+ "toggle-command-bar");
+ if (!action)
+ return;
+
+ params = g_variant_new_boolean (visible);
+ g_action_activate (action, params);
+ g_variant_unref (params);
EXIT;
}
@@ -1016,53 +1022,6 @@ on_vim_begin_search (GbEditorVim *vim,
}
static void
-on_vim_command_entry_activate (GtkEntry *entry,
- GbEditorTab *tab)
-{
- GtkWidget *toplevel;
- GbWorkspace *workspace;
- GActionGroup *actions;
- GAction *action = NULL;
- const gchar *text;
-
- g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (GB_IS_EDITOR_TAB (tab));
-
- if (!(text = gtk_entry_get_text (entry)))
- return;
-
- while (*text == ':')
- text++;
-
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));
- workspace = gb_workbench_get_workspace (GB_WORKBENCH (toplevel),
- GB_TYPE_EDITOR_WORKSPACE);
- actions = gb_workspace_get_actions (workspace);
-
- /*
- * TODO: This is a very crappy way to commands. If you support Builder,
- * I'll have time to fix this ;-)
- */
-
- if (g_str_equal (text, "w"))
- {
- gb_editor_vim_set_mode (tab->priv->vim, GB_EDITOR_VIM_NORMAL);
- action = g_action_map_lookup_action (G_ACTION_MAP (actions), "save");
- g_action_activate (action, NULL);
- return;
- }
- else if (g_str_equal (text, "e"))
- {
- gb_editor_vim_set_mode (tab->priv->vim, GB_EDITOR_VIM_NORMAL);
- action = g_action_map_lookup_action (G_ACTION_MAP (actions), "open");
- g_action_activate (action, NULL);
- return;
- }
-
- gb_editor_vim_execute_command (tab->priv->vim, text);
-}
-
-static void
on_vim_notify_phrase (GbEditorVim *vim,
GParamSpec *pspec,
GbEditorTab *tab)
@@ -1090,28 +1049,6 @@ on_vim_notify_mode (GbEditorVim *vim,
}
static gboolean
-on_vim_command_entry_key_press_event (GtkEntry *entry,
- GdkEventKey *event,
- GbEditorTab *tab)
-{
- ENTRY;
-
- g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (event);
- g_return_if_fail (GB_IS_EDITOR_TAB (tab));
-
- switch (event->keyval)
- {
- case GDK_KEY_Escape:
- gb_editor_vim_set_mode (tab->priv->vim, GB_EDITOR_VIM_NORMAL);
- RETURN (TRUE);
-
- default:
- RETURN (FALSE);
- }
-}
-
-static gboolean
transform_file_to_language (GBinding *binding,
const GValue *src_value,
GValue *dst_value,
@@ -1316,16 +1253,6 @@ gb_editor_tab_constructed (GObject *object)
G_CALLBACK (on_vim_notify_mode),
tab);
- g_signal_connect (priv->vim_command_entry,
- "activate",
- G_CALLBACK (on_vim_command_entry_activate),
- tab);
-
- g_signal_connect (priv->vim_command_entry,
- "key-press-event",
- G_CALLBACK (on_vim_command_entry_key_press_event),
- tab);
-
settings = g_settings_new ("org.gnome.builder.editor");
g_settings_bind (settings, "vim-mode", priv->vim, "enabled",
G_SETTINGS_BIND_DEFAULT);
@@ -1619,10 +1546,6 @@ gb_editor_tab_class_init (GbEditorTabClass *klass)
snippets_provider);
gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
source_view);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- vim_command_entry);
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
- vim_command_entry_revealer);
g_type_ensure (GB_TYPE_EDITOR_DOCUMENT);
g_type_ensure (GB_TYPE_SOURCE_CHANGE_MONITOR);
diff --git a/src/resources/ui/gb-editor-tab.ui b/src/resources/ui/gb-editor-tab.ui
index f500a71..fdf08ad 100644
--- a/src/resources/ui/gb-editor-tab.ui
+++ b/src/resources/ui/gb-editor-tab.ui
@@ -110,32 +110,6 @@
</child>
</object>
</child>
- <child type="overlay">
- <object class="GtkRevealer" id="vim_command_entry_revealer">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="valign">end</property>
- <property name="reveal_child">False</property>
- <property name="transition_type">GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP</property>
- <child>
- <object class="GtkFrame" id="vim_command_frame">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <style>
- <class name="gb-vim-command-slider"/>
- </style>
- <child>
- <object class="GtkEntry" id="vim_command_entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="width_chars">40</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
</object>
</child>
<child>
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 5429dff..e512f52 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -297,15 +297,55 @@ on_show_command_bar_activate (GSimpleAction *action,
{
GbWorkbenchPrivate *priv;
GbWorkbench *workbench = user_data;
+ gboolean show = TRUE;
g_return_if_fail (GB_IS_WORKBENCH (workbench));
priv = workbench->priv;
- if (gtk_revealer_get_reveal_child (GTK_REVEALER (priv->command_bar)))
- gb_command_bar_hide (priv->command_bar);
+ show = !gtk_revealer_get_reveal_child (GTK_REVEALER (priv->command_bar));
+
+ if (show)
+ gb_command_bar_show (priv->command_bar);
else
+ gb_command_bar_hide (priv->command_bar);
+}
+
+static void
+on_toggle_command_bar_activate (GSimpleAction *action,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ GbWorkbenchPrivate *priv;
+ GbWorkbench *workbench = user_data;
+ gboolean show = TRUE;
+
+ g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+ priv = workbench->priv;
+
+ show = g_variant_get_boolean (parameters);
+
+ if (show)
gb_command_bar_show (priv->command_bar);
+ else
+ gb_command_bar_hide (priv->command_bar);
+}
+
+static void
+on_command_bar_notify_child_revealed (GbCommandBar *command_bar,
+ GParamSpec *pspec,
+ GbWorkbench *workbench)
+{
+ gboolean reveal_child;
+
+ g_return_if_fail (GB_IS_COMMAND_BAR (command_bar));
+ g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+ reveal_child = gtk_revealer_get_reveal_child (GTK_REVEALER (command_bar));
+
+ if (!reveal_child && workbench->priv->active_workspace)
+ gtk_widget_grab_focus (GTK_WIDGET (workbench->priv->active_workspace));
}
static void
@@ -317,6 +357,7 @@ gb_workbench_constructed (GObject *object)
{ "go-backward", on_go_backward_activate },
{ "go-forward", on_go_forward_activate },
{ "show-command-bar", on_show_command_bar_activate },
+ { "toggle-command-bar", on_toggle_command_bar_activate, "b" },
};
GbWorkbenchPrivate *priv;
GbWorkbench *workbench = (GbWorkbench *)object;
@@ -363,6 +404,10 @@ gb_workbench_constructed (GObject *object)
g_object_bind_property (priv->navigation_list, "can-go-forward",
action, "enabled", G_BINDING_SYNC_CREATE);
+ g_signal_connect (priv->command_bar, "notify::child-revealed",
+ G_CALLBACK (on_command_bar_notify_child_revealed),
+ workbench);
+
G_OBJECT_CLASS (gb_workbench_parent_class)->constructed (object);
EXIT;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]