[gnome-builder] plugins/beautifier: leave notes about porting



commit ab0f9cb7306d0b2278a629c7a54b9a580ee8fc27
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 11 22:09:45 2022 -0700

    plugins/beautifier: leave notes about porting
    
    This module needs quite a bit of work and probably wont be ported for the
    GTK 4 port initially.

 src/plugins/beautifier/TODO.md                     | 10 +++++
 src/plugins/beautifier/beautifier.plugin           |  1 -
 .../beautifier/gb-beautifier-editor-addin.c        | 45 +++++-----------------
 src/plugins/beautifier/gb-beautifier-helper.c      | 14 +++----
 src/plugins/beautifier/gb-beautifier-process.c     | 28 ++++++++------
 src/plugins/beautifier/gtk/menus.ui                | 20 ++++------
 6 files changed, 51 insertions(+), 67 deletions(-)
---
diff --git a/src/plugins/beautifier/TODO.md b/src/plugins/beautifier/TODO.md
new file mode 100644
index 000000000..aef5a4a57
--- /dev/null
+++ b/src/plugins/beautifier/TODO.md
@@ -0,0 +1,10 @@
+# GTK 4 port
+
+A lot of this plugin needs to be refactored given how much has changed
+in Builder since it's inception.
+
+ * It should probably use a buffer addin to provide the beautify actions.
+ * It should probably use a dyanmic GMenu attached to the sourceview context menu, attached from an 
IdeEditorPageAddin.
+ * It should add an IdeShortcutProvider to wire up dynamic shortcuts.
+ * It should use IdeWorkspaceAddin instead of IdeEditorAddin to track pages.
+ * It probably needs a preferences addin to setup beautifiers.
diff --git a/src/plugins/beautifier/beautifier.plugin b/src/plugins/beautifier/beautifier.plugin
index 063e23a16..30402a883 100644
--- a/src/plugins/beautifier/beautifier.plugin
+++ b/src/plugins/beautifier/beautifier.plugin
@@ -2,7 +2,6 @@
 Authors=Sébastien Lafargue <slafargue gnome org>
 Builtin=true
 Copyright=Copyright © 2016 Sébastien Lafargue
-Depends=editor;
 Description=Beautify code according to profiles
 Embedded=_gb_beautifier_register_types
 Module=beautifier
diff --git a/src/plugins/beautifier/gb-beautifier-editor-addin.c 
b/src/plugins/beautifier/gb-beautifier-editor-addin.c
index 23fbdc938..3b46b66a3 100644
--- a/src/plugins/beautifier/gb-beautifier-editor-addin.c
+++ b/src/plugins/beautifier/gb-beautifier-editor-addin.c
@@ -22,10 +22,10 @@
 
 #include "config.h"
 
-#include <dazzle.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtksourceview/gtksource.h>
+
 #include <libide-editor.h>
 
 #include "gb-beautifier-editor-addin.h"
@@ -133,7 +133,6 @@ set_default_keybinding (GbBeautifierEditorAddin *self,
                         const gchar             *action_name)
 {
   static const gchar *accel = "<primary><Alt>b";
-  DzlShortcutController *controller;
 
   g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (action_name != NULL);
@@ -141,12 +140,6 @@ set_default_keybinding (GbBeautifierEditorAddin *self,
   if (self->current_view == NULL)
     return;
 
-  controller = dzl_shortcut_controller_find (GTK_WIDGET (self->current_view));
-  dzl_shortcut_controller_add_command_action (controller,
-                                              "org.gnome.builder.editor-view.beautifier-default",
-                                              I_(accel),
-                                              DZL_SHORTCUT_PHASE_CAPTURE,
-                                              action_name);
 }
 
 static void
@@ -201,7 +194,7 @@ view_populate_submenu (GbBeautifierEditorAddin *self,
   if (entries == NULL)
     return;
 
-  default_menu = dzl_application_get_menu_by_id (DZL_APPLICATION_DEFAULT, "gb-beautify-default-section");
+  default_menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "gb-beautify-default-section");
   g_menu_remove_all (default_menu);
 
   lang_id = gb_beautifier_helper_get_lang_id (self, view);
@@ -269,7 +262,7 @@ view_populate_popup (GbBeautifierEditorAddin *self,
   g_assert (GTK_IS_WIDGET (popup));
   g_assert (IDE_IS_SOURCE_VIEW (source_view));
 
-  submenu = dzl_application_get_menu_by_id (DZL_APPLICATION_DEFAULT, "gb-beautify-profiles-section");
+  submenu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "gb-beautify-profiles-section");
   g_menu_remove_all (submenu);
   view_populate_submenu (self, source_view, submenu, self->entries);
 }
@@ -336,31 +329,13 @@ cleanup_view_cb (GtkWidget               *widget,
       g_action_map_remove_action (G_ACTION_MAP (actions), "beautify");
       g_action_map_remove_action (G_ACTION_MAP (actions), "beautify-default");
     }
-
-  /* TODO: if we close the view we are fine but if we desactivate the plugin, we should remove
-   * the dzl shortcut and action mapping from the controler, dzl do not have this feature yet.
-   */
 }
 
-static const DzlShortcutEntry beautifier_shortcut_entry[] = {
-  { "org.gnome.builder.editor-view.beautifier-default",
-    0,
-    "<primary><Alt>b",
-    N_("Editor shortcuts"),
-    N_("Editing"),
-    N_("Beautify the code"),
-    N_("Trigger the default entry") },
-};
-
 static void
 add_shortcut_window_entry (GbBeautifierEditorAddin *self)
 {
   g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
 
-  dzl_shortcut_manager_add_shortcut_entries (NULL,
-                                             beautifier_shortcut_entry,
-                                             G_N_ELEMENTS (beautifier_shortcut_entry),
-                                             GETTEXT_PACKAGE);
 }
 
 static void
@@ -401,15 +376,15 @@ gb_beautifier_editor_addin_reap_cb (GObject      *object,
                                     GAsyncResult *result,
                                     gpointer      user_data)
 {
-  DzlDirectoryReaper *reaper = (DzlDirectoryReaper *)object;
+  IdeDirectoryReaper *reaper = (IdeDirectoryReaper *)object;
   g_autoptr(GbBeautifierEditorAddin) self = user_data;
   g_autoptr(GError) error = NULL;
 
-  g_assert (DZL_IS_DIRECTORY_REAPER (reaper));
+  g_assert (IDE_IS_DIRECTORY_REAPER (reaper));
   g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
 
-  if (!dzl_directory_reaper_execute_finish (reaper, result, &error))
+  if (!ide_directory_reaper_execute_finish (reaper, result, &error))
     g_warning ("Failed to reap old beautifier data: %s", error->message);
 
   if (g_mkdir_with_parents (self->tmp_dir, 0750) != 0)
@@ -431,7 +406,7 @@ gb_beautifier_editor_addin_load (IdeEditorAddin       *addin,
 {
   GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
   IdeWorkbench *workbench;
-  g_autoptr(DzlDirectoryReaper) reaper = NULL;
+  g_autoptr(IdeDirectoryReaper) reaper = NULL;
   g_autoptr (GFile) tmp_file = NULL;
 
   g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
@@ -446,11 +421,11 @@ gb_beautifier_editor_addin_load (IdeEditorAddin       *addin,
     self->tmp_dir = ide_context_cache_filename (self->context, "beautifier", NULL);
 
   /* Cleanup old beautifier cache directory */
-  reaper = dzl_directory_reaper_new ();
+  reaper = ide_directory_reaper_new ();
   tmp_file = g_file_new_for_path (self->tmp_dir);
-  dzl_directory_reaper_add_directory (reaper, tmp_file, 0);
+  ide_directory_reaper_add_directory (reaper, tmp_file, 0);
 
-  dzl_directory_reaper_execute_async (reaper,
+  ide_directory_reaper_execute_async (reaper,
                                       NULL,
                                       gb_beautifier_editor_addin_reap_cb,
                                       g_object_ref (self));
diff --git a/src/plugins/beautifier/gb-beautifier-helper.c b/src/plugins/beautifier/gb-beautifier-helper.c
index 70cf74870..6dfa3e272 100644
--- a/src/plugins/beautifier/gb-beautifier-helper.c
+++ b/src/plugins/beautifier/gb-beautifier-helper.c
@@ -36,10 +36,10 @@ check_path_is_in_tmp_dir (const gchar *path,
 {
   g_autofree gchar *with_slash = NULL;
 
-  g_assert (!dzl_str_empty0 (path));
-  g_assert (!dzl_str_empty0 (tmp_dir));
+  g_assert (!ide_str_empty0 (path));
+  g_assert (!ide_str_empty0 (tmp_dir));
 
-  if (dzl_str_equal0 (path, tmp_dir))
+  if (ide_str_equal0 (path, tmp_dir))
     return TRUE;
 
   if (!g_str_has_suffix (tmp_dir, G_DIR_SEPARATOR_S))
@@ -125,7 +125,7 @@ gb_beautifier_helper_config_entry_remove_temp_files (GbBeautifierEditorAddin *se
         {
           const GbBeautifierCommandArg *arg = &g_array_index (config_entry->command_args, 
GbBeautifierCommandArg, i);
 
-          if (arg->is_temp && !dzl_str_empty0 (arg->str))
+          if (arg->is_temp && !ide_str_empty0 (arg->str))
             {
               if (check_path_is_in_tmp_dir (arg->str, self->tmp_dir))
                 g_unlink (arg->str);
@@ -181,7 +181,7 @@ gb_beautifier_helper_create_tmp_file_async (GbBeautifierEditorAddin *self,
   gint fd;
 
   g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
-  g_assert (!dzl_str_empty0 (text));
+  g_assert (!ide_str_empty0 (text));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
   g_assert (callback != NULL);
 
@@ -235,8 +235,8 @@ gb_beautifier_helper_match_and_replace (const gchar *str,
   gchar *needle;
   gsize head_len;
 
-  g_assert (!dzl_str_empty0 (str));
-  g_assert (!dzl_str_empty0 (pattern));
+  g_assert (!ide_str_empty0 (str));
+  g_assert (!ide_str_empty0 (pattern));
 
   if (NULL != (needle = g_strstr_len (str, -1, pattern)))
     {
diff --git a/src/plugins/beautifier/gb-beautifier-process.c b/src/plugins/beautifier/gb-beautifier-process.c
index 055ee3b34..64586dcf6 100644
--- a/src/plugins/beautifier/gb-beautifier-process.c
+++ b/src/plugins/beautifier/gb-beautifier-process.c
@@ -18,16 +18,20 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
+#define G_LOG_DOMAIN "gb-beautifier-process"
+
+#include "config.h"
+
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtksourceview/gtksource.h>
+#include <string.h>
+
 #include <libide-editor.h>
 #include <libide-threading.h>
-#include <string.h>
 
-#include "gb-beautifier-private.h"
 #include "gb-beautifier-helper.h"
-
+#include "gb-beautifier-private.h"
 #include "gb-beautifier-process.h"
 
 typedef struct
@@ -150,8 +154,8 @@ gb_beautifier_process_create_generic (GbBeautifierEditorAddin  *self,
 
   src_path = g_file_get_path (state->src_file);
 
-  g_assert (!dzl_str_empty0 (src_path));
-  g_assert (!dzl_str_empty0 (state->lang_id));
+  g_assert (!ide_str_empty0 (src_path));
+  g_assert (!ide_str_empty0 (state->lang_id));
 
   command_args_expand (self, state->command_args_strs, state);
 
@@ -184,7 +188,7 @@ gb_beautifier_process_create_for_clang_format (GbBeautifierEditorAddin  *self,
   g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (state != NULL);
 
-  g_assert (!dzl_str_empty0 (state->lang_id));
+  g_assert (!ide_str_empty0 (state->lang_id));
 
   tmp_workdir = g_build_filename (self->tmp_dir, "clang-XXXXXX.txt", NULL);
   if (g_mkdtemp (tmp_workdir) == NULL)
@@ -249,7 +253,7 @@ process_communicate_utf8_cb (GObject      *object,
   const gchar *stdout_str = NULL;
   const gchar *stderr_str = NULL;
   g_autoptr(GError) error = NULL;
-  IdeCompletion *completion;
+  GtkSourceCompletion *completion;
   GtkTextBuffer *buffer;
   GtkTextIter begin;
   GtkTextIter end;
@@ -271,7 +275,7 @@ process_communicate_utf8_cb (GObject      *object,
   state = (ProcessState *)ide_task_get_task_data (task);
   if (stderr_gb != NULL &&
       NULL != (stderr_str = g_bytes_get_data (stderr_gb, NULL)) &&
-      !dzl_str_empty0 (stderr_str) &&
+      !ide_str_empty0 (stderr_str) &&
       g_utf8_validate (stderr_str, -1, NULL))
     {
       if (ide_subprocess_get_if_exited (process) && ide_subprocess_get_exit_status (process) != 0)
@@ -286,16 +290,16 @@ process_communicate_utf8_cb (GObject      *object,
   if (stdout_gb != NULL)
     stdout_str = g_bytes_get_data (stdout_gb, NULL);
 
-  if (stdout_gb != NULL && dzl_str_empty0 (stdout_str))
+  if (stdout_gb != NULL && ide_str_empty0 (stdout_str))
     {
       ide_object_warning (state->self, _("Beautifier plugin: the command output is empty"));
     }
   else if (g_utf8_validate (stdout_str, -1, NULL))
     {
       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (state->source_view));
-      completion = ide_source_view_get_completion (IDE_SOURCE_VIEW (state->source_view));
+      completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (state->source_view));
 
-      ide_completion_block_interactive (completion);
+      gtk_source_completion_block_interactive (completion);
       gtk_text_buffer_begin_user_action (buffer);
 
       gtk_text_buffer_get_iter_at_mark (buffer, &begin, state->begin_mark);
@@ -310,7 +314,7 @@ process_communicate_utf8_cb (GObject      *object,
       g_signal_emit_by_name (state->source_view, "selection-theatric", IDE_SOURCE_VIEW_THEATRIC_EXPAND);
 
       gtk_text_buffer_end_user_action (buffer);
-      ide_completion_unblock_interactive (completion);
+      gtk_source_completion_unblock_interactive (completion);
 
       ide_task_return_boolean (task, TRUE);
     }
diff --git a/src/plugins/beautifier/gtk/menus.ui b/src/plugins/beautifier/gtk/menus.ui
index a6c85cf44..f3ee60407 100644
--- a/src/plugins/beautifier/gtk/menus.ui
+++ b/src/plugins/beautifier/gtk/menus.ui
@@ -1,17 +1,13 @@
 <?xml version="1.0"?>
 <interface>
-  <menu id="ide-source-view-popup-menu">
-    <section id="ide-source-view-popup-menu-selection-section">
-      <submenu id="ide-source-view-popup-menu-selection-submenu">
-        <section id="gb-beautify-section">
-          <attribute name="after">ide-source-view-popup-menu-line-section</attribute>
-          <submenu id="gb-beautify-submenu">
-            <attribute name="label" translatable="yes">_Beautify</attribute>
-            <section id="gb-beautify-default-section">
-            </section>
-            <section id="gb-beautify-profiles-section">
-            </section>
-          </submenu>
+  <menu id="ide-source-view-popup-menu-selection-submenu">
+    <section id="gb-beautify-section">
+      <attribute name="after">ide-source-view-popup-menu-line-section</attribute>
+      <submenu id="gb-beautify-submenu">
+        <attribute name="label" translatable="yes">_Beautify</attribute>
+        <section id="gb-beautify-default-section">
+        </section>
+        <section id="gb-beautify-profiles-section">
         </section>
       </submenu>
     </section>


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