[gnome-builder/wip/gtk4-port: 1471/1774] plugins/shellcmd: more listmodel cleanup
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1471/1774] plugins/shellcmd: more listmodel cleanup
- Date: Mon, 11 Jul 2022 22:31:47 +0000 (UTC)
commit ddd8e16457804091d1504cecf7f66d31905fbf45
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 10 21:12:22 2022 -0700
plugins/shellcmd: more listmodel cleanup
src/plugins/shellcmd/gbp-shellcmd-command-model.c | 27 ++++++++++++++++++
src/plugins/shellcmd/gbp-shellcmd-command-model.h | 8 ++++--
.../shellcmd/gbp-shellcmd-run-command-provider.c | 32 ++--------------------
.../shellcmd/gbp-shellcmd-run-command-provider.h | 2 --
4 files changed, 34 insertions(+), 35 deletions(-)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-model.c
b/src/plugins/shellcmd/gbp-shellcmd-command-model.c
index fbfb27422..35ba00a53 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-model.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-model.c
@@ -25,6 +25,8 @@
#include "gbp-shellcmd-command-model.h"
#include "gbp-shellcmd-run-command.h"
+#define SHELLCMD_SETTINGS_BASE "/org/gnome/builder/shellcmd/"
+
struct _GbpShellcmdCommandModel
{
GObject parent_instance;
@@ -300,3 +302,28 @@ gbp_shellcmd_command_model_new (GSettings *settings,
"key", key,
NULL);
}
+
+GbpShellcmdCommandModel *
+gbp_shellcmd_command_model_new_for_app (void)
+{
+ g_autoptr(GSettings) settings = NULL;
+
+ settings = g_settings_new_with_path ("org.gnome.builder.shellcmd", SHELLCMD_SETTINGS_BASE);
+ return gbp_shellcmd_command_model_new (settings, "run-commands");
+}
+
+GbpShellcmdCommandModel *
+gbp_shellcmd_command_model_new_for_project (IdeContext *context)
+{
+ g_autofree char *project_id = NULL;
+ g_autofree char *project_settings_path = NULL;
+ g_autoptr(GSettings) settings = NULL;
+
+ g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
+
+ project_id = ide_context_dup_project_id (context);
+ project_settings_path = g_strconcat (SHELLCMD_SETTINGS_BASE, "projects/", project_id, "/", NULL);
+ settings = g_settings_new_with_path ("org.gnome.builder.shellcmd", project_settings_path);
+
+ return gbp_shellcmd_command_model_new (settings, "run-commands");
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-model.h
b/src/plugins/shellcmd/gbp-shellcmd-command-model.h
index 201c739e0..6310c970f 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-model.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-model.h
@@ -20,7 +20,7 @@
#pragma once
-#include <gio/gio.h>
+#include <libide-core.h>
G_BEGIN_DECLS
@@ -28,7 +28,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpShellcmdCommandModel, gbp_shellcmd_command_model, GBP, SHELLCMD_COMMAND_MODEL,
GObject)
-GbpShellcmdCommandModel *gbp_shellcmd_command_model_new (GSettings *settings,
- const char *key);
+GbpShellcmdCommandModel *gbp_shellcmd_command_model_new_for_app (void);
+GbpShellcmdCommandModel *gbp_shellcmd_command_model_new_for_project (IdeContext *context);
+GbpShellcmdCommandModel *gbp_shellcmd_command_model_new (GSettings *settings,
+ const char *key);
G_END_DECLS
diff --git a/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.c
b/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.c
index 72e4a393c..93d28be31 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.c
@@ -19,7 +19,6 @@
*/
#define G_LOG_DOMAIN "gbp-shellcmd-run-command-provider"
-#define SHELLCMD_SETTINGS_BASE "/org/gnome/builder/shellcmd/"
#include "config.h"
@@ -43,11 +42,7 @@ gbp_shellcmd_run_command_provider_list_commands_async (IdeRunCommandProvider *pr
g_autoptr(GbpShellcmdCommandModel) app_commands = NULL;
g_autoptr(GbpShellcmdCommandModel) project_commands = NULL;
g_autoptr(GListStore) store = NULL;
- g_autoptr(GSettings) app_settings = NULL;
- g_autoptr(GSettings) project_settings = NULL;
g_autoptr(IdeTask) task = NULL;
- g_autofree char *project_id = NULL;
- g_autofree char *project_settings_path = NULL;
IdeContext *context;
IDE_ENTRY;
@@ -59,14 +54,9 @@ gbp_shellcmd_run_command_provider_list_commands_async (IdeRunCommandProvider *pr
ide_task_set_source_tag (task, gbp_shellcmd_run_command_provider_list_commands_async);
context = ide_object_get_context (IDE_OBJECT (provider));
- project_id = ide_context_dup_project_id (context);
- project_settings_path = g_strconcat (SHELLCMD_SETTINGS_BASE, "projects/", project_id, "/", NULL);
- app_settings = g_settings_new_with_path ("org.gnome.builder.shellcmd", SHELLCMD_SETTINGS_BASE);
- project_settings = g_settings_new_with_path ("org.gnome.builder.shellcmd", project_settings_path);
-
- app_commands = gbp_shellcmd_command_model_new (app_settings, "run-commands");
- project_commands = gbp_shellcmd_command_model_new (project_settings, "run-commands");
+ app_commands = gbp_shellcmd_command_model_new_for_app ();
+ project_commands = gbp_shellcmd_command_model_new_for_project (context);
store = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (store, project_commands);
@@ -117,21 +107,3 @@ static void
gbp_shellcmd_run_command_provider_init (GbpShellcmdRunCommandProvider *self)
{
}
-
-char *
-gbp_shellcmd_run_command_provider_create_settings_path (IdeContext *context)
-{
- g_autofree char *uuid = NULL;
-
- g_assert (!context || IDE_IS_CONTEXT (context));
-
- uuid = g_uuid_string_random ();
-
- if (ide_context_has_project (context))
- {
- g_autofree char *project_id = ide_context_dup_project_id (context);
- return g_strconcat (SHELLCMD_SETTINGS_BASE, "projects/", project_id, "/", uuid, "/", NULL);
- }
-
- return g_strconcat (SHELLCMD_SETTINGS_BASE, "/", uuid, "/", NULL);
-}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.h
b/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.h
index 21f9668a4..91e9ea4e9 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-run-command-provider.h
@@ -28,6 +28,4 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpShellcmdRunCommandProvider, gbp_shellcmd_run_command_provider, GBP,
SHELLCMD_RUN_COMMAND_PROVIDER, IdeObject)
-char *gbp_shellcmd_run_command_provider_create_settings_path (IdeContext *context);
-
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]