[gnome-builder] gui: implement icons for IdeCommand
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] gui: implement icons for IdeCommand
- Date: Wed, 7 Aug 2019 06:50:36 +0000 (UTC)
commit 8edfac94d5f8100bec06045702978d372d6bf7ed
Author: Christian Hergert <chergert redhat com>
Date: Tue Aug 6 23:44:42 2019 -0700
gui: implement icons for IdeCommand
This allows us to propagate a GIcon to the suggestion rows which may
provide some additional context.
src/libide/gui/ide-command.c | 21 ++++++++++++++++++++
src/libide/gui/ide-command.h | 23 ++++++++++++----------
.../command-bar/gbp-command-bar-suggestion.c | 17 ++++++++++++++++
3 files changed, 51 insertions(+), 10 deletions(-)
---
diff --git a/src/libide/gui/ide-command.c b/src/libide/gui/ide-command.c
index 5a923ed1b..36975b6c7 100644
--- a/src/libide/gui/ide-command.c
+++ b/src/libide/gui/ide-command.c
@@ -180,3 +180,24 @@ ide_command_get_priority (IdeCommand *self)
return G_MAXINT;
}
+
+/**
+ * ide_command_get_icon:
+ * @self: a #IdeCommand
+ *
+ * Gets the icon for the command to be displayed in UI if necessary.
+ *
+ * Returns: (transfer full) (nullable): a #GIcon or %NULL
+ *
+ * Since: 3.34
+ */
+GIcon *
+ide_command_get_icon (IdeCommand *self)
+{
+ g_return_val_if_fail (IDE_IS_COMMAND (self), NULL);
+
+ if (IDE_COMMAND_GET_IFACE (self)->get_icon)
+ return IDE_COMMAND_GET_IFACE (self)->get_icon (self);
+
+ return NULL;
+}
diff --git a/src/libide/gui/ide-command.h b/src/libide/gui/ide-command.h
index 57ad694ae..0f1057a8e 100644
--- a/src/libide/gui/ide-command.h
+++ b/src/libide/gui/ide-command.h
@@ -37,18 +37,21 @@ struct _IdeCommandInterface
{
GTypeInterface parent_iface;
- gchar *(*get_title) (IdeCommand *self);
- gchar *(*get_subtitle) (IdeCommand *self);
- void (*run_async) (IdeCommand *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
- gboolean (*run_finish) (IdeCommand *self,
- GAsyncResult *result,
- GError **error);
- gint (*get_priority) (IdeCommand *self);
+ gchar *(*get_title) (IdeCommand *self);
+ gchar *(*get_subtitle) (IdeCommand *self);
+ void (*run_async) (IdeCommand *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*run_finish) (IdeCommand *self,
+ GAsyncResult *result,
+ GError **error);
+ gint (*get_priority) (IdeCommand *self);
+ GIcon *(*get_icon) (IdeCommand *self);
};
+IDE_AVAILABLE_IN_3_34
+GIcon *ide_command_get_icon (IdeCommand *self);
IDE_AVAILABLE_IN_3_34
gint ide_command_get_priority (IdeCommand *self);
IDE_AVAILABLE_IN_3_32
diff --git a/src/plugins/command-bar/gbp-command-bar-suggestion.c
b/src/plugins/command-bar/gbp-command-bar-suggestion.c
index 71a528314..da0f10d0f 100644
--- a/src/plugins/command-bar/gbp-command-bar-suggestion.c
+++ b/src/plugins/command-bar/gbp-command-bar-suggestion.c
@@ -57,6 +57,20 @@ gbp_command_bar_suggestion_set_command (GbpCommandBarSuggestion *self,
}
}
+static GIcon *
+gbp_command_bar_suggestion_get_icon (DzlSuggestion *suggestion)
+{
+ GbpCommandBarSuggestion *self = (GbpCommandBarSuggestion *)suggestion;
+ IdeCommand *command;
+
+ g_assert (GBP_IS_COMMAND_BAR_SUGGESTION (self));
+
+ if ((command = gbp_command_bar_suggestion_get_command (self)))
+ return ide_command_get_icon (command);
+
+ return NULL;
+}
+
static void
gbp_command_bar_suggestion_dispose (GObject *object)
{
@@ -109,11 +123,14 @@ static void
gbp_command_bar_suggestion_class_init (GbpCommandBarSuggestionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ DzlSuggestionClass *suggestion_class = DZL_SUGGESTION_CLASS (klass);
object_class->dispose = gbp_command_bar_suggestion_dispose;
object_class->get_property = gbp_command_bar_suggestion_get_property;
object_class->set_property = gbp_command_bar_suggestion_set_property;
+ suggestion_class->get_icon = gbp_command_bar_suggestion_get_icon;
+
properties [PROP_COMMAND] =
g_param_spec_object ("command",
"Command",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]