implement set_context() and set the view renderers' contexts.

2006-09-01  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpcontainercombobox.c: implement set_context() and
	set the view renderers' contexts.

	(gimp_container_combo_box_insert_item): unselect after inserting
	the first item, GimpContainerView doesn't select items by itself.

	* app/dialogs/image-new-dialog.c: create a local context for the
	combo box, connect to the context's "template-changed" signal
	instead of the combo boxed's "select-item", fix some stuff and
	don't leak the local GimpTemplate.
This commit is contained in:
Michael Natterer 2006-09-01 16:55:37 +00:00 committed by Michael Natterer
parent f596bb1a1b
commit cc8553fd1e
3 changed files with 126 additions and 68 deletions

View File

@ -1,3 +1,16 @@
2006-09-01 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcontainercombobox.c: implement set_context() and
set the view renderers' contexts.
(gimp_container_combo_box_insert_item): unselect after inserting
the first item, GimpContainerView doesn't select items by itself.
* app/dialogs/image-new-dialog.c: create a local context for the
combo box, connect to the context's "template-changed" signal
instead of the combo boxed's "select-item", fix some stuff and
don't leak the local GimpTemplate.
2006-09-01 Sven Neumann <sven@gimp.org>
* app/core/gimpgradient.c: disallow NULL context and removed code

View File

@ -37,7 +37,6 @@
#include "core/gimptemplate.h"
#include "widgets/gimpcontainercombobox.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
@ -65,15 +64,15 @@ typedef struct
/* local function prototypes */
static void image_new_response (GtkWidget *widget,
gint response_id,
ImageNewDialog *dialog);
static void image_new_template_select (GimpContainerView *view,
GimpTemplate *template,
gpointer insert_data,
ImageNewDialog *dialog);
static void image_new_confirm_dialog (ImageNewDialog *dialog);
static void image_new_create_image (ImageNewDialog *dialog);
static void image_new_free (ImageNewDialog *dialog);
static void image_new_response (GtkWidget *widget,
gint response_id,
ImageNewDialog *dialog);
static void image_new_template_changed (GimpContext *context,
GimpTemplate *template,
ImageNewDialog *dialog);
static void image_new_confirm_dialog (ImageNewDialog *dialog);
static void image_new_create_image (ImageNewDialog *dialog);
/* public functions */
@ -90,7 +89,8 @@ image_new_dialog_new (GimpContext *context)
dialog = g_new0 (ImageNewDialog, 1);
dialog->context = context;
dialog->context = gimp_context_new (context->gimp, "image-new-dialog",
context);
dialog->template = g_object_new (GIMP_TYPE_TEMPLATE, NULL);
dialog->dialog = gimp_dialog_new (_("Create a New Image"),
@ -108,7 +108,7 @@ image_new_dialog_new (GimpContext *context)
g_object_set_data_full (G_OBJECT (dialog->dialog),
"gimp-image-new-dialog", dialog,
(GDestroyNotify) g_free);
(GDestroyNotify) image_new_free);
g_signal_connect (dialog->dialog, "response",
G_CALLBACK (image_new_response),
@ -133,6 +133,7 @@ image_new_dialog_new (GimpContext *context)
dialog->combo = g_object_new (GIMP_TYPE_CONTAINER_COMBO_BOX,
"container", context->gimp->templates,
"context", dialog->context,
"view-size", 16,
"view-border-width", 0,
"ellipsize", PANGO_ELLIPSIZE_NONE,
@ -143,8 +144,8 @@ image_new_dialog_new (GimpContext *context)
_("_Template:"), 0.0, 0.5,
dialog->combo, 1, TRUE);
g_signal_connect (dialog->combo, "select-item",
G_CALLBACK (image_new_template_select),
g_signal_connect (dialog->context, "template-changed",
G_CALLBACK (image_new_template_changed),
dialog);
/* Template editor */
@ -157,6 +158,10 @@ image_new_dialog_new (GimpContext *context)
gimp_size_entry_set_activates_default (entry, TRUE);
gimp_size_entry_grab_focus (entry);
image_new_template_changed (dialog->context,
gimp_context_get_template (dialog->context),
dialog);
return dialog->dialog;
}
@ -175,12 +180,9 @@ image_new_dialog_set (GtkWidget *widget,
g_return_if_fail (dialog != NULL);
if (template)
{
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (dialog->combo),
GIMP_VIEWABLE (template));
}
else
gimp_context_set_template (dialog->context, template);
if (! template)
{
template = gimp_image_new_get_last_template (dialog->context->gimp,
image);
@ -194,6 +196,14 @@ image_new_dialog_set (GtkWidget *widget,
/* private functions */
static void
image_new_free (ImageNewDialog *dialog)
{
g_object_unref (dialog->context);
g_object_unref (dialog->template);
g_free (dialog);
}
static void
image_new_response (GtkWidget *widget,
gint response_id,
@ -204,8 +214,7 @@ image_new_response (GtkWidget *widget,
case RESPONSE_RESET:
gimp_config_sync (G_OBJECT (dialog->context->gimp->config->default_image),
G_OBJECT (dialog->template), 0);
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (dialog->combo),
NULL);
gimp_context_set_template (dialog->context, NULL);
break;
case GTK_RESPONSE_OK:
@ -223,10 +232,9 @@ image_new_response (GtkWidget *widget,
}
static void
image_new_template_select (GimpContainerView *view,
GimpTemplate *template,
gpointer insert_data,
ImageNewDialog *dialog)
image_new_template_changed (GimpContext *context,
GimpTemplate *template,
ImageNewDialog *dialog)
{
gchar *comment = NULL;

View File

@ -63,6 +63,8 @@ static void gimp_container_combo_box_get_property (GObject *o
static void gimp_container_combo_box_unrealize (GtkWidget *widget);
static void gimp_container_combo_box_set_context (GimpContainerView *view,
GimpContext *context);
static gpointer gimp_container_combo_box_insert_item (GimpContainerView *view,
GimpViewable *viewable,
gint index);
@ -120,6 +122,26 @@ gimp_container_combo_box_class_init (GimpContainerComboBoxClass *klass)
G_PARAM_CONSTRUCT));
}
static void
gimp_container_combo_box_view_iface_init (GimpContainerViewInterface *iface)
{
parent_view_iface = g_type_interface_peek_parent (iface);
if (! parent_view_iface)
parent_view_iface = g_type_default_interface_peek (GIMP_TYPE_CONTAINER_VIEW);
iface->set_context = gimp_container_combo_box_set_context;
iface->insert_item = gimp_container_combo_box_insert_item;
iface->remove_item = gimp_container_combo_box_remove_item;
iface->reorder_item = gimp_container_combo_box_reorder_item;
iface->rename_item = gimp_container_combo_box_rename_item;
iface->select_item = gimp_container_combo_box_select_item;
iface->clear_items = gimp_container_combo_box_clear_items;
iface->set_view_size = gimp_container_combo_box_set_view_size;
iface->insert_data_free = (GDestroyNotify) g_free;
}
static void
gimp_container_combo_box_init (GimpContainerComboBox *combo_box)
{
@ -159,25 +181,6 @@ gimp_container_combo_box_init (GimpContainerComboBox *combo_box)
}
static void
gimp_container_combo_box_view_iface_init (GimpContainerViewInterface *iface)
{
parent_view_iface = g_type_interface_peek_parent (iface);
if (! parent_view_iface)
parent_view_iface = g_type_default_interface_peek (GIMP_TYPE_CONTAINER_VIEW);
iface->insert_item = gimp_container_combo_box_insert_item;
iface->remove_item = gimp_container_combo_box_remove_item;
iface->reorder_item = gimp_container_combo_box_reorder_item;
iface->rename_item = gimp_container_combo_box_rename_item;
iface->select_item = gimp_container_combo_box_select_item;
iface->clear_items = gimp_container_combo_box_clear_items;
iface->set_view_size = gimp_container_combo_box_set_view_size;
iface->insert_data_free = (GDestroyNotify) g_free;
}
static void
gimp_container_combo_box_set_property (GObject *object,
guint property_id,
@ -220,6 +223,30 @@ gimp_container_combo_box_get_property (GObject *object,
}
}
static void
gimp_container_combo_box_unrealize (GtkWidget *widget)
{
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
GtkTreeIter iter;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
GimpViewRenderer *renderer;
gtk_tree_model_get (model, &iter,
COLUMN_RENDERER, &renderer,
-1);
gimp_view_renderer_unrealize (renderer);
g_object_unref (renderer);
}
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
GtkWidget *
gimp_container_combo_box_new (GimpContainer *container,
GimpContext *context,
@ -286,32 +313,38 @@ gimp_container_combo_box_set (GimpContainerComboBox *combo_box,
g_free (name);
}
static void
gimp_container_combo_box_unrealize (GtkWidget *widget)
{
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
GtkTreeIter iter;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
GimpViewRenderer *renderer;
gtk_tree_model_get (model, &iter,
COLUMN_RENDERER, &renderer,
-1);
gimp_view_renderer_unrealize (renderer);
g_object_unref (renderer);
}
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
/* GimpContainerView methods */
static void
gimp_container_combo_box_set_context (GimpContainerView *view,
GimpContext *context)
{
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (view));
parent_view_iface->set_context (view, context);
if (model)
{
GtkTreeIter iter;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
GimpViewRenderer *renderer;
gtk_tree_model_get (model, &iter,
COLUMN_RENDERER, &renderer,
-1);
gimp_view_renderer_set_context (renderer, context);
g_object_unref (renderer);
}
}
}
static gpointer
gimp_container_combo_box_insert_item (GimpContainerView *view,
GimpViewable *viewable,
@ -327,6 +360,10 @@ gimp_container_combo_box_insert_item (GimpContainerView *view,
else
gtk_list_store_insert (GTK_LIST_STORE (model), iter, index);
/* GimpContainerViews don't select items by default */
if (gtk_tree_model_iter_n_children (model, NULL) == 1)
gtk_combo_box_set_active (GTK_COMBO_BOX (view), -1);
gimp_container_combo_box_set (GIMP_CONTAINER_COMBO_BOX (view),
iter, viewable);