[gnome-builder] vim: q should just close the current frame
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: q should just close the current frame
- Date: Wed, 21 Jan 2015 07:34:18 +0000 (UTC)
commit 72fcadb20ce9df6b5e4f45044482fe56b27a75ff
Author: Christian Hergert <christian hergert me>
Date: Tue Jan 20 23:33:54 2015 -0800
vim: q should just close the current frame
src/editor/gb-editor-frame.c | 60 ------------------------------------------
src/editor/gb-editor-view.c | 50 +++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 60 deletions(-)
---
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index 4feff02..29f8484 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -53,27 +53,6 @@ gb_editor_frame_new (void)
return g_object_new (GB_TYPE_EDITOR_FRAME, NULL);
}
-static void
-gb_editor_frame_activate_action (GbEditorFrame *self,
- const gchar *prefix,
- const gchar *name)
-{
- GtkWidget *widget;
-
- widget = GTK_WIDGET (self);
-
- do {
- GActionGroup *group;
-
- group = gtk_widget_get_action_group (widget, prefix);
- if (group && g_action_group_has_action (group, name))
- {
- g_action_group_activate_action (group, name, NULL);
- break;
- }
- } while ((widget = gtk_widget_get_parent (widget)));
-}
-
/**
* gb_editor_frame_link:
* @src: (in): The source frame.
@@ -1041,40 +1020,6 @@ cleanup:
return ret;
}
-static gboolean
-gb_editor_frame_on_execute_command (GbEditorFrame *self,
- const gchar *command_text,
- GbSourceVim *vim)
-{
- g_return_val_if_fail (GB_IS_EDITOR_FRAME (self), FALSE);
- g_return_val_if_fail (command_text, FALSE);
-
- if ((g_strcmp0 (command_text, "w") == 0) ||
- (g_strcmp0 (command_text, "wq") == 0))
- {
- /* TODO: If we wait until the document has saved, we can then
- * call gtk_window_close() on the toplevel.
- */
- gb_editor_frame_activate_action (self, "stack", "save");
- return TRUE;
- }
- else if (g_strcmp0 (command_text, "q") == 0)
- {
- GtkWidget *toplevel;
-
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
- gtk_window_close (GTK_WINDOW (toplevel));
- return TRUE;
- }
- else if (g_strcmp0 (command_text, "q!") == 0)
- {
- g_application_quit (g_application_get_default ());
- return TRUE;
- }
-
- return FALSE;
-}
-
static void
gb_editor_frame_on_switch_to_file (GbEditorFrame *self,
GFile *file,
@@ -1514,11 +1459,6 @@ gb_editor_frame_constructed (GObject *object)
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (vim,
- "execute-command",
- G_CALLBACK (gb_editor_frame_on_execute_command),
- self,
- G_CONNECT_SWAPPED | G_CONNECT_AFTER);
- g_signal_connect_object (vim,
"switch-to-file",
G_CALLBACK (gb_editor_frame_on_switch_to_file),
self,
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index 1ff381e..1f87252 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -666,6 +666,46 @@ gb_editor_view_switch_pane (GSimpleAction *action,
}
static gboolean
+gb_editor_view_on_execute_command (GbEditorView *self,
+ const gchar *command_text,
+ GbSourceVim *vim)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_VIEW (self), FALSE);
+ g_return_val_if_fail (command_text, FALSE);
+ g_return_val_if_fail (GB_IS_SOURCE_VIM (vim), FALSE);
+
+ if (g_str_equal (command_text, "w"))
+ {
+ gb_widget_activate_action (GTK_WIDGET (self), "stack", "save", NULL);
+ return TRUE;
+ }
+ else if (g_str_equal (command_text, "wq"))
+ {
+ gb_widget_activate_action (GTK_WIDGET (self), "stack", "save", NULL);
+ gb_widget_activate_action (GTK_WIDGET (self), "stack", "close", NULL);
+ return TRUE;
+ }
+ else if (g_str_equal (command_text, "q"))
+ {
+ if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (self->priv->document)))
+ {
+ /* TODO: Plumb warning message */
+ }
+ else
+ gb_widget_activate_action (GTK_WIDGET (self), "stack", "close", NULL);
+ return TRUE;
+ }
+ else if (g_str_equal (command_text, "q!"))
+ {
+ /* TODO: don't prompt about saving */
+ gb_widget_activate_action (GTK_WIDGET (self), "stack", "close", NULL);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
gb_editor_view_on_vim_split (GbEditorView *self,
GbSourceVimSplit split,
GbSourceVim *vim)
@@ -778,6 +818,11 @@ gb_editor_view_toggle_split (GbEditorView *view)
NULL);
vim = gb_source_view_get_vim (GB_EDITOR_FRAME (child2)->priv->source_view);
g_signal_connect_object (vim,
+ "execute-command",
+ G_CALLBACK (gb_editor_view_on_execute_command),
+ view,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (vim,
"split",
G_CALLBACK (gb_editor_view_on_vim_split),
view,
@@ -1148,6 +1193,11 @@ gb_editor_view_init (GbEditorView *self)
vim = gb_source_view_get_vim (self->priv->frame->priv->source_view);
g_signal_connect_object (vim,
+ "execute-command",
+ G_CALLBACK (gb_editor_view_on_execute_command),
+ self,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (vim,
"split",
G_CALLBACK (gb_editor_view_on_vim_split),
self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]