added a "const gchar *extension" parameter to

2003-02-10  Michael Natterer  <mitch@gimp.org>

	* app/tools/tool_options.[ch]: added a "const gchar *extension"
	parameter to gimp_tool_options_[de]serialize(). Default to
	"default" if NULL is passed.

	* app/tools/tool_manager.[ch]: load the tool_options from the
	default files in tool_manager_restore(), added tool_manager_save()
	which saves the default files.

	* app/app_procs.c: call tool_manager_save() on app exit.

	* app/gui/tool-options-dialog.c: pass "user" when loading/saving
	the user defaults. Changed tooltips of the load & save buttons.
This commit is contained in:
Michael Natterer 2003-02-10 11:46:10 +00:00 committed by Michael Natterer
parent b3c941e9d5
commit a071be69ae
10 changed files with 123 additions and 40 deletions

View File

@ -1,3 +1,18 @@
2003-02-10 Michael Natterer <mitch@gimp.org>
* app/tools/tool_options.[ch]: added a "const gchar *extension"
parameter to gimp_tool_options_[de]serialize(). Default to
"default" if NULL is passed.
* app/tools/tool_manager.[ch]: load the tool_options from the
default files in tool_manager_restore(), added tool_manager_save()
which saves the default files.
* app/app_procs.c: call tool_manager_save() on app exit.
* app/gui/tool-options-dialog.c: pass "user" when loading/saving
the user defaults. Changed tooltips of the load & save buttons.
2003-02-10 Michael Natterer <mitch@gimp.org>
* app/tools/gimpinktool.c: take the drawable offset into account

View File

@ -285,7 +285,10 @@ app_exit_callback (Gimp *gimp,
plug_ins_exit (gimp);
if (! gimp->no_interface)
tool_manager_exit (gimp);
{
tool_manager_save (gimp);
tool_manager_exit (gimp);
}
return FALSE; /* continue exiting */
}

View File

@ -173,8 +173,31 @@ gimp_tool_options_reset (GimpToolOptions *tool_options)
GIMP_TOOL_OPTIONS_GET_CLASS (tool_options)->reset (tool_options);
}
static gchar *
gimp_tool_options_build_filename (GimpToolOptions *tool_options,
const gchar *extension)
{
gchar *basename;
gchar *filename;
if (! extension)
extension = "default";
basename = g_strconcat (GIMP_OBJECT (tool_options->tool_info)->name,
".", extension, NULL);
filename = g_build_filename (gimp_directory (),
"tool-options", basename,
NULL);
g_free (basename);
return filename;
}
gboolean
gimp_tool_options_serialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error)
{
gchar *filename;
@ -183,10 +206,7 @@ gimp_tool_options_serialize (GimpToolOptions *tool_options,
g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = g_build_filename (gimp_directory (),
"tool-options",
GIMP_OBJECT (tool_options->tool_info)->name,
NULL);
filename = gimp_tool_options_build_filename (tool_options, extension);
retval = gimp_config_serialize (G_OBJECT (tool_options),
filename,
@ -202,6 +222,7 @@ gimp_tool_options_serialize (GimpToolOptions *tool_options,
gboolean
gimp_tool_options_deserialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error)
{
gchar *filename;
@ -210,10 +231,7 @@ gimp_tool_options_deserialize (GimpToolOptions *tool_options,
g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = g_build_filename (gimp_directory (),
"tool-options",
GIMP_OBJECT (tool_options->tool_info)->name,
NULL);
filename = gimp_tool_options_build_filename (tool_options, extension);
retval = gimp_config_deserialize (G_OBJECT (tool_options),
filename,

View File

@ -53,8 +53,10 @@ GType gimp_tool_options_get_type (void) G_GNUC_CONST;
void gimp_tool_options_reset (GimpToolOptions *tool_options);
gboolean gimp_tool_options_serialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error);
gboolean gimp_tool_options_deserialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error);
gpointer gimp_tool_options_gui (GimpToolOptions *tool_options);

View File

@ -97,7 +97,7 @@ tool_options_dialog_create (Gimp *gimp)
options_save_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_SAVE,
_("Save current settings to disk"),
_("Save current settings as default values"),
NULL,
G_CALLBACK (tool_options_dialog_save_callback),
NULL,
@ -106,7 +106,7 @@ tool_options_dialog_create (Gimp *gimp)
options_revert_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_REVERT_TO_SAVED,
_("Restore saved settings"),
_("Restore saved default values"),
NULL,
G_CALLBACK (tool_options_dialog_restore_callback),
NULL,
@ -115,7 +115,7 @@ tool_options_dialog_create (Gimp *gimp)
options_reset_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GIMP_STOCK_RESET,
_("Reset"),
_("Reset to factory defaults"),
NULL,
G_CALLBACK (tool_options_dialog_reset_callback),
NULL,
@ -249,7 +249,7 @@ tool_options_dialog_save_callback (GtkWidget *widget,
if (! tool_info)
return;
if (! gimp_tool_options_serialize (tool_info->tool_options, &error))
if (! gimp_tool_options_serialize (tool_info->tool_options, "user", &error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);
@ -268,7 +268,7 @@ tool_options_dialog_restore_callback (GtkWidget *widget,
if (! tool_info)
return;
if (! gimp_tool_options_deserialize (tool_info->tool_options, &error))
if (! gimp_tool_options_deserialize (tool_info->tool_options, "user", &error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);

View File

@ -154,6 +154,29 @@ tool_manager_init (Gimp *gimp)
gimp_container_thaw (gimp->tool_info_list);
}
void
tool_manager_exit (Gimp *gimp)
{
GimpToolManager *tool_manager;
g_return_if_fail (GIMP_IS_GIMP (gimp));
tool_manager = tool_manager_get (gimp);
tool_manager_set (gimp, NULL);
g_object_unref (tool_manager->global_tool_context);
gimp_container_remove_handler (gimp->images,
tool_manager->image_dirty_handler_id);
gimp_container_remove_handler (gimp->images,
tool_manager->image_undo_start_handler_id);
if (tool_manager->active_tool)
g_object_unref (tool_manager->active_tool);
g_free (tool_manager);
}
void
tool_manager_restore (Gimp *gimp)
{
@ -174,6 +197,8 @@ tool_manager_restore (Gimp *gimp)
tool_info = GIMP_TOOL_INFO (list->data);
gimp_tool_options_deserialize (tool_info->tool_options, NULL, NULL);
options_gui_func = g_object_get_data (G_OBJECT (tool_info),
"gimp-tool-options-gui-func");
@ -198,26 +223,24 @@ tool_manager_restore (Gimp *gimp)
}
void
tool_manager_exit (Gimp *gimp)
tool_manager_save (Gimp *gimp)
{
GimpToolManager *tool_manager;
GimpToolInfo *tool_info;
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
tool_manager = tool_manager_get (gimp);
tool_manager_set (gimp, NULL);
g_object_unref (tool_manager->global_tool_context);
for (list = GIMP_LIST (gimp->tool_info_list)->list;
list;
list = g_list_next (list))
{
tool_info = GIMP_TOOL_INFO (list->data);
gimp_container_remove_handler (gimp->images,
tool_manager->image_dirty_handler_id);
gimp_container_remove_handler (gimp->images,
tool_manager->image_undo_start_handler_id);
if (tool_manager->active_tool)
g_object_unref (tool_manager->active_tool);
g_free (tool_manager);
gimp_tool_options_serialize (tool_info->tool_options, NULL, NULL);
}
}
GimpTool *

View File

@ -21,9 +21,11 @@
void tool_manager_init (Gimp *gimp);
void tool_manager_restore (Gimp *gimp);
void tool_manager_exit (Gimp *gimp);
void tool_manager_restore (Gimp *gimp);
void tool_manager_save (Gimp *gimp);
GimpTool * tool_manager_get_active (Gimp *gimp);
void tool_manager_select_tool (Gimp *gimp,

View File

@ -173,8 +173,31 @@ gimp_tool_options_reset (GimpToolOptions *tool_options)
GIMP_TOOL_OPTIONS_GET_CLASS (tool_options)->reset (tool_options);
}
static gchar *
gimp_tool_options_build_filename (GimpToolOptions *tool_options,
const gchar *extension)
{
gchar *basename;
gchar *filename;
if (! extension)
extension = "default";
basename = g_strconcat (GIMP_OBJECT (tool_options->tool_info)->name,
".", extension, NULL);
filename = g_build_filename (gimp_directory (),
"tool-options", basename,
NULL);
g_free (basename);
return filename;
}
gboolean
gimp_tool_options_serialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error)
{
gchar *filename;
@ -183,10 +206,7 @@ gimp_tool_options_serialize (GimpToolOptions *tool_options,
g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = g_build_filename (gimp_directory (),
"tool-options",
GIMP_OBJECT (tool_options->tool_info)->name,
NULL);
filename = gimp_tool_options_build_filename (tool_options, extension);
retval = gimp_config_serialize (G_OBJECT (tool_options),
filename,
@ -202,6 +222,7 @@ gimp_tool_options_serialize (GimpToolOptions *tool_options,
gboolean
gimp_tool_options_deserialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error)
{
gchar *filename;
@ -210,10 +231,7 @@ gimp_tool_options_deserialize (GimpToolOptions *tool_options,
g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
filename = g_build_filename (gimp_directory (),
"tool-options",
GIMP_OBJECT (tool_options->tool_info)->name,
NULL);
filename = gimp_tool_options_build_filename (tool_options, extension);
retval = gimp_config_deserialize (G_OBJECT (tool_options),
filename,

View File

@ -53,8 +53,10 @@ GType gimp_tool_options_get_type (void) G_GNUC_CONST;
void gimp_tool_options_reset (GimpToolOptions *tool_options);
gboolean gimp_tool_options_serialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error);
gboolean gimp_tool_options_deserialize (GimpToolOptions *tool_options,
const gchar *extension,
GError **error);
gpointer gimp_tool_options_gui (GimpToolOptions *tool_options);

View File

@ -97,7 +97,7 @@ tool_options_dialog_create (Gimp *gimp)
options_save_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_SAVE,
_("Save current settings to disk"),
_("Save current settings as default values"),
NULL,
G_CALLBACK (tool_options_dialog_save_callback),
NULL,
@ -106,7 +106,7 @@ tool_options_dialog_create (Gimp *gimp)
options_revert_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_REVERT_TO_SAVED,
_("Restore saved settings"),
_("Restore saved default values"),
NULL,
G_CALLBACK (tool_options_dialog_restore_callback),
NULL,
@ -115,7 +115,7 @@ tool_options_dialog_create (Gimp *gimp)
options_reset_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GIMP_STOCK_RESET,
_("Reset"),
_("Reset to factory defaults"),
NULL,
G_CALLBACK (tool_options_dialog_reset_callback),
NULL,
@ -249,7 +249,7 @@ tool_options_dialog_save_callback (GtkWidget *widget,
if (! tool_info)
return;
if (! gimp_tool_options_serialize (tool_info->tool_options, &error))
if (! gimp_tool_options_serialize (tool_info->tool_options, "user", &error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);
@ -268,7 +268,7 @@ tool_options_dialog_restore_callback (GtkWidget *widget,
if (! tool_info)
return;
if (! gimp_tool_options_deserialize (tool_info->tool_options, &error))
if (! gimp_tool_options_deserialize (tool_info->tool_options, "user", &error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);