[gtksourceview/gtksourcecompletion] Use GtkBuilder for building completion window
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtksourceview/gtksourcecompletion] Use GtkBuilder for building completion window
- Date: Sat, 19 Sep 2009 16:32:58 +0000 (UTC)
commit adb098d1932a9a41769ca125eda95b99aa4b1225
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Sat Sep 19 17:14:57 2009 +0200
Use GtkBuilder for building completion window
The info button how has an appropriate label, and show/hide is now
toggled using a mnemonic rather than a non-configurable binding
gtksourceview/Makefile.am | 6 +-
gtksourceview/completion.ui | 122 ++++++++++++++
gtksourceview/gtksourcecompletion.c | 303 ++++++++++++++++-------------------
3 files changed, 266 insertions(+), 165 deletions(-)
---
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index c9b86ed..26f8fa0 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -90,6 +90,9 @@ libgtksourceview_2_0_include_HEADERS = \
$(libgtksourceview_headers) \
gtksourceview-typebuiltins.h
+uidir = $(datadir)/gtksourceview-2.0/ui
+ui_DATA = completion.ui
+
gtksourceview-marshal.h: gtksourceview-marshal.list $(GLIB_GENMARSHAL)
$(GLIB_GENMARSHAL) $< --header --prefix=_gtksourceview_marshal > $@
@@ -135,6 +138,7 @@ stamp-gtksourceview-typebuiltins.h: Makefile.am $(libgtksourceview_headers)
&& rm -f xgen-gth && echo stamp > $(@F)
EXTRA_DIST = \
- gtksourceview-marshal.list
+ gtksourceview-marshal.list \
+ $(ui_DATA)
CLEANFILES = $(BUILT_SOURCES) stamp-gtksourceview-typebuiltins.h stamp-gtksourceview-typebuiltins.c
diff --git a/gtksourceview/completion.ui b/gtksourceview/completion.ui
new file mode 100644
index 0000000..d930a11
--- /dev/null
+++ b/gtksourceview/completion.ui
@@ -0,0 +1,122 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkWindow" id="window_completion">
+ <property name="border_width">1</property>
+ <property name="type">popup</property>
+ <property name="resizable">False</property>
+ <property name="skip_taskbar_hint">True</property>
+ <property name="skip_pager_hint">True</property>
+ <property name="accept_focus">False</property>
+ <property name="focus_on_map">False</property>
+ <property name="decorated">False</property>
+ <child>
+ <object class="GtkVBox" id="vbox_completion">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolled_window_completion">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <child>
+ <object class="GtkTreeView" id="tree_view_completion">
+ <property name="visible">True</property>
+ <property name="headers_visible">False</property>
+ <property name="headers_clickable">False</property>
+ <property name="enable_search">False</property>
+ <property name="fixed_height_mode">True</property>
+ <property name="show_expanders">False</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="tree_view_column_proposal">
+ <property name="sizing">GTK_TREE_VIEW_COLUMN_FIXED</property>
+ <property name="expand">True</property>
+ <child>
+ <object class="GtkCellRendererPixbuf" id="cell_renderer_icon"/>
+ </child>
+ <child>
+ <object class="GtkCellRendererText" id="cell_renderer_proposal"/>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox_bottom_bar">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkToggleButton" id="toggle_button_info">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Show proposal information</property>
+ <property name="focus_on_click">False</property>
+ <child>
+ <object class="GtkHBox" id="hbox_info">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkImage" id="image_info">
+ <property name="visible">True</property>
+ <property name="stock">gtk-info</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_info">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">S_how info</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkImage" id="image_selection">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_selection">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="padding">6</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index d49e1aa..8611c4f 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -88,12 +88,14 @@ struct _GtkSourceCompletionPrivate
GtkWidget *bottom_bar;
GtkWidget *default_info;
GtkWidget *selection_image;
+ GtkWidget *hbox_info;
+ GtkWidget *label_info;
+ GtkWidget *image_info;
GtkWidget *tree_view_proposals;
GtkSourceCompletionModel *model_proposals;
gboolean destroy_has_run;
- gboolean manage_keys;
gboolean remember_info_visibility;
gboolean info_visible;
gboolean select_on_show;
@@ -925,16 +927,6 @@ info_size_allocate_cb (GtkWidget *widget,
update_info_position (completion);
}
-static void
-gtk_source_completion_realize (GtkWidget *widget,
- GtkSourceCompletion *completion)
-{
- gtk_container_set_border_width (GTK_CONTAINER (completion->priv->window), 1);
- gtk_widget_set_size_request (GTK_WIDGET (completion->priv->window),
- WINDOW_WIDTH, WINDOW_HEIGHT);
- gtk_window_set_resizable (GTK_WINDOW (completion->priv->window), TRUE);
-}
-
static gboolean
gtk_source_completion_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
@@ -984,15 +976,28 @@ view_key_press_event_cb (GtkSourceView *view,
{
gboolean ret = FALSE;
GdkModifierType mod;
+ GtkLabel *label_info;
mod = gtk_accelerator_get_default_mod_mask () & event->state;
- if (!GTK_WIDGET_VISIBLE (completion->priv->window)
- || !completion->priv->manage_keys)
+ if (!GTK_WIDGET_VISIBLE (completion->priv->window))
{
return FALSE;
}
+ label_info = GTK_LABEL (completion->priv->label_info);
+
+ /* Handle info button mnemonic */
+ if (event->keyval == gtk_label_get_mnemonic_keyval (label_info) &&
+ mod == GDK_MOD1_MASK)
+ {
+ GtkToggleButton *button = GTK_TOGGLE_BUTTON (completion->priv->info_button);
+
+ gtk_toggle_button_set_active (button,
+ !gtk_toggle_button_get_active (button));
+ return TRUE;
+ }
+
switch (event->keyval)
{
case GDK_Escape:
@@ -1040,16 +1045,6 @@ view_key_press_event_cb (GtkSourceView *view,
gtk_source_completion_hide (completion);
break;
}
- case GDK_i:
- {
- if (mod == GDK_CONTROL_MASK)
- {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (completion->priv->info_button),
- !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (completion->priv->info_button)));
- ret = TRUE;
- }
- break;
- }
case GDK_Left:
{
if (mod == GDK_CONTROL_MASK)
@@ -1828,21 +1823,121 @@ on_providers_changed (GtkSourceCompletionModel *model,
update_selection_label (completion);
}
-static GtkWidget *
-initialize_proposals_ui (GtkSourceCompletion *completion)
+static void
+info_button_style_set (GtkWidget *button,
+ GtkStyle *previous_style,
+ GtkSourceCompletion *completion)
+{
+ gint spacing;
+ GtkSettings *settings;
+ gboolean show_image;
+
+ gtk_style_get (gtk_widget_get_style (button),
+ GTK_TYPE_BUTTON,
+ "image-spacing",
+ &spacing,
+ NULL);
+
+ gtk_box_set_spacing (GTK_BOX (completion->priv->hbox_info),
+ spacing);
+
+ settings = gtk_widget_get_settings (button);
+ g_object_get (settings,
+ "gtk-button-images",
+ &show_image,
+ NULL);
+
+ if (show_image)
+ {
+ gtk_widget_show (completion->priv->image_info);
+ }
+ else
+ {
+ gtk_widget_hide (completion->priv->image_info);
+ }
+}
+
+static void
+initialize_ui (GtkSourceCompletion *completion)
{
- GtkCellRenderer *renderer;
+ GtkBuilder *builder;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
- GtkWidget *scrolled_window;
- GtkWidget *tree_view;
+ GtkWidget *toggle_button_info;
+
+ builder = gtk_builder_new ();
+
+ if (!gtk_builder_add_from_file (builder,
+ DATADIR "/gtksourceview-2.0/ui/completion.ui",
+ NULL))
+ {
+ g_error ("Could not load UI file for completion");
+ return;
+ }
+ completion->priv->window =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "window_completion"));
+ completion->priv->info_button =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "toggle_button_info"));
+ completion->priv->selection_label =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "label_selection"));
+ completion->priv->selection_image =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "image_selection"));
+ completion->priv->tree_view_proposals =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "tree_view_completion"));
+ completion->priv->label_info =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "label_info"));
+ completion->priv->image_info =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "image_info"));
+ completion->priv->hbox_info =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "hbox_info"));
+
+ info_button_style_set (completion->priv->info_button,
+ NULL,
+ completion);
+
+ gtk_widget_set_size_request (completion->priv->window,
+ WINDOW_WIDTH,
+ WINDOW_HEIGHT);
+
+ /* Tree view and model */
completion->priv->model_proposals = gtk_source_completion_model_new ();
-
gtk_source_completion_model_set_show_headers (completion->priv->model_proposals,
completion->priv->show_headers);
- tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (completion->priv->model_proposals));
- completion->priv->tree_view_proposals = tree_view;
+
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view_proposals),
+ GTK_TREE_MODEL (completion->priv->model_proposals));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view_proposals));
+ gtk_tree_selection_set_select_function (selection,
+ (GtkTreeSelectionFunc)selection_func,
+ completion,
+ NULL);
+
+ column = GTK_TREE_VIEW_COLUMN (gtk_builder_get_object (builder,
+ "tree_view_column_proposal"));
+ gtk_tree_view_column_set_cell_data_func (column,
+ GTK_CELL_RENDERER (gtk_builder_get_object (builder,
+ "cell_renderer_icon")),
+ (GtkTreeCellDataFunc)render_proposal_icon_func,
+ completion,
+ NULL);
+
+ gtk_tree_view_column_set_cell_data_func (column,
+ GTK_CELL_RENDERER (gtk_builder_get_object (builder,
+ "cell_renderer_proposal")),
+ (GtkTreeCellDataFunc)render_proposal_text_func,
+ completion,
+ NULL);
g_signal_connect_after (completion->priv->model_proposals,
"row-inserted",
@@ -1858,147 +1953,32 @@ initialize_proposals_ui (GtkSourceCompletion *completion)
"providers-changed",
G_CALLBACK (on_providers_changed),
completion);
-
- gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (tree_view), FALSE);
-
- gtk_widget_show (tree_view);
- g_object_set (tree_view, "can-focus", FALSE, NULL);
-
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
-
- /* Create the tree */
- column = gtk_tree_view_column_new ();
- renderer = gtk_cell_renderer_pixbuf_new ();
-
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
-
- gtk_tree_view_column_set_cell_data_func (column,
- renderer,
- (GtkTreeCellDataFunc)render_proposal_icon_func,
- completion,
- NULL);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer, TRUE);
-
- gtk_tree_view_column_set_cell_data_func (column,
- renderer,
- (GtkTreeCellDataFunc)render_proposal_text_func,
- completion,
- NULL);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
- g_signal_connect (tree_view,
+ g_signal_connect (completion->priv->tree_view_proposals,
"row-activated",
G_CALLBACK (row_activated_cb),
completion);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
- gtk_tree_selection_set_select_function (selection,
- (GtkTreeSelectionFunc)selection_func,
- completion,
- NULL);
+
g_signal_connect (selection,
"changed",
G_CALLBACK (selection_changed_cb),
completion);
-
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_show (scrolled_window);
-
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- gtk_container_add (GTK_CONTAINER (scrolled_window),
- tree_view);
-
- return scrolled_window;
-}
-static void
-initialize_ui (GtkSourceCompletion *completion)
-{
- GtkWidget *info_icon;
- GtkWidget *info_button;
- GtkWidget *vbox;
- GtkWidget *container;
-
- /* Window */
- completion->priv->window = gtk_window_new (GTK_WINDOW_POPUP);
-
- gtk_window_set_type_hint (GTK_WINDOW (completion->priv->window),
- GDK_WINDOW_TYPE_HINT_NORMAL);
- gtk_window_set_focus_on_map (GTK_WINDOW (completion->priv->window),
- FALSE);
- gtk_widget_set_size_request (GTK_WIDGET (completion->priv->window),
- WINDOW_WIDTH, WINDOW_HEIGHT);
- gtk_window_set_decorated (GTK_WINDOW (completion->priv->window), FALSE);
-
- /* Bottom bar */
- completion->priv->bottom_bar = gtk_hbox_new (FALSE, 1);
- gtk_widget_show (completion->priv->bottom_bar);
-
- /* Info button */
- info_icon = gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_MENU);
- gtk_widget_show (info_icon);
- gtk_widget_set_tooltip_text (info_icon, _("Show Proposal Info"));
-
- info_button = gtk_toggle_button_new ();
- gtk_widget_show (info_button);
- g_object_set (G_OBJECT (info_button), "can-focus", FALSE, NULL);
-
- gtk_button_set_focus_on_click (GTK_BUTTON (info_button), FALSE);
- gtk_container_add (GTK_CONTAINER (info_button), info_icon);
- g_signal_connect (G_OBJECT (info_button),
+ toggle_button_info =
+ GTK_WIDGET (gtk_builder_get_object (builder,
+ "toggle_button_info"));
+
+ g_signal_connect (toggle_button_info,
"toggled",
G_CALLBACK (info_toggled_cb),
completion);
- completion->priv->info_button = info_button;
-
- gtk_box_pack_start (GTK_BOX (completion->priv->bottom_bar),
- info_button,
- FALSE,
- FALSE,
- 0);
-
- /* Selection label */
- completion->priv->selection_label = gtk_label_new (NULL);
- gtk_widget_show (completion->priv->selection_label);
- gtk_box_pack_end (GTK_BOX (completion->priv->bottom_bar),
- completion->priv->selection_label,
- FALSE,
- TRUE,
- 10);
-
- completion->priv->selection_image = gtk_image_new ();
- gtk_widget_show (completion->priv->selection_image);
- gtk_box_pack_end (GTK_BOX (completion->priv->bottom_bar),
- completion->priv->selection_image,
- FALSE,
- TRUE,
- 0);
-
- container = initialize_proposals_ui (completion);
-
- /* Main vbox */
- vbox = gtk_vbox_new (FALSE, 1);
- gtk_widget_show (vbox);
- gtk_box_pack_start (GTK_BOX (vbox),
- container,
- TRUE,
- TRUE,
- 0);
-
- gtk_box_pack_end (GTK_BOX (vbox),
- completion->priv->bottom_bar,
- FALSE,
- FALSE,
- 0);
-
- gtk_container_add (GTK_CONTAINER (completion->priv->window), vbox);
+ g_signal_connect (toggle_button_info,
+ "style-set",
+ G_CALLBACK (info_button_style_set),
+ completion);
+
+ g_object_unref (builder);
/* Info window */
completion->priv->info_window = GTK_WIDGET (gtk_source_completion_info_new ());
@@ -2025,11 +2005,6 @@ initialize_ui (GtkSourceCompletion *completion)
completion);
g_signal_connect (completion->priv->window,
- "realize",
- G_CALLBACK (gtk_source_completion_realize),
- completion);
-
- g_signal_connect (completion->priv->window,
"delete-event",
G_CALLBACK (gtk_widget_hide_on_delete),
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]