[gtksourceview] Completion: simplify the code for the "Details" button
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Completion: simplify the code for the "Details" button
- Date: Thu, 14 Feb 2013 23:07:28 +0000 (UTC)
commit c92066f3c4c1765e0608894527593f15e9317127
Author: SÃbastien Wilmet <swilmet gnome org>
Date: Thu Feb 14 18:28:05 2013 +0100
Completion: simplify the code for the "Details" button
Use the 'label' and 'image' properties of a GtkButton, instead of
reinventing the wheel.
It is a little less convenient for getting the mnemonic keyval of the
label.
gtksourceview/gtksourcecompletion.c | 59 +++++++++------------------------
gtksourceview/gtksourcecompletion.ui | 34 +++++--------------
2 files changed, 25 insertions(+), 68 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 082386f..c2f96b6 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -169,11 +169,8 @@ struct _GtkSourceCompletionPrivate
/* The default widget (a GtkLabel) for the info window */
GtkWidget *default_info;
- /* The "Details" button with its components, for showing the info window */
+ /* The "Details" button, for showing the info window */
GtkWidget *info_button;
- GtkWidget *hgrid_info;
- GtkWidget *image_info;
- GtkWidget *label_info;
/* List of proposals */
GtkWidget *tree_view_proposals;
@@ -1531,10 +1528,23 @@ view_key_press_event_cb (GtkSourceView *view,
GdkEventKey *event,
GtkSourceCompletion *completion)
{
+ static gboolean mnemonic_keyval_set = FALSE;
+ static guint mnemonic_keyval = GDK_KEY_VoidSymbol;
GdkModifierType mod;
- GtkLabel *label_info;
GtkBindingSet *binding_set;
+ if (G_UNLIKELY (!mnemonic_keyval_set))
+ {
+ const gchar *label_text = gtk_button_get_label (GTK_BUTTON (completion->priv->info_button));
+ GtkWidget *label = gtk_label_new_with_mnemonic (label_text);
+ g_object_ref_sink (label);
+
+ mnemonic_keyval = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
+ mnemonic_keyval_set = TRUE;
+
+ g_object_unref (label);
+ }
+
mod = gtk_accelerator_get_default_mod_mask () & event->state;
if (!gtk_widget_get_visible (completion->priv->main_window))
@@ -1542,10 +1552,8 @@ view_key_press_event_cb (GtkSourceView *view,
return FALSE;
}
- label_info = GTK_LABEL (completion->priv->label_info);
-
/* Handle info button mnemonic */
- if (event->keyval == gtk_label_get_mnemonic_keyval (label_info) &&
+ if (event->keyval == mnemonic_keyval &&
(mod & GDK_MOD1_MASK) != 0)
{
GtkToggleButton *button = GTK_TOGGLE_BUTTON (completion->priv->info_button);
@@ -2895,31 +2903,6 @@ selection_func (GtkTreeSelection *selection,
}
static void
-info_button_style_updated (GtkWidget *button,
- GtkSourceCompletion *completion)
-{
- GtkStyleContext *context;
- gint spacing;
- GtkSettings *settings;
- gboolean show_image;
-
- context = gtk_widget_get_style_context (button);
-
- gtk_style_context_get_style (context,
- "image-spacing", &spacing,
- NULL);
-
- gtk_grid_set_column_spacing (GTK_GRID (completion->priv->hgrid_info), spacing);
-
- settings = gtk_widget_get_settings (button);
- g_object_get (settings,
- "gtk-button-images", &show_image,
- NULL);
-
- gtk_widget_set_visible (completion->priv->image_info, show_image);
-}
-
-static void
replace_model (GtkSourceCompletion *completion)
{
if (completion->priv->model_proposals != NULL)
@@ -2952,15 +2935,10 @@ initialize_ui (GtkSourceCompletion *completion)
completion->priv->selection_image = GTK_WIDGET (gtk_builder_get_object (builder, "selection_image"));
completion->priv->selection_label = GTK_WIDGET (gtk_builder_get_object (builder, "selection_label"));
completion->priv->info_button = GTK_WIDGET (gtk_builder_get_object (builder, "info_button"));
- completion->priv->hgrid_info = GTK_WIDGET (gtk_builder_get_object (builder, "info_button_hgrid"));
- completion->priv->image_info = GTK_WIDGET (gtk_builder_get_object (builder, "info_button_image"));
- completion->priv->label_info = GTK_WIDGET (gtk_builder_get_object (builder, "info_button_label"));
gtk_window_set_attached_to (GTK_WINDOW (completion->priv->main_window),
GTK_WIDGET (completion->priv->view));
- info_button_style_updated (completion->priv->info_button, completion);
-
/* Tree view */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view_proposals));
gtk_tree_selection_set_select_function (selection,
@@ -3019,11 +2997,6 @@ initialize_ui (GtkSourceCompletion *completion)
G_CALLBACK (info_toggled_cb),
completion);
- g_signal_connect (completion->priv->info_button,
- "style-updated",
- G_CALLBACK (info_button_style_updated),
- completion);
-
g_object_unref (builder);
/* Info window */
diff --git a/gtksourceview/gtksourcecompletion.ui b/gtksourceview/gtksourcecompletion.ui
index 9c2f302..18b627d 100644
--- a/gtksourceview/gtksourcecompletion.ui
+++ b/gtksourceview/gtksourcecompletion.ui
@@ -5,7 +5,7 @@ gtksourcecompletion.ui
This file is part of GtkSourceView
Copyright (C) 2009 - Jesse van den Kieboom <jessevdk gnome org>
-Copyright (C) 2012 - SÃbastien Wilmet <swilmet src gnome org>
+Copyright (C) 2012, 2013 - SÃbastien Wilmet <swilmet gnome org>
GtkSourceView is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -24,6 +24,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
<interface>
<requires lib="gtk+" version="3.0"/>
+ <object class="GtkImage" id="info_button_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-info</property>
+ </object>
<object class="GtkWindow" id="main_window">
<property name="border_width">1</property>
<property name="type">popup</property>
@@ -88,30 +93,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
<property name="tooltip_text" translatable="yes">Show detailed proposal
information</property>
<property name="focus_on_click">False</property>
<property name="relief">GTK_RELIEF_NONE</property>
- <child>
- <object class="GtkGrid" id="info_button_hgrid">
- <property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="column_spacing">2</property>
- <property name="valign">center</property>
- <child>
- <object class="GtkImage" id="info_button_image">
- <property name="visible">True</property>
- <property name="stock">gtk-info</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="info_button_label">
- <property name="visible">True</property>
- <property name="label" translatable="yes">_Details...</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- </packing>
- </child>
- </object>
- </child>
+ <property name="label" translatable="yes">_Details...</property>
+ <property name="use_underline">True</property>
+ <property name="image">info_button_image</property>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]