Commit 1a8a806d authored by Martin Nordholts's avatar Martin Nordholts

app: Make GimpToolbox use parent UI manager

Make GimpToolbox and GimpToolPalette use the GimpUIManager and
GimpDialogFactory of the top container instead of holding references
on their own. If they hold references on their own, we need to update
these when we move e.g. GimpToolbox between different top level
containers such as GimpDockWindow and GimpImageWindow. Failure to do
this cased problems talked about in bug 646794 (case 2).
parent 77ac7ffa
......@@ -51,7 +51,7 @@ brush_preview_clicked (GtkWidget *widget,
GdkModifierType state,
GimpToolbox *toolbox)
{
gimp_dialog_factory_dialog_raise (gimp_toolbox_get_dialog_factory (toolbox),
gimp_dialog_factory_dialog_raise (gimp_dock_get_dialog_factory (GIMP_DOCK (toolbox)),
gtk_widget_get_screen (widget),
"gimp-brush-grid|gimp-brush-list", -1);
}
......@@ -73,7 +73,7 @@ pattern_preview_clicked (GtkWidget *widget,
GdkModifierType state,
GimpToolbox *toolbox)
{
gimp_dialog_factory_dialog_raise (gimp_toolbox_get_dialog_factory (toolbox),
gimp_dialog_factory_dialog_raise (gimp_dock_get_dialog_factory (GIMP_DOCK (toolbox)),
gtk_widget_get_screen (widget),
"gimp-pattern-grid|gimp-pattern-list", -1);
}
......@@ -95,7 +95,7 @@ gradient_preview_clicked (GtkWidget *widget,
GdkModifierType state,
GimpToolbox *toolbox)
{
gimp_dialog_factory_dialog_raise (gimp_toolbox_get_dialog_factory (toolbox),
gimp_dialog_factory_dialog_raise (gimp_dock_get_dialog_factory (GIMP_DOCK (toolbox)),
gtk_widget_get_screen (widget),
"gimp-gradient-list|gimp-gradient-grid", -1);
}
......
......@@ -60,17 +60,13 @@
enum
{
PROP_0,
PROP_CONTEXT,
PROP_DIALOG_FACTORY,
PROP_UI_MANAGER
PROP_CONTEXT
};
struct _GimpToolboxPrivate
{
GimpContext *context;
GimpDialogFactory *dialog_factory;
GimpUIManager *ui_manager;
GtkWidget *vbox;
......@@ -90,8 +86,8 @@ struct _GimpToolboxPrivate
};
static void gimp_toolbox_constructed (GObject *object);
static void gimp_toolbox_dispose (GObject *object);
static void gimp_toolbox_constructed (GObject *object);
static void gimp_toolbox_dispose (GObject *object);
static void gimp_toolbox_set_property (GObject *object,
guint property_id,
const GValue *value,
......@@ -182,20 +178,6 @@ gimp_toolbox_class_init (GimpToolboxClass *klass)
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_DIALOG_FACTORY,
g_param_spec_object ("dialog-factory",
NULL, NULL,
GIMP_TYPE_DIALOG_FACTORY,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_UI_MANAGER,
g_param_spec_object ("ui-manager",
NULL, NULL,
GIMP_TYPE_UI_MANAGER,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (klass, sizeof (GimpToolboxPrivate));
}
......@@ -220,8 +202,6 @@ gimp_toolbox_constructed (GObject *object)
GList *list;
g_assert (GIMP_IS_CONTEXT (toolbox->p->context));
g_assert (GIMP_IS_UI_MANAGER (toolbox->p->ui_manager));
g_assert (GIMP_IS_DIALOG_FACTORY (toolbox->p->dialog_factory));
config = GIMP_GUI_CONFIG (toolbox->p->context->gimp->config);
......@@ -273,9 +253,9 @@ gimp_toolbox_constructed (GObject *object)
G_CALLBACK (toolbox_wilber_notify),
toolbox->p->header, 0);
toolbox->p->tool_palette = gimp_tool_palette_new (toolbox->p->context,
toolbox->p->ui_manager,
toolbox->p->dialog_factory);
toolbox->p->tool_palette = gimp_tool_palette_new ();
gimp_tool_palette_set_toolbox (GIMP_TOOL_PALETTE (toolbox->p->tool_palette),
toolbox);
gtk_box_pack_start (GTK_BOX (toolbox->p->vbox), toolbox->p->tool_palette,
FALSE, FALSE, 0);
gtk_widget_show (toolbox->p->tool_palette);
......@@ -361,18 +341,6 @@ gimp_toolbox_dispose (GObject *object)
toolbox->p->context = NULL;
}
if (toolbox->p->dialog_factory)
{
g_object_unref (toolbox->p->dialog_factory);
toolbox->p->dialog_factory = NULL;
}
if (toolbox->p->ui_manager)
{
g_object_unref (toolbox->p->ui_manager);
toolbox->p->ui_manager = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
toolbox->p->in_destruction = FALSE;
......@@ -392,14 +360,6 @@ gimp_toolbox_set_property (GObject *object,
toolbox->p->context = g_value_dup_object (value);
break;
case PROP_DIALOG_FACTORY:
toolbox->p->dialog_factory = g_value_dup_object (value);
break;
case PROP_UI_MANAGER:
toolbox->p->ui_manager = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -420,14 +380,6 @@ gimp_toolbox_get_property (GObject *object,
g_value_set_object (value, toolbox->p->context);
break;
case PROP_DIALOG_FACTORY:
g_value_set_object (value, toolbox->p->dialog_factory);
break;
case PROP_UI_MANAGER:
g_value_set_object (value, toolbox->p->ui_manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -683,9 +635,7 @@ gimp_toolbox_new (GimpDialogFactory *factory,
g_return_val_if_fail (GIMP_IS_UI_MANAGER (ui_manager), NULL);
return g_object_new (GIMP_TYPE_TOOLBOX,
"dialog-factory", factory,
"context", context,
"ui-manager", ui_manager,
"context", context,
NULL);
}
......@@ -697,14 +647,6 @@ gimp_toolbox_get_context (GimpToolbox *toolbox)
return toolbox->p->context;
}
GimpDialogFactory *
gimp_toolbox_get_dialog_factory (GimpToolbox *toolbox)
{
g_return_val_if_fail (GIMP_IS_TOOLBOX (toolbox), NULL);
return toolbox->p->dialog_factory;
}
void
gimp_toolbox_set_drag_handler (GimpToolbox *toolbox,
GimpPanedBox *drag_handler)
......
......@@ -51,7 +51,6 @@ GtkWidget * gimp_toolbox_new (GimpDialogFactory *factory,
GimpContext *context,
GimpUIManager *ui_manager);
GimpContext * gimp_toolbox_get_context (GimpToolbox *toolbox);
GimpDialogFactory * gimp_toolbox_get_dialog_factory (GimpToolbox *toolbox);
void gimp_toolbox_set_drag_handler (GimpToolbox *toolbox,
GimpPanedBox *drag_handler);
......
......@@ -31,6 +31,7 @@
#include "core/gimptoolinfo.h"
#include "gimpdialogfactory.h"
#include "gimptoolbox.h"
#include "gimptoolpalette.h"
#include "gimptoolpalette.h"
#include "gimpuimanager.h"
......@@ -46,25 +47,14 @@
#define TOOL_INFO_DATA_KEY "gimp-tool-info"
enum
{
PROP_0,
PROP_CONTEXT,
PROP_UI_MANAGER,
PROP_DIALOG_FACTORY
};
typedef struct _GimpToolPalettePrivate GimpToolPalettePrivate;
struct _GimpToolPalettePrivate
{
GimpContext *context;
GimpUIManager *ui_manager;
GimpDialogFactory *dialog_factory;
GimpToolbox *toolbox;
gint tool_rows;
gint tool_columns;
gint tool_rows;
gint tool_columns;
};
#define GET_PRIVATE(p) G_TYPE_INSTANCE_GET_PRIVATE (p, \
......@@ -72,16 +62,6 @@ struct _GimpToolPalettePrivate
GimpToolPalettePrivate)
static void gimp_tool_palette_constructed (GObject *object);
static void gimp_tool_palette_dispose (GObject *object);
static void gimp_tool_palette_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_tool_palette_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_tool_palette_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gimp_tool_palette_style_set (GtkWidget *widget,
......@@ -113,38 +93,11 @@ G_DEFINE_TYPE (GimpToolPalette, gimp_tool_palette, GTK_TYPE_TOOL_PALETTE)
static void
gimp_tool_palette_class_init (GimpToolPaletteClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = gimp_tool_palette_constructed;
object_class->dispose = gimp_tool_palette_dispose;
object_class->set_property = gimp_tool_palette_set_property;
object_class->get_property = gimp_tool_palette_get_property;
widget_class->size_allocate = gimp_tool_palette_size_allocate;
widget_class->style_set = gimp_tool_palette_style_set;
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("context",
NULL, NULL,
GIMP_TYPE_CONTEXT,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_UI_MANAGER,
g_param_spec_object ("ui-manager",
NULL, NULL,
GIMP_TYPE_UI_MANAGER,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_DIALOG_FACTORY,
g_param_spec_object ("dialog-factory",
NULL, NULL,
GIMP_TYPE_DIALOG_FACTORY,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_enum ("tool-icon-size",
NULL, NULL,
......@@ -167,109 +120,6 @@ gimp_tool_palette_init (GimpToolPalette *palette)
{
}
static void
gimp_tool_palette_constructed (GObject *object)
{
GimpToolPalettePrivate *private = GET_PRIVATE (object);
g_assert (GIMP_IS_CONTEXT (private->context));
g_assert (GIMP_IS_UI_MANAGER (private->ui_manager));
g_assert (GIMP_IS_DIALOG_FACTORY (private->dialog_factory));
gimp_tool_palette_initialize_tools (GIMP_TOOL_PALETTE (object));
g_signal_connect_object (private->context->gimp->tool_info_list, "reorder",
G_CALLBACK (gimp_tool_palette_tool_reorder),
object, 0);
g_signal_connect_object (private->context, "tool-changed",
G_CALLBACK (gimp_tool_palette_tool_changed),
object,
0);
}
static void
gimp_tool_palette_dispose (GObject *object)
{
GimpToolPalettePrivate *private = GET_PRIVATE (object);
if (private->context)
{
g_object_unref (private->context);
private->context = NULL;
}
if (private->ui_manager)
{
g_object_unref (private->ui_manager);
private->ui_manager = NULL;
}
if (private->dialog_factory)
{
g_object_unref (private->dialog_factory);
private->dialog_factory = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_tool_palette_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpToolPalettePrivate *private = GET_PRIVATE (object);
switch (property_id)
{
case PROP_CONTEXT:
private->context = g_value_dup_object (value);
break;
case PROP_UI_MANAGER:
private->ui_manager = g_value_dup_object (value);
break;
case PROP_DIALOG_FACTORY:
private->dialog_factory = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_tool_palette_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpToolPalettePrivate *private = GET_PRIVATE (object);
switch (property_id)
{
case PROP_CONTEXT:
g_value_set_object (value, private->context);
break;
case PROP_UI_MANAGER:
g_value_set_object (value, private->ui_manager);
break;
case PROP_DIALOG_FACTORY:
g_value_set_object (value, private->ui_manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_tool_palette_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
......@@ -283,7 +133,7 @@ gimp_tool_palette_size_allocate (GtkWidget *widget,
if (gimp_tool_palette_get_button_size (GIMP_TOOL_PALETTE (widget),
&button_width, &button_height))
{
Gimp *gimp = private->context->gimp;
Gimp *gimp = gimp_toolbox_get_context (private->toolbox)->gimp;
GList *list;
gint n_tools;
gint tool_rows;
......@@ -329,10 +179,10 @@ gimp_tool_palette_style_set (GtkWidget *widget,
GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
if (! private->context)
if (! gimp_toolbox_get_context (private->toolbox))
return;
gimp = private->context->gimp;
gimp = gimp_toolbox_get_context (private->toolbox)->gimp;
gtk_widget_style_get (widget,
"tool-icon-size", &tool_icon_size,
......@@ -361,19 +211,43 @@ gimp_tool_palette_style_set (GtkWidget *widget,
}
GtkWidget *
gimp_tool_palette_new (GimpContext *context,
GimpUIManager *ui_manager,
GimpDialogFactory *dialog_factory)
gimp_tool_palette_new (void)
{
return g_object_new (GIMP_TYPE_TOOL_PALETTE, NULL);
}
void
gimp_tool_palette_set_toolbox (GimpToolPalette *palette,
GimpToolbox *toolbox)
{
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (GIMP_IS_UI_MANAGER (ui_manager), NULL);
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
return g_object_new (GIMP_TYPE_TOOL_PALETTE,
"context", context,
"ui-manager", ui_manager,
"dialog-factory", dialog_factory,
NULL);
GimpToolPalettePrivate *private;
GimpContext *context;
g_return_if_fail (GIMP_IS_TOOL_PALETTE (palette));
g_return_if_fail (GIMP_IS_TOOLBOX (toolbox));
private = GET_PRIVATE (palette);
private->toolbox = toolbox;
context = gimp_toolbox_get_context (toolbox);
/**
* We must wait until GimpToolbox has a parent so we can use
* GimpDock::get_ui_manager() and ::get_dialog_factory().
*/
g_signal_connect_swapped (private->toolbox, "parent-set",
G_CALLBACK (gimp_tool_palette_initialize_tools),
palette);
g_signal_connect_object (context->gimp->tool_info_list, "reorder",
G_CALLBACK (gimp_tool_palette_tool_reorder),
palette, 0);
g_signal_connect_object (context, "tool-changed",
G_CALLBACK (gimp_tool_palette_tool_changed),
palette,
0);
}
gboolean
......@@ -391,7 +265,7 @@ gimp_tool_palette_get_button_size (GimpToolPalette *palette,
private = GET_PRIVATE (palette);
tool_info = gimp_get_tool_info (private->context->gimp,
tool_info = gimp_get_tool_info (gimp_toolbox_get_context (private->toolbox)->gimp,
"gimp-rect-select-tool");
tool_button = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
......@@ -476,7 +350,7 @@ gimp_tool_palette_tool_button_toggled (GtkWidget *widget,
tool_info = g_object_get_data (G_OBJECT (widget), TOOL_INFO_DATA_KEY);
if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (widget)))
gimp_context_set_tool (private->context, tool_info);
gimp_context_set_tool (gimp_toolbox_get_context (private->toolbox), tool_info);
}
static gboolean
......@@ -488,7 +362,9 @@ gimp_tool_palette_tool_button_press (GtkWidget *widget,
if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
{
gimp_dialog_factory_dialog_raise (private->dialog_factory,
GimpDock *dock = GIMP_DOCK (private->toolbox);
gimp_dialog_factory_dialog_raise (gimp_dock_get_dialog_factory (dock),
gtk_widget_get_screen (widget),
"gimp-tool-options",
-1);
......@@ -500,6 +376,7 @@ gimp_tool_palette_tool_button_press (GtkWidget *widget,
static void
gimp_tool_palette_initialize_tools (GimpToolPalette *palette)
{
GimpContext *context;
GimpToolInfo *active_tool;
GList *list;
GSList *item_group = NULL;
......@@ -511,15 +388,17 @@ gimp_tool_palette_initialize_tools (GimpToolPalette *palette)
gtk_container_add (GTK_CONTAINER (palette), group);
gtk_widget_show (group);
active_tool = gimp_context_get_tool (private->context);
context = gimp_toolbox_get_context (private->toolbox);
active_tool = gimp_context_get_tool (context);
for (list = gimp_get_tool_info_iter (private->context->gimp);
for (list = gimp_get_tool_info_iter (context->gimp);
list;
list = g_list_next (list))
{
GimpToolInfo *tool_info = list->data;
GtkToolItem *item;
const gchar *stock_id;
GimpToolInfo *tool_info = list->data;
GtkToolItem *item;
const gchar *stock_id;
GimpUIManager *ui_manager;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
......@@ -549,7 +428,8 @@ gimp_tool_palette_initialize_tools (GimpToolPalette *palette)
G_CALLBACK (gimp_tool_palette_tool_button_press),
palette);
if (private->ui_manager)
ui_manager = gimp_dock_get_ui_manager (GIMP_DOCK (private->toolbox));
if (ui_manager)
{
GtkAction *action = NULL;
const gchar *identifier = NULL;
......@@ -563,8 +443,7 @@ gimp_tool_palette_initialize_tools (GimpToolPalette *palette)
name = g_strdup_printf ("tools-%s", tmp);
g_free (tmp);
action = gimp_ui_manager_find_action (private->ui_manager,
"tools", name);
action = gimp_ui_manager_find_action (ui_manager, "tools", name);
g_free (name);
if (action)
......
......@@ -45,9 +45,9 @@ struct _GimpToolPaletteClass
GType gimp_tool_palette_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_tool_palette_new (GimpContext *context,
GimpUIManager *ui_manager,
GimpDialogFactory *dialog_factory);
GtkWidget * gimp_tool_palette_new (void);
void gimp_tool_palette_set_toolbox (GimpToolPalette *palette,
GimpToolbox *toolbox);
gboolean gimp_tool_palette_get_button_size (GimpToolPalette *palette,
gint *width,
gint *height);
......
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