gimp/app/actions/documents-commands.c
Michael Natterer 2632cd8f64 app/actions/documents-actions.c app/actions/documents-commands.c
2004-05-12  Michael Natterer  <mitch@gimp.org>

	* app/actions/documents-actions.c
	* app/actions/documents-commands.c
	* app/actions/edit-actions.c
	* app/actions/edit-commands.[ch]
	* app/actions/layers-actions.c
	* app/actions/layers-commands.c
	* app/actions/select-actions.c
	* app/actions/select-commands.[ch]
	* app/actions/vectors-actions.c
	* app/actions/vectors-commands.[ch]: added tooltips for actions
	which are now used for dialog buttons, added callback
	implementations which formerly lived in various widgets, moved
	some actions around and did some general cleanups.

	* menus/image-menu.xml.in: s/edit-stroke/select-stroke/

	* menus/Makefile.am
	* menus/selection-editor-menu.xml: new popup menu.

	* app/menus/menus.c: register <SelectionEditor> and <UndoEditor>
	UI managers.

	* app/widgets/gimpeditor.[ch]: added construct properties
	"menu-factory", "menu-identifier", "ui-path" and "popup-data".
	Implement GObject::constructor() and create the UI manager
	if all needed properties were set. Enables creating action
	buttons at widget construction time because they need a
	UI manager.

	(gimp_editor_add_action_button): changed to take a va_list of
	"extended" actions which are invoked if the resp. button emits
	"extended_clicked". Store the actions and their modifier masks in
	a list attached to the button.

	* app/widgets/gimpcontainerview.c
	(gimp_container_view_item_selected): if the view has container
	*and* context, simply change the context and return.

	(gimp_container_view_context_changed): don't emit "select_item"
	manually but simply call gimp_container_view_select_item().

	(gimp_container_view_viewable_dropped): use
	gimp_container_view_item_selected() instead of changing the
	context directly.

	* app/widgets/gimpcontainereditor.c
	(gimp_container_editor_select_item): update the UI manager.

	* app/widgets/gimpdockable.c: don't try to fiddle with the
	dialog's menu if it doesn't have a ui_path (happens if the UI
	manager is just a collection of actions for the dialog buttons and
	has no menu registered).

	* app/widgets/gimpimageeditor.c: connect to the image's "flush"
	signal and update the UI manager in the callback.

	* app/widgets/gimpitemtreeview.c: use GimpEditor's construct
	properties to create the UI manager so GimpItemTreeView subclasses
	can have action buttons. Update the UI manager in
	gimp_item_tree_view_select_item().

	* app/widgets/gimpbufferview.c
	* app/widgets/gimpcolormapeditor.c
	* app/widgets/gimpcontainergridview.c
	* app/widgets/gimpdatafactoryview.c
	* app/widgets/gimpfontview.c
	* app/widgets/gimpimageview.c
	* app/widgets/gimptemplateview.c
	* app/widgets/gimptoolview.c: changed calls to
	gimp_editor_add_action_button() accordingly and removed some
	unneeded select_item() implementations.

	* app/widgets/gimpchanneltreeview.c
	* app/widgets/gimpvectorstreeview.[ch]
	* app/widgets/gimpdocumentview.[ch]
	* app/widgets/gimplayertreeview.c
	* app/widgets/gimpselectioneditor.[ch]
	* app/widgets/gimpundoeditor.[ch]: use action buttons and removed
	lots of callbacks which went to the resp. action callbacks.

	* app/widgets/widgets-types.h: removed some now unneeded function
	prototypes.

	* app/gui/dialogs-constructors.c: changed (simplified) many dialog
	constructors accordingly.
2004-05-12 18:36:33 +00:00

272 lines
7.6 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <string.h>
#include <gtk/gtk.h>
#include "libgimpthumb/gimpthumb.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpimagefile.h"
#include "file/file-open.h"
#include "file/file-utils.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimpdocumentview.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
#include "documents-commands.h"
#include "file-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void documents_open_image (GimpContext *context,
GimpImagefile *imagefile);
/* public functions */
void
documents_open_document_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)))
{
documents_open_image (context, imagefile);
}
else
{
file_file_open_dialog (context->gimp, NULL, GTK_WIDGET (editor));
}
}
typedef struct _RaiseClosure RaiseClosure;
struct _RaiseClosure
{
const gchar *name;
gboolean found;
};
static void
documents_raise_display (gpointer data,
gpointer user_data)
{
GimpDisplay *gdisp = (GimpDisplay *) data;
RaiseClosure *closure = (RaiseClosure *) user_data;
const gchar *uri;
uri = gimp_object_get_name (GIMP_OBJECT (gdisp->gimage));
if (uri && ! strcmp (closure->name, uri))
{
closure->found = TRUE;
gtk_window_present (GTK_WINDOW (gdisp->shell));
}
}
void
documents_raise_or_open_document_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)))
{
RaiseClosure closure;
closure.name = gimp_object_get_name (GIMP_OBJECT (imagefile));
closure.found = FALSE;
gimp_container_foreach (context->gimp->displays,
documents_raise_display,
&closure);
if (! closure.found)
documents_open_image (context, imagefile);
}
}
void
documents_file_open_dialog_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)))
{
file_file_open_dialog (context->gimp,
gimp_object_get_name (GIMP_OBJECT (imagefile)),
GTK_WIDGET (editor));
}
}
void
documents_remove_document_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));
}
}
void
documents_recreate_preview_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)))
{
gint preview_size;
preview_size = gimp_container_view_get_preview_size (editor->view, NULL);
gimp_imagefile_create_thumbnail (imagefile, context, preview_size);
}
}
void
documents_reload_previews_cmd_callback (GtkAction *action,
gpointer data)
{
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
GimpContainer *container;
container = gimp_container_view_get_container (editor->view);
gimp_container_foreach (container,
(GFunc) gimp_imagefile_update,
editor->view);
}
static void
documents_delete_dangling_foreach (GimpImagefile *imagefile,
GimpContainer *container)
{
if (gimp_thumbnail_peek_image (imagefile->thumbnail) ==
GIMP_THUMB_STATE_NOT_FOUND)
{
gimp_container_remove (container, GIMP_OBJECT (imagefile));
}
}
void
documents_delete_dangling_documents_cmd_callback (GtkAction *action,
gpointer data)
{
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
GimpContainer *container;
container = gimp_container_view_get_container (editor->view);
gimp_container_foreach (container,
(GFunc) documents_delete_dangling_foreach,
container);
}
/* private functions */
static void
documents_open_image (GimpContext *context,
GimpImagefile *imagefile)
{
const gchar *uri;
GimpImage *gimage;
GimpPDBStatusType status;
GError *error = NULL;
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
gimage = file_open_with_display (context->gimp, context,
uri, &status, &error);
if (! gimage && status != GIMP_PDB_CANCEL)
{
gchar *filename;
filename = file_utils_uri_to_utf8_filename (uri);
g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message);
g_clear_error (&error);
g_free (filename);
}
}