Commit 52a42769 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

automatically add an "(Empty)" item if the store is empty and remove it as

2004-04-22  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/gimpintstore.[ch]: automatically add an "(Empty)"
	item if the store is empty and remove it as soon as other items
	are being added.

	* libgimp/gimpdrawablecombobox.c
	* libgimp/gimpimagecombobox.c: removed handling of the empty list;
	the store does this for us now.
parent 331ae427
2004-04-22 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpintstore.[ch]: automatically add an "(Empty)"
item if the store is empty and remove it as soon as other items
are being added.
* libgimp/gimpdrawablecombobox.c
* libgimp/gimpimagecombobox.c: removed handling of the empty list;
the store does this for us now.
2004-04-22 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpintcombobox.c (gimp_int_combo_box_new):
......
......@@ -31,19 +31,16 @@
#include "gimpdrawablecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
static void gimp_drawable_combo_box_model_add_empty (GtkListStore *store);
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
/**
......@@ -73,7 +70,6 @@ gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
......@@ -88,25 +84,22 @@ gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_empty (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
......@@ -134,7 +127,6 @@ gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
......@@ -149,18 +141,15 @@ gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gint num_drawables;
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_empty (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
......@@ -188,7 +177,6 @@ gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
......@@ -203,18 +191,15 @@ gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_empty (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
......@@ -271,15 +256,3 @@ gimp_drawable_combo_box_model_add (GtkListStore *store,
return added;
}
static void
gimp_drawable_combo_box_model_add_empty (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(Empty)"),
-1);
}
......@@ -31,18 +31,15 @@
#include "gimpimagecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static void gimp_image_combo_box_model_add (GtkListStore *store,
gint num_images,
gint32 *images,
GimpImageConstraintFunc constraint,
gpointer data);
static void gimp_image_combo_box_model_add_empty (GtkListStore *store);
static void gimp_image_combo_box_model_add (GtkListStore *store,
gint num_images,
gint32 *images,
GimpImageConstraintFunc constraint,
gpointer data);
/**
......@@ -79,13 +76,9 @@ gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
images = gimp_image_list (&num_images);
if (num_images > 0)
gimp_image_combo_box_model_add (GTK_LIST_STORE (model),
num_images, images,
constraint, data);
else
gimp_image_combo_box_model_add_empty (GTK_LIST_STORE (model));
gimp_image_combo_box_model_add (GTK_LIST_STORE (model),
num_images, images,
constraint, data);
g_free (images);
if (gtk_tree_model_get_iter_first (model, &iter))
......@@ -135,15 +128,3 @@ gimp_image_combo_box_model_add (GtkListStore *store,
}
}
}
static void
gimp_image_combo_box_model_add_empty (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(Empty)"),
-1);
}
......@@ -31,19 +31,16 @@
#include "gimpdrawablecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
static void gimp_drawable_combo_box_model_add_empty (GtkListStore *store);
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
/**
......@@ -73,7 +70,6 @@ gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
......@@ -88,25 +84,22 @@ gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_empty (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
......@@ -134,7 +127,6 @@ gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
......@@ -149,18 +141,15 @@ gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gint num_drawables;
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_empty (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
......@@ -188,7 +177,6 @@ gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
......@@ -203,18 +191,15 @@ gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_empty (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
......@@ -271,15 +256,3 @@ gimp_drawable_combo_box_model_add (GtkListStore *store,
return added;
}
static void
gimp_drawable_combo_box_model_add_empty (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(Empty)"),
-1);
}
......@@ -22,14 +22,31 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "gimpwidgetstypes.h"
#include "gimpintstore.h"
#include "libgimp/libgimp-intl.h"
static void gimp_int_store_class_init (GimpIntStoreClass *klass);
static void gimp_int_store_tree_model_init (GtkTreeModelIface *iface);
static void gimp_int_store_init (GimpIntStore *store);
static void gimp_int_store_finalize (GObject *object);
static void gimp_int_store_row_inserted (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter);
static void gimp_int_store_row_deleted (GtkTreeModel *model,
GtkTreePath *path);
static void gimp_int_store_add_empty (GimpIntStore *store);
static void gimp_int_store_init (GimpIntStore *store);
static GtkListStoreClass *parent_class = NULL;
static GtkTreeModelIface *parent_iface = NULL;
GType
......@@ -44,22 +61,51 @@ gimp_int_store_get_type (void)
sizeof (GimpIntStoreClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_init */
(GClassInitFunc) gimp_int_store_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpIntStore),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_int_store_init
};
static const GInterfaceInfo iface_info =
{
(GInterfaceInitFunc) gimp_int_store_tree_model_init,
NULL, /* iface_finalize */
NULL /* iface_data */
};
store_type = g_type_register_static (GTK_TYPE_LIST_STORE,
"GimpIntStore",
&store_info, 0);
g_type_add_interface_static (store_type, GTK_TYPE_TREE_MODEL,
&iface_info);
}
return store_type;
}
static void
gimp_int_store_class_init (GimpIntStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_int_store_finalize;
}
static void
gimp_int_store_tree_model_init (GtkTreeModelIface *iface)
{
parent_iface = g_type_interface_peek_parent (iface);
iface->row_inserted = gimp_int_store_row_inserted;
iface->row_deleted = gimp_int_store_row_deleted;
}
static void
gimp_int_store_init (GimpIntStore *store)
{
......@@ -72,10 +118,71 @@ gimp_int_store_init (GimpIntStore *store)
G_TYPE_POINTER /* GIMP_INT_STORE_USER_DATA */
};
store->empty_iter = NULL;
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
GIMP_INT_STORE_NUM_COLUMNS, types);
gimp_int_store_add_empty (store);
}
static void
gimp_int_store_finalize (GObject *object)
{
GimpIntStore *store = GIMP_INT_STORE (object);
if (store->empty_iter)
{
gtk_tree_iter_free (store->empty_iter);
store->empty_iter = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_int_store_row_inserted (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter)
{
GimpIntStore *store = GIMP_INT_STORE (model);
if (parent_iface->row_inserted)
parent_iface->row_inserted (model, path, iter);
if (store->empty_iter &&
memcmp (iter, store->empty_iter, sizeof (GtkTreeIter)))
{
gtk_list_store_remove (GTK_LIST_STORE (store), store->empty_iter);
gtk_tree_iter_free (store->empty_iter);
store->empty_iter = NULL;
}
}
static void
gimp_int_store_row_deleted (GtkTreeModel *model,
GtkTreePath *path)
{
if (parent_iface->row_deleted)
parent_iface->row_deleted (model, path);
if (gtk_tree_model_iter_n_children (model, NULL) == 0)
gimp_int_store_add_empty (GIMP_INT_STORE (model));
}
static void
gimp_int_store_add_empty (GimpIntStore *store)
{
g_return_if_fail (store->empty_iter == NULL);
store->empty_iter = g_new (GtkTreeIter, 1);
gtk_list_store_prepend (GTK_LIST_STORE (store), store->empty_iter);
gtk_list_store_set (GTK_LIST_STORE (store), store->empty_iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, (_("(Empty)")),
-1);
}
/**
* gimp_int_store_new:
......@@ -109,8 +216,8 @@ gimp_int_store_new (void)
**/
gboolean
gimp_int_store_lookup_by_value (GtkTreeModel *model,
gint value,
GtkTreeIter *iter)
gint value,
GtkTreeIter *iter)
{
gboolean iter_valid;
......
......@@ -56,6 +56,9 @@ struct _GimpIntStoreClass
struct _GimpIntStore
{
GtkListStore parent_instance;
/*< private >*/
GtkTreeIter *empty_iter;
};
......
2004-04-22 Sven Neumann <sven@gimp.org>
* POTFILES.in: removed some files again, added another one instead.
* de.po: updated.
2004-04-22 Sigurd Gartmann <sigurd-translate@brogar.org>
......
......@@ -2,11 +2,9 @@
# marked to allow runtime translation of messages
libgimp/gimpbrushmenu.c
libgimp/gimpdrawablecombobox.c
libgimp/gimpexport.c
libgimp/gimpfontmenu.c
libgimp/gimpgradientmenu.c
libgimp/gimpimagecombobox.c
libgimp/gimpmenu.c
libgimp/gimppatternmenu.c
libgimp/gimpunitcache.c
......@@ -23,6 +21,7 @@ libgimpwidgets/gimpcolorscales.c
libgimpwidgets/gimpcolorselect.c
libgimpwidgets/gimpcolorselection.c
libgimpwidgets/gimpfileentry.c
libgimpwidgets/gimpintstore.c
libgimpwidgets/gimpmemsizeentry.c
libgimpwidgets/gimppatheditor.c
libgimpwidgets/gimppickbutton.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment