[gedit-cossa] previewer: simpliply code
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-cossa] previewer: simpliply code
- Date: Wed, 15 Jun 2011 07:25:32 +0000 (UTC)
commit 2592cd6b95e99a1fb0700b75332ef5b10fc55f5f
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Jun 15 09:25:11 2011 +0200
previewer: simpliply code
src/cossa-previewer.c | 68 +++++++++++++++++-------------------------------
src/cossa-previewer.h | 2 -
src/cossa-window.c | 5 +---
3 files changed, 25 insertions(+), 50 deletions(-)
---
diff --git a/src/cossa-previewer.c b/src/cossa-previewer.c
index 15dd012..0d11970 100644
--- a/src/cossa-previewer.c
+++ b/src/cossa-previewer.c
@@ -52,7 +52,6 @@ struct _CossaPreviewerPrivate
CossaZoomLevel zoom_level;
GList *samples;
GList *cur_sample;
- gboolean show_all;
GtkCssProvider *provider;
};
@@ -241,7 +240,7 @@ cossa_previewer_draw (GtkWidget *widget,
gtk_render_background (context, cr, 0, 0, (gdouble) allocation.width, (gdouble) allocation.height);
gtk_style_context_restore (context);
- if (priv->show_all)
+ if (!priv->cur_sample)
{
GList *l;
gint y;
@@ -279,7 +278,7 @@ cossa_previewer_draw (GtkWidget *widget,
l = l->next;
}
}
- else if (priv->cur_sample)
+ else
{
sample = priv->cur_sample->data;
@@ -313,7 +312,7 @@ cossa_previewer_get_preferred_width (GtkWidget *widget,
CossaPreviewer *previewer = (CossaPreviewer *) widget;
CossaPreviewerPrivate *priv = previewer->priv;
- if (priv->show_all)
+ if (!priv->cur_sample)
{
GList *sample;
gint width = 0;
@@ -344,7 +343,7 @@ end_width:
width = MAX (width, row_width);
*minimum_width = *natural_width = width;
}
- else if (priv->cur_sample)
+ else
{
SampleData *data = priv->cur_sample->data;
@@ -361,7 +360,7 @@ cossa_previewer_get_preferred_height_for_width (GtkWidget *widget,
CossaPreviewer *previewer = (CossaPreviewer *) widget;
CossaPreviewerPrivate *priv = previewer->priv;
- if (priv->show_all)
+ if (!priv->cur_sample)
{
GList *sample;
gint height = 0;
@@ -392,7 +391,7 @@ end_height:
height += row_height;
*minimum_height = *natural_height = height;
}
- else if (priv->cur_sample)
+ else
{
SampleData *data = priv->cur_sample->data;
@@ -488,17 +487,11 @@ cossa_previewer_add_sample (CossaPreviewer *previewer,
priv->samples = g_list_prepend (priv->samples, sample);
- if (priv->show_all)
- gtk_widget_queue_resize (GTK_WIDGET (previewer));
- else if (!priv->cur_sample)
- {
- priv->cur_sample = priv->samples;
-
- if (gtk_widget_is_drawable (GTK_WIDGET (previewer)))
- gtk_widget_queue_draw (GTK_WIDGET (previewer));
- }
+ if (!priv->cur_sample && gtk_widget_is_drawable (GTK_WIDGET (previewer)))
+ gtk_widget_queue_draw (GTK_WIDGET (previewer));
}
+/* if @sample is %NULL all samples are shown */
void
cossa_previewer_select_sample (CossaPreviewer *previewer,
GtkWidget *sample)
@@ -508,12 +501,19 @@ cossa_previewer_select_sample (CossaPreviewer *previewer,
GList *samples;
g_return_if_fail (COSSA_IS_PREVIEWER (previewer));
- g_return_if_fail (GTK_IS_WIDGET (sample));
- widget = GTK_WIDGET (previewer);
priv = previewer->priv;
+
+ if (sample == NULL)
+ {
+ priv->cur_sample = NULL;
+ gtk_widget_queue_resize (GTK_WIDGET (previewer));
+
+ return;
+ }
+
+ widget = GTK_WIDGET (previewer);
samples = priv->samples;
- priv->show_all = FALSE;
while (samples)
{
@@ -538,21 +538,6 @@ cossa_previewer_select_sample (CossaPreviewer *previewer,
gtk_widget_queue_draw (GTK_WIDGET (previewer));
}
-void
-cossa_previewer_show_all_samples (CossaPreviewer *previewer)
-{
- CossaPreviewerPrivate *priv;
-
- g_return_if_fail (COSSA_IS_PREVIEWER (previewer));
-
- priv = previewer->priv;
-
- priv->show_all = TRUE;
- priv->cur_sample = NULL;
-
- gtk_widget_queue_resize (GTK_WIDGET (previewer));
-}
-
static void
cossa_previewer_invalidate_samples (CossaPreviewer *previewer,
guint invalidation)
@@ -570,19 +555,14 @@ cossa_previewer_invalidate_samples (CossaPreviewer *previewer,
data->invalidation |= invalidation;
- if (priv->show_all)
+ if (!priv->cur_sample)
update_sample_surface (data, priv->zoom_level);
}
- if (priv->show_all)
- {
- gtk_widget_queue_resize (widget);
- }
- else if (priv->cur_sample)
- {
- update_sample_surface (priv->cur_sample->data, priv->zoom_level);
- gtk_widget_queue_resize (widget);
- }
+ if (priv->cur_sample)
+ update_sample_surface (priv->cur_sample->data, priv->zoom_level);
+
+ gtk_widget_queue_resize (widget);
}
void
diff --git a/src/cossa-previewer.h b/src/cossa-previewer.h
index 016a4dc..7c3edbf 100644
--- a/src/cossa-previewer.h
+++ b/src/cossa-previewer.h
@@ -63,8 +63,6 @@ void cossa_previewer_add_sample (CossaPreviewer *previewer,
void cossa_previewer_select_sample (CossaPreviewer *previewer,
GtkWidget *sample);
-void cossa_previewer_show_all_samples (CossaPreviewer *previewer);
-
void cossa_previewer_set_zoom_level (CossaPreviewer *previewer,
CossaZoomLevel zoom);
CossaZoomLevel cossa_previewer_get_zoom_level (CossaPreviewer *previewer);
diff --git a/src/cossa-window.c b/src/cossa-window.c
index 1eed79f..3661a17 100644
--- a/src/cossa-window.c
+++ b/src/cossa-window.c
@@ -96,10 +96,7 @@ select_sample_cb (GtkAction *action,
widget = g_object_get_data (G_OBJECT (action), "cossa-sample-widget");
priv = COSSA_WINDOW (user_data)->priv;
- if (widget != NULL)
- cossa_previewer_select_sample (COSSA_PREVIEWER (priv->previewer), widget);
- else
- cossa_previewer_show_all_samples (COSSA_PREVIEWER (priv->previewer));
+ cossa_previewer_select_sample (COSSA_PREVIEWER (priv->previewer), widget);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]