[gtksourceview/wip/compact-completion: 2/6] Completion: hide bottom bar in some cases
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/compact-completion: 2/6] Completion: hide bottom bar in some cases
- Date: Mon, 29 Apr 2013 10:49:59 +0000 (UTC)
commit 47db12514eb5037b362d64f738054db5630ce4a8
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Apr 28 19:29:38 2013 +0200
Completion: hide bottom bar in some cases
If there is only one provider, the label "All" in the bottom bar (on the
right) is useless.
If there is no extra information, the Details button is useless.
When both widgets are useless, we hide the bottom bar.
The main completion window has always the same size, so when the bottom
bar is hidden, the GtkTreeView is bigger.
gtksourceview/gtksourcecompletion.c | 32 ++++++++++++++
gtksourceview/gtksourcecompletion.ui | 2 +-
gtksourceview/gtksourcecompletionmodel.c | 67 ++++++++++++++++++++++++++++++
gtksourceview/gtksourcecompletionmodel.h | 3 +
4 files changed, 103 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index c227c9b..c1b6ee0 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -134,6 +134,10 @@ struct _GtkSourceCompletionPrivate
GtkWindow *main_window;
GtkSourceCompletionInfo *info_window;
+ /* Bottom bar, containing the "Details" button and the selection image
+ * and label. */
+ GtkWidget *bottom_bar;
+
/* Image and label in the bottom bar, on the right, for showing which
* provider(s) are selected. */
GtkImage *selection_image;
@@ -1362,6 +1366,32 @@ buffer_insert_text_cb (GtkTextBuffer *buffer,
}
static void
+update_bottom_bar_visibility (GtkSourceCompletion *completion)
+{
+ GList *providers;
+ guint nb_providers;
+
+ providers = gtk_source_completion_model_get_providers (completion->priv->model_proposals);
+ nb_providers = g_list_length (providers);
+ g_list_free (providers);
+
+ if (nb_providers > 1)
+ {
+ gtk_widget_show (completion->priv->bottom_bar);
+ return;
+ }
+
+ if (gtk_source_completion_model_has_info (completion->priv->model_proposals))
+ {
+ gtk_widget_show (completion->priv->bottom_bar);
+ }
+ else
+ {
+ gtk_widget_hide (completion->priv->bottom_bar);
+ }
+}
+
+static void
populating_done (GtkSourceCompletion *completion,
GtkSourceCompletionContext *context)
{
@@ -1375,6 +1405,7 @@ populating_done (GtkSourceCompletion *completion,
GTK_TREE_MODEL (completion->priv->model_proposals));
update_selection_label (completion);
+ update_bottom_bar_visibility (completion);
if (!gtk_widget_get_visible (GTK_WIDGET (completion->priv->main_window)))
{
@@ -2150,6 +2181,7 @@ init_main_window (GtkSourceCompletion *completion,
completion->priv->info_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "info_button"));
completion->priv->selection_image = GTK_IMAGE (gtk_builder_get_object (builder, "selection_image"));
completion->priv->selection_label = GTK_LABEL (gtk_builder_get_object (builder, "selection_label"));
+ completion->priv->bottom_bar = GTK_WIDGET (gtk_builder_get_object (builder, "bottom_bar"));
gtk_window_set_attached_to (completion->priv->main_window,
GTK_WIDGET (completion->priv->view));
diff --git a/gtksourceview/gtksourcecompletion.ui b/gtksourceview/gtksourcecompletion.ui
index 7c7f86b..219292e 100644
--- a/gtksourceview/gtksourcecompletion.ui
+++ b/gtksourceview/gtksourcecompletion.ui
@@ -79,7 +79,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
</object>
</child>
<child>
- <object class="GtkGrid" id="hgrid_bottom_bar">
+ <object class="GtkGrid" id="bottom_bar">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index 9453f1b..55cc1bc 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -1122,6 +1122,73 @@ gtk_source_completion_model_previous_proposal (GtkSourceCompletionModel *model,
return TRUE;
}
+static gboolean
+proposal_has_info (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionProposal *proposal)
+{
+ gchar *info;
+
+ if (gtk_source_completion_provider_get_info_widget (provider, proposal) != NULL)
+ {
+ return TRUE;
+ }
+
+ info = gtk_source_completion_proposal_get_info (proposal);
+
+ if (info != NULL)
+ {
+ g_free (info);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+provider_has_info (ProviderInfo *provider_info)
+{
+ GList *l;
+
+ for (l = provider_info->proposals->head; l != NULL; l = l->next)
+ {
+ ProposalInfo *proposal_info = l->data;
+
+ if (proposal_info->completion_proposal == NULL)
+ {
+ continue;
+ }
+
+ if (proposal_has_info (provider_info->completion_provider,
+ proposal_info->completion_proposal))
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+/* Returns whether the model contains one or more proposal with extra
+ * information. If the function returns %FALSE, the "Details" button is useless.
+ */
+gboolean
+gtk_source_completion_model_has_info (GtkSourceCompletionModel *model)
+{
+ GList *l;
+
+ for (l = model->priv->providers; l != NULL; l = l->next)
+ {
+ ProviderInfo *provider_info = l->data;
+
+ if (provider_has_info (provider_info))
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
gboolean
gtk_source_completion_model_iter_equal (GtkSourceCompletionModel *model,
GtkTreeIter *iter1,
diff --git a/gtksourceview/gtksourcecompletionmodel.h b/gtksourceview/gtksourcecompletionmodel.h
index f1cedec..927051d 100644
--- a/gtksourceview/gtksourcecompletionmodel.h
+++ b/gtksourceview/gtksourcecompletionmodel.h
@@ -116,6 +116,9 @@ gboolean gtk_source_completion_model_previous_proposal (GtkSourceComple
GtkTreeIter *iter);
G_GNUC_INTERNAL
+gboolean gtk_source_completion_model_has_info (GtkSourceCompletionModel *model);
+
+G_GNUC_INTERNAL
gboolean gtk_source_completion_model_iter_equal (GtkSourceCompletionModel *model,
GtkTreeIter *iter1,
GtkTreeIter *iter2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]