Commit 37354a92 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Cleaned up and fixed the order in which default tool options and user

2005-09-04  Michael Natterer  <mitch@gimp.org>

	Cleaned up and fixed the order in which default tool options and
	user context values are initialized, and added loading / saving of
	the global user context.  Fixes bug #165078.

	* app/core/Makefile.am
	* app/core/gimp-contexts.[ch]: new files which manage the global
	contexts. Contains gimp_contexts_init/exit/load/save/clear().

	* app/core/gimp.c: use the new init/exit functions instead of
	implementing the stuff here.

	* app/tools/gimp-tools.c: load/save/clear the user context from
	here so it follows the same logic as the tool options. Reset all
	tool options before loading the user context and copy the user
	context's property to all tool options before loading tool
	options.

	* app/core/gimptoolinfo.c (gimp_tool_info_new): don't initialize
	the tool options with the users context's properties. It's way too
	early here and they will be overwritten later.

	* app/widgets/gimpdevices.c (gimp_devices_restore): initialize all
	device contexts with the user context's properties before loading
	the devices and copying the active one back to the user context.
parent 2a1805b3
2005-09-04 Michael Natterer <mitch@gimp.org>
Cleaned up and fixed the order in which default tool options and
user context values are initialized, and added loading / saving of
the global user context. Fixes bug #165078.
* app/core/Makefile.am
* app/core/gimp-contexts.[ch]: new files which manage the global
contexts. Contains gimp_contexts_init/exit/load/save/clear().
* app/core/gimp.c: use the new init/exit functions instead of
implementing the stuff here.
* app/tools/gimp-tools.c: load/save/clear the user context from
here so it follows the same logic as the tool options. Reset all
tool options before loading the user context and copy the user
context's property to all tool options before loading tool
options.
* app/core/gimptoolinfo.c (gimp_tool_info_new): don't initialize
the tool options with the users context's properties. It's way too
early here and they will be overwritten later.
* app/widgets/gimpdevices.c (gimp_devices_restore): initialize all
device contexts with the user context's properties before loading
the devices and copying the active one back to the user context.
2005-09-04 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/scripts/coffee.scm
......
......@@ -20,6 +20,8 @@ libappcore_a_sources = \
core-types.h \
gimp.c \
gimp.h \
gimp-contexts.c \
gimp-contexts.h \
gimp-documents.c \
gimp-documents.h \
gimp-edit.c \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* gimp-contexts.c
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <glib/gstdio.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
#include "gimp.h"
#include "gimp-contexts.h"
#include "gimpcontext.h"
#include "config/gimpconfig-file.h"
#include "gimp-intl.h"
void
gimp_contexts_init (Gimp *gimp)
{
GimpContext *context;
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* the default context contains the user's saved preferences
*
* TODO: load from disk
*/
context = gimp_context_new (gimp, "Default", NULL);
gimp_set_default_context (gimp, context);
g_object_unref (context);
/* the initial user_context is a straight copy of the default context
*/
context = gimp_context_new (gimp, "User", context);
gimp_set_user_context (gimp, context);
g_object_unref (context);
}
void
gimp_contexts_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp_set_user_context (gimp, NULL);
gimp_set_default_context (gimp, NULL);
}
void
gimp_contexts_load (Gimp *gimp)
{
gchar *filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
filename = gimp_personal_rc_file ("contextrc");
if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
filename,
NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message (error->message);
g_error_free (error);
}
g_free (filename);
}
void
gimp_contexts_save (Gimp *gimp)
{
gchar *filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
filename = gimp_personal_rc_file ("contextrc");
if (! gimp_config_serialize_to_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
filename,
"GIMP user context",
"end of user context",
NULL, &error))
{
g_message (error->message);
g_error_free (error);
}
g_free (filename);
}
gboolean
gimp_contexts_clear (Gimp *gimp,
GError **error)
{
gchar *filename;
gboolean success = TRUE;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
filename = gimp_personal_rc_file ("contextrc");
if (g_unlink (filename) != 0 && errno != ENOENT)
{
g_set_error (error, 0, 0, _("Deleting \"%s\" failed: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
success = FALSE;
}
g_free (filename);
return success;
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimp-contexts.h
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_CONTEXTS_H__
#define __GIMP_CONTEXTS_H__
void gimp_contexts_init (Gimp *gimp);
void gimp_contexts_exit (Gimp *gimp);
void gimp_contexts_load (Gimp *gimp);
void gimp_contexts_save (Gimp *gimp);
gboolean gimp_contexts_clear (Gimp *gimp,
GError **error);
#endif /* __GIMP_CONTEXTS_H__ */
......@@ -40,6 +40,7 @@
#include "xcf/xcf.h"
#include "gimp.h"
#include "gimp-contexts.h"
#include "gimp-documents.h"
#include "gimp-gradients.h"
#include "gimp-modules.h"
......@@ -319,8 +320,7 @@ gimp_finalize (GObject *object)
if (gimp->be_verbose)
g_print ("EXIT: gimp_finalize\n");
gimp_set_user_context (gimp, NULL);
gimp_set_default_context (gimp, NULL);
gimp_contexts_exit (gimp);
if (gimp->image_new_last_template)
{
......@@ -541,7 +541,6 @@ static void
gimp_real_initialize (Gimp *gimp,
GimpInitStatusFunc status_callback)
{
GimpContext *context;
gchar *path;
static const GimpDataFactoryLoaderEntry brush_loader_entries[] =
......@@ -626,19 +625,8 @@ gimp_real_initialize (Gimp *gimp,
gimp->have_current_cut_buffer = FALSE;
/* the default context contains the user's saved preferences
*
* TODO: load from disk
*/
context = gimp_context_new (gimp, "Default", NULL);
gimp_set_default_context (gimp, context);
g_object_unref (context);
/* the initial user_context is a straight copy of the default context
*/
context = gimp_context_new (gimp, "User", context);
gimp_set_user_context (gimp, context);
g_object_unref (context);
/* create user and default context */
gimp_contexts_init (gimp);
/* add the builtin FG -> BG etc. gradients */
gimp_gradients_init (gimp);
......@@ -999,8 +987,10 @@ gimp_set_default_context (Gimp *gimp,
GimpContext *context)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (! context || GIMP_IS_CONTEXT (context));
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
if (context != gimp->default_context)
{
if (gimp->default_context)
g_object_unref (gimp->default_context);
......@@ -1008,6 +998,7 @@ gimp_set_default_context (Gimp *gimp,
if (gimp->default_context)
g_object_ref (gimp->default_context);
}
}
GimpContext *
......@@ -1023,8 +1014,10 @@ gimp_set_user_context (Gimp *gimp,
GimpContext *context)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (! context || GIMP_IS_CONTEXT (context));
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
if (context != gimp->user_context)
{
if (gimp->user_context)
g_object_unref (gimp->user_context);
......@@ -1032,6 +1025,7 @@ gimp_set_user_context (Gimp *gimp,
if (gimp->user_context)
g_object_ref (gimp->user_context);
}
}
GimpContext *
......
......@@ -307,10 +307,6 @@ gimp_tool_info_new (Gimp *gimp,
{
gimp_context_define_properties (GIMP_CONTEXT (tool_info->tool_options),
tool_info->context_props, FALSE);
gimp_context_copy_properties (gimp_get_user_context (gimp),
GIMP_CONTEXT (tool_info->tool_options),
GIMP_CONTEXT_ALL_PROPS_MASK);
}
gimp_context_set_serialize_properties (GIMP_CONTEXT (tool_info->tool_options),
......
......@@ -33,6 +33,7 @@
#include "tools-types.h"
#include "core/gimp.h"
#include "core/gimp-contexts.h"
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
#include "core/gimptooloptions.h"
......@@ -273,14 +274,25 @@ gimp_tools_restore (Gimp *gimp)
list;
list = g_list_next (list))
{
GimpToolInfo *tool_info;
GimpToolOptionsGUIFunc options_gui_func;
GtkWidget *options_gui;
tool_info = GIMP_TOOL_INFO (list->data);
GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);
/* get default values from prefs (see bug #120832) */
gimp_tool_options_reset (tool_info->tool_options);
}
gimp_contexts_load (gimp);
for (list = GIMP_LIST (gimp->tool_info_list)->list;
list;
list = g_list_next (list))
{
GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);
GimpToolOptionsGUIFunc options_gui_func;
GtkWidget *options_gui;
gimp_context_copy_properties (gimp_get_user_context (gimp),
GIMP_CONTEXT (tool_info->tool_options),
GIMP_CONTEXT_ALL_PROPS_MASK);
gimp_tool_options_deserialize (tool_info->tool_options, NULL, NULL);
......@@ -338,6 +350,9 @@ gimp_tools_save (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (save_tool_options && (! tool_options_deleted || always_save))
gimp_contexts_save (gimp);
for (list = GIMP_LIST (gimp->tool_info_list)->list;
list;
list = g_list_next (list))
......@@ -409,6 +424,9 @@ gimp_tools_clear (Gimp *gimp,
g_free (filename);
}
if (success)
success = gimp_contexts_clear (gimp, error);
if (success)
tool_options_deleted = TRUE;
......
......@@ -124,6 +124,7 @@ gimp_devices_restore (Gimp *gimp)
GimpDeviceManager *manager;
GimpDeviceInfo *device_info;
GimpContext *user_context;
GList *list;
gchar *filename;
GError *error = NULL;
......@@ -133,6 +134,18 @@ gimp_devices_restore (Gimp *gimp)
g_return_if_fail (manager != NULL);
user_context = gimp_get_user_context (gimp);
for (list = GIMP_LIST (manager->device_info_list)->list;
list;
list = g_list_next (list))
{
GimpDeviceInfo *device_info = list->data;
gimp_context_copy_properties (user_context, GIMP_CONTEXT (device_info),
GIMP_DEVICE_INFO_CONTEXT_MASK);
}
filename = gimp_personal_rc_file ("devicerc");
if (! gimp_config_deserialize_file (GIMP_CONFIG (manager->device_info_list),
......@@ -155,8 +168,6 @@ gimp_devices_restore (Gimp *gimp)
g_return_if_fail (GIMP_IS_DEVICE_INFO (device_info));
user_context = gimp_get_user_context (gimp);
gimp_context_copy_properties (GIMP_CONTEXT (device_info), user_context,
GIMP_DEVICE_INFO_CONTEXT_MASK);
gimp_context_set_parent (GIMP_CONTEXT (device_info), user_context);
......
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