[gnome-builder/wip/gtk4-port] plugins/rust-analyzer: port preferences to IdePreferencesWindow



commit 20f9253756790a99f6c7f641bd72b67a66825996
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 7 10:34:17 2022 -0700

    plugins/rust-analyzer: port preferences to IdePreferencesWindow
    
    We still don't have a way to remove preferences yet, but that will come
    later on and might even be able to be automatically triggered by gsettings.

 .../rust-analyzer-preferences-addin.c              | 101 +++++++++++----------
 1 file changed, 52 insertions(+), 49 deletions(-)
---
diff --git a/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c 
b/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c
index 93d50b42c..dfb336e6c 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c
@@ -18,76 +18,64 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#include "rust-analyzer-preferences-addin.h"
+#define G_LOG_DOMAIN "rust-analyzer-preferences-addin"
+
+#include "config.h"
+
 #include <glib/gi18n.h>
 
+#include <libide-gui.h>
+
+#include "rust-analyzer-preferences-addin.h"
+
 struct _RustAnalyzerPreferencesAddin
 {
   IdeObject parent_instance;
-  guint check_id;
-  guint clippy_id;
 };
 
-static void preferences_addin_iface_init (IdePreferencesAddinInterface *iface);
-
-G_DEFINE_FINAL_TYPE_WITH_CODE (RustAnalyzerPreferencesAddin,
-                         rust_analyzer_preferences_addin,
-                         IDE_TYPE_OBJECT,
-                         G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN, preferences_addin_iface_init))
+static const IdePreferenceGroupEntry groups[] = {
+  { "insight", "rust-analyer", 2000, N_("Rust Analyzer") },
+};
 
-static void
-rust_analyzer_preferences_addin_class_init (RustAnalyzerPreferencesAddinClass *klass)
-{
-}
+static const IdePreferenceItemEntry items[] = {
+  { "insight", "rust-analyzer", "cargo-command-check", 0, ide_preferences_window_check,
+    N_("Cargo Check"),
+    N_("Run “cargo check” as the default cargo command"),
+    "org.gnome.builder.rust-analyzer", NULL, "cargo-command", "'check'" },
 
-static void
-rust_analyzer_preferences_addin_init (RustAnalyzerPreferencesAddin *self)
-{
-}
+  { "insight", "rust-analyzer", "cargo-command-clippy", 0, ide_preferences_window_check,
+    N_("Cargo Clippy"),
+    N_("Run “cargo clippy” as the default cargo command"),
+    "org.gnome.builder.rust-analyzer", NULL, "cargo-command", "'clippy'" },
+};
 
 static void
-rust_analyzer_preferences_addin_load (IdePreferencesAddin *addin,
-                                      DzlPreferences      *preferences)
+rust_analyzer_preferences_addin_load (IdePreferencesAddin  *addin,
+                                      IdePreferencesWindow *window)
 {
   RustAnalyzerPreferencesAddin *self = (RustAnalyzerPreferencesAddin *)addin;
 
+  IDE_ENTRY;
+
   g_return_if_fail (RUST_IS_ANALYZER_PREFERENCES_ADDIN (self));
-  g_return_if_fail (DZL_IS_PREFERENCES (preferences));
-
-  dzl_preferences_add_list_group (preferences, "code-insight", "rust-analyzer", _("Rust Analyzer: Cargo 
command for diagnostics"), GTK_SELECTION_NONE, 0);
-  self->check_id = dzl_preferences_add_radio (preferences,
-                                              "code-insight",
-                                              "rust-analyzer",
-                                              "org.gnome.builder.rust-analyzer",
-                                              "cargo-command",
-                                              NULL,
-                                              "\"check\"",
-                                              "Cargo check",
-                                              _("the default cargo command"),
-                                              NULL, 1);
-  self->clippy_id = dzl_preferences_add_radio (preferences,
-                                               "code-insight",
-                                               "rust-analyzer",
-                                               "org.gnome.builder.rust-analyzer",
-                                               "cargo-command",
-                                               NULL,
-                                               "\"clippy\"",
-                                               "Cargo clippy",
-                                               _("clippy adds additional lints to catch common mistakes but 
is in general slower"),
-                                               NULL, 2);
+  g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (window));
+
+  ide_preferences_window_add_groups (window, groups, G_N_ELEMENTS (groups), NULL);
+  ide_preferences_window_add_items (window, items, G_N_ELEMENTS (items), window, NULL);
+
+  IDE_EXIT;
 }
 
 static void
-rust_analyzer_preferences_addin_unload (IdePreferencesAddin *addin,
-                                        DzlPreferences      *preferences)
+rust_analyzer_preferences_addin_unload (IdePreferencesAddin  *addin,
+                                        IdePreferencesWindow *window)
 {
-  RustAnalyzerPreferencesAddin *self = (RustAnalyzerPreferencesAddin *)addin;
+  IDE_ENTRY;
 
-  g_return_if_fail (RUST_IS_ANALYZER_PREFERENCES_ADDIN (self));
-  g_return_if_fail (DZL_IS_PREFERENCES (preferences));
+  g_return_if_fail (RUST_IS_ANALYZER_PREFERENCES_ADDIN (addin));
+  g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (window));
 
-  dzl_preferences_remove_id (preferences, self->check_id);
-  dzl_preferences_remove_id (preferences, self->clippy_id);
+  IDE_EXIT;
 }
 
 static void
@@ -96,3 +84,18 @@ preferences_addin_iface_init (IdePreferencesAddinInterface *iface)
   iface->load = rust_analyzer_preferences_addin_load;
   iface->unload = rust_analyzer_preferences_addin_unload;
 }
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (RustAnalyzerPreferencesAddin,
+                               rust_analyzer_preferences_addin,
+                               IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN, 
preferences_addin_iface_init))
+
+static void
+rust_analyzer_preferences_addin_class_init (RustAnalyzerPreferencesAddinClass *klass)
+{
+}
+
+static void
+rust_analyzer_preferences_addin_init (RustAnalyzerPreferencesAddin *self)
+{
+}


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