[gnome-builder] shellcmd: allow searching model for matching commands
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] shellcmd: allow searching model for matching commands
- Date: Thu, 8 Aug 2019 23:40:15 +0000 (UTC)
commit e5e52aeec488c25f6c785812dd00d2c9f66ee23a
Author: Christian Hergert <chergert redhat com>
Date: Thu Aug 8 16:40:02 2019 -0700
shellcmd: allow searching model for matching commands
src/plugins/shellcmd/gbp-shellcmd-command-model.c | 32 ++++++++++++++++++++++
src/plugins/shellcmd/gbp-shellcmd-command-model.h | 3 ++
.../shellcmd/gbp-shellcmd-command-provider.c | 2 ++
src/plugins/shellcmd/gbp-shellcmd-command.c | 18 ++++++++++++
src/plugins/shellcmd/gbp-shellcmd-command.h | 2 ++
5 files changed, 57 insertions(+)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-model.c
b/src/plugins/shellcmd/gbp-shellcmd-command-model.c
index 65cb582dc..9ff5e0d0d 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-model.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-model.c
@@ -23,6 +23,7 @@
#include "config.h"
#include <libide-core.h>
+#include <libide-sourceview.h>
#include <libide-threading.h>
#include "gbp-shellcmd-command.h"
@@ -217,3 +218,34 @@ gbp_shellcmd_command_model_get_command (GbpShellcmdCommandModel *self,
return NULL;
}
+
+void
+gbp_shellcmd_command_model_query (GbpShellcmdCommandModel *self,
+ GPtrArray *items,
+ const gchar *typed_text)
+{
+ g_autofree gchar *q = NULL;
+
+ g_return_if_fail (GBP_IS_SHELLCMD_COMMAND_MODEL (self));
+ g_return_if_fail (items != NULL);
+ g_return_if_fail (typed_text != NULL);
+
+ q = g_utf8_casefold (typed_text, -1);
+
+ for (guint i = 0; i < self->items->len; i++)
+ {
+ GbpShellcmdCommand *command = g_ptr_array_index (self->items, i);
+ g_autofree gchar *title = ide_command_get_title (IDE_COMMAND (command));
+ const gchar *cmdstr = gbp_shellcmd_command_get_command (command);
+ guint prio1 = G_MAXINT;
+ guint prio2 = G_MAXINT;
+
+ if (ide_completion_fuzzy_match (title, q, &prio1) ||
+ ide_completion_fuzzy_match (cmdstr, q, &prio2))
+ {
+ GbpShellcmdCommand *copy = gbp_shellcmd_command_copy (command);
+ gbp_shellcmd_command_set_priority (copy, MIN (prio1, prio2));
+ g_ptr_array_add (items, g_steal_pointer (©));
+ }
+ }
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-model.h
b/src/plugins/shellcmd/gbp-shellcmd-command-model.h
index 9a51889bd..897cfd424 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-model.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-model.h
@@ -33,6 +33,9 @@ G_DECLARE_FINAL_TYPE (GbpShellcmdCommandModel, gbp_shellcmd_command_model, GBP,
GbpShellcmdCommandModel *gbp_shellcmd_command_model_new (void);
GbpShellcmdCommand *gbp_shellcmd_command_model_get_command (GbpShellcmdCommandModel *self,
const gchar *command_id);
+void gbp_shellcmd_command_model_query (GbpShellcmdCommandModel *self,
+ GPtrArray *items,
+ const gchar *typed_text);
gboolean gbp_shellcmd_command_model_load (GbpShellcmdCommandModel *self,
GCancellable *cancellable,
GError **error);
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-provider.c
b/src/plugins/shellcmd/gbp-shellcmd-command-provider.c
index 1eccd6fd4..2babff004 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-provider.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-provider.c
@@ -79,6 +79,8 @@ gbp_shellcmd_command_provider_query_async (IdeCommandProvider *provider,
ret = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_object_unref_and_destroy);
+ gbp_shellcmd_command_model_query (get_model (), ret, typed_text);
+
if (!g_shell_parse_argv (typed_text, NULL, NULL, NULL))
goto skip_commands;
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command.c b/src/plugins/shellcmd/gbp-shellcmd-command.c
index 99f056e32..04e8948ee 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command.c
@@ -37,6 +37,7 @@ struct _GbpShellcmdCommand
{
IdeObject parent_instance;
GbpShellcmdCommandLocality locality;
+ gint priority;
gchar *id;
gchar *shortcut;
gchar *subtitle;
@@ -270,6 +271,7 @@ gbp_shellcmd_command_class_init (GbpShellcmdCommandClass *klass)
static void
gbp_shellcmd_command_init (GbpShellcmdCommand *self)
{
+ self->priority = G_MAXINT;
}
const gchar *
@@ -715,6 +717,12 @@ gbp_shellcmd_command_get_icon (IdeCommand *command)
return g_object_ref (icon);
}
+static gint
+gbp_shellcmd_command_get_priority (IdeCommand *command)
+{
+ return GBP_SHELLCMD_COMMAND (command)->priority;
+}
+
static void
command_iface_init (IdeCommandInterface *iface)
{
@@ -723,6 +731,7 @@ command_iface_init (IdeCommandInterface *iface)
iface->get_subtitle = gbp_shellcmd_command_get_subtitle;
iface->run_async = gbp_shellcmd_command_run_async;
iface->run_finish = gbp_shellcmd_command_run_finish;
+ iface->get_priority = gbp_shellcmd_command_get_priority;
}
GbpShellcmdCommandLocality
@@ -955,3 +964,12 @@ gbp_shellcmd_command_copy (GbpShellcmdCommand *self)
return g_steal_pointer (&ret);
}
+
+void
+gbp_shellcmd_command_set_priority (GbpShellcmdCommand *self,
+ gint priority)
+{
+ g_return_if_fail (GBP_IS_SHELLCMD_COMMAND (self));
+
+ self->priority = priority;
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command.h b/src/plugins/shellcmd/gbp-shellcmd-command.h
index 501c2653e..70e7d913d 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-command.h
@@ -55,6 +55,8 @@ const gchar *gbp_shellcmd_command_get_cwd (GbpShellcmdCom
void gbp_shellcmd_command_set_cwd (GbpShellcmdCommand *self,
const gchar *cwd);
IdeEnvironment *gbp_shellcmd_command_get_environment (GbpShellcmdCommand *self);
+void gbp_shellcmd_command_set_priority (GbpShellcmdCommand *self,
+ gint priority);
const gchar *gbp_shellcmd_command_get_shortcut (GbpShellcmdCommand *self);
void gbp_shellcmd_command_set_shortcut (GbpShellcmdCommand *self,
const gchar *shortcut);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]