[gnome-builder/wip/gtk4-port: 384/1774] plugins/vim: start wiring up vim support from sourceview
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 384/1774] plugins/vim: start wiring up vim support from sourceview
- Date: Mon, 11 Jul 2022 22:31:10 +0000 (UTC)
commit 980ae70f683ac0461ee25b61d33ca6666b6dc0cd
Author: Christian Hergert <chergert redhat com>
Date: Mon Apr 4 20:40:17 2022 -0700
plugins/vim: start wiring up vim support from sourceview
src/plugins/vim/gbp-vim-editor-page-addin.c | 174 ++++++++++++++++++++++++++++
src/plugins/vim/gbp-vim-editor-page-addin.h | 31 +++++
src/plugins/vim/gbp-vim-workspace-addin.c | 132 +++++++++++++++++++++
src/plugins/vim/gbp-vim-workspace-addin.h | 36 ++++++
src/plugins/vim/meson.build | 2 +
src/plugins/vim/vim-plugin.c | 9 ++
src/plugins/vim/vim.plugin | 1 +
7 files changed, 385 insertions(+)
---
diff --git a/src/plugins/vim/gbp-vim-editor-page-addin.c b/src/plugins/vim/gbp-vim-editor-page-addin.c
new file mode 100644
index 000000000..9ce7ab424
--- /dev/null
+++ b/src/plugins/vim/gbp-vim-editor-page-addin.c
@@ -0,0 +1,174 @@
+/* gbp-vim-editor-page-addin.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-vim-editor-page-addin"
+
+#include "config.h"
+
+#include <libide-gui.h>
+#include <libide-editor.h>
+
+#include "gbp-vim-editor-page-addin.h"
+#include "gbp-vim-workspace-addin.h"
+
+struct _GbpVimEditorPageAddin
+{
+ GObject parent_instance;
+ IdeEditorPage *page;
+ GbpVimWorkspaceAddin *workspace_addin;
+};
+
+static void
+gbp_vim_editor_page_addin_update (GbpVimEditorPageAddin *self)
+{
+ IdeWorkspaceAddin *workspace_addin;
+ IdeWorkspace *workspace;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_EDITOR_PAGE_ADDIN (self));
+ g_assert (IDE_IS_EDITOR_PAGE (self->page));
+
+ self->workspace_addin = NULL;
+
+ workspace = ide_widget_get_workspace (GTK_WIDGET (self->page));
+ workspace_addin = ide_workspace_addin_find_by_module_name (workspace, "vim");
+
+ if (workspace_addin == NULL || !GBP_IS_VIM_WORKSPACE_ADDIN (workspace_addin))
+ IDE_GOTO (failure);
+
+ self->workspace_addin = GBP_VIM_WORKSPACE_ADDIN (workspace_addin);
+
+failure:
+ IDE_EXIT;
+}
+
+static void
+notify_command_bar_text_cb (GbpVimEditorPageAddin *self,
+ GParamSpec *pspec,
+ GtkSourceVimIMContext *im_context)
+{
+ const char *command_bar;
+
+ g_assert (GBP_IS_VIM_EDITOR_PAGE_ADDIN (self));
+ g_assert (GTK_SOURCE_IS_VIM_IM_CONTEXT (im_context));
+
+ command_bar = gtk_source_vim_im_context_get_command_bar_text (im_context);
+
+ if (self->workspace_addin)
+ gbp_vim_workspace_addin_set_command_bar (self->workspace_addin, command_bar);
+}
+
+static void
+notify_command_text_cb (GbpVimEditorPageAddin *self,
+ GParamSpec *pspec,
+ GtkSourceVimIMContext *im_context)
+{
+ const char *command;
+
+ g_assert (GBP_IS_VIM_EDITOR_PAGE_ADDIN (self));
+ g_assert (GTK_SOURCE_IS_VIM_IM_CONTEXT (im_context));
+
+ command = gtk_source_vim_im_context_get_command_text (im_context);
+
+ if (self->workspace_addin)
+ gbp_vim_workspace_addin_set_command (self->workspace_addin, command);
+}
+
+static void
+gbp_vim_editor_page_addin_load (IdeEditorPageAddin *addin,
+ IdeEditorPage *page)
+{
+ GbpVimEditorPageAddin *self = (GbpVimEditorPageAddin *)addin;
+ GtkEventController *key;
+ IdeSourceView *view;
+ GtkIMContext *im_context;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_EDITOR_PAGE_ADDIN (self));
+ g_assert (IDE_IS_EDITOR_PAGE (page));
+
+ self->page = page;
+
+ gbp_vim_editor_page_addin_update (self);
+
+ view = ide_editor_page_get_view (page);
+ key = gtk_event_controller_key_new ();
+ im_context = gtk_source_vim_im_context_new ();
+ gtk_im_context_set_client_widget (im_context, GTK_WIDGET (view));
+ gtk_event_controller_set_propagation_phase (key, GTK_PHASE_CAPTURE);
+ gtk_event_controller_key_set_im_context (GTK_EVENT_CONTROLLER_KEY (key), im_context);
+ gtk_widget_add_controller (GTK_WIDGET (view), key);
+
+ /* TODO: Make this toggleable via GSettings, and bind a property from
+ * the workspace addin to enable this.
+ */
+
+ g_signal_connect_object (im_context,
+ "notify::command-bar-text",
+ G_CALLBACK (notify_command_bar_text_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (im_context,
+ "notify::command-text",
+ G_CALLBACK (notify_command_text_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_object_unref (im_context);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_vim_editor_page_addin_unload (IdeEditorPageAddin *addin,
+ IdeEditorPage *page)
+{
+ GbpVimEditorPageAddin *self = (GbpVimEditorPageAddin *)addin;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_EDITOR_PAGE_ADDIN (self));
+ g_assert (IDE_IS_EDITOR_PAGE (page));
+
+ IDE_EXIT;
+}
+
+static void
+editor_page_addin_iface_init (IdeEditorPageAddinInterface *iface)
+{
+ iface->load = gbp_vim_editor_page_addin_load;
+ iface->unload = gbp_vim_editor_page_addin_unload;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpVimEditorPageAddin, gbp_vim_editor_page_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_PAGE_ADDIN,
editor_page_addin_iface_init))
+
+static void
+gbp_vim_editor_page_addin_class_init (GbpVimEditorPageAddinClass *klass)
+{
+}
+
+static void
+gbp_vim_editor_page_addin_init (GbpVimEditorPageAddin *self)
+{
+}
diff --git a/src/plugins/vim/gbp-vim-editor-page-addin.h b/src/plugins/vim/gbp-vim-editor-page-addin.h
new file mode 100644
index 000000000..d7edc9b78
--- /dev/null
+++ b/src/plugins/vim/gbp-vim-editor-page-addin.h
@@ -0,0 +1,31 @@
+/* gbp-vim-editor-page-addin.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_VIM_EDITOR_PAGE_ADDIN (gbp_vim_editor_page_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpVimEditorPageAddin, gbp_vim_editor_page_addin, GBP, VIM_EDITOR_PAGE_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/vim/gbp-vim-workspace-addin.c b/src/plugins/vim/gbp-vim-workspace-addin.c
new file mode 100644
index 000000000..a30b12c35
--- /dev/null
+++ b/src/plugins/vim/gbp-vim-workspace-addin.c
@@ -0,0 +1,132 @@
+/* gbp-vim-workspace-addin.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-vim-workspace-addin"
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <libpanel.h>
+
+#include <libide-gui.h>
+
+#include "gbp-vim-workspace-addin.h"
+
+struct _GbpVimWorkspaceAddin
+{
+ GObject parent_instance;
+
+ GtkLabel *command_bar;
+ GtkLabel *command;
+};
+
+static void
+gbp_vim_workspace_addin_load (IdeWorkspaceAddin *addin,
+ IdeWorkspace *workspace)
+{
+ GbpVimWorkspaceAddin *self = (GbpVimWorkspaceAddin *)addin;
+ PanelStatusbar *statusbar;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_WORKSPACE_ADDIN (self));
+ g_assert (IDE_IS_WORKSPACE (workspace));
+
+ self->command_bar = g_object_new (GTK_TYPE_LABEL,
+ "hexpand", TRUE,
+ "selectable", TRUE,
+ "xalign", .0f,
+ NULL);
+ self->command = g_object_new (GTK_TYPE_LABEL,
+ "xalign", 1.f,
+ "visible", FALSE,
+ NULL);
+
+ statusbar = ide_workspace_get_statusbar (workspace);
+
+ /* TODO: priorities for packing */
+ panel_statusbar_add_prefix (statusbar, GTK_WIDGET (self->command_bar));
+ panel_statusbar_add_prefix (statusbar, GTK_WIDGET (self->command));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_vim_workspace_addin_unload (IdeWorkspaceAddin *addin,
+ IdeWorkspace *workspace)
+{
+ GbpVimWorkspaceAddin *self = (GbpVimWorkspaceAddin *)addin;
+ PanelStatusbar *statusbar;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_WORKSPACE_ADDIN (self));
+ g_assert (IDE_IS_WORKSPACE (workspace));
+
+ statusbar = ide_workspace_get_statusbar (workspace);
+
+ panel_statusbar_remove (statusbar, GTK_WIDGET (self->command_bar));
+ panel_statusbar_remove (statusbar, GTK_WIDGET (self->command));
+
+ self->command_bar = NULL;
+ self->command = NULL;
+
+ IDE_EXIT;
+}
+
+static void
+workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface)
+{
+ iface->load = gbp_vim_workspace_addin_load;
+ iface->unload = gbp_vim_workspace_addin_unload;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpVimWorkspaceAddin, gbp_vim_workspace_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKSPACE_ADDIN, workspace_addin_iface_init))
+
+static void
+gbp_vim_workspace_addin_class_init (GbpVimWorkspaceAddinClass *klass)
+{
+}
+
+static void
+gbp_vim_workspace_addin_init (GbpVimWorkspaceAddin *self)
+{
+}
+
+void
+gbp_vim_workspace_addin_set_command (GbpVimWorkspaceAddin *self,
+ const char *command)
+{
+ g_return_if_fail (GBP_IS_VIM_WORKSPACE_ADDIN (self));
+
+ gtk_label_set_label (self->command, command);
+ gtk_widget_set_visible (GTK_WIDGET (self->command), command && *command);
+}
+
+void
+gbp_vim_workspace_addin_set_command_bar (GbpVimWorkspaceAddin *self,
+ const char *command_bar)
+{
+ g_return_if_fail (GBP_IS_VIM_WORKSPACE_ADDIN (self));
+
+ if (self->command_bar != NULL)
+ gtk_label_set_label (self->command_bar, command_bar);
+}
diff --git a/src/plugins/vim/gbp-vim-workspace-addin.h b/src/plugins/vim/gbp-vim-workspace-addin.h
new file mode 100644
index 000000000..d4a8bd700
--- /dev/null
+++ b/src/plugins/vim/gbp-vim-workspace-addin.h
@@ -0,0 +1,36 @@
+/* gbp-vim-workspace-addin.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_VIM_WORKSPACE_ADDIN (gbp_vim_workspace_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpVimWorkspaceAddin, gbp_vim_workspace_addin, GBP, VIM_WORKSPACE_ADDIN, GObject)
+
+void gbp_vim_workspace_addin_set_command (GbpVimWorkspaceAddin *self,
+ const char *command);
+void gbp_vim_workspace_addin_set_command_bar (GbpVimWorkspaceAddin *self,
+ const char *command_bar);
+
+G_END_DECLS
diff --git a/src/plugins/vim/meson.build b/src/plugins/vim/meson.build
index ec147497c..8fdfd0080 100644
--- a/src/plugins/vim/meson.build
+++ b/src/plugins/vim/meson.build
@@ -1,6 +1,8 @@
plugins_sources += files([
'vim-plugin.c',
+ 'gbp-vim-editor-page-addin.c',
'gbp-vim-preferences-addin.c',
+ 'gbp-vim-workspace-addin.c',
])
plugin_vim_resources = gnome.compile_resources(
diff --git a/src/plugins/vim/vim-plugin.c b/src/plugins/vim/vim-plugin.c
index d35b539e3..417836cd2 100644
--- a/src/plugins/vim/vim-plugin.c
+++ b/src/plugins/vim/vim-plugin.c
@@ -26,13 +26,22 @@
#include <libide-core.h>
#include <libide-gui.h>
+#include <libide-editor.h>
+#include "gbp-vim-editor-page-addin.h"
#include "gbp-vim-preferences-addin.h"
+#include "gbp-vim-workspace-addin.h"
_IDE_EXTERN void
_gbp_vim_register_types (PeasObjectModule *module)
{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_EDITOR_PAGE_ADDIN,
+ GBP_TYPE_VIM_EDITOR_PAGE_ADDIN);
peas_object_module_register_extension_type (module,
IDE_TYPE_PREFERENCES_ADDIN,
GBP_TYPE_VIM_PREFERENCES_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_WORKSPACE_ADDIN,
+ GBP_TYPE_VIM_WORKSPACE_ADDIN);
}
diff --git a/src/plugins/vim/vim.plugin b/src/plugins/vim/vim.plugin
index c134f97c6..b1b550fa3 100644
--- a/src/plugins/vim/vim.plugin
+++ b/src/plugins/vim/vim.plugin
@@ -6,3 +6,4 @@ Description=Emulation of various VIM features
Embedded=_gbp_vim_register_types
Module=vim
Name=VIM Emulation
+X-Workspace-Kind=editor;primary;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]