[gnome-builder] vim: Check for open buffer in :bnext and :bprev commands
- From: Matthew Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: Check for open buffer in :bnext and :bprev commands
- Date: Mon, 4 Jul 2016 19:28:12 +0000 (UTC)
commit bd41b3fa1641e13067c78670a371576e31ebaf4d
Author: Matthew Leeds <mleeds redhat com>
Date: Mon Jul 4 00:25:23 2016 -0400
vim: Check for open buffer in :bnext and :bprev commands
The vim commands :bnext and :bprev let the user switch to another
buffer. If those commands are executed without any buffers open,
ide_widget_action() fails and emits a warning. This commit checks if any
buffers are open, and if not the command gracefully gives up. This
matches vim's behavior.
https://bugzilla.gnome.org/show_bug.cgi?id=768356
plugins/command-bar/gb-vim.c | 28 ++++++++++++++++++++++++----
1 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/plugins/command-bar/gb-vim.c b/plugins/command-bar/gb-vim.c
index 48701f1..c2bcade 100644
--- a/plugins/command-bar/gb-vim.c
+++ b/plugins/command-bar/gb-vim.c
@@ -749,10 +749,20 @@ gb_vim_command_bnext (GtkWidget *active_widget,
const gchar *options,
GError **error)
{
+ IdeWorkbench *workbench;
+ IdeContext *context;
+ IdeBufferManager *bufmgr;
+ guint n_buffers;
+
g_assert (GTK_IS_WIDGET (active_widget));
- // TODO: check for an open buffer ?
- ide_widget_action (GTK_WIDGET (active_widget), "view-stack", "next-view", NULL);
+ workbench = ide_widget_get_workbench (GTK_WIDGET (active_widget));
+ context = ide_workbench_get_context (workbench);
+ bufmgr = ide_context_get_buffer_manager (context);
+ n_buffers = ide_buffer_manager_get_n_buffers (bufmgr);
+
+ if (n_buffers > 0)
+ ide_widget_action (GTK_WIDGET (active_widget), "view-stack", "next-view", NULL);
return TRUE;
}
@@ -763,10 +773,20 @@ gb_vim_command_bprevious (GtkWidget *active_widget,
const gchar *options,
GError **error)
{
+ IdeWorkbench *workbench;
+ IdeContext *context;
+ IdeBufferManager *bufmgr;
+ guint n_buffers;
+
g_assert (GTK_IS_WIDGET (active_widget));
- // TODO: check for an open buffer ?
- ide_widget_action (GTK_WIDGET (active_widget), "view-stack", "previous-view", NULL);
+ workbench = ide_widget_get_workbench (GTK_WIDGET (active_widget));
+ context = ide_workbench_get_context (workbench);
+ bufmgr = ide_context_get_buffer_manager (context);
+ n_buffers = ide_buffer_manager_get_n_buffers (bufmgr);
+
+ if (n_buffers > 0)
+ ide_widget_action (GTK_WIDGET (active_widget), "view-stack", "previous-view", NULL);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]