mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-21 12:02:32 +00:00
05e15eb1cc
2001-10-29 Michael Natterer <mitch@gimp.org> Cleanup weekend... * app/app_procs.c: pass "no_interface" to gimp_new(). * app/core/gimp.[ch]: added "gboolean no_interface" and the load_procs and save_procs GSLists. * app/core/gimptoolinfo.[ch]: added a "Gimp" pointer to the GimpToolInfo object so more functions find their context without accessing the global "the_gimp" variable. * app/display/display-types.h: removed the GDisplay -> GimpDisplay typedef. * app/display/gimpdisplay.c: look at gimp->no_interface, don't include "appenv.h". * app/file/file-open.[ch] * app/file/file-save.[ch]: don't use "the_gimp" any more. Instead, pass around lots of "Gimp" pointers. Removed the global load_procs and save_procs variables here. Use access() to find out whether a file is readable/writable, removed the manual voodoo and it's Win32 wrappers. Added an optional (can be NULL) "PlunInProcDef" parameter to file_save(), removed file_save_with_proc(). * app/gui/menus.c: Use the unused "gpointer data" parameter of the GtkItemFactory callbacks to pass a "Gimp" pointer to all of them. This reduces the usage of the global "the_gimp" hack to zero in app/gui/... yeah. * app/gui/channels-commands.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/image-commands.c * app/gui/layers-commands.c * app/gui/palettes-commands.c * app/gui/select-commands.c * app/gui/test-commands.c * app/gui/tools-commands.c * app/gui/view-commands.c: use the passed "Gimp" pointer. * app/gui/color-area.[ch] * app/gui/convert-dialog.c * app/gui/dialogs-constructors.c * app/gui/file-new-dialog.[ch] * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.[ch] * app/gui/gui.c * app/gui/info-window.[ch] * app/gui/module-browser.[ch] * app/gui/palette-editor.c * app/gui/palette-import-dialog.[ch] * app/gui/paths-dialog.c * app/gui/preferences-dialog.[ch] * app/gui/resize-dialog.[ch] * app/gui/tool-options-dialog.[ch] * app/gui/toolbox.c: pass around lots more "Gimp" and "GimpContext" pointers and don't use "the_gimp" any more. * app/tools/gimptool.h: added a pointer to the corresponding GimpToolInfo object (which in turn has a pointer to a Gimp). * app/tools/tool_manager.[ch]: set the pointer after creating the tool object. Removed tool_manager_get_info_by_tool() as there is a tool->tool_info pointer now. * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimpdodgeburntool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpellipseselecttool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprectselecttool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimptexttool.c * app/tools/gimpthresholdtool.c * app/tools/path_tool.c * app/tools/xinput_airbrush.c: s/GDisplay/GimpDisplay/g. Use tool->tool_info and tool_info->gimp in some places to get rid of using "the_gimp". Removing the remaining ones involves changing the tool options system and is scheduled next... * app/widgets/gimpdnd.c * app/widgets/gimpdocumentview.c: pass a "Gimp" pointer to all file_open_*() functions. * app/gdisplay_color.[ch] * app/gdisplay_color_ui.[ch] * app/image_map.[ch] * app/nav_window.[ch] * app/path.c * app/path_bezier.c * app/path_transform.h * app/qmask.[ch]: s/GDisplay/GimpDisplay/g * tools/pdbgen/pdb/fileops.pdb: load_procs and save_procs are members of the "Gimp" object now. * tools/pdbgen/pdb/plug_in.pdb: use gimp->no_interface, don't include "appenv.h". * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
356 lines
11 KiB
C
356 lines
11 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
*
|
|
* gimpdocumentview.c
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
|
*
|
|
* 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 "libgimpwidgets/gimpwidgets.h"
|
|
|
|
#include "widgets-types.h"
|
|
|
|
#include "core/gimpcontainer.h"
|
|
#include "core/gimpcontext.h"
|
|
#include "core/gimpedit.h"
|
|
#include "core/gimpimage.h"
|
|
#include "core/gimpimagefile.h"
|
|
|
|
#include "display/gimpdisplay.h"
|
|
#include "display/gimpdisplay-foreach.h"
|
|
|
|
#include "gui/file-open-dialog.h"
|
|
|
|
#include "gimpcontainerview.h"
|
|
#include "gimpdocumentview.h"
|
|
#include "gimpdnd.h"
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
static void gimp_document_view_class_init (GimpDocumentViewClass *klass);
|
|
static void gimp_document_view_init (GimpDocumentView *view);
|
|
|
|
static void gimp_document_view_open_clicked (GtkWidget *widget,
|
|
GimpDocumentView *view);
|
|
static void gimp_document_view_open_extended_clicked (GtkWidget *widget,
|
|
guint state,
|
|
GimpDocumentView *view);
|
|
static void gimp_document_view_delete_clicked (GtkWidget *widget,
|
|
GimpDocumentView *view);
|
|
static void gimp_document_view_refresh_clicked (GtkWidget *widget,
|
|
GimpDocumentView *view);
|
|
|
|
static void gimp_document_view_select_item (GimpContainerEditor *editor,
|
|
GimpViewable *viewable);
|
|
static void gimp_document_view_activate_item (GimpContainerEditor *editor,
|
|
GimpViewable *viewable);
|
|
|
|
|
|
static GimpContainerEditorClass *parent_class = NULL;
|
|
|
|
|
|
GType
|
|
gimp_document_view_get_type (void)
|
|
{
|
|
static GType view_type = 0;
|
|
|
|
if (! view_type)
|
|
{
|
|
static const GTypeInfo view_info =
|
|
{
|
|
sizeof (GimpDocumentViewClass),
|
|
NULL, /* base_init */
|
|
NULL, /* base_finalize */
|
|
(GClassInitFunc) gimp_document_view_class_init,
|
|
NULL, /* class_finalize */
|
|
NULL, /* class_data */
|
|
sizeof (GimpDocumentView),
|
|
0, /* n_preallocs */
|
|
(GInstanceInitFunc) gimp_document_view_init,
|
|
};
|
|
|
|
view_type = g_type_register_static (GIMP_TYPE_CONTAINER_EDITOR,
|
|
"GimpDocumentView",
|
|
&view_info, 0);
|
|
}
|
|
|
|
return view_type;
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_class_init (GimpDocumentViewClass *klass)
|
|
{
|
|
GimpContainerEditorClass *editor_class;
|
|
|
|
editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
editor_class->select_item = gimp_document_view_select_item;
|
|
editor_class->activate_item = gimp_document_view_activate_item;
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_init (GimpDocumentView *view)
|
|
{
|
|
view->open_button = NULL;
|
|
view->delete_button = NULL;
|
|
view->refresh_button = NULL;
|
|
}
|
|
|
|
GtkWidget *
|
|
gimp_document_view_new (GimpViewType view_type,
|
|
GimpContainer *container,
|
|
GimpContext *context,
|
|
gint preview_size,
|
|
gint min_items_x,
|
|
gint min_items_y,
|
|
GimpContainerContextFunc context_func)
|
|
{
|
|
GimpDocumentView *document_view;
|
|
GimpContainerEditor *editor;
|
|
|
|
document_view = g_object_new (GIMP_TYPE_DOCUMENT_VIEW, NULL);
|
|
|
|
if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (document_view),
|
|
view_type,
|
|
container,
|
|
context,
|
|
preview_size,
|
|
TRUE, /* reorderable */
|
|
min_items_x,
|
|
min_items_y,
|
|
context_func))
|
|
{
|
|
g_object_unref (G_OBJECT (document_view));
|
|
return NULL;
|
|
}
|
|
|
|
editor = GIMP_CONTAINER_EDITOR (document_view);
|
|
|
|
document_view->open_button =
|
|
gimp_container_view_add_button (editor->view,
|
|
GTK_STOCK_OPEN,
|
|
_("Open the selected entry\n"
|
|
"<Shift> Raise window if already open\n"
|
|
"<Ctrl> Open image dialog"),
|
|
NULL,
|
|
G_CALLBACK (gimp_document_view_open_clicked),
|
|
G_CALLBACK (gimp_document_view_open_extended_clicked),
|
|
editor);
|
|
|
|
document_view->delete_button =
|
|
gimp_container_view_add_button (editor->view,
|
|
GIMP_STOCK_DELETE,
|
|
_("Remove selected entry"), NULL,
|
|
G_CALLBACK (gimp_document_view_delete_clicked),
|
|
NULL,
|
|
editor);
|
|
|
|
document_view->refresh_button =
|
|
gimp_container_view_add_button (editor->view,
|
|
GIMP_STOCK_REFRESH,
|
|
_("Refresh (check files for existence)"),
|
|
NULL,
|
|
G_CALLBACK (gimp_document_view_refresh_clicked),
|
|
NULL,
|
|
editor);
|
|
|
|
/* set button sensitivity */
|
|
if (GIMP_CONTAINER_EDITOR_GET_CLASS (editor)->select_item)
|
|
GIMP_CONTAINER_EDITOR_GET_CLASS (editor)->select_item
|
|
(editor, (GimpViewable *) gimp_context_get_imagefile (context));
|
|
|
|
gimp_container_view_enable_dnd (editor->view,
|
|
GTK_BUTTON (document_view->open_button),
|
|
GIMP_TYPE_IMAGEFILE);
|
|
gimp_container_view_enable_dnd (editor->view,
|
|
GTK_BUTTON (document_view->delete_button),
|
|
GIMP_TYPE_IMAGEFILE);
|
|
|
|
return GTK_WIDGET (document_view);
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_open_clicked (GtkWidget *widget,
|
|
GimpDocumentView *view)
|
|
{
|
|
GimpContainerEditor *editor;
|
|
GimpImagefile *imagefile;
|
|
|
|
editor = GIMP_CONTAINER_EDITOR (view);
|
|
|
|
imagefile = gimp_context_get_imagefile (editor->view->context);
|
|
|
|
if (imagefile && gimp_container_have (editor->view->container,
|
|
GIMP_OBJECT (imagefile)))
|
|
{
|
|
file_open_with_display (editor->view->context->gimp,
|
|
gimp_object_get_name (GIMP_OBJECT (imagefile)));
|
|
}
|
|
else
|
|
{
|
|
file_open_dialog_show (editor->view->context->gimp);
|
|
}
|
|
}
|
|
|
|
|
|
typedef struct _RaiseClosure RaiseClosure;
|
|
|
|
struct _RaiseClosure
|
|
{
|
|
const gchar *name;
|
|
gboolean found;
|
|
};
|
|
|
|
static void
|
|
gimp_document_view_raise_display (gpointer data,
|
|
gpointer user_data)
|
|
{
|
|
GimpDisplay *gdisp;
|
|
RaiseClosure *closure;
|
|
const gchar *filename;
|
|
|
|
gdisp = (GimpDisplay *) data;
|
|
closure = (RaiseClosure *) user_data;
|
|
|
|
filename = gimp_object_get_name (GIMP_OBJECT (gdisp->gimage));
|
|
|
|
if (filename && ! strcmp (closure->name, filename))
|
|
{
|
|
closure->found = TRUE;
|
|
gdk_window_raise (gdisp->shell->window);
|
|
}
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_open_extended_clicked (GtkWidget *widget,
|
|
guint state,
|
|
GimpDocumentView *view)
|
|
{
|
|
GimpContainerEditor *editor;
|
|
GimpImagefile *imagefile;
|
|
|
|
editor = GIMP_CONTAINER_EDITOR (view);
|
|
|
|
imagefile = gimp_context_get_imagefile (editor->view->context);
|
|
|
|
if (imagefile && gimp_container_have (editor->view->container,
|
|
GIMP_OBJECT (imagefile)))
|
|
{
|
|
if (state & GDK_CONTROL_MASK)
|
|
{
|
|
file_open_dialog_show (editor->view->context->gimp);
|
|
}
|
|
else if (state & GDK_SHIFT_MASK)
|
|
{
|
|
RaiseClosure closure;
|
|
|
|
closure.name = gimp_object_get_name (GIMP_OBJECT (imagefile));
|
|
closure.found = FALSE;
|
|
|
|
gdisplays_foreach (gimp_document_view_raise_display, &closure);
|
|
|
|
if (! closure.found)
|
|
{
|
|
file_open_with_display (editor->view->context->gimp,
|
|
closure.name);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
file_open_dialog_show (editor->view->context->gimp);
|
|
}
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_delete_clicked (GtkWidget *widget,
|
|
GimpDocumentView *view)
|
|
{
|
|
GimpContainerEditor *editor;
|
|
GimpImagefile *imagefile;
|
|
|
|
editor = GIMP_CONTAINER_EDITOR (view);
|
|
|
|
imagefile = gimp_context_get_imagefile (editor->view->context);
|
|
|
|
if (imagefile && gimp_container_have (editor->view->container,
|
|
GIMP_OBJECT (imagefile)))
|
|
{
|
|
gimp_container_remove (editor->view->container,
|
|
GIMP_OBJECT (imagefile));
|
|
}
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_refresh_clicked (GtkWidget *widget,
|
|
GimpDocumentView *view)
|
|
{
|
|
GimpContainerEditor *editor;
|
|
|
|
editor = GIMP_CONTAINER_EDITOR (view);
|
|
|
|
g_print ("refresh clicked\n");
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_select_item (GimpContainerEditor *editor,
|
|
GimpViewable *viewable)
|
|
{
|
|
GimpDocumentView *view;
|
|
|
|
gboolean delete_sensitive = FALSE;
|
|
|
|
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
|
|
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
|
|
|
|
view = GIMP_DOCUMENT_VIEW (editor);
|
|
|
|
if (viewable && gimp_container_have (editor->view->container,
|
|
GIMP_OBJECT (viewable)))
|
|
{
|
|
delete_sensitive = TRUE;
|
|
}
|
|
|
|
gtk_widget_set_sensitive (view->delete_button, delete_sensitive);
|
|
}
|
|
|
|
static void
|
|
gimp_document_view_activate_item (GimpContainerEditor *editor,
|
|
GimpViewable *viewable)
|
|
{
|
|
GimpDocumentView *view;
|
|
|
|
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
|
|
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
|
|
|
|
view = GIMP_DOCUMENT_VIEW (editor);
|
|
|
|
if (viewable && gimp_container_have (editor->view->container,
|
|
GIMP_OBJECT (viewable)))
|
|
{
|
|
gimp_document_view_open_clicked (NULL, view);
|
|
}
|
|
}
|