Commit a5eff271 authored by Michael Natterer's avatar Michael Natterer 😴

app: add new GimpData subclass GimpMybrush and infrastructure around it

- GimpContext API and property
- a GimpDataFactory
- List and grid views with GimpDataFactoryView
- actions and a context menu

None of this is connected to the actual tool yet, or depends on
libmypaint in any way.
parent 4f8bc154
......@@ -117,6 +117,8 @@ libappactions_a_SOURCES = \
layers-actions.h \
layers-commands.c \
layers-commands.h \
mypaint-brushes-actions.c \
mypaint-brushes-actions.h \
palette-editor-actions.c \
palette-editor-actions.h \
palette-editor-commands.c \
......
......@@ -76,6 +76,7 @@
#include "image-actions.h"
#include "images-actions.h"
#include "layers-actions.h"
#include "mypaint-brushes-actions.h"
#include "palette-editor-actions.h"
#include "palettes-actions.h"
#include "patterns-actions.h"
......@@ -190,6 +191,9 @@ static const GimpActionFactoryEntry action_groups[] =
{ "layers", N_("Layers"), GIMP_STOCK_LAYER,
layers_actions_setup,
layers_actions_update },
{ "mypaint-brushes", N_("MyPaint Brushes"), GIMP_STOCK_MYPAINT_BRUSH,
mypaint_brushes_actions_setup,
mypaint_brushes_actions_update },
{ "palette-editor", N_("Palette Editor"), GIMP_STOCK_PALETTE,
palette_editor_actions_setup,
palette_editor_actions_update },
......
......@@ -151,6 +151,12 @@ const GimpStringActionEntry dialogs_dockable_actions[] =
"gimp-dynamics-editor",
GIMP_HELP_DYNAMICS_EDITOR_DIALOG },
{ "dialogs-mypaint-brushes", GIMP_STOCK_MYPAINT_BRUSH,
NC_("dialogs-action", "_MyPaint Brushes"), "<primary><shift>Y",
NC_("dialogs-action", "Open the mypaint brushes dialog"),
"gimp-mypaint-brush-grid|gimp-mapyint-brush-list",
GIMP_HELP_MYPAINT_BRUSH_DIALOG },
{ "dialogs-patterns", GIMP_STOCK_PATTERN,
NC_("dialogs-action", "P_atterns"), "<primary><shift>P",
NC_("dialogs-action", "Open the patterns dialog"),
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
#include "core/gimpcontext.h"
#include "core/gimpmybrush.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
#include "actions.h"
#include "data-commands.h"
#include "mypaint-brushes-actions.h"
#include "gimp-intl.h"
static const GimpActionEntry mypaint_brushes_actions[] =
{
{ "mypaint-brushes-popup", GIMP_STOCK_MYPAINT_BRUSH,
NC_("mypaint-brushes-action", "MyPaint Brushes Menu"), NULL, NULL, NULL,
GIMP_HELP_MYPAINT_BRUSH_DIALOG },
{ "mypaint-brushes-new", "document-new",
NC_("mypaint-brushes-action", "_New MyPaint Brush"), NULL,
NC_("mypaint-brushes-action", "Create a new MyPaint brush"),
G_CALLBACK (data_new_cmd_callback),
GIMP_HELP_MYPAINT_BRUSH_NEW },
{ "mypaint-brushes-duplicate", GIMP_STOCK_DUPLICATE,
NC_("mypaint-brushes-action", "D_uplicate MyPaint Brush"), NULL,
NC_("mypaint-brushes-action", "Duplicate this MyPaint brush"),
G_CALLBACK (data_duplicate_cmd_callback),
GIMP_HELP_MYPAINT_BRUSH_DUPLICATE },
{ "mypaint-brushes-copy-location", "edit-copy",
NC_("mypaint-brushes-action", "Copy MyPaint Brush _Location"), NULL,
NC_("mypaint-brushes-action", "Copy MyPaint brush file location to clipboard"),
G_CALLBACK (data_copy_location_cmd_callback),
GIMP_HELP_MYPAINT_BRUSH_COPY_LOCATION },
{ "mypaint-brushes-show-in-file-manager", "gtk-directory",
NC_("mypaint-brushes-action", "Show in _File Manager"), NULL,
NC_("mypaint-brushes-action", "Show MyPaint brush file location in the file manager"),
G_CALLBACK (data_show_in_file_manager_cmd_callback),
GIMP_HELP_MYPAINT_BRUSH_SHOW_IN_FILE_MANAGER },
{ "mypaint-brushes-delete", "edit-delete",
NC_("mypaint-brushes-action", "_Delete MyPaint Brush"), NULL,
NC_("mypaint-brushes-action", "Delete this MyPaint brush"),
G_CALLBACK (data_delete_cmd_callback),
GIMP_HELP_MYPAINT_BRUSH_DELETE },
{ "mypaint-brushes-refresh", "view-refresh",
NC_("mypaint-brushes-action", "_Refresh MyPaint Brushes"), NULL,
NC_("mypaint-brushes-action", "Refresh MyPaint brushes"),
G_CALLBACK (data_refresh_cmd_callback),
GIMP_HELP_MYPAINT_BRUSH_REFRESH }
};
static const GimpStringActionEntry mypaint_brushes_edit_actions[] =
{
{ "mypaint-brushes-edit", "gtk-edit",
NC_("mypaint-brushes-action", "_Edit MyPaint Brush..."), NULL,
NC_("mypaint-bruahes-action", "Edit MyPaint brush"),
"gimp-mypaint-bruah-editor",
GIMP_HELP_MYPAINT_BRUSH_EDIT }
};
void
mypaint_brushes_actions_setup (GimpActionGroup *group)
{
gimp_action_group_add_actions (group, "mypaint-brushes-action",
mypaint_brushes_actions,
G_N_ELEMENTS (mypaint_brushes_actions));
gimp_action_group_add_string_actions (group, "mypaint-brushes-action",
mypaint_brushes_edit_actions,
G_N_ELEMENTS (mypaint_brushes_edit_actions),
G_CALLBACK (data_edit_cmd_callback));
}
void
mypaint_brushes_actions_update (GimpActionGroup *group,
gpointer user_data)
{
GimpContext *context = action_data_get_context (user_data);
GimpMybrush *brush = NULL;
GimpData *data = NULL;
GFile *file = NULL;
if (context)
{
brush = gimp_context_get_mybrush (context);
if (action_data_sel_count (user_data) > 1)
{
brush = NULL;
}
if (brush)
{
data = GIMP_DATA (brush);
file = gimp_data_get_file (data);
}
}
#define SET_SENSITIVE(action,condition) \
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
SET_SENSITIVE ("mypaint-brushes-edit", brush && FALSE);
SET_SENSITIVE ("mypaint-brushes-duplicate", brush && GIMP_DATA_GET_CLASS (data)->duplicate);
SET_SENSITIVE ("mypaint-brushes-copy-location", file);
SET_SENSITIVE ("mypaint-brushes-show-in-file-manager", file);
SET_SENSITIVE ("mypaint-brushes-delete", brush && gimp_data_is_deletable (data));
#undef SET_SENSITIVE
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MYPAINT_BRUSHES_ACTIONS_H__
#define __MYPAINT_BRUSHES_ACTIONS_H__
void mypaint_brushes_actions_setup (GimpActionGroup *group);
void mypaint_brushes_actions_update (GimpActionGroup *group,
gpointer data);
#endif /* __MYPAINT_BRUSHES_ACTIONS_H__ */
......@@ -302,6 +302,10 @@ libappcore_a_sources = \
gimplist.h \
gimpmaskundo.c \
gimpmaskundo.h \
gimpmybrush.c \
gimpmybrush.h \
gimpmybrush-load.c \
gimpmybrush-load.h \
gimpobject.c \
gimpobject.h \
gimppaintinfo.c \
......
......@@ -556,14 +556,15 @@ typedef enum /*< pdb-skip, skip >*/
GIMP_CONTEXT_PROP_PAINT_MODE = 9,
GIMP_CONTEXT_PROP_BRUSH = 10,
GIMP_CONTEXT_PROP_DYNAMICS = 11,
GIMP_CONTEXT_PROP_PATTERN = 12,
GIMP_CONTEXT_PROP_GRADIENT = 13,
GIMP_CONTEXT_PROP_PALETTE = 14,
GIMP_CONTEXT_PROP_TOOL_PRESET = 15,
GIMP_CONTEXT_PROP_FONT = 16,
GIMP_CONTEXT_PROP_BUFFER = 17,
GIMP_CONTEXT_PROP_IMAGEFILE = 18,
GIMP_CONTEXT_PROP_TEMPLATE = 19,
GIMP_CONTEXT_PROP_MYBRUSH = 12,
GIMP_CONTEXT_PROP_PATTERN = 13,
GIMP_CONTEXT_PROP_GRADIENT = 14,
GIMP_CONTEXT_PROP_PALETTE = 15,
GIMP_CONTEXT_PROP_TOOL_PRESET = 16,
GIMP_CONTEXT_PROP_FONT = 17,
GIMP_CONTEXT_PROP_BUFFER = 18,
GIMP_CONTEXT_PROP_IMAGEFILE = 19,
GIMP_CONTEXT_PROP_TEMPLATE = 20,
GIMP_CONTEXT_PROP_LAST = GIMP_CONTEXT_PROP_TEMPLATE
} GimpContextPropType;
......@@ -581,14 +582,15 @@ typedef enum /*< pdb-skip, skip >*/
GIMP_CONTEXT_PROP_MASK_PAINT_MODE = 1 << 9,
GIMP_CONTEXT_PROP_MASK_BRUSH = 1 << 10,
GIMP_CONTEXT_PROP_MASK_DYNAMICS = 1 << 11,
GIMP_CONTEXT_PROP_MASK_PATTERN = 1 << 12,
GIMP_CONTEXT_PROP_MASK_GRADIENT = 1 << 13,
GIMP_CONTEXT_PROP_MASK_PALETTE = 1 << 14,
GIMP_CONTEXT_PROP_MASK_TOOL_PRESET = 1 << 15,
GIMP_CONTEXT_PROP_MASK_FONT = 1 << 16,
GIMP_CONTEXT_PROP_MASK_BUFFER = 1 << 17,
GIMP_CONTEXT_PROP_MASK_IMAGEFILE = 1 << 18,
GIMP_CONTEXT_PROP_MASK_TEMPLATE = 1 << 19,
GIMP_CONTEXT_PROP_MASK_MYBRUSH = 1 << 12,
GIMP_CONTEXT_PROP_MASK_PATTERN = 1 << 13,
GIMP_CONTEXT_PROP_MASK_GRADIENT = 1 << 14,
GIMP_CONTEXT_PROP_MASK_PALETTE = 1 << 15,
GIMP_CONTEXT_PROP_MASK_TOOL_PRESET = 1 << 16,
GIMP_CONTEXT_PROP_MASK_FONT = 1 << 17,
GIMP_CONTEXT_PROP_MASK_BUFFER = 1 << 18,
GIMP_CONTEXT_PROP_MASK_IMAGEFILE = 1 << 19,
GIMP_CONTEXT_PROP_MASK_TEMPLATE = 1 << 20,
/* aliases */
GIMP_CONTEXT_PROP_MASK_PAINT = (GIMP_CONTEXT_PROP_MASK_FOREGROUND |
......@@ -604,6 +606,7 @@ typedef enum /*< pdb-skip, skip >*/
GIMP_CONTEXT_PROP_MASK_DISPLAY |
GIMP_CONTEXT_PROP_MASK_TOOL |
GIMP_CONTEXT_PROP_MASK_PAINT_INFO |
GIMP_CONTEXT_PROP_MASK_MYBRUSH |
GIMP_CONTEXT_PROP_MASK_PALETTE |
GIMP_CONTEXT_PROP_MASK_FONT |
GIMP_CONTEXT_PROP_MASK_BUFFER |
......
......@@ -133,6 +133,7 @@ typedef struct _GimpCurve GimpCurve;
typedef struct _GimpDynamics GimpDynamics;
typedef struct _GimpDynamicsOutput GimpDynamicsOutput;
typedef struct _GimpGradient GimpGradient;
typedef struct _GimpMybrush GimpMybrush;
typedef struct _GimpPalette GimpPalette;
typedef struct _GimpPaletteMru GimpPaletteMru;
typedef struct _GimpPattern GimpPattern;
......
......@@ -70,6 +70,8 @@
#include "gimpimagefile.h"
#include "gimplist.h"
#include "gimpmarshal.h"
#include "gimpmybrush-load.h"
#include "gimpmybrush.h"
#include "gimppalette-load.h"
#include "gimppalette.h"
#include "gimpparasitelist.h"
......@@ -331,6 +333,9 @@ gimp_dispose (GObject *object)
if (gimp->dynamics_factory)
gimp_data_factory_data_free (gimp->dynamics_factory);
if (gimp->mybrush_factory)
gimp_data_factory_data_free (gimp->mybrush_factory);
if (gimp->pattern_factory)
gimp_data_factory_data_free (gimp->pattern_factory);
......@@ -359,6 +364,8 @@ gimp_finalize (GObject *object)
gimp_brush_get_standard (gimp->user_context));
standards = g_list_prepend (standards,
gimp_dynamics_get_standard (gimp->user_context));
standards = g_list_prepend (standards,
gimp_mybrush_get_standard (gimp->user_context));
standards = g_list_prepend (standards,
gimp_pattern_get_standard (gimp->user_context));
standards = g_list_prepend (standards,
......@@ -416,6 +423,12 @@ gimp_finalize (GObject *object)
gimp->dynamics_factory = NULL;
}
if (gimp->mybrush_factory)
{
g_object_unref (gimp->mybrush_factory);
gimp->mybrush_factory = NULL;
}
if (gimp->pattern_factory)
{
g_object_unref (gimp->pattern_factory);
......@@ -580,6 +593,8 @@ gimp_get_memsize (GimpObject *object,
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->dynamics_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->mybrush_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->pattern_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->gradient_factory),
......@@ -635,6 +650,11 @@ gimp_real_initialize (Gimp *gimp,
{ gimp_dynamics_load, GIMP_DYNAMICS_FILE_EXTENSION, TRUE }
};
static const GimpDataFactoryLoaderEntry mybrush_loader_entries[] =
{
{ gimp_mybrush_load, GIMP_MYBRUSH_FILE_EXTENSION, FALSE }
};
static const GimpDataFactoryLoaderEntry pattern_loader_entries[] =
{
{ gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION, FALSE },
......@@ -689,6 +709,17 @@ gimp_real_initialize (Gimp *gimp,
gimp_object_set_static_name (GIMP_OBJECT (gimp->dynamics_factory),
"dynamics factory");
gimp->mybrush_factory =
gimp_data_factory_new (gimp,
GIMP_TYPE_MYBRUSH,
"mypaint-brush-path", "mypaint-brush-path-writable",
mybrush_loader_entries,
G_N_ELEMENTS (mybrush_loader_entries),
NULL,
NULL);
gimp_object_set_static_name (GIMP_OBJECT (gimp->mybrush_factory),
"mypaint brush factory");
gimp->pattern_factory =
gimp_data_factory_new (gimp,
GIMP_TYPE_PATTERN,
......@@ -813,6 +844,7 @@ gimp_real_exit (Gimp *gimp,
gimp_data_factory_data_save (gimp->brush_factory);
gimp_data_factory_data_save (gimp->dynamics_factory);
gimp_data_factory_data_save (gimp->mybrush_factory);
gimp_data_factory_data_save (gimp->pattern_factory);
gimp_data_factory_data_save (gimp->gradient_factory);
gimp_data_factory_data_save (gimp->palette_factory);
......@@ -1055,6 +1087,11 @@ gimp_restore (Gimp *gimp,
gimp_data_factory_data_init (gimp->dynamics_factory, gimp->user_context,
gimp->no_data);
/* initialize the list of mypaint brushes */
status_callback (NULL, _("MyPaint Brushes"), 0.25);
gimp_data_factory_data_init (gimp->mybrush_factory, gimp->user_context,
gimp->no_data);
/* initialize the list of gimp patterns */
status_callback (NULL, _("Patterns"), 0.3);
gimp_data_factory_data_init (gimp->pattern_factory, gimp->user_context,
......@@ -1101,6 +1138,8 @@ gimp_restore (Gimp *gimp,
gimp_data_factory_get_container (gimp->brush_factory));
gimp_tag_cache_add_container (gimp->tag_cache,
gimp_data_factory_get_container (gimp->dynamics_factory));
gimp_tag_cache_add_container (gimp->tag_cache,
gimp_data_factory_get_container (gimp->mybrush_factory));
gimp_tag_cache_add_container (gimp->tag_cache,
gimp_data_factory_get_container (gimp->pattern_factory));
gimp_tag_cache_add_container (gimp->tag_cache,
......@@ -1118,6 +1157,7 @@ gimp_restore (Gimp *gimp,
*/
gimp_data_factory_data_clean (gimp->brush_factory);
gimp_data_factory_data_clean (gimp->dynamics_factory);
gimp_data_factory_data_clean (gimp->mybrush_factory);
gimp_data_factory_data_clean (gimp->pattern_factory);
gimp_data_factory_data_clean (gimp->palette_factory);
gimp_data_factory_data_clean (gimp->gradient_factory);
......
......@@ -94,6 +94,7 @@ struct _Gimp
GimpDataFactory *brush_factory;
GimpDataFactory *dynamics_factory;
GimpDataFactory *mybrush_factory;
GimpDataFactory *pattern_factory;
GimpDataFactory *gradient_factory;
GimpDataFactory *palette_factory;
......
......@@ -44,6 +44,7 @@
#include "gimpgradient.h"
#include "gimpimage.h"
#include "gimpmarshal.h"
#include "gimpmybrush.h"
#include "gimppaintinfo.h"
#include "gimppalette.h"
#include "gimppattern.h"
......@@ -177,6 +178,17 @@ static void gimp_context_dynamics_list_thaw (GimpContainer *container,
static void gimp_context_real_set_dynamics (GimpContext *context,
GimpDynamics *dynamics);
/* mybrush */
static void gimp_context_mybrush_dirty (GimpMybrush *brush,
GimpContext *context);
static void gimp_context_mybrush_removed (GimpContainer *brush_list,
GimpMybrush *brush,
GimpContext *context);
static void gimp_context_mybrush_list_thaw (GimpContainer *container,
GimpContext *context);
static void gimp_context_real_set_mybrush (GimpContext *context,
GimpMybrush *brush);
/* pattern */
static void gimp_context_pattern_dirty (GimpPattern *pattern,
GimpContext *context);
......@@ -297,6 +309,7 @@ enum
PAINT_MODE_CHANGED,
BRUSH_CHANGED,
DYNAMICS_CHANGED,
MYBRUSH_CHANGED,
PATTERN_CHANGED,
GRADIENT_CHANGED,
PALETTE_CHANGED,
......@@ -323,6 +336,7 @@ static const gchar * const gimp_context_prop_names[] =
"paint-mode",
"brush",
"dynamics",
"mybrush",
"pattern",
"gradient",
"palette",
......@@ -354,6 +368,7 @@ static GType gimp_context_prop_types[] =
0,
0,
0,
0,
0
};
......@@ -478,6 +493,16 @@ gimp_context_class_init (GimpContextClass *klass)
G_TYPE_NONE, 1,
GIMP_TYPE_DYNAMICS);
gimp_context_signals[MYBRUSH_CHANGED] =
g_signal_new ("mybrush-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpContextClass, mybrush_changed),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_MYBRUSH);
gimp_context_signals[PATTERN_CHANGED] =
g_signal_new ("pattern-changed",
G_TYPE_FROM_CLASS (klass),
......@@ -586,6 +611,7 @@ gimp_context_class_init (GimpContextClass *klass)
klass->paint_mode_changed = NULL;
klass->brush_changed = NULL;
klass->dynamics_changed = NULL;
klass->mybrush_changed = NULL;
klass->pattern_changed = NULL;
klass->gradient_changed = NULL;
klass->palette_changed = NULL;
......@@ -601,6 +627,7 @@ gimp_context_class_init (GimpContextClass *klass)
gimp_context_prop_types[GIMP_CONTEXT_PROP_PAINT_INFO] = GIMP_TYPE_PAINT_INFO;
gimp_context_prop_types[GIMP_CONTEXT_PROP_BRUSH] = GIMP_TYPE_BRUSH;
gimp_context_prop_types[GIMP_CONTEXT_PROP_DYNAMICS] = GIMP_TYPE_DYNAMICS;
gimp_context_prop_types[GIMP_CONTEXT_PROP_MYBRUSH] = GIMP_TYPE_MYBRUSH;
gimp_context_prop_types[GIMP_CONTEXT_PROP_PATTERN] = GIMP_TYPE_PATTERN;
gimp_context_prop_types[GIMP_CONTEXT_PROP_GRADIENT] = GIMP_TYPE_GRADIENT;
gimp_context_prop_types[GIMP_CONTEXT_PROP_PALETTE] = GIMP_TYPE_PALETTE;
......@@ -678,6 +705,12 @@ gimp_context_class_init (GimpContextClass *klass)
GIMP_TYPE_DYNAMICS,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_MYBRUSH,
gimp_context_prop_names[GIMP_CONTEXT_PROP_MYBRUSH],
NULL,
GIMP_TYPE_MYBRUSH,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_PATTERN,
gimp_context_prop_names[GIMP_CONTEXT_PROP_PATTERN],
NULL,
......@@ -752,6 +785,9 @@ gimp_context_init (GimpContext *context)
context->dynamics = NULL;
context->dynamics_name = NULL;
context->mybrush = NULL;
context->mybrush_name = NULL;
context->pattern = NULL;
context->pattern_name = NULL;
......@@ -837,6 +873,14 @@ gimp_context_constructed (GObject *object)
G_CALLBACK (gimp_context_dynamics_list_thaw),
object, 0);
container = gimp_data_factory_get_container (gimp->mybrush_factory);
g_signal_connect_object (container, "remove",
G_CALLBACK (gimp_context_mybrush_removed),
object, 0);
g_signal_connect_object (container, "thaw",
G_CALLBACK (gimp_context_mybrush_list_thaw),
object, 0);
container = gimp_data_factory_get_container (gimp->pattern_factory);
g_signal_connect_object (container, "remove",
G_CALLBACK (gimp_context_pattern_removed),
......@@ -934,6 +978,12 @@ gimp_context_dispose (GObject *object)
context->dynamics = NULL;
}
if (context->mybrush)
{
g_object_unref (context->mybrush);
context->mybrush = NULL;
}
if (context->pattern)
{
g_object_unref (context->pattern);
......@@ -1018,6 +1068,12 @@ gimp_context_finalize (GObject *object)
context->dynamics_name = NULL;
}
if (context->mybrush_name)
{
g_free (context->mybrush_name);
context->mybrush_name = NULL;
}
if (context->pattern_name)
{
g_free (context->pattern_name);
......@@ -1112,6 +1168,9 @@ gimp_context_set_property (GObject *object,
case GIMP_CONTEXT_PROP_DYNAMICS:
gimp_context_set_dynamics (context, g_value_get_object (value));
break;
case GIMP_CONTEXT_PROP_MYBRUSH:
gimp_context_set_mybrush (context, g_value_get_object (value));
break;
case GIMP_CONTEXT_PROP_PATTERN:
gimp_context_set_pattern (context, g_value_get_object (value));
break;
......@@ -1195,6 +1254,9 @@ gimp_context_get_property (GObject *object,
case GIMP_CONTEXT_PROP_DYNAMICS:
g_value_set_object (value, gimp_context_get_dynamics (context));
break;
case GIMP_CONTEXT_PROP_MYBRUSH:
g_value_set_object (value, gimp_context_get_mybrush (context));
break;
case GIMP_CONTEXT_PROP_PATTERN:
g_value_set_object (value, gimp_context_get_pattern (context));
break;
......@@ -1236,6 +1298,7 @@ gimp_context_get_memsize (GimpObject *object,
memsize += gimp_string_get_memsize (context->paint_name);
memsize += gimp_string_get_memsize (context->brush_name);
memsize += gimp_string_get_memsize (context->dynamics_name);
memsize += gimp_string_get_memsize (context->mybrush_name);
memsize += gimp_string_get_memsize (context->pattern_name);
memsize += gimp_string_get_memsize (context->palette_name);
memsize += gimp_string_get_memsize (context->tool_preset_name);
......@@ -1297,6 +1360,7 @@ gimp_context_serialize_property (GimpConfig *config,
case GIMP_CONTEXT_PROP_PAINT_INFO:
case GIMP_CONTEXT_PROP_BRUSH:
case GIMP_CONTEXT_PROP_DYNAMICS:
case GIMP_CONTEXT_PROP_MYBRUSH:
case GIMP_CONTEXT_PROP_PATTERN:
case GIMP_CONTEXT_PROP_GRADIENT:
case GIMP_CONTEXT_PROP_PALETTE:
......@@ -1364,6 +1428,12 @@ gimp_context_deserialize_property (GimpConfig *object,
name_loc = &context->dynamics_name;
break;
case GIMP_CONTEXT_PROP_MYBRUSH:
container = gimp_data_factory_get_container (context->gimp->mybrush_factory);
current = (GimpObject *) context->mybrush;
name_loc = &context->mybrush_name;
break;
case GIMP_CONTEXT_PROP_PATTERN:
container = gimp_data_factory_get_container (context->gimp->pattern_factory);
current = (GimpObject *) context->pattern;
......@@ -1690,6 +1760,14 @@ gimp_context_copy_property (GimpContext *src,
dest_name_loc = &dest->dynamics_name;
break;
case GIMP_CONTEXT_PROP_MYBRUSH:
gimp_context_real_set_mybrush (dest, src->mybrush);
object = src->mybrush;
standard_object = gimp_mybrush_get_standard (src);
src_name = src->mybrush_name;
dest_name_loc = &dest->mybrush_name;
break;
case GIMP_CONTEXT_PROP_PATTERN:
gimp_context_real_set_pattern (dest, src->pattern);
object = src->pattern;
......@@ -2807,6 +2885,130 @@ gimp_context_real_set_dynamics (GimpContext *context,
}
/*****************************************************************************/
/* mybrush *****************************************************************/
GimpMybrush *
gimp_context_get_mybrush (GimpContext *context)
{
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
return context->mybrush;
}
void
gimp_context_set_mybrush (GimpContext *context,
GimpMybrush *brush)
{
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (! brush || GIMP_IS_MYBRUSH (brush));
context_find_defined (context, GIMP_CONTEXT_PROP_MYBRUSH);
gimp_context_real_set_mybrush (context, brush);
}
void
gimp_context_mybrush_changed (GimpContext *context)
{
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_signal_emit (context,
gimp_context_signals[MYBRUSH_CHANGED], 0,
context->mybrush);
}
/* the active mybrush was modified */
static void
gimp_context_mybrush_dirty (GimpMybrush *brush,
GimpContext *context)
{
g_free (context->mybrush_name);
context->mybrush_name = g_strdup (gimp_object_get_name (brush));
g_signal_emit (context, gimp_context_signals[PROP_NAME_CHANGED], 0,
GIMP_CONTEXT_PROP_MYBRUSH);
}
/* the global mybrush list is there again after refresh */
static void
gimp_context_mybrush_list_thaw (GimpContainer *container,
GimpContext *context)
{
GimpMybrush *brush;
if (! context->mybrush_name)
context->mybrush_name = g_strdup (context->gimp->config->default_mypaint_brush);
brush = gimp_context_find_object (context, container,
context->mybrush_name,
gimp_mybrush_get_standard (context));
gimp_context_real_set_mybrush (context, brush);
}
/* the active mybrush disappeared */
static void
gimp_context_mybrush_removed (GimpContainer *container,
GimpMybrush *brush,
GimpContext *context)
{
if (brush == context->mybrush)
{
context->mybrush = NULL;
g_signal_handlers_disconnect_by_func (brush,
gimp_context_mybrush_dirty,
context);
g_object_unref (brush);
if (! gimp_container_frozen (container))
gimp_context_mybrush_list_thaw (container, context);
}
}
static void
gimp_context_real_set_mybrush (GimpContext *context,
GimpMybrush *brush)
{
if (context->mybrush == brush)
return;
if (context->mybrush_name &&
brush != GIMP_MYBRUSH (gimp_mybrush_get_standard (context)))
{
g_free (context->mybrush_name);
context->mybrush_name = NULL;
}
/* disconnect from the old mybrush's signals */
if (context->mybrush)
{
g_signal_handlers_disconnect_by_func (context->mybrush,
gimp_context_mybrush_dirty,
context);
g_object_unref (context->mybrush);
}
context->mybrush = brush;
if (brush)
{
g_object_ref (brush);
g_signal_connect_object (brush, "name-changed",
G_CALLBACK (gimp_context_mybrush_dirty),
context,
0);
if (brush != GIMP_MYBRUSH (gimp_mybrush_get_standard (context)))
context->mybrush_name = g_strdup (gimp_object_get_name (brush));
}
g_object_notify (G_OBJECT (context), "mybrush");
gimp_context_mybrush_changed (context);
}
/*****************************************************************************/
/* pattern ***********************************************************