[gnome-builder] command: Add CommandProvider::complete signal and gb_command_manager_complete
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] command: Add CommandProvider::complete signal and gb_command_manager_complete
- Date: Mon, 24 Nov 2014 19:30:32 +0000 (UTC)
commit db6d5e6267142ea497dcf16a04750566934be5e6
Author: Alexander Larsson <alexl redhat com>
Date: Mon Nov 24 15:38:08 2014 +0100
command: Add CommandProvider::complete signal and gb_command_manager_complete
This adds the initial scaffolding to get commandline completion in
the command bar. It just lets you fill in possible completions given
some existing text.
https://bugzilla.gnome.org/show_bug.cgi?id=740629
src/commands/gb-command-manager.c | 37 +++++++++++++++++++++++++++++++
src/commands/gb-command-manager.h | 2 +
src/commands/gb-command-provider.c | 43 ++++++++++++++++++++++++++++++++++++
src/commands/gb-command-provider.h | 6 +++++
4 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/src/commands/gb-command-manager.c b/src/commands/gb-command-manager.c
index df083c7..1eb560d 100644
--- a/src/commands/gb-command-manager.c
+++ b/src/commands/gb-command-manager.c
@@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <string.h>
+
#include "gb-command-manager.h"
struct _GbCommandManagerPrivate
@@ -107,6 +109,41 @@ gb_command_manager_lookup (GbCommandManager *manager,
return NULL;
}
+static gint
+sort_strings (const gchar * const * a,
+ const gchar * const * b)
+{
+ return strcmp (*a, *b);
+}
+
+gchar **
+gb_command_manager_complete (GbCommandManager *manager,
+ const gchar *initial_command_text)
+{
+ GPtrArray *completions;
+ int i;
+
+ g_return_val_if_fail (GB_IS_COMMAND_MANAGER (manager), NULL);
+ g_return_val_if_fail (initial_command_text, NULL);
+
+ completions = g_ptr_array_new ();
+
+ for (i = 0; i < manager->priv->providers->len; i++)
+ {
+ GbCommandProvider *provider;
+
+ provider = g_ptr_array_index (manager->priv->providers, i);
+ gb_command_provider_complete (provider, completions, initial_command_text);
+ }
+
+ g_ptr_array_sort (completions, (GCompareFunc)sort_strings);
+
+ g_ptr_array_add (completions, NULL);
+
+ return (gchar **)g_ptr_array_free (completions, FALSE);
+}
+
+
static void
gb_command_manager_finalize (GObject *object)
{
diff --git a/src/commands/gb-command-manager.h b/src/commands/gb-command-manager.h
index cacc65e..69e6cba 100644
--- a/src/commands/gb-command-manager.h
+++ b/src/commands/gb-command-manager.h
@@ -54,6 +54,8 @@ struct _GbCommandManagerClass
GType gb_command_manager_get_type (void) G_GNUC_CONST;
GbCommand *gb_command_manager_lookup (GbCommandManager *manager,
const gchar *command_text);
+gchar ** gb_command_manager_complete (GbCommandManager *manager,
+ const gchar *initial_command_text);
void gb_command_manager_add_provider (GbCommandManager *manager,
GbCommandProvider *provider);
diff --git a/src/commands/gb-command-provider.c b/src/commands/gb-command-provider.c
index 81e68d2..1c65f86 100644
--- a/src/commands/gb-command-provider.c
+++ b/src/commands/gb-command-provider.c
@@ -40,6 +40,7 @@ enum {
enum {
LOOKUP,
+ COMPLETE,
LAST_SIGNAL
};
@@ -230,6 +231,26 @@ gb_command_provider_lookup (GbCommandProvider *provider,
return ret;
}
+/**
+ * gb_command_provider_complete:
+ * @provider: (in): The #GbCommandProvider
+ * @completions: (in): A #GPtrArray where completed strings can be added
+ * @command_text: (in): Initial command text to be completed
+ *
+ */
+void
+gb_command_provider_complete (GbCommandProvider *provider,
+ GPtrArray *completions,
+ const gchar *initial_command_text)
+{
+ g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider));
+ g_return_if_fail (completions);
+ g_return_if_fail (initial_command_text);
+
+ g_signal_emit (provider, gSignals [COMPLETE], 0, completions, initial_command_text);
+}
+
+
static void
gb_command_provider_get_property (GObject *object,
guint prop_id,
@@ -362,6 +383,28 @@ gb_command_provider_class_init (GbCommandProviderClass *klass)
GB_TYPE_COMMAND,
1,
G_TYPE_STRING);
+
+ /**
+ * GbCommandProvider::complete:
+ * @completions: (in): A #GPtrArray where completed strings can be added
+ * @initial_command_text: (in): the command line text to be processed.
+ *
+ * This signal is emitted when a request to complete a command text is
+ * received. All providers should all all possible completions, matching
+ * the initial test.
+ */
+ gSignals [COMPLETE] =
+ g_signal_new ("complete",
+ GB_TYPE_COMMAND_PROVIDER,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GbCommandProviderClass, complete),
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_PTR_ARRAY,
+ G_TYPE_STRING);
}
static void
diff --git a/src/commands/gb-command-provider.h b/src/commands/gb-command-provider.h
index e801b90..2ba5ae5 100644
--- a/src/commands/gb-command-provider.h
+++ b/src/commands/gb-command-provider.h
@@ -53,6 +53,9 @@ struct _GbCommandProviderClass
GbCommand *(*lookup) (GbCommandProvider *provider,
const gchar *command_text);
+ void (*complete) (GbCommandProvider *provider,
+ GPtrArray *completions,
+ const gchar *command_text);
};
GType gb_command_provider_get_type (void) G_GNUC_CONST;
@@ -64,6 +67,9 @@ void gb_command_provider_set_priority (GbCommandProvider *provid
gint priority);
GbCommand *gb_command_provider_lookup (GbCommandProvider *provider,
const gchar *command_text);
+void gb_command_provider_complete (GbCommandProvider *provider,
+ GPtrArray *completions,
+ const gchar *initial_command_text);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]