Commit 0ceeeb02 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

added a writeable field to GimpData and set it from

2003-02-26  Sven Neumann  <sven@gimp.org>

	* app/core/gimpdata.[ch]: added a writeable field to GimpData and
	set it from gimp_data_set_filename().

	* app/gui/brushes-menu.c
	* app/gui/gradients-menu.c
	* app/gui/palettes-menu.c
	* app/gui/patterns-menu.c
	* app/widgets/gimpbrushfactoryview.c
	* app/widgets/gimpdatafactoryview.c
	* app/widgets/gimpgradienteditor.c: look at data->writeable when
	setting widgets sensitivity.

	* app/gui/user-install-dialog.c (user_install_dialog_create): reduce
	some of the dialog clutter by not showing the directories created for
	plug-ins.

	* app/core/gimpviewable.[ch]: added a default_stock_id to
	GimpViewableClass so we don't need to hold a copy in each instance.
	Added accessor functions to set and get the stock_id.

	* app/core/gimptoolinfo.c
	* app/gui/dialogs-constructors.c
	* app/gui/image-menu.c
	* app/tools/gimpcroptool.c
	* app/tools/gimphistogramtool.c
	* app/tools/gimpimagemaptool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimptransformtool.c
	* app/widgets/gimpcellrendererviewable.c
	* app/widgets/gimppreview.c
	* app/widgets/gimptoolbox.c: use gimp_viewable_get_stock_id().

	* app/text/gimptextlayer.c: set a text icon as default stock_id.
parent 305db405
2003-02-26 Sven Neumann <sven@gimp.org>
* app/core/gimpdata.[ch]: added a writeable field to GimpData and
set it from gimp_data_set_filename().
* app/gui/brushes-menu.c
* app/gui/gradients-menu.c
* app/gui/palettes-menu.c
* app/gui/patterns-menu.c
* app/widgets/gimpbrushfactoryview.c
* app/widgets/gimpdatafactoryview.c
* app/widgets/gimpgradienteditor.c: look at data->writeable when
setting widgets sensitivity.
* app/gui/user-install-dialog.c (user_install_dialog_create): reduce
some of the dialog clutter by not showing the directories created for
plug-ins.
* app/core/gimpviewable.[ch]: added a default_stock_id to
GimpViewableClass so we don't need to hold a copy in each instance.
Added accessor functions to set and get the stock_id.
* app/core/gimptoolinfo.c
* app/gui/dialogs-constructors.c
* app/gui/image-menu.c
* app/tools/gimpcroptool.c
* app/tools/gimphistogramtool.c
* app/tools/gimpimagemaptool.c
* app/tools/gimpmeasuretool.c
* app/tools/gimptransformtool.c
* app/widgets/gimpcellrendererviewable.c
* app/widgets/gimppreview.c
* app/widgets/gimptoolbox.c: use gimp_viewable_get_stock_id().
* app/text/gimptextlayer.c: set a text icon as default stock_id.
2003-02-26 Michael Natterer <mitch@gimp.org>
 
* app/core/gimpviewable.[ch]: added "gchar *stock_id" to the
......@@ -24,6 +24,7 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
......@@ -125,9 +126,10 @@ gimp_data_class_init (GimpDataClass *klass)
static void
gimp_data_init (GimpData *data)
{
data->filename = NULL;
data->dirty = FALSE;
data->internal = FALSE;
data->filename = NULL;
data->writeable = TRUE;
data->dirty = FALSE;
data->internal = FALSE;
}
static void
......@@ -255,7 +257,24 @@ gimp_data_set_filename (GimpData *data,
g_free (data->filename);
data->filename = g_strdup (filename);
data->filename = NULL;
data->writeable = TRUE;
if (filename)
{
data->filename = g_strdup (filename);
if (access (filename, W_OK) && /* check if the file is writeable */
access (filename, F_OK) == 0) /* or doesn't exist */
{
gchar *dirname = g_path_get_dirname (filename);
if (access (dirname, W_OK | X_OK)) /* check if we can write to the dir */
data->writeable = FALSE;
g_free (dirname);
}
}
}
void
......
......@@ -50,8 +50,9 @@ struct _GimpData
GimpViewable parent_instance;
gchar *filename;
gboolean dirty;
gboolean internal;
guint writeable : 1;
guint dirty : 1;
guint internal : 1;
};
struct _GimpDataClass
......
......@@ -205,9 +205,7 @@ gimp_tool_info_new (Gimp *gimp,
tool_info->help_domain = g_strdup (help_domain);
tool_info->help_data = g_strdup (help_data);
if (viewable->stock_id)
g_free (viewable->stock_id);
viewable->stock_id = g_strdup (stock_id);
gimp_viewable_set_stock_id (viewable, stock_id);
return tool_info;
}
......
......@@ -128,6 +128,7 @@ gimp_viewable_class_init (GimpViewableClass *klass)
gimp_object_class->get_memsize = gimp_viewable_get_memsize;
klass->default_stock_id = "gtk-dialog-question";
klass->name_changed_signal = "name_changed";
klass->invalidate_preview = gimp_viewable_real_invalidate_preview;
......@@ -141,7 +142,7 @@ gimp_viewable_class_init (GimpViewableClass *klass)
static void
gimp_viewable_init (GimpViewable *viewable)
{
viewable->stock_id = g_strdup ("gtk-dialog-question");
viewable->stock_id = NULL;
}
static void
......@@ -446,3 +447,24 @@ gimp_viewable_get_new_preview_pixbuf (GimpViewable *viewable,
return pixbuf;
}
const gchar *
gimp_viewable_get_stock_id (GimpViewable *viewable)
{
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
if (viewable->stock_id)
return (const gchar *) viewable->stock_id;
return GIMP_VIEWABLE_GET_CLASS (viewable)->default_stock_id;
}
void
gimp_viewable_set_stock_id (GimpViewable *viewable,
const gchar *stock_id)
{
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
g_free (viewable->stock_id);
viewable->stock_id = g_strdup (stock_id);
}
......@@ -42,6 +42,7 @@ struct _GimpViewable
{
GimpObject parent_instance;
/*< private >*/
gchar *stock_id;
};
......@@ -49,6 +50,7 @@ struct _GimpViewableClass
{
GimpObjectClass parent_class;
const gchar *default_stock_id;
const gchar *name_changed_signal;
/* signals */
......@@ -107,6 +109,9 @@ GdkPixbuf * gimp_viewable_get_preview_pixbuf (GimpViewable *viewable,
GdkPixbuf * gimp_viewable_get_new_preview_pixbuf (GimpViewable *viewable,
gint width,
gint height);
const gchar * gimp_viewable_get_stock_id (GimpViewable *viewable);
void gimp_viewable_set_stock_id (GimpViewable *viewable,
const gchar *stock_id);
#endif /* __GIMP_VIEWABLE_H__ */
......@@ -1280,9 +1280,10 @@ dialogs_tool_tab_tool_changed (GimpContext *context,
GimpToolInfo *tool_info,
GtkImage *image)
{
gtk_image_set_from_stock (image,
GIMP_VIEWABLE (tool_info)->stock_id,
image->icon_size);
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
gtk_image_set_from_stock (image, stock_id, image->icon_size);
}
static GtkWidget *
......@@ -1298,7 +1299,8 @@ dialogs_tool_tab_func (GimpDockable *dockable,
viewable = GIMP_VIEWABLE (gimp_context_get_tool (context));
image = gtk_image_new_from_stock (viewable->stock_id, size);
image = gtk_image_new_from_stock (gimp_viewable_get_stock_id (viewable),
size);
g_signal_connect_object (context, "tool_changed",
G_CALLBACK (dialogs_tool_tab_tool_changed),
......@@ -1316,9 +1318,12 @@ dialogs_tool_options_tool_changed (GimpContext *context,
GtkImage *image;
if ((image = g_object_get_data (G_OBJECT (label), "tool-icon")))
gtk_image_set_from_stock (image,
GIMP_VIEWABLE (tool_info)->stock_id,
image->icon_size);
{
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
gtk_image_set_from_stock (image, stock_id, image->icon_size);
}
gtk_label_set_text (label, tool_info->blurb);
......@@ -1339,6 +1344,7 @@ dialogs_tool_options_tab_func (GimpDockable *dockable,
GtkWidget *label;
gint width;
gint height;
const gchar *stock_id;
context = dockbook->dock->context;
......@@ -1348,8 +1354,8 @@ dialogs_tool_options_tab_func (GimpDockable *dockable,
hbox = gtk_hbox_new (FALSE, 2);
image = gtk_image_new_from_stock (GIMP_VIEWABLE (tool_info)->stock_id,
size);
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
image = gtk_image_new_from_stock (stock_id, size);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
......
......@@ -284,34 +284,22 @@ tree_items[] =
},
{
TRUE, "fractalexplorer",
N_("This is folder used to store user defined fractals to\n"
"be used by the FractalExplorer plug-in. The GIMP\n"
"checks this folder in addition to the systemwide\n"
"FractalExplorer installation when searching for fractals."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
},
{
TRUE, "gfig",
N_("This folder is used to store user defined figures to\n"
"be used by the GFig plug-in. The GIMP checks this\n"
"folder in addition to the systemwide GFig installation\n"
"when searching for gfig figures."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
},
{
TRUE, "gflare",
N_("This folder is used to store user defined gflares to\n"
"be used by the GFlare plug-in. The GIMP checks this\n"
"folder in addition to the systemwide GFlares\n"
"installation when searching for gflares."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
},
{
TRUE, "gimpressionist",
N_("This folder is used to store user defined data to be\n"
"used by the Gimpressionist plug-in. The GIMP checks\n"
"this folder in addition to the systemwide Gimpressionist\n"
"installation when searching for data."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
}
};
......@@ -867,6 +855,9 @@ user_install_dialog_create (const gchar *alternate_system_gimprc,
for (i = 0; i < G_N_ELEMENTS (tree_items); i++)
{
if (!tree_items[i].description)
continue;
gtk_tree_store_append (tree, &child, &iter);
gtk_tree_store_set (tree, &child,
DIRENT_COLUMN, tree_items[i].text,
......
......@@ -76,28 +76,28 @@ gint n_brushes_menu_entries = G_N_ELEMENTS (brushes_menu_entries);
void
brushes_menu_update (GtkItemFactory *factory,
gpointer data)
gpointer user_data)
{
GimpContainerEditor *editor;
GimpBrush *brush;
gboolean internal = FALSE;
GimpData *data = NULL;
editor = GIMP_CONTAINER_EDITOR (data);
editor = GIMP_CONTAINER_EDITOR (user_data);
brush = gimp_context_get_brush (editor->view->context);
if (brush)
internal = GIMP_DATA (brush)->internal;
data = GIMP_DATA (brush);
#define SET_SENSITIVE(menu,condition) \
gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)
SET_SENSITIVE ("/Duplicate Brush",
brush && GIMP_DATA_GET_CLASS (brush)->duplicate);
brush && GIMP_DATA_GET_CLASS (data)->duplicate);
SET_SENSITIVE ("/Edit Brush...",
brush && GIMP_DATA_FACTORY_VIEW (editor)->data_edit_func);
SET_SENSITIVE ("/Delete Brush...",
brush && ! internal);
brush && data->writeable && !data->internal);
#undef SET_SENSITIVE
}
......@@ -1280,9 +1280,10 @@ dialogs_tool_tab_tool_changed (GimpContext *context,
GimpToolInfo *tool_info,
GtkImage *image)
{
gtk_image_set_from_stock (image,
GIMP_VIEWABLE (tool_info)->stock_id,
image->icon_size);
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
gtk_image_set_from_stock (image, stock_id, image->icon_size);
}
static GtkWidget *
......@@ -1298,7 +1299,8 @@ dialogs_tool_tab_func (GimpDockable *dockable,
viewable = GIMP_VIEWABLE (gimp_context_get_tool (context));
image = gtk_image_new_from_stock (viewable->stock_id, size);
image = gtk_image_new_from_stock (gimp_viewable_get_stock_id (viewable),
size);
g_signal_connect_object (context, "tool_changed",
G_CALLBACK (dialogs_tool_tab_tool_changed),
......@@ -1316,9 +1318,12 @@ dialogs_tool_options_tool_changed (GimpContext *context,
GtkImage *image;
if ((image = g_object_get_data (G_OBJECT (label), "tool-icon")))
gtk_image_set_from_stock (image,
GIMP_VIEWABLE (tool_info)->stock_id,
image->icon_size);
{
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
gtk_image_set_from_stock (image, stock_id, image->icon_size);
}
gtk_label_set_text (label, tool_info->blurb);
......@@ -1339,6 +1344,7 @@ dialogs_tool_options_tab_func (GimpDockable *dockable,
GtkWidget *label;
gint width;
gint height;
const gchar *stock_id;
context = dockbook->dock->context;
......@@ -1348,8 +1354,8 @@ dialogs_tool_options_tab_func (GimpDockable *dockable,
hbox = gtk_hbox_new (FALSE, 2);
image = gtk_image_new_from_stock (GIMP_VIEWABLE (tool_info)->stock_id,
size);
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
image = gtk_image_new_from_stock (stock_id, size);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
......
......@@ -85,28 +85,28 @@ gint n_gradients_menu_entries = G_N_ELEMENTS (gradients_menu_entries);
void
gradients_menu_update (GtkItemFactory *factory,
gpointer data)
gpointer user_data)
{
GimpContainerEditor *editor;
GimpGradient *gradient;
gboolean internal = FALSE;
GimpData *data = NULL;
editor = GIMP_CONTAINER_EDITOR (data);
editor = GIMP_CONTAINER_EDITOR (user_data);
gradient = gimp_context_get_gradient (editor->view->context);
if (gradient)
internal = GIMP_DATA (gradient)->internal;
data = GIMP_DATA (gradient);
#define SET_SENSITIVE(menu,condition) \
gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)
SET_SENSITIVE ("/Duplicate Gradient",
gradient && GIMP_DATA_GET_CLASS (gradient)->duplicate);
gradient && GIMP_DATA_GET_CLASS (data)->duplicate);
SET_SENSITIVE ("/Edit Gradient...",
gradient && GIMP_DATA_FACTORY_VIEW (editor)->data_edit_func);
SET_SENSITIVE ("/Delete Gradient...",
gradient && ! internal);
gradient && data->writeable && !data->internal);
SET_SENSITIVE ("/Save as POV-Ray...",
gradient);
......
......@@ -853,14 +853,17 @@ image_menu_setup (GimpItemFactory *factory)
if (tool_info->menu_path)
{
GimpItemFactoryEntry entry;
GimpItemFactoryEntry entry;
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
entry.entry.path = tool_info->menu_path;
entry.entry.accelerator = tool_info->menu_accel;
entry.entry.callback = tools_select_cmd_callback;
entry.entry.callback_action = 0;
entry.entry.item_type = "<StockItem>";
entry.entry.extra_data = GIMP_VIEWABLE (tool_info)->stock_id;
entry.entry.extra_data = stock_id;
entry.quark_string = NULL;
entry.help_page = tool_info->help_data;
entry.description = NULL;
......
......@@ -89,28 +89,28 @@ gint n_palettes_menu_entries = G_N_ELEMENTS (palettes_menu_entries);
void
palettes_menu_update (GtkItemFactory *factory,
gpointer data)
gpointer user_data)
{
GimpContainerEditor *editor;
GimpPalette *palette;
gboolean internal = FALSE;
GimpData *data = NULL;
editor = GIMP_CONTAINER_EDITOR (data);
editor = GIMP_CONTAINER_EDITOR (user_data);
palette = gimp_context_get_palette (editor->view->context);
if (palette)
internal = GIMP_DATA (palette)->internal;
data = GIMP_DATA (palette);
#define SET_SENSITIVE(menu,condition) \
gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)
SET_SENSITIVE ("/Duplicate Palette",
palette && GIMP_DATA_GET_CLASS (palette)->duplicate);
palette && GIMP_DATA_GET_CLASS (data)->duplicate);
SET_SENSITIVE ("/Edit Palette...",
palette && GIMP_DATA_FACTORY_VIEW (editor)->data_edit_func);
SET_SENSITIVE ("/Delete Palette...",
palette && ! internal);
palette && data->writeable && !data->internal);
SET_SENSITIVE ("/Merge Palettes...",
FALSE); /* FIXME palette && GIMP_IS_CONTAINER_LIST_VIEW (editor->view)); */
......
......@@ -76,28 +76,28 @@ gint n_patterns_menu_entries = G_N_ELEMENTS (patterns_menu_entries);
void
patterns_menu_update (GtkItemFactory *factory,
gpointer data)
gpointer user_data)
{
GimpContainerEditor *editor;
GimpPattern *pattern;
gboolean internal = FALSE;
GimpData *data = NULL;
editor = GIMP_CONTAINER_EDITOR (data);
editor = GIMP_CONTAINER_EDITOR (user_data);
pattern = gimp_context_get_pattern (editor->view->context);
if (pattern)
internal = GIMP_DATA (pattern)->internal;
data = GIMP_DATA (pattern);
#define SET_SENSITIVE(menu,condition) \
gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)
SET_SENSITIVE ("/Duplicate Pattern",
pattern && GIMP_DATA_GET_CLASS (pattern)->duplicate);
pattern && GIMP_DATA_GET_CLASS (data)->duplicate);
SET_SENSITIVE ("/Edit Pattern...",
pattern && GIMP_DATA_FACTORY_VIEW (editor)->data_edit_func);
SET_SENSITIVE ("/Delete Pattern...",
pattern && ! internal);
pattern && data->writeable && !data->internal);
#undef SET_SENSITIVE
}
......@@ -284,34 +284,22 @@ tree_items[] =
},
{
TRUE, "fractalexplorer",
N_("This is folder used to store user defined fractals to\n"
"be used by the FractalExplorer plug-in. The GIMP\n"
"checks this folder in addition to the systemwide\n"
"FractalExplorer installation when searching for fractals."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
},
{
TRUE, "gfig",
N_("This folder is used to store user defined figures to\n"
"be used by the GFig plug-in. The GIMP checks this\n"
"folder in addition to the systemwide GFig installation\n"
"when searching for gfig figures."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
},
{
TRUE, "gflare",
N_("This folder is used to store user defined gflares to\n"
"be used by the GFlare plug-in. The GIMP checks this\n"
"folder in addition to the systemwide GFlares\n"
"installation when searching for gflares."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
},
{
TRUE, "gimpressionist",
N_("This folder is used to store user defined data to be\n"
"used by the Gimpressionist plug-in. The GIMP checks\n"
"this folder in addition to the systemwide Gimpressionist\n"
"installation when searching for data."),
NULL,
TREE_ITEM_MKDIR_ONLY, NULL
}
};
......@@ -867,6 +855,9 @@ user_install_dialog_create (const gchar *alternate_system_gimprc,
for (i = 0; i < G_N_ELEMENTS (tree_items); i++)
{
if (!tree_items[i].description)
continue;
gtk_tree_store_append (tree, &child, &iter);
gtk_tree_store_set (tree, &child,
DIRENT_COLUMN, tree_items[i].text,
......
......@@ -853,14 +853,17 @@ image_menu_setup (GimpItemFactory *factory)
if (tool_info->menu_path)
{
GimpItemFactoryEntry entry;
GimpItemFactoryEntry entry;
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
entry.entry.path = tool_info->menu_path;
entry.entry.accelerator = tool_info->menu_accel;
entry.entry.callback = tools_select_cmd_callback;
entry.entry.callback_action = 0;
entry.entry.item_type = "<StockItem>";
entry.entry.extra_data = GIMP_VIEWABLE (tool_info)->stock_id;
entry.entry.extra_data = stock_id;
entry.quark_string = NULL;
entry.help_page = tool_info->help_data;
entry.description = NULL;
......
......@@ -106,13 +106,14 @@ gimp_text_layer_class_init (GimpTextLayerClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->dispose = gimp_text_layer_dispose;
object_class->dispose = gimp_text_layer_dispose;
gimp_object_class->get_memsize = gimp_text_layer_get_memsize;
gimp_object_class->get_memsize = gimp_text_layer_get_memsize;
viewable_class->get_preview = gimp_text_layer_get_preview;
viewable_class->default_stock_id = "gimp-tool-text";
viewable_class->get_preview = gimp_text_layer_get_preview;
item_class->duplicate = gimp_text_layer_duplicate;
item_class->duplicate = gimp_text_layer_duplicate;
}
static void
......
......@@ -937,16 +937,19 @@ crop_info_create (GimpCropTool *crop)
GtkWidget *spinbutton;
GtkWidget *bbox;
GtkWidget *button;
const gchar *stock_id;
tool = GIMP_TOOL (crop);
gdisp = tool->gdisp;
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool->tool_info));
crop->crop_info = info_dialog_new (NULL,
tool->tool_info->blurb,
GIMP_OBJECT (tool->tool_info)->name,
GIMP_VIEWABLE (tool->tool_info)->stock_id,
stock_id,