[gnome-builder/wip/commands] commands: add provider to execute vim commands via command bar
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/commands] commands: add provider to execute vim commands via command bar
- Date: Wed, 8 Oct 2014 04:57:37 +0000 (UTC)
commit db4c1ded4573da22805ab848f24dbdd6de99de12
Author: Christian Hergert <christian hergert me>
Date: Tue Oct 7 21:57:14 2014 -0700
commands: add provider to execute vim commands via command bar
src/commands/gb-commands-internal.c | 5 +
src/commands/gb-vim-command-provider.c | 89 +++++++++++++++++
src/commands/gb-vim-command-provider.h | 56 +++++++++++
src/commands/gb-vim-command.c | 169 ++++++++++++++++++++++++++++++++
src/commands/gb-vim-command.h | 56 +++++++++++
src/gnome-builder.mk | 4 +
6 files changed, 379 insertions(+), 0 deletions(-)
---
diff --git a/src/commands/gb-commands-internal.c b/src/commands/gb-commands-internal.c
index 6557766..bd91afb 100644
--- a/src/commands/gb-commands-internal.c
+++ b/src/commands/gb-commands-internal.c
@@ -27,6 +27,7 @@
#include "gb-editor-tab.h"
#include "gb-editor-workspace.h"
#include "gb-python-command-provider.h"
+#include "gb-vim-command-provider.h"
typedef void (*TextCommandFunc) (GbCommand *command,
GVariant *parameters,
@@ -182,4 +183,8 @@ gb_commands_internal_init (void)
provider = gb_python_command_provider_new ();
gb_command_manager_add_provider (manager, provider);
g_object_unref (provider);
+
+ provider = gb_vim_command_provider_new ();
+ gb_command_manager_add_provider (manager, provider);
+ g_object_unref (provider);
}
diff --git a/src/commands/gb-vim-command-provider.c b/src/commands/gb-vim-command-provider.c
new file mode 100644
index 0000000..7b02d80
--- /dev/null
+++ b/src/commands/gb-vim-command-provider.c
@@ -0,0 +1,89 @@
+/* gb-vim-command-provider.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gb-editor-vim.h"
+#include "gb-vim-command.h"
+#include "gb-vim-command-provider.h"
+
+struct _GbVimCommandProviderPrivate
+{
+ GSettings *settings;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbVimCommandProvider, gb_vim_command_provider,
+ GB_TYPE_COMMAND_PROVIDER)
+
+GbCommandProvider *
+gb_vim_command_provider_new (void)
+{
+ return g_object_new (GB_TYPE_VIM_COMMAND_PROVIDER, NULL);
+}
+
+static GbCommand *
+gb_vim_command_provider_create (GbCommandProvider *provider,
+ const gchar *command_text)
+{
+ GbVimCommandProviderPrivate *priv;
+
+ g_return_val_if_fail (GB_IS_VIM_COMMAND_PROVIDER (provider), NULL);
+ g_return_val_if_fail (command_text, NULL);
+
+ priv = GB_VIM_COMMAND_PROVIDER (provider)->priv;
+
+ if (!g_settings_get_boolean (priv->settings, "vim-mode"))
+ return NULL;
+
+ if (gb_editor_vim_is_command (command_text))
+ return g_object_new (GB_TYPE_VIM_COMMAND,
+ "command-text", command_text,
+ NULL);
+
+ return NULL;
+}
+
+static void
+gb_vim_command_provider_finalize (GObject *object)
+{
+ GbVimCommandProviderPrivate *priv = GB_VIM_COMMAND_PROVIDER (object)->priv;
+
+ g_clear_object (&priv->settings);
+
+ G_OBJECT_CLASS (gb_vim_command_provider_parent_class)->finalize (object);
+}
+
+static void
+gb_vim_command_provider_class_init (GbVimCommandProviderClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GbCommandProviderClass *provider_class = GB_COMMAND_PROVIDER_CLASS (klass);
+
+ object_class->finalize = gb_vim_command_provider_finalize;
+
+ provider_class->create = gb_vim_command_provider_create;
+}
+
+static void
+gb_vim_command_provider_init (GbVimCommandProvider *self)
+{
+ self->priv = gb_vim_command_provider_get_instance_private (self);
+
+ self->priv->settings = g_settings_new ("org.gnome.builder.editor");
+
+ gb_command_provider_set_id (GB_COMMAND_PROVIDER (self), "vim");
+ gb_command_provider_set_name (GB_COMMAND_PROVIDER (self), "VIM");
+}
diff --git a/src/commands/gb-vim-command-provider.h b/src/commands/gb-vim-command-provider.h
new file mode 100644
index 0000000..8307624
--- /dev/null
+++ b/src/commands/gb-vim-command-provider.h
@@ -0,0 +1,56 @@
+/* gb-vim-command-provider.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_VIM_COMMAND_PROVIDER_H
+#define GB_VIM_COMMAND_PROVIDER_H
+
+#include "gb-command-provider.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_VIM_COMMAND_PROVIDER (gb_vim_command_provider_get_type())
+#define GB_VIM_COMMAND_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_VIM_COMMAND_PROVIDER, GbVimCommandProvider))
+#define GB_VIM_COMMAND_PROVIDER_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_VIM_COMMAND_PROVIDER, GbVimCommandProvider const))
+#define GB_VIM_COMMAND_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GB_TYPE_VIM_COMMAND_PROVIDER, GbVimCommandProviderClass))
+#define GB_IS_VIM_COMMAND_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GB_TYPE_VIM_COMMAND_PROVIDER))
+#define GB_IS_VIM_COMMAND_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GB_TYPE_VIM_COMMAND_PROVIDER))
+#define GB_VIM_COMMAND_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GB_TYPE_VIM_COMMAND_PROVIDER, GbVimCommandProviderClass))
+
+typedef struct _GbVimCommandProvider GbVimCommandProvider;
+typedef struct _GbVimCommandProviderClass GbVimCommandProviderClass;
+typedef struct _GbVimCommandProviderPrivate GbVimCommandProviderPrivate;
+
+struct _GbVimCommandProvider
+{
+ GbCommandProvider parent;
+
+ /*< private >*/
+ GbVimCommandProviderPrivate *priv;
+};
+
+struct _GbVimCommandProviderClass
+{
+ GbCommandProviderClass parent;
+};
+
+GType gb_vim_command_provider_get_type (void) G_GNUC_CONST;
+GbCommandProvider *gb_vim_command_provider_new (void);
+
+G_END_DECLS
+
+#endif /* GB_VIM_COMMAND_PROVIDER_H */
diff --git a/src/commands/gb-vim-command.c b/src/commands/gb-vim-command.c
new file mode 100644
index 0000000..8abc8d5
--- /dev/null
+++ b/src/commands/gb-vim-command.c
@@ -0,0 +1,169 @@
+/* gb-vim-command.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gb-editor-tab-private.h"
+#include "gb-editor-workspace.h"
+#include "gb-vim-command.h"
+
+struct _GbVimCommandPrivate
+{
+ gchar *command_text;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbVimCommand, gb_vim_command, GB_TYPE_COMMAND)
+
+enum {
+ PROP_0,
+ PROP_COMMAND_TEXT,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+GbCommand *
+gb_vim_command_new (const gchar *command_text)
+{
+ return g_object_new (GB_TYPE_VIM_COMMAND,
+ "command-text", command_text,
+ NULL);
+}
+
+const gchar *
+gb_vim_command_get_command_text (GbVimCommand *command)
+{
+ g_return_val_if_fail (GB_IS_VIM_COMMAND (command), NULL);
+
+ return command->priv->command_text;
+}
+
+void
+gb_vim_command_set_command_text (GbVimCommand *command,
+ const gchar *command_text)
+{
+ g_return_if_fail (GB_IS_VIM_COMMAND (command));
+
+ if (command->priv->command_text != command_text)
+ {
+ g_free (command->priv->command_text);
+ command->priv->command_text = g_strdup (command_text);
+ g_object_notify_by_pspec (G_OBJECT (command),
+ gParamSpecs [PROP_COMMAND_TEXT]);
+ }
+}
+
+static GbCommandTask *
+gb_vim_command_execute (GbCommand *command,
+ GVariant *parameters,
+ GbWorkbench *workbench)
+{
+ GbVimCommand *self = (GbVimCommand *)command;
+ GbWorkspace *workspace;
+ GbEditorTab *tab;
+
+ g_return_val_if_fail (GB_IS_VIM_COMMAND (command), NULL);
+ g_return_val_if_fail (GB_IS_WORKBENCH (workbench), NULL);
+
+ workspace = gb_workbench_get_workspace (workbench, GB_TYPE_EDITOR_WORKSPACE);
+ tab = gb_editor_workspace_get_active_tab (GB_EDITOR_WORKSPACE (workspace));
+
+ if (tab->priv->vim && self->priv->command_text)
+ gb_editor_vim_execute_command (tab->priv->vim, self->priv->command_text);
+
+ return NULL;
+}
+
+
+static void
+gb_vim_command_finalize (GObject *object)
+{
+ GbVimCommandPrivate *priv = GB_VIM_COMMAND (object)->priv;
+
+ g_clear_pointer (&priv->command_text, g_free);
+
+ G_OBJECT_CLASS (gb_vim_command_parent_class)->finalize (object);
+}
+
+static void
+gb_vim_command_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbVimCommand *self = GB_VIM_COMMAND (object);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND_TEXT:
+ g_value_set_string (value, gb_vim_command_get_command_text (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_vim_command_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbVimCommand *self = GB_VIM_COMMAND (object);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND_TEXT:
+ gb_vim_command_set_command_text (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_vim_command_class_init (GbVimCommandClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GbCommandClass *command_class = GB_COMMAND_CLASS (klass);
+
+ object_class->finalize = gb_vim_command_finalize;
+ object_class->get_property = gb_vim_command_get_property;
+ object_class->set_property = gb_vim_command_set_property;
+
+ command_class->execute = gb_vim_command_execute;
+
+ gParamSpecs [PROP_COMMAND_TEXT] =
+ g_param_spec_string ("command-text",
+ _("Command Text"),
+ _("The command text to execute."),
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_COMMAND_TEXT,
+ gParamSpecs [PROP_COMMAND_TEXT]);
+}
+
+static void
+gb_vim_command_init (GbVimCommand *self)
+{
+ self->priv = gb_vim_command_get_instance_private (self);
+}
diff --git a/src/commands/gb-vim-command.h b/src/commands/gb-vim-command.h
new file mode 100644
index 0000000..0bbcbca
--- /dev/null
+++ b/src/commands/gb-vim-command.h
@@ -0,0 +1,56 @@
+/* gb-vim-command.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_VIM_COMMAND_H
+#define GB_VIM_COMMAND_H
+
+#include "gb-command.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_VIM_COMMAND (gb_vim_command_get_type())
+#define GB_VIM_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_VIM_COMMAND,
GbVimCommand))
+#define GB_VIM_COMMAND_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_VIM_COMMAND, GbVimCommand
const))
+#define GB_VIM_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GB_TYPE_VIM_COMMAND,
GbVimCommandClass))
+#define GB_IS_VIM_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GB_TYPE_VIM_COMMAND))
+#define GB_IS_VIM_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GB_TYPE_VIM_COMMAND))
+#define GB_VIM_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GB_TYPE_VIM_COMMAND,
GbVimCommandClass))
+
+typedef struct _GbVimCommand GbVimCommand;
+typedef struct _GbVimCommandClass GbVimCommandClass;
+typedef struct _GbVimCommandPrivate GbVimCommandPrivate;
+
+struct _GbVimCommand
+{
+ GbCommand parent;
+
+ /*< private >*/
+ GbVimCommandPrivate *priv;
+};
+
+struct _GbVimCommandClass
+{
+ GbCommandClass parent;
+};
+
+GType gb_vim_command_get_type (void) G_GNUC_CONST;
+GbCommand *gb_vim_command_new (const gchar *command_text);
+
+G_END_DECLS
+
+#endif /* GB_VIM_COMMAND_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 4fd4c6c..e300743 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -27,6 +27,10 @@ libgnome_builder_la_SOURCES = \
src/commands/gb-python-command.h \
src/commands/gb-python-command-provider.c \
src/commands/gb-python-command-provider.h \
+ src/commands/gb-vim-command.c \
+ src/commands/gb-vim-command.h \
+ src/commands/gb-vim-command-provider.c \
+ src/commands/gb-vim-command-provider.h \
src/devhelp/gb-devhelp-navigation-item.c \
src/devhelp/gb-devhelp-navigation-item.h \
src/devhelp/gb-devhelp-tab.c \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]