[gnome-font-viewer] font-view: don't recreate a different SushiFontWidget every time
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-font-viewer] font-view: don't recreate a different SushiFontWidget every time
- Date: Tue, 1 May 2012 20:04:19 +0000 (UTC)
commit 39a188f54fbc0edf11958a412565a0c2a7488407
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue May 1 16:02:00 2012 -0400
font-view: don't recreate a different SushiFontWidget every time
Creating one initializes a FreeType library object, so it's not cheap.
It's better to just change the URI on the existing widget, like Sushi
does, if possible.
src/font-view.c | 38 ++++++++++++++++++++------------------
1 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/src/font-view.c b/src/font-view.c
index 7ac4c42..8651891 100644
--- a/src/font-view.c
+++ b/src/font-view.c
@@ -422,14 +422,6 @@ static void
font_view_application_do_open (FontViewApplication *self)
{
gchar *uri;
- GtkWidget *font_widget;
- GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
- GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
- GtkWidget *w;
-
- w = gtk_bin_get_child (GTK_BIN (self->swin_preview));
- if (w)
- gtk_widget_destroy (w);
self->info_button = gd_main_toolbar_add_button (GD_MAIN_TOOLBAR (self->toolbar),
NULL, _("Info"),
@@ -454,20 +446,30 @@ font_view_application_do_open (FontViewApplication *self)
gtk_widget_set_vexpand (self->toolbar, FALSE);
uri = g_file_get_uri (self->font_file);
- self->font_widget = font_widget = GTK_WIDGET (sushi_font_widget_new (uri));
- gtk_widget_override_color (font_widget, GTK_STATE_NORMAL, &black);
- gtk_widget_override_background_color (font_widget, GTK_STATE_FLAG_NORMAL, &white);
- g_free (uri);
+ if (self->font_widget == NULL) {
+ GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
+ GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
+ GtkWidget *w;
+
+ self->font_widget = GTK_WIDGET (sushi_font_widget_new (uri));
+
+ gtk_widget_override_color (self->font_widget, GTK_STATE_NORMAL, &black);
+ gtk_widget_override_background_color (self->font_widget, GTK_STATE_FLAG_NORMAL, &white);
- w = gtk_viewport_new (NULL, NULL);
- gtk_viewport_set_shadow_type (GTK_VIEWPORT (w), GTK_SHADOW_NONE);
+ w = gtk_viewport_new (NULL, NULL);
+ gtk_viewport_set_shadow_type (GTK_VIEWPORT (w), GTK_SHADOW_NONE);
- gtk_container_add (GTK_CONTAINER (w), font_widget);
- gtk_container_add (GTK_CONTAINER (self->swin_preview), w);
+ gtk_container_add (GTK_CONTAINER (w), self->font_widget);
+ gtk_container_add (GTK_CONTAINER (self->swin_preview), w);
- g_signal_connect (font_widget, "loaded",
- G_CALLBACK (font_widget_loaded_cb), self);
+ g_signal_connect (self->font_widget, "loaded",
+ G_CALLBACK (font_widget_loaded_cb), self);
+ } else {
+ g_object_set (self->font_widget, "uri", uri, NULL);
+ }
+
+ g_free (uri);
gtk_widget_show_all (self->swin_preview);
gtk_notebook_set_current_page (GTK_NOTEBOOK (self->notebook), 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]