mirror of https://github.com/GNOME/gimp.git
app: Make GimpToolEditor changes cancellable
Allow the user to cancel rearrangements of tool order and visibility in Preferences. See enhancement request/bug #500930.
This commit is contained in:
parent
9cddfeba73
commit
6a41c872f6
|
@ -126,6 +126,7 @@ static void prefs_tool_options_clear_callback (GtkWidget *widget,
|
|||
/* private variables */
|
||||
|
||||
static GtkWidget *prefs_dialog = NULL;
|
||||
static GtkWidget *tool_editor = NULL;
|
||||
|
||||
|
||||
/* public function */
|
||||
|
@ -406,10 +407,14 @@ prefs_response (GtkWidget *widget,
|
|||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
gimp_tool_editor_revert_changes (GIMP_TOOL_EDITOR (tool_editor));
|
||||
|
||||
g_object_thaw_notify (G_OBJECT (gimp->edit_config));
|
||||
|
||||
g_list_free (diff);
|
||||
}
|
||||
|
||||
tool_editor = NULL;
|
||||
}
|
||||
|
||||
/* enable autosaving again */
|
||||
|
@ -1992,19 +1997,15 @@ prefs_dialog_new (Gimp *gimp,
|
|||
g_object_unref (size_group);
|
||||
size_group = NULL;
|
||||
|
||||
/* Tool Order */
|
||||
{
|
||||
GtkWidget *tool_view;
|
||||
|
||||
/* Tool Editor */
|
||||
vbox2 = prefs_frame_new (_("Tools configuration"),
|
||||
GTK_CONTAINER (vbox), TRUE);
|
||||
tool_view = gimp_tool_editor_new (gimp->tool_info_list, gimp->user_context,
|
||||
tool_editor = gimp_tool_editor_new (gimp->tool_info_list, gimp->user_context,
|
||||
gimp_tools_get_default_order (gimp),
|
||||
GIMP_VIEW_SIZE_SMALL, 1);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), tool_view, TRUE, TRUE, 0);
|
||||
gtk_widget_show (tool_view);
|
||||
}
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), tool_editor, TRUE, TRUE, 0);
|
||||
gtk_widget_show (tool_editor);
|
||||
|
||||
|
||||
/***********************/
|
||||
|
|
|
@ -54,12 +54,20 @@ struct _GimpToolEditorPrivate
|
|||
GtkWidget *lower_button;
|
||||
GtkWidget *reset_button;
|
||||
|
||||
/* State of tools at creation of the editor, stored to support
|
||||
* reverting changes
|
||||
*/
|
||||
gchar **initial_tool_order;
|
||||
gboolean *initial_tool_visibility;
|
||||
gint n_tools;
|
||||
|
||||
GQuark visible_handler_id;
|
||||
GList *default_tool_order;
|
||||
};
|
||||
|
||||
|
||||
static void gimp_tool_editor_destroy (GtkObject *object);
|
||||
static void gimp_tool_editor_finalize (GObject *object);
|
||||
|
||||
static void gimp_tool_editor_visible_notify
|
||||
(GimpToolInfo *tool_info,
|
||||
|
@ -107,11 +115,13 @@ G_DEFINE_TYPE (GimpToolEditor, gimp_tool_editor, GIMP_TYPE_CONTAINER_TREE_VIEW)
|
|||
static void
|
||||
gimp_tool_editor_class_init (GimpToolEditorClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpToolEditorPrivate));
|
||||
|
||||
object_class->destroy = gimp_tool_editor_destroy;
|
||||
object_class->finalize = gimp_tool_editor_finalize;
|
||||
gtk_object_class->destroy = gimp_tool_editor_destroy;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -127,11 +137,48 @@ gimp_tool_editor_init (GimpToolEditor *tool_editor)
|
|||
priv->visible_handler_id = 0;
|
||||
priv->default_tool_order = NULL;
|
||||
|
||||
priv->initial_tool_order = NULL;
|
||||
priv->initial_tool_visibility = NULL;
|
||||
priv->n_tools = 0;
|
||||
|
||||
priv->raise_button = NULL;
|
||||
priv->lower_button = NULL;
|
||||
priv->reset_button = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_tool_editor_finalize (GObject *object)
|
||||
{
|
||||
GimpToolEditor *tool_editor;
|
||||
GimpToolEditorPrivate *priv;
|
||||
|
||||
tool_editor = GIMP_TOOL_EDITOR (object);
|
||||
priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
|
||||
|
||||
if (priv->initial_tool_order)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->n_tools; i++)
|
||||
{
|
||||
g_free (priv->initial_tool_order[i]);
|
||||
}
|
||||
|
||||
g_free (priv->initial_tool_order);
|
||||
priv->initial_tool_order = NULL;
|
||||
}
|
||||
|
||||
if (priv->initial_tool_visibility)
|
||||
{
|
||||
g_slice_free1 (sizeof (gboolean) * priv->n_tools,
|
||||
priv->initial_tool_visibility);
|
||||
|
||||
priv->initial_tool_visibility = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_tool_editor_destroy (GtkObject *object)
|
||||
{
|
||||
|
@ -163,10 +210,12 @@ gimp_tool_editor_new (GimpContainer *container,
|
|||
gint view_size,
|
||||
gint view_border_width)
|
||||
{
|
||||
int i;
|
||||
GimpToolEditor *tool_editor;
|
||||
GimpContainerTreeView *tree_view;
|
||||
GimpContainerView *container_view;
|
||||
GObject *object;
|
||||
GimpObject *gimp_object;
|
||||
GimpToolEditorPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
|
||||
|
@ -182,6 +231,17 @@ gimp_tool_editor_new (GimpContainer *container,
|
|||
priv->context = context;
|
||||
priv->model = tree_view->model;
|
||||
priv->default_tool_order = default_tool_order;
|
||||
priv->initial_tool_order = gimp_container_get_name_array (container,
|
||||
&priv->n_tools);
|
||||
priv->initial_tool_visibility = g_slice_alloc (sizeof (gboolean) *
|
||||
priv->n_tools);
|
||||
for (i = 0; i < priv->n_tools; i++)
|
||||
{
|
||||
gimp_object = gimp_container_get_child_by_index (container, i);
|
||||
|
||||
g_object_get (gimp_object,
|
||||
"visible", &(priv->initial_tool_visibility[i]), NULL);
|
||||
}
|
||||
|
||||
gimp_container_view_set_view_size (container_view,
|
||||
view_size, view_border_width);
|
||||
|
@ -255,6 +315,32 @@ gimp_tool_editor_new (GimpContainer *container,
|
|||
return GTK_WIDGET (tool_editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_tool_editor_revert_changes:
|
||||
* @tool_editor:
|
||||
*
|
||||
* Reverts the tool order and visibility to the state at creation.
|
||||
**/
|
||||
void
|
||||
gimp_tool_editor_revert_changes (GimpToolEditor *tool_editor)
|
||||
{
|
||||
int i;
|
||||
GimpToolEditorPrivate *priv;
|
||||
|
||||
priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
|
||||
|
||||
for (i = 0; i < priv->n_tools; i++)
|
||||
{
|
||||
GimpObject *object;
|
||||
|
||||
object = gimp_container_get_child_by_name (priv->container,
|
||||
priv->initial_tool_order[i]);
|
||||
|
||||
gimp_container_reorder (priv->container, object, i);
|
||||
g_object_set (object, "visible", priv->initial_tool_visibility[i], NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_tool_editor_raise_clicked (GtkButton *button,
|
||||
GimpToolEditor *tool_editor)
|
||||
|
|
|
@ -55,5 +55,7 @@ GtkWidget * gimp_tool_editor_new (GimpContainer *container,
|
|||
gint view_size,
|
||||
gint view_border_width);
|
||||
|
||||
void gimp_tool_editor_revert_changes (GimpToolEditor *tool_editor);
|
||||
|
||||
|
||||
#endif /* __GIMP_TOOL_EDITOR_H__ */
|
||||
|
|
Loading…
Reference in New Issue