[gnome-builder: 129/139] todo: port to libide-gui and libide-editor



commit b6ec41d4c0d4db2471ee97d68ef2a4d0d40bcc1c
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:41:24 2019 -0800

    todo: port to libide-gui and libide-editor

 src/plugins/todo/gbp-todo-model.c                  |  5 +-
 src/plugins/todo/gbp-todo-model.h                  |  3 +-
 src/plugins/todo/gbp-todo-panel.c                  | 26 +++---
 src/plugins/todo/gbp-todo-panel.h                  |  2 +-
 ...orkbench-addin.c => gbp-todo-workspace-addin.c} | 98 +++++++++++-----------
 ...orkbench-addin.h => gbp-todo-workspace-addin.h} |  8 +-
 src/plugins/todo/meson.build                       | 27 +++---
 .../todo/{gbp-todo-plugin.c => todo-plugin.c}      | 16 ++--
 src/plugins/todo/todo.gresource.xml                |  2 +-
 src/plugins/todo/todo.plugin                       | 13 +--
 10 files changed, 100 insertions(+), 100 deletions(-)
---
diff --git a/src/plugins/todo/gbp-todo-model.c b/src/plugins/todo/gbp-todo-model.c
index fe879f826..438db3091 100644
--- a/src/plugins/todo/gbp-todo-model.c
+++ b/src/plugins/todo/gbp-todo-model.c
@@ -20,7 +20,8 @@
 
 #define G_LOG_DOMAIN "gbp-todo-model"
 
-#include <ide.h>
+#include <libide-code.h>
+#include <libide-gui.h>
 #include <string.h>
 
 #include "gbp-todo-model.h"
@@ -668,7 +669,7 @@ gbp_todo_model_mine_async (GbpTodoModel        *self,
       return;
     }
 
-  workdir = ide_vcs_get_working_directory (self->vcs);
+  workdir = ide_vcs_get_workdir (self->vcs);
 
   m = g_slice_new0 (Mine);
   m->file = g_object_ref (file);
diff --git a/src/plugins/todo/gbp-todo-model.h b/src/plugins/todo/gbp-todo-model.h
index 210eeafa8..95e04ea79 100644
--- a/src/plugins/todo/gbp-todo-model.h
+++ b/src/plugins/todo/gbp-todo-model.h
@@ -20,7 +20,8 @@
 
 #pragma once
 
-#include <ide.h>
+#include <gtk/gtk.h>
+#include <libide-vcs.h>
 
 G_BEGIN_DECLS
 
diff --git a/src/plugins/todo/gbp-todo-panel.c b/src/plugins/todo/gbp-todo-panel.c
index 04e90c2c8..02bb1fc06 100644
--- a/src/plugins/todo/gbp-todo-panel.c
+++ b/src/plugins/todo/gbp-todo-panel.c
@@ -21,7 +21,8 @@
 #define G_LOG_DOMAIN "gbp-todo-panel"
 
 #include <glib/gi18n.h>
-#include <ide.h>
+#include <libide-code.h>
+#include <libide-gui.h>
 
 #include "gbp-todo-item.h"
 #include "gbp-todo-panel.h"
@@ -96,7 +97,6 @@ gbp_todo_panel_row_activated (GbpTodoPanel      *self,
 {
   g_autoptr(GbpTodoItem) item = NULL;
   g_autoptr(GFile) file = NULL;
-  g_autoptr(IdeUri) uri = NULL;
   g_autofree gchar *fragment = NULL;
   IdeWorkbench *workbench;
   GtkTreeModel *model;
@@ -130,26 +130,26 @@ gbp_todo_panel_row_activated (GbpTodoPanel      *self,
       GFile *workdir;
 
       context = ide_workbench_get_context (workbench);
-      vcs = ide_context_get_vcs (context);
-      workdir = ide_vcs_get_working_directory (vcs);
+      vcs = ide_vcs_from_context (context);
+      workdir = ide_vcs_get_workdir (vcs);
       file = g_file_get_child (workdir, path);
     }
 
-  uri = ide_uri_new_from_file (file);
-
-  /* Set lineno info so that the editor can jump
-   * to the location of the TODO item. Our line number
-   * from the model is 1-based, and we need 0-based for
+  /* Set lineno info so that the editor can jump to the location of the TODO
+   * item. Our line number from the model is 1-based, and we need 0-based for
    * our API to open files.
    */
   lineno = gbp_todo_item_get_lineno (item);
   if (lineno > 0)
     lineno--;
 
-  fragment = g_strdup_printf ("L%u", lineno);
-  ide_uri_set_fragment (uri, fragment);
-
-  ide_workbench_open_uri_async (workbench, uri, "editor", 0, NULL, NULL, NULL);
+  ide_workbench_open_at_async (workbench,
+                               file,
+                               "editor",
+                               lineno,
+                               -1,
+                               IDE_BUFFER_OPEN_FLAGS_NONE,
+                               NULL, NULL, NULL);
 }
 
 static gboolean
diff --git a/src/plugins/todo/gbp-todo-panel.h b/src/plugins/todo/gbp-todo-panel.h
index 6dcdf2ec0..5da1addce 100644
--- a/src/plugins/todo/gbp-todo-panel.h
+++ b/src/plugins/todo/gbp-todo-panel.h
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include <ide.h>
+#include <dazzle.h>
 
 #include "gbp-todo-model.h"
 
diff --git a/src/plugins/todo/gbp-todo-workbench-addin.c b/src/plugins/todo/gbp-todo-workspace-addin.c
similarity index 62%
rename from src/plugins/todo/gbp-todo-workbench-addin.c
rename to src/plugins/todo/gbp-todo-workspace-addin.c
index 999c129aa..3931eeffd 100644
--- a/src/plugins/todo/gbp-todo-workbench-addin.c
+++ b/src/plugins/todo/gbp-todo-workspace-addin.c
@@ -1,4 +1,4 @@
-/* gbp-todo-workbench-addin.c
+/* gbp-todo-workspace-addin.c
  *
  * Copyright 2017-2019 Christian Hergert <chergert redhat com>
  *
@@ -18,14 +18,15 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#define G_LOG_DOMAIN "gbp-todo-workbench-addin"
+#define G_LOG_DOMAIN "gbp-todo-workspace-addin"
 
+#include <libide-editor.h>
 #include <glib/gi18n.h>
 
-#include "gbp-todo-workbench-addin.h"
+#include "gbp-todo-workspace-addin.h"
 #include "gbp-todo-panel.h"
 
-struct _GbpTodoWorkbenchAddin
+struct _GbpTodoWorkspaceAddin
 {
   GObject       parent_instance;
 
@@ -39,15 +40,15 @@ struct _GbpTodoWorkbenchAddin
 };
 
 static void
-gbp_todo_workbench_addin_mine_cb (GObject      *object,
+gbp_todo_workspace_addin_mine_cb (GObject      *object,
                                   GAsyncResult *result,
                                   gpointer      user_data)
 {
   GbpTodoModel *model = (GbpTodoModel *)object;
-  g_autoptr(GbpTodoWorkbenchAddin) self = user_data;
+  g_autoptr(GbpTodoWorkspaceAddin) self = user_data;
   g_autoptr(GError) error = NULL;
 
-  g_assert (GBP_IS_TODO_WORKBENCH_ADDIN (self));
+  g_assert (GBP_IS_TODO_WORKSPACE_ADDIN (self));
   g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (GBP_IS_TODO_MODEL (model));
 
@@ -55,17 +56,17 @@ gbp_todo_workbench_addin_mine_cb (GObject      *object,
   self->is_global_mining = FALSE;
 
   if (!gbp_todo_model_mine_finish (model, result, &error))
-    ide_widget_warning (self->panel, "todo: %s", error->message);
+    g_warning ("todo: %s", error->message);
 
   if (self->panel != NULL)
     gbp_todo_panel_make_ready (self->panel);
 }
 
 static void
-gbp_todo_workbench_addin_presented_cb (GbpTodoWorkbenchAddin *self,
+gbp_todo_workspace_addin_presented_cb (GbpTodoWorkspaceAddin *self,
                                        GbpTodoPanel          *panel)
 {
-  g_assert (GBP_IS_TODO_WORKBENCH_ADDIN (self));
+  g_assert (GBP_IS_TODO_WORKSPACE_ADDIN (self));
   g_assert (GBP_IS_TODO_PANEL (panel));
 
   if (self->has_presented)
@@ -77,19 +78,18 @@ gbp_todo_workbench_addin_presented_cb (GbpTodoWorkbenchAddin *self,
   gbp_todo_model_mine_async (self->model,
                              self->workdir,
                              self->cancellable,
-                             gbp_todo_workbench_addin_mine_cb,
+                             gbp_todo_workspace_addin_mine_cb,
                              g_object_ref (self));
 }
 
 static void
-gbp_todo_workbench_addin_buffer_saved (GbpTodoWorkbenchAddin *self,
+gbp_todo_workspace_addin_buffer_saved (GbpTodoWorkspaceAddin *self,
                                        IdeBuffer             *buffer,
                                        IdeBufferManager      *bufmgr)
 {
-  IdeFile *file;
-  GFile *gfile;
+  GFile *file;
 
-  g_assert (GBP_IS_TODO_WORKBENCH_ADDIN (self));
+  g_assert (GBP_IS_TODO_WORKSPACE_ADDIN (self));
   g_assert (self->model != NULL);
   g_assert (IDE_IS_BUFFER (buffer));
   g_assert (IDE_IS_BUFFER_MANAGER (bufmgr));
@@ -98,43 +98,42 @@ gbp_todo_workbench_addin_buffer_saved (GbpTodoWorkbenchAddin *self,
     return;
 
   file = ide_buffer_get_file (buffer);
-  gfile = ide_file_get_file (file);
   gbp_todo_model_mine_async (self->model,
-                             gfile,
+                             file,
                              self->cancellable,
-                             gbp_todo_workbench_addin_mine_cb,
+                             gbp_todo_workspace_addin_mine_cb,
                              g_object_ref (self));
 }
 
 static void
-gbp_todo_workbench_addin_load (IdeWorkbenchAddin *addin,
-                               IdeWorkbench      *workbench)
+gbp_todo_workspace_addin_load (IdeWorkspaceAddin *addin,
+                               IdeWorkspace      *workspace)
 {
-  GbpTodoWorkbenchAddin *self = (GbpTodoWorkbenchAddin *)addin;
+  GbpTodoWorkspaceAddin *self = (GbpTodoWorkspaceAddin *)addin;
   IdeEditorSidebar *sidebar;
   IdeBufferManager *bufmgr;
-  IdePerspective *editor;
+  IdeSurface *editor;
   IdeContext *context;
   IdeVcs *vcs;
   GFile *workdir;
 
-  g_assert (GBP_IS_TODO_WORKBENCH_ADDIN (self));
-  g_assert (IDE_IS_WORKBENCH (workbench));
+  g_assert (GBP_IS_TODO_WORKSPACE_ADDIN (self));
+  g_assert (IDE_IS_WORKSPACE (workspace));
 
   self->cancellable = g_cancellable_new ();
 
-  context = ide_workbench_get_context (workbench);
-  vcs = ide_context_get_vcs (context);
-  workdir = ide_vcs_get_working_directory (vcs);
-  bufmgr = ide_context_get_buffer_manager (context);
-  editor = ide_workbench_get_perspective_by_name (workbench, "editor");
-  sidebar = ide_editor_perspective_get_sidebar (IDE_EDITOR_PERSPECTIVE (editor));
+  context = ide_workspace_get_context (workspace);
+  vcs = ide_vcs_from_context (context);
+  workdir = ide_vcs_get_workdir (vcs);
+  bufmgr = ide_buffer_manager_from_context (context);
+  editor = ide_workspace_get_surface_by_name (workspace, "editor");
+  sidebar = ide_editor_surface_get_sidebar (IDE_EDITOR_SURFACE (editor));
 
   self->workdir = g_object_ref (workdir);
 
   g_signal_connect_object (bufmgr,
                            "buffer-saved",
-                           G_CALLBACK (gbp_todo_workbench_addin_buffer_saved),
+                           G_CALLBACK (gbp_todo_workspace_addin_buffer_saved),
                            self,
                            G_CONNECT_SWAPPED);
 
@@ -146,7 +145,7 @@ gbp_todo_workbench_addin_load (IdeWorkbenchAddin *addin,
                               NULL);
   g_signal_connect_object (self->panel,
                            "presented",
-                           G_CALLBACK (gbp_todo_workbench_addin_presented_cb),
+                           G_CALLBACK (gbp_todo_workspace_addin_presented_cb),
                            self,
                            G_CONNECT_SWAPPED);
   g_signal_connect (self->panel,
@@ -163,27 +162,28 @@ gbp_todo_workbench_addin_load (IdeWorkbenchAddin *addin,
 }
 
 static void
-gbp_todo_workbench_addin_unload (IdeWorkbenchAddin *addin,
-                                 IdeWorkbench      *workbench)
+gbp_todo_workspace_addin_unload (IdeWorkspaceAddin *addin,
+                                 IdeWorkspace      *workspace)
 {
-  GbpTodoWorkbenchAddin *self = (GbpTodoWorkbenchAddin *)addin;
+  GbpTodoWorkspaceAddin *self = (GbpTodoWorkspaceAddin *)addin;
   IdeBufferManager *bufmgr;
   IdeContext *context;
 
-  g_assert (GBP_IS_TODO_WORKBENCH_ADDIN (self));
-  g_assert (IDE_IS_WORKBENCH (workbench));
+  g_assert (GBP_IS_TODO_WORKSPACE_ADDIN (self));
+  g_assert (IDE_IS_WORKSPACE (workspace));
 
   g_cancellable_cancel (self->cancellable);
   g_clear_object (&self->cancellable);
 
-  context = ide_workbench_get_context (workbench);
-  bufmgr = ide_context_get_buffer_manager (context);
+  context = ide_widget_get_context (GTK_WIDGET (workspace));
+  bufmgr = ide_buffer_manager_from_context (context);
 
   g_signal_handlers_disconnect_by_func (bufmgr,
-                                        G_CALLBACK (gbp_todo_workbench_addin_buffer_saved),
+                                        G_CALLBACK (gbp_todo_workspace_addin_buffer_saved),
                                         self);
 
-  gtk_widget_destroy (GTK_WIDGET (self->panel));
+  if (self->panel != NULL)
+    gtk_widget_destroy (GTK_WIDGET (self->panel));
 
   g_assert (self->panel == NULL);
 
@@ -192,22 +192,22 @@ gbp_todo_workbench_addin_unload (IdeWorkbenchAddin *addin,
 }
 
 static void
-workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
+workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface)
 {
-  iface->load = gbp_todo_workbench_addin_load;
-  iface->unload = gbp_todo_workbench_addin_unload;
+  iface->load = gbp_todo_workspace_addin_load;
+  iface->unload = gbp_todo_workspace_addin_unload;
 }
 
-G_DEFINE_TYPE_WITH_CODE (GbpTodoWorkbenchAddin, gbp_todo_workbench_addin, G_TYPE_OBJECT,
-                         G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN,
-                                                workbench_addin_iface_init))
+G_DEFINE_TYPE_WITH_CODE (GbpTodoWorkspaceAddin, gbp_todo_workspace_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKSPACE_ADDIN,
+                                                workspace_addin_iface_init))
 
 static void
-gbp_todo_workbench_addin_class_init (GbpTodoWorkbenchAddinClass *klass)
+gbp_todo_workspace_addin_class_init (GbpTodoWorkspaceAddinClass *klass)
 {
 }
 
 static void
-gbp_todo_workbench_addin_init (GbpTodoWorkbenchAddin *self)
+gbp_todo_workspace_addin_init (GbpTodoWorkspaceAddin *self)
 {
 }
diff --git a/src/plugins/todo/gbp-todo-workbench-addin.h b/src/plugins/todo/gbp-todo-workspace-addin.h
similarity index 78%
rename from src/plugins/todo/gbp-todo-workbench-addin.h
rename to src/plugins/todo/gbp-todo-workspace-addin.h
index bb3de7fc0..ea1b8f930 100644
--- a/src/plugins/todo/gbp-todo-workbench-addin.h
+++ b/src/plugins/todo/gbp-todo-workspace-addin.h
@@ -1,4 +1,4 @@
-/* gbp-todo-workbench-addin.h
+/* gbp-todo-workspace-addin.h
  *
  * Copyright 2017-2019 Christian Hergert <chergert redhat com>
  *
@@ -20,12 +20,12 @@
 
 #pragma once
 
-#include <ide.h>
+#include <glib-object.h>
 
 G_BEGIN_DECLS
 
-#define GBP_TYPE_TODO_WORKBENCH_ADDIN (gbp_todo_workbench_addin_get_type())
+#define GBP_TYPE_TODO_WORKSPACE_ADDIN (gbp_todo_workspace_addin_get_type())
 
-G_DECLARE_FINAL_TYPE (GbpTodoWorkbenchAddin, gbp_todo_workbench_addin, GBP, TODO_WORKBENCH_ADDIN, GObject)
+G_DECLARE_FINAL_TYPE (GbpTodoWorkspaceAddin, gbp_todo_workspace_addin, GBP, TODO_WORKSPACE_ADDIN, GObject)
 
 G_END_DECLS
diff --git a/src/plugins/todo/meson.build b/src/plugins/todo/meson.build
index cc76a72fa..0e8b6f67a 100644
--- a/src/plugins/todo/meson.build
+++ b/src/plugins/todo/meson.build
@@ -1,24 +1,19 @@
-if get_option('with_todo')
+if get_option('plugin_todo')
 
-todo_resources = gnome.compile_resources(
+plugins_sources += files([
+  'gbp-todo-item.c',
+  'gbp-todo-model.c',
+  'gbp-todo-panel.c',
+  'gbp-todo-workspace-addin.c',
+  'todo-plugin.c',
+])
+
+plugin_todo_resources = gnome.compile_resources(
   'todo-resources',
   'todo.gresource.xml',
   c_name: 'gbp_todo',
 )
 
-todo_sources = [
-  'gbp-todo-item.c',
-  'gbp-todo-item.h',
-  'gbp-todo-model.c',
-  'gbp-todo-model.h',
-  'gbp-todo-plugin.c',
-  'gbp-todo-panel.c',
-  'gbp-todo-panel.h',
-  'gbp-todo-workbench-addin.c',
-  'gbp-todo-workbench-addin.h',
-]
-
-gnome_builder_plugins_sources += files(todo_sources)
-gnome_builder_plugins_sources += todo_resources[0]
+plugins_sources += plugin_todo_resources[0]
 
 endif
diff --git a/src/plugins/todo/gbp-todo-plugin.c b/src/plugins/todo/todo-plugin.c
similarity index 78%
rename from src/plugins/todo/gbp-todo-plugin.c
rename to src/plugins/todo/todo-plugin.c
index 84778506c..7c93c5de7 100644
--- a/src/plugins/todo/gbp-todo-plugin.c
+++ b/src/plugins/todo/todo-plugin.c
@@ -1,4 +1,4 @@
-/* gbp-todo-plugin.c
+/* todo-plugin.c
  *
  * Copyright 2015-2019 Christian Hergert <chergert redhat com>
  *
@@ -18,15 +18,17 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
+#include "config.h"
+
 #include <libpeas/peas.h>
-#include <ide.h>
+#include <libide-gui.h>
 
-#include "gbp-todo-workbench-addin.h"
+#include "gbp-todo-workspace-addin.h"
 
-void
-gbp_todo_register_types (PeasObjectModule *module)
+_IDE_EXTERN void
+_gbp_todo_register_types (PeasObjectModule *module)
 {
   peas_object_module_register_extension_type (module,
-                                              IDE_TYPE_WORKBENCH_ADDIN,
-                                              GBP_TYPE_TODO_WORKBENCH_ADDIN);
+                                              IDE_TYPE_WORKSPACE_ADDIN,
+                                              GBP_TYPE_TODO_WORKSPACE_ADDIN);
 }
diff --git a/src/plugins/todo/todo.gresource.xml b/src/plugins/todo/todo.gresource.xml
index 793c8cebd..991ecb4a8 100644
--- a/src/plugins/todo/todo.gresource.xml
+++ b/src/plugins/todo/todo.gresource.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/builder/plugins">
+  <gresource prefix="/plugins/todo">
     <file>todo.plugin</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/todo/todo.plugin b/src/plugins/todo/todo.plugin
index 580dc8c70..a249e9b6f 100644
--- a/src/plugins/todo/todo.plugin
+++ b/src/plugins/todo/todo.plugin
@@ -1,9 +1,10 @@
 [Plugin]
-Module=todo-plugin
-Name=To-Do Tracker
-Description=Find and present To-Do items from source code
 Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2015-2017 Christian Hergert
 Builtin=true
-Depends=editor
-Embedded=gbp_todo_register_types
+Copyright=Copyright © 2015-2018 Christian Hergert
+Depends=editor;
+Description=Find and present To-Do items from source code
+Embedded=_gbp_todo_register_types
+Module=todo
+Name=To-Do Tracker
+X-Workspace-Kind=primary;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]