From 65ef13729f4e3cb6eb83d2f4b4136162ee6fbe3a Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 27 May 2007 15:13:45 +0000 Subject: [PATCH] new utility function which returns the neighbor of a container's active 2007-05-27 Michael Natterer * app/core/gimp-utils.[ch] (gimp_container_get_neighbor_of_active): new utility function which returns the neighbor of a container's active item. * app/widgets/gimpcontainerview-utils.[ch] (gimp_container_view_remove_active): remove a container view's active item, using above function to select its neighbor. * app/actions/data-commands.c * app/actions/buffers-commands.c * app/actions/documents-commands.c * app/actions/templates-commands.c: use above functions to select reasonable items when deleting from a list (instead of always jumping to the first item). svn path=/trunk/; revision=22632 --- ChangeLog | 17 ++++++++++++ app/actions/buffers-commands.c | 14 ++-------- app/actions/data-commands.c | 27 ++++++++++++++----- app/actions/documents-commands.c | 14 ++-------- app/actions/templates-commands.c | 14 ++++++++++ app/core/gimp-utils.c | 31 ++++++++++++++++++++++ app/core/gimp-utils.h | 4 +++ app/widgets/gimpcontainerview-utils.c | 37 +++++++++++++++++++++++++++ app/widgets/gimpcontainerview-utils.h | 4 ++- 9 files changed, 130 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 204cb082bb..c7db275905 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-05-27 Michael Natterer + + * app/core/gimp-utils.[ch] (gimp_container_get_neighbor_of_active): + new utility function which returns the neighbor of a container's + active item. + + * app/widgets/gimpcontainerview-utils.[ch] + (gimp_container_view_remove_active): remove a container view's + active item, using above function to select its neighbor. + + * app/actions/data-commands.c + * app/actions/buffers-commands.c + * app/actions/documents-commands.c + * app/actions/templates-commands.c: use above functions to select + reasonable items when deleting from a list (instead of always + jumping to the first item). + 2007-05-26 Sven Neumann * libgimpwidgets/gimpwidgets.c (gimp_coordinates_new): update the diff --git a/app/actions/buffers-commands.c b/app/actions/buffers-commands.c index f0331c3ada..d2901cbd54 100644 --- a/app/actions/buffers-commands.c +++ b/app/actions/buffers-commands.c @@ -30,6 +30,7 @@ #include "widgets/gimpbufferview.h" #include "widgets/gimpcontainerview.h" +#include "widgets/gimpcontainerview-utils.h" #include "display/gimpdisplay.h" #include "display/gimpdisplayshell.h" @@ -101,19 +102,8 @@ buffers_delete_cmd_callback (GtkAction *action, gpointer data) { GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data); - GimpContainer *container; - GimpContext *context; - GimpBuffer *buffer; - container = gimp_container_view_get_container (editor->view); - context = gimp_container_view_get_context (editor->view); - - buffer = gimp_context_get_buffer (context); - - if (buffer && gimp_container_have (container, GIMP_OBJECT (buffer))) - { - gimp_container_remove (container, GIMP_OBJECT (buffer)); - } + gimp_container_view_remove_active (editor->view); } diff --git a/app/actions/data-commands.c b/app/actions/data-commands.c index ab999c9656..1986c5463c 100644 --- a/app/actions/data-commands.c +++ b/app/actions/data-commands.c @@ -25,6 +25,7 @@ #include "actions-types.h" #include "core/gimp.h" +#include "core/gimp-utils.h" #include "core/gimpcontainer.h" #include "core/gimpcontext.h" #include "core/gimpdata.h" @@ -53,6 +54,7 @@ typedef struct _GimpDataDeleteData GimpDataDeleteData; struct _GimpDataDeleteData { + GimpContext *context; GimpDataFactoryView *view; GimpData *data; }; @@ -222,8 +224,9 @@ data_delete_cmd_callback (GtkAction *action, delete_data = g_slice_new0 (GimpDataDeleteData); - delete_data->view = view; - delete_data->data = data; + delete_data->context = context; + delete_data->view = view; + delete_data->data = data; dialog = gimp_message_dialog_new (_("Delete Object"), GIMP_STOCK_QUESTION, GTK_WIDGET (view), 0, @@ -313,17 +316,27 @@ data_delete_confirm_response (GtkWidget *dialog, if (response_id == GTK_RESPONSE_OK) { - GError *error = NULL; + GimpDataFactory *factory = delete_data->view->factory; + GimpData *data = delete_data->data; + GimpObject *new_active; + GError *error = NULL; - if (! gimp_data_factory_data_delete (delete_data->view->factory, - delete_data->data, - TRUE, &error)) + new_active = gimp_container_get_neighbor_of_active (factory->container, + delete_data->context, + GIMP_OBJECT (data)); + + if (! gimp_data_factory_data_delete (factory, data, TRUE, &error)) { - gimp_message (delete_data->view->factory->gimp, + gimp_message (factory->gimp, G_OBJECT (delete_data->view), GIMP_MESSAGE_ERROR, "%s", error->message); g_clear_error (&error); } + + if (new_active) + gimp_context_set_by_type (delete_data->context, + factory->container->children_type, + new_active); } g_slice_free (GimpDataDeleteData, delete_data); diff --git a/app/actions/documents-commands.c b/app/actions/documents-commands.c index b112412b4e..2ae1699625 100644 --- a/app/actions/documents-commands.c +++ b/app/actions/documents-commands.c @@ -40,6 +40,7 @@ #include "widgets/gimpclipboard.h" #include "widgets/gimpcontainerview.h" +#include "widgets/gimpcontainerview-utils.h" #include "widgets/gimpdocumentview.h" #include "widgets/gimpmessagebox.h" #include "widgets/gimpmessagedialog.h" @@ -169,19 +170,8 @@ documents_remove_cmd_callback (GtkAction *action, gpointer data) { GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data); - GimpContext *context; - GimpContainer *container; - GimpImagefile *imagefile; - context = gimp_container_view_get_context (editor->view); - container = gimp_container_view_get_container (editor->view); - - imagefile = gimp_context_get_imagefile (context); - - if (imagefile && gimp_container_have (container, GIMP_OBJECT (imagefile))) - { - gimp_container_remove (container, GIMP_OBJECT (imagefile)); - } + gimp_container_view_remove_active (editor->view); } void diff --git a/app/actions/templates-commands.c b/app/actions/templates-commands.c index ed1f615d35..203336f63b 100644 --- a/app/actions/templates-commands.c +++ b/app/actions/templates-commands.c @@ -28,6 +28,7 @@ #include "config/gimpcoreconfig.h" #include "core/gimp.h" +#include "core/gimp-utils.h" #include "core/gimpcontainer.h" #include "core/gimpcontext.h" #include "core/gimptemplate.h" @@ -51,6 +52,7 @@ typedef struct { + GimpContext *context; GimpContainer *container; GimpTemplate *template; } TemplateDeleteData; @@ -211,6 +213,7 @@ templates_delete_cmd_callback (GtkAction *action, TemplateDeleteData *delete_data = g_slice_new (TemplateDeleteData); GtkWidget *dialog; + delete_data->context = context; delete_data->container = container; delete_data->template = template; @@ -293,9 +296,20 @@ templates_delete_response (GtkWidget *dialog, { if (response_id == GTK_RESPONSE_OK) { + GimpObject *new_active; + + new_active = gimp_container_get_neighbor_of_active (delete_data->container, + delete_data->context, + GIMP_OBJECT (delete_data->template)); + if (gimp_container_have (delete_data->container, GIMP_OBJECT (delete_data->template))) { + if (new_active) + gimp_context_set_by_type (delete_data->context, + delete_data->container->children_type, + new_active); + gimp_container_remove (delete_data->container, GIMP_OBJECT (delete_data->template)); } diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c index a7e717efed..dac26b0687 100644 --- a/app/core/gimp-utils.c +++ b/app/core/gimp-utils.c @@ -52,6 +52,8 @@ #include "gimp.h" #include "gimp-utils.h" +#include "gimpcontainer.h" +#include "gimpcontext.h" #include "gimpparamspecs.h" @@ -508,3 +510,32 @@ gimp_get_temp_filename (Gimp *gimp, return filename; } + +GimpObject * +gimp_container_get_neighbor_of_active (GimpContainer *container, + GimpContext *context, + GimpObject *active) +{ + g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + g_return_val_if_fail (GIMP_IS_OBJECT (active), NULL); + + if (active == gimp_context_get_by_type (context, container->children_type)) + { + gint index = gimp_container_get_child_index (container, active); + + if (index != -1) + { + GimpObject *new; + + new = gimp_container_get_child_by_index (container, index + 1); + + if (! new && index > 0) + new = gimp_container_get_child_by_index (container, index - 1); + + return new; + } + } + + return NULL; +} diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h index b2dfa8d8e4..936c940cbd 100644 --- a/app/core/gimp-utils.h +++ b/app/core/gimp-utils.h @@ -63,5 +63,9 @@ void gimp_value_array_truncate (GValueArray *args, gchar * gimp_get_temp_filename (Gimp *gimp, const gchar *extension); +GimpObject * gimp_container_get_neighbor_of_active (GimpContainer *container, + GimpContext *context, + GimpObject *active); + #endif /* __APP_GIMP_UTILS_H__ */ diff --git a/app/widgets/gimpcontainerview-utils.c b/app/widgets/gimpcontainerview-utils.c index 6451ee11fd..a3bba62239 100644 --- a/app/widgets/gimpcontainerview-utils.c +++ b/app/widgets/gimpcontainerview-utils.c @@ -22,6 +22,10 @@ #include "widgets-types.h" +#include "core/gimp-utils.h" +#include "core/gimpcontainer.h" +#include "core/gimpcontext.h" + #include "gimpcontainereditor.h" #include "gimpcontainerview.h" #include "gimpcontainerview-utils.h" @@ -53,3 +57,36 @@ gimp_container_view_get_by_dockable (GimpDockable *dockable) return NULL; } + +void +gimp_container_view_remove_active (GimpContainerView *view) +{ + GimpContext *context; + GimpContainer *container; + + g_return_if_fail (GIMP_IS_CONTAINER_VIEW (view)); + + context = gimp_container_view_get_context (view); + container = gimp_container_view_get_container (view); + + if (context && container) + { + GimpObject *active; + + active = gimp_context_get_by_type (context, container->children_type); + + if (active) + { + GimpObject *new; + + new = gimp_container_get_neighbor_of_active (container, context, + active); + + if (new) + gimp_context_set_by_type (context, container->children_type, + new); + + gimp_container_remove (container, active); + } + } +} diff --git a/app/widgets/gimpcontainerview-utils.h b/app/widgets/gimpcontainerview-utils.h index 581cc8b1e1..04f02859ea 100644 --- a/app/widgets/gimpcontainerview-utils.h +++ b/app/widgets/gimpcontainerview-utils.h @@ -23,7 +23,9 @@ #define __GIMP_CONTAINER_VIEW_UTILS_H__ -GimpContainerView * gimp_container_view_get_by_dockable (GimpDockable *dockable); +GimpContainerView * gimp_container_view_get_by_dockable (GimpDockable *dockable); + +void gimp_container_view_remove_active (GimpContainerView *view); #endif /* __GIMP_CONTAINER_VIEW_UTILS_H__ */