[gnome-builder/wip/gtk4-port: 305/343] libide/gui: simplify open API




commit bb411ca974953fde7527f7a13f041ff7a5a23340
Author: Christian Hergert <chergert redhat com>
Date:   Sat Apr 2 00:54:26 2022 -0700

    libide/gui: simplify open API
    
    We can have a single open vfunc now that we're breaking ABI everywhere
    and just use that version with line & offset.

 src/libide/gui/ide-workbench-addin.c | 106 +++++------------------------------
 src/libide/gui/ide-workbench-addin.h |  23 ++------
 src/libide/gui/ide-workbench.c       |  36 ++++++------
 3 files changed, 37 insertions(+), 128 deletions(-)
---
diff --git a/src/libide/gui/ide-workbench-addin.c b/src/libide/gui/ide-workbench-addin.c
index 3876fe118..d312b86fb 100644
--- a/src/libide/gui/ide-workbench-addin.c
+++ b/src/libide/gui/ide-workbench-addin.c
@@ -26,23 +26,6 @@
 
 G_DEFINE_INTERFACE (IdeWorkbenchAddin, ide_workbench_addin, G_TYPE_OBJECT)
 
-static void ide_workbench_addin_real_open_at_async (IdeWorkbenchAddin   *self,
-                                                    GFile               *file,
-                                                    const gchar         *hint,
-                                                    gint                 at_line,
-                                                    gint                 at_line_offset,
-                                                    IdeBufferOpenFlags   flags,
-                                                    GCancellable        *cancellable,
-                                                    GAsyncReadyCallback  callback,
-                                                    gpointer             user_data);
-static void ide_workbench_addin_real_open_async    (IdeWorkbenchAddin   *self,
-                                                    GFile               *file,
-                                                    const gchar         *hint,
-                                                    IdeBufferOpenFlags   flags,
-                                                    GCancellable        *cancellable,
-                                                    GAsyncReadyCallback  callback,
-                                                    gpointer             user_data);
-
 static void
 ide_workbench_addin_real_load_project_async (IdeWorkbenchAddin   *self,
                                              IdeProjectInfo      *project_info,
@@ -91,62 +74,26 @@ static void
 ide_workbench_addin_real_open_async (IdeWorkbenchAddin   *self,
                                      GFile               *file,
                                      const gchar         *hint,
+                                     int                  at_line,
+                                     int                  at_line_offset,
                                      IdeBufferOpenFlags   flags,
                                      GCancellable        *cancellable,
                                      GAsyncReadyCallback  callback,
                                      gpointer             user_data)
 {
-  IdeWorkbenchAddinInterface *iface;
-
-  g_assert (IDE_IS_WORKBENCH_ADDIN (self));
-  g_assert (G_IS_FILE (file));
-  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
-
-  iface = IDE_WORKBENCH_ADDIN_GET_IFACE (self);
-
-  if (iface->open_at_async == (gpointer)ide_workbench_addin_real_open_at_async)
-    {
-      ide_task_report_new_error (self, callback, user_data,
-                                 ide_workbench_addin_real_open_async,
-                                 G_IO_ERROR,
-                                 G_IO_ERROR_NOT_SUPPORTED,
-                                 "Opening files is not supported");
-      return;
-    }
-
-  iface->open_at_async (self, file, hint, -1, -1, flags, cancellable, callback, user_data);
-}
-
-static void
-ide_workbench_addin_real_open_at_async (IdeWorkbenchAddin   *self,
-                                        GFile               *file,
-                                        const gchar         *hint,
-                                        gint                 at_line,
-                                        gint                 at_line_offset,
-                                        IdeBufferOpenFlags   flags,
-                                        GCancellable        *cancellable,
-                                        GAsyncReadyCallback  callback,
-                                        gpointer             user_data)
-{
-  IdeWorkbenchAddinInterface *iface;
-
   g_assert (IDE_IS_WORKBENCH_ADDIN (self));
   g_assert (G_IS_FILE (file));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  iface = IDE_WORKBENCH_ADDIN_GET_IFACE (self);
-
-  if (iface->open_async == (gpointer)ide_workbench_addin_real_open_async)
-    {
-      ide_task_report_new_error (self, callback, user_data,
-                                 ide_workbench_addin_real_open_at_async,
-                                 G_IO_ERROR,
-                                 G_IO_ERROR_NOT_SUPPORTED,
-                                 "Opening files is not supported");
-      return;
-    }
-
-  iface->open_async (self, file, hint, flags, cancellable, callback, user_data);
+  IDE_WORKBENCH_ADDIN_GET_IFACE (self)->open_async (self,
+                                                    file,
+                                                    hint,
+                                                    at_line,
+                                                    at_line_offset,
+                                                    flags,
+                                                    cancellable,
+                                                    callback,
+                                                    user_data);
 }
 
 static gboolean
@@ -165,7 +112,6 @@ ide_workbench_addin_default_init (IdeWorkbenchAddinInterface *iface)
   iface->unload_project_async = ide_workbench_addin_real_unload_project_async;
   iface->unload_project_finish = ide_workbench_addin_real_unload_project_finish;
   iface->open_async = ide_workbench_addin_real_open_async;
-  iface->open_at_async = ide_workbench_addin_real_open_at_async;
   iface->open_finish = ide_workbench_addin_real_open_finish;
 }
 
@@ -297,6 +243,8 @@ void
 ide_workbench_addin_open_async (IdeWorkbenchAddin   *self,
                                 GFile               *file,
                                 const gchar         *content_type,
+                                int                  at_line,
+                                int                  at_line_offset,
                                 IdeBufferOpenFlags   flags,
                                 GCancellable        *cancellable,
                                 GAsyncReadyCallback  callback,
@@ -309,38 +257,14 @@ ide_workbench_addin_open_async (IdeWorkbenchAddin   *self,
   IDE_WORKBENCH_ADDIN_GET_IFACE (self)->open_async (self,
                                                     file,
                                                     content_type,
+                                                    at_line,
+                                                    at_line_offset,
                                                     flags,
                                                     cancellable,
                                                     callback,
                                                     user_data);
 }
 
-void
-ide_workbench_addin_open_at_async (IdeWorkbenchAddin   *self,
-                                   GFile               *file,
-                                   const gchar         *content_type,
-                                   gint                 at_line,
-                                   gint                 at_line_offset,
-                                   IdeBufferOpenFlags   flags,
-                                   GCancellable        *cancellable,
-                                   GAsyncReadyCallback  callback,
-                                   gpointer             user_data)
-{
-  g_return_if_fail (IDE_IS_WORKBENCH_ADDIN (self));
-  g_return_if_fail (G_IS_FILE (file));
-  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
-
-  IDE_WORKBENCH_ADDIN_GET_IFACE (self)->open_at_async (self,
-                                                       file,
-                                                       content_type,
-                                                       at_line,
-                                                       at_line_offset,
-                                                       flags,
-                                                       cancellable,
-                                                       callback,
-                                                       user_data);
-}
-
 gboolean
 ide_workbench_addin_open_finish (IdeWorkbenchAddin  *self,
                                  GAsyncResult       *result,
diff --git a/src/libide/gui/ide-workbench-addin.h b/src/libide/gui/ide-workbench-addin.h
index 6453ab6ce..89d5ae601 100644
--- a/src/libide/gui/ide-workbench-addin.h
+++ b/src/libide/gui/ide-workbench-addin.h
@@ -67,15 +67,8 @@ struct _IdeWorkbenchAddinInterface
   void     (*open_async)            (IdeWorkbenchAddin     *self,
                                      GFile                 *file,
                                      const gchar           *content_type,
-                                     IdeBufferOpenFlags     flags,
-                                     GCancellable          *cancellable,
-                                     GAsyncReadyCallback    callback,
-                                     gpointer               user_data);
-  void     (*open_at_async)         (IdeWorkbenchAddin     *self,
-                                     GFile                 *file,
-                                     const gchar           *content_type,
-                                     gint                   at_line,
-                                     gint                   at_line_offset,
+                                     int                    at_line,
+                                     int                    at_line_offset,
                                      IdeBufferOpenFlags     flags,
                                      GCancellable          *cancellable,
                                      GAsyncReadyCallback    callback,
@@ -131,16 +124,8 @@ IDE_AVAILABLE_IN_ALL
 void               ide_workbench_addin_open_async            (IdeWorkbenchAddin    *self,
                                                               GFile                *file,
                                                               const gchar          *content_type,
-                                                              IdeBufferOpenFlags    flags,
-                                                              GCancellable         *cancellable,
-                                                              GAsyncReadyCallback   callback,
-                                                              gpointer              user_data);
-IDE_AVAILABLE_IN_ALL
-void               ide_workbench_addin_open_at_async         (IdeWorkbenchAddin    *self,
-                                                              GFile                *file,
-                                                              const gchar          *content_type,
-                                                              gint                  at_line,
-                                                              gint                  at_line_offset,
+                                                              int                   at_line,
+                                                              int                   at_line_offset,
                                                               IdeBufferOpenFlags    flags,
                                                               GCancellable         *cancellable,
                                                               GAsyncReadyCallback   callback,
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 5df239c28..8e4e284f1 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -1836,15 +1836,15 @@ ide_workbench_open_cb (GObject      *object,
 
   next = g_ptr_array_index (o->addins, 0);
 
-  ide_workbench_addin_open_at_async (next,
-                                     o->file,
-                                     o->content_type,
-                                     o->at_line,
-                                     o->at_line_offset,
-                                     o->flags,
-                                     cancellable,
-                                     ide_workbench_open_cb,
-                                     g_steal_pointer (&task));
+  ide_workbench_addin_open_async (next,
+                                  o->file,
+                                  o->content_type,
+                                  o->at_line,
+                                  o->at_line_offset,
+                                  o->flags,
+                                  cancellable,
+                                  ide_workbench_open_cb,
+                                  g_steal_pointer (&task));
 }
 
 static gint
@@ -1953,15 +1953,15 @@ ide_workbench_open_query_info_cb (GObject      *object,
 
   first = g_ptr_array_index (o->addins, 0);
 
-  ide_workbench_addin_open_at_async (first,
-                                     o->file,
-                                     o->content_type,
-                                     o->at_line,
-                                     o->at_line_offset,
-                                     o->flags,
-                                     cancellable,
-                                     ide_workbench_open_cb,
-                                     g_steal_pointer (&task));
+  ide_workbench_addin_open_async (first,
+                                  o->file,
+                                  o->content_type,
+                                  o->at_line,
+                                  o->at_line_offset,
+                                  o->flags,
+                                  cancellable,
+                                  ide_workbench_open_cb,
+                                  g_steal_pointer (&task));
 }
 
 /**


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