[gedit] Use a template for the view frame
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Use a template for the view frame
- Date: Thu, 2 May 2013 14:43:00 +0000 (UTC)
commit bc0185f489bc6ee42a9cab8f96bace4312fbb4c3
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu May 2 15:54:36 2013 +0200
Use a template for the view frame
gedit/Makefile.am | 3 +-
gedit/gedit-view-frame.c | 108 ++++++++------------------------------------
gedit/gedit-view-frame.h | 4 +-
gedit/gedit-view-frame.ui | 89 +++++++++++++++++++++++++++++++++++++
gedit/gedit.gresource.xml | 1 +
5 files changed, 114 insertions(+), 91 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 8a9dfc2..a7cce7e 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -261,7 +261,8 @@ EXTRA_DIST = \
gedit-print-preview.ui \
gedit-print-preferences.ui \
gedit-progress-info-bar.ui \
- gedit-status-menu-button.ui
+ gedit-status-menu-button.ui \
+ gedit-view-frame.ui
CLEANFILES = $(BUILT_SOURCES) $(BUILT_SOURCES_PRIVATE)
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index 85fb34a..f5150f7 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -48,8 +48,6 @@ typedef enum
struct _GeditViewFramePrivate
{
GtkWidget *view;
- GtkWidget *overlay;
-
SearchMode search_mode;
SearchMode request_search_mode;
@@ -94,7 +92,7 @@ typedef enum
GEDIT_SEARCH_ENTRY_NOT_FOUND
} GeditSearchEntryBgColor;
-G_DEFINE_TYPE (GeditViewFrame, gedit_view_frame, GTK_TYPE_BOX)
+G_DEFINE_TYPE (GeditViewFrame, gedit_view_frame, GTK_TYPE_OVERLAY)
static void
gedit_view_frame_finalize (GObject *object)
@@ -893,20 +891,6 @@ search_entry_focus_out_event (GtkWidget *widget,
return FALSE;
}
-static GtkWidget *
-create_button_from_symbolic (const gchar *icon_name)
-{
- GtkWidget *button;
-
- button = gtk_button_new ();
- gtk_widget_set_can_focus (button, FALSE);
- gtk_button_set_image (GTK_BUTTON (button),
- gtk_image_new_from_icon_name (icon_name,
- GTK_ICON_SIZE_MENU));
-
- return button;
-}
-
static void
on_go_up_button_clicked (GtkWidget *button,
GeditViewFrame *frame)
@@ -921,38 +905,17 @@ on_go_down_button_clicked (GtkWidget *button,
search_again (frame, FALSE);
}
-static GtkWidget *
-create_search_widget (GeditViewFrame *frame)
+static void
+setup_search_widget (GeditViewFrame *frame)
{
- GtkWidget *search_widget;
- GtkWidget *hbox;
- GtkStyleContext *context;
-
- /* wrap it in a frame, so we can specify borders etc */
- search_widget = gtk_frame_new (NULL);
- context = gtk_widget_get_style_context (search_widget);
- gtk_style_context_add_class (context, "gedit-search-slider");
- gtk_widget_show (search_widget);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- context = gtk_widget_get_style_context (hbox);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
- gtk_container_add (GTK_CONTAINER (search_widget), hbox);
- gtk_widget_show (hbox);
-
- g_signal_connect (hbox, "key-press-event",
+ g_signal_connect (frame->priv->slider, "key-press-event",
G_CALLBACK (search_widget_key_press_event),
frame);
- g_signal_connect (hbox, "scroll-event",
+ g_signal_connect (frame->priv->slider, "scroll-event",
G_CALLBACK (search_widget_scroll_event),
frame);
/* add entry */
- frame->priv->search_entry = gtk_entry_new ();
- gtk_widget_show (frame->priv->search_entry);
-
- gtk_entry_set_width_chars (GTK_ENTRY (frame->priv->search_entry), 25);
-
g_signal_connect (frame->priv->search_entry, "populate-popup",
G_CALLBACK (search_entry_populate_popup),
frame);
@@ -974,27 +937,16 @@ create_search_widget (GeditViewFrame *frame)
G_CALLBACK (search_entry_focus_out_event),
frame);
- gtk_container_add (GTK_CONTAINER (hbox),
- frame->priv->search_entry);
-
/* Up/Down buttons */
- frame->priv->go_up_button = create_button_from_symbolic ("go-up-symbolic");
- gtk_box_pack_start (GTK_BOX (hbox), frame->priv->go_up_button,
- FALSE, FALSE, 0);
g_signal_connect (frame->priv->go_up_button,
"clicked",
G_CALLBACK (on_go_up_button_clicked),
frame);
- frame->priv->go_down_button = create_button_from_symbolic ("go-down-symbolic");
- gtk_box_pack_start (GTK_BOX (hbox), frame->priv->go_down_button,
- FALSE, FALSE, 0);
g_signal_connect (frame->priv->go_down_button,
"clicked",
G_CALLBACK (on_go_down_button_clicked),
frame);
-
- return search_widget;
}
static gboolean
@@ -1190,6 +1142,7 @@ static void
gedit_view_frame_class_init (GeditViewFrameClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = gedit_view_frame_finalize;
object_class->dispose = gedit_view_frame_dispose;
@@ -1211,6 +1164,15 @@ gedit_view_frame_class_init (GeditViewFrameClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+ /* Bind class to template */
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/gedit/ui/gedit-view-frame.ui");
+ gtk_widget_class_bind_child (widget_class, GeditViewFramePrivate, view);
+ gtk_widget_class_bind_child (widget_class, GeditViewFramePrivate, slider);
+ gtk_widget_class_bind_child (widget_class, GeditViewFramePrivate, search_entry);
+ gtk_widget_class_bind_child (widget_class, GeditViewFramePrivate, go_up_button);
+ gtk_widget_class_bind_child (widget_class, GeditViewFramePrivate, go_down_button);
+
g_type_class_add_private (object_class, sizeof (GeditViewFramePrivate));
}
@@ -1230,7 +1192,6 @@ static void
gedit_view_frame_init (GeditViewFrame *frame)
{
GeditDocument *doc;
- GtkWidget *sw;
GdkRGBA transparent = {0, 0, 0, 0};
frame->priv = GEDIT_VIEW_FRAME_GET_PRIVATE (frame);
@@ -1238,43 +1199,17 @@ gedit_view_frame_init (GeditViewFrame *frame)
frame->priv->typeselect_flush_timeout = 0;
frame->priv->wrap_around = TRUE;
- gtk_orientable_set_orientation (GTK_ORIENTABLE (frame),
- GTK_ORIENTATION_VERTICAL);
+ gtk_widget_init_template (GTK_WIDGET (frame));
- doc = gedit_document_new ();
+ gtk_widget_override_background_color (GTK_WIDGET (frame), 0, &transparent);
+ doc = gedit_view_frame_get_document (frame);
_gedit_document_set_mount_operation_factory (doc,
view_frame_mount_operation_factory,
frame);
- frame->priv->view = gedit_view_new (doc);
- gtk_widget_set_vexpand (frame->priv->view, TRUE);
- gtk_widget_show (frame->priv->view);
-
- g_object_unref (doc);
-
- /* Create the scrolled window */
- sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (sw), frame->priv->view);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_widget_show (sw);
-
- frame->priv->overlay = gtk_overlay_new ();
- gtk_container_add (GTK_CONTAINER (frame->priv->overlay), sw);
- gtk_widget_override_background_color (frame->priv->overlay, 0, &transparent);
- gtk_widget_show (frame->priv->overlay);
-
- gtk_box_pack_start (GTK_BOX (frame), frame->priv->overlay, TRUE, TRUE, 0);
-
- /* Add slider */
- frame->priv->slider = gtk_revealer_new ();
- gtk_container_add (GTK_CONTAINER (frame->priv->slider),
- create_search_widget (frame));
- gtk_widget_show (frame->priv->slider);
- gtk_widget_set_halign (frame->priv->slider, GTK_ALIGN_END);
- gtk_widget_set_valign (frame->priv->slider, GTK_ALIGN_START);
+ /* Slider margin */
+ setup_search_widget (frame);
if (gtk_widget_get_direction (frame->priv->slider) == GTK_TEXT_DIR_LTR)
{
@@ -1284,9 +1219,6 @@ gedit_view_frame_init (GeditViewFrame *frame)
{
gtk_widget_set_margin_left (frame->priv->slider, SEARCH_POPUP_MARGIN);
}
-
- gtk_overlay_add_overlay (GTK_OVERLAY (frame->priv->overlay),
- frame->priv->slider);
}
GeditViewFrame *
diff --git a/gedit/gedit-view-frame.h b/gedit/gedit-view-frame.h
index 12265da..0ef07e4 100644
--- a/gedit/gedit-view-frame.h
+++ b/gedit/gedit-view-frame.h
@@ -43,14 +43,14 @@ typedef struct _GeditViewFrameClass GeditViewFrameClass;
struct _GeditViewFrame
{
- GtkBox parent;
+ GtkOverlay parent;
GeditViewFramePrivate *priv;
};
struct _GeditViewFrameClass
{
- GtkBoxClass parent_class;
+ GtkOverlayClass parent_class;
};
GType gedit_view_frame_get_type (void) G_GNUC_CONST;
diff --git a/gedit/gedit-view-frame.ui b/gedit/gedit-view-frame.ui
new file mode 100644
index 0000000..f6d44e6
--- /dev/null
+++ b/gedit/gedit-view-frame.ui
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <object class="GeditDocument" id="doc"/>
+ <template class="GeditViewFrame" parent="GtkOverlay">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GeditView" id="view">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="buffer">doc</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkRevealer" id="slider">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="valign">start</property>
+ <child>
+ <object class="GtkFrame" id="frame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <style>
+ <class name="gedit-search-slider"/>
+ </style>
+ <child>
+ <object class="GtkBox" id="hbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <object class="GtkEntry" id="search_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="width_chars">25</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="go_up_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImage" id="up_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_size">1</property>
+ <property name="icon_name">go-up-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="go_down_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImage" id="down_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_size">1</property>
+ <property name="icon_name">go-down-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gedit/gedit.gresource.xml b/gedit/gedit.gresource.xml
index 44662d5..6938cb8 100644
--- a/gedit/gedit.gresource.xml
+++ b/gedit/gedit.gresource.xml
@@ -11,5 +11,6 @@
<file preprocess="xml-stripblanks">gedit-print-preferences.ui</file>
<file preprocess="xml-stripblanks">gedit-progress-info-bar.ui</file>
<file preprocess="xml-stripblanks">gedit-status-menu-button.ui</file>
+ <file preprocess="xml-stripblanks">gedit-view-frame.ui</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]