Commit 65ef1372 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

new utility function which returns the neighbor of a container's active

2007-05-27  Michael Natterer  <mitch@gimp.org>

	* 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
parent e601d3e7
2007-05-27 Michael Natterer <mitch@gimp.org>
* 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 <sven@gimp.org>
* libgimpwidgets/gimpwidgets.c (gimp_coordinates_new): update the
......@@ -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);
}
......
......@@ -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;
new_active = gimp_container_get_neighbor_of_active (factory->container,
delete_data->context,
GIMP_OBJECT (data));
if (! gimp_data_factory_data_delete (delete_data->view->factory,
delete_data->data,
TRUE, &error))
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);
......
......@@ -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
......
......@@ -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));
}
......
......@@ -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;
}
......@@ -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__ */
......@@ -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);
}
}
}
......@@ -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__ */
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