2004-07-10 04:38:35 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Sven Neumann <sven@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 <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
#include "dialogs-types.h"
|
2004-07-10 04:38:35 +08:00
|
|
|
|
2004-07-10 06:28:27 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2004-07-10 04:38:35 +08:00
|
|
|
#include "core/gimp.h"
|
2004-10-15 22:34:34 +08:00
|
|
|
#include "core/gimplist.h"
|
2004-07-10 04:38:35 +08:00
|
|
|
|
2004-10-15 22:34:34 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2004-07-10 04:38:35 +08:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
|
|
|
|
2004-07-10 06:28:27 +08:00
|
|
|
#include "widgets/gimpcontainertreeview.h"
|
2005-03-31 17:55:47 +08:00
|
|
|
#include "widgets/gimpcontainerview.h"
|
|
|
|
#include "widgets/gimpdnd.h"
|
2004-08-25 05:42:29 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
#include "widgets/gimpmessagebox.h"
|
2004-10-13 22:35:28 +08:00
|
|
|
#include "widgets/gimpmessagedialog.h"
|
2004-07-10 04:38:35 +08:00
|
|
|
|
|
|
|
#include "quit-dialog.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2004-10-15 22:34:34 +08:00
|
|
|
static void quit_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp);
|
|
|
|
static void quit_dialog_container_changed (GimpContainer *images,
|
|
|
|
GimpObject *image,
|
|
|
|
GimpMessageBox *box);
|
|
|
|
static void quit_dialog_image_activated (GimpContainerView *view,
|
|
|
|
GimpImage *image,
|
|
|
|
gpointer insert_data,
|
|
|
|
Gimp *gimp);
|
2004-07-10 04:38:35 +08:00
|
|
|
|
|
|
|
|
2004-10-15 22:34:34 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2004-07-10 04:38:35 +08:00
|
|
|
GtkWidget *
|
|
|
|
quit_dialog_new (Gimp *gimp)
|
|
|
|
{
|
2004-10-13 22:35:28 +08:00
|
|
|
GimpContainer *images;
|
|
|
|
GimpMessageBox *box;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *label;
|
2004-10-26 04:11:50 +08:00
|
|
|
GtkWidget *button;
|
2004-10-13 22:35:28 +08:00
|
|
|
GtkWidget *view;
|
|
|
|
gint rows;
|
|
|
|
gint preview_size;
|
2004-07-10 04:38:35 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
2004-09-14 07:09:10 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning FIXME: need container of dirty images
|
|
|
|
#endif
|
|
|
|
|
2004-07-10 06:28:27 +08:00
|
|
|
images = gimp_displays_get_dirty_images (gimp);
|
|
|
|
|
|
|
|
g_return_val_if_fail (images != NULL, NULL);
|
|
|
|
|
2004-10-13 22:35:28 +08:00
|
|
|
dialog =
|
|
|
|
gimp_message_dialog_new (_("Quit The GIMP"), GIMP_STOCK_WILBER_EEK,
|
|
|
|
NULL, 0,
|
|
|
|
gimp_standard_help_func, NULL,
|
2004-07-10 06:28:27 +08:00
|
|
|
|
2004-10-26 04:11:50 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2004-07-10 06:28:27 +08:00
|
|
|
|
2004-10-13 22:35:28 +08:00
|
|
|
NULL);
|
2004-07-10 06:28:27 +08:00
|
|
|
|
2004-10-15 22:34:34 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (dialog), "dirty-images",
|
|
|
|
images, (GDestroyNotify) g_object_unref);
|
|
|
|
|
2004-07-10 06:28:27 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (quit_dialog_response),
|
|
|
|
gimp);
|
|
|
|
|
2004-10-13 22:35:28 +08:00
|
|
|
box = GIMP_MESSAGE_DIALOG (dialog)->box;
|
2004-07-10 06:28:27 +08:00
|
|
|
|
2004-10-26 22:45:25 +08:00
|
|
|
button = gtk_dialog_add_button (GTK_DIALOG (dialog), "", GTK_RESPONSE_OK);
|
|
|
|
|
2004-10-26 04:11:50 +08:00
|
|
|
g_object_set_data (G_OBJECT (box), "ok-button", button);
|
|
|
|
|
2004-10-13 09:39:57 +08:00
|
|
|
g_signal_connect_object (images, "add",
|
|
|
|
G_CALLBACK (quit_dialog_container_changed),
|
|
|
|
box, 0);
|
2004-07-12 19:12:19 +08:00
|
|
|
g_signal_connect_object (images, "remove",
|
|
|
|
G_CALLBACK (quit_dialog_container_changed),
|
2004-08-25 05:42:29 +08:00
|
|
|
box, 0);
|
2004-07-12 19:12:19 +08:00
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-07-10 06:28:27 +08:00
|
|
|
preview_size = gimp->config->layer_preview_size;
|
2004-10-15 22:34:34 +08:00
|
|
|
rows = CLAMP (gimp_container_num_children (images), 3, 6);
|
2004-07-10 06:28:27 +08:00
|
|
|
|
2004-07-12 19:12:19 +08:00
|
|
|
view = gimp_container_tree_view_new (images, NULL, preview_size, 1);
|
|
|
|
gimp_container_box_set_size_request (GIMP_CONTAINER_BOX (view),
|
|
|
|
-1,
|
|
|
|
rows * (preview_size + 2));
|
2004-10-15 22:34:34 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), view, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (view);
|
|
|
|
|
|
|
|
g_signal_connect (view, "activate-item",
|
|
|
|
G_CALLBACK (quit_dialog_image_activated),
|
|
|
|
gimp);
|
2004-07-12 19:12:19 +08:00
|
|
|
|
2005-03-31 17:55:47 +08:00
|
|
|
gimp_dnd_xds_source_add (gimp_container_view_get_dnd_widget (view),
|
|
|
|
(GimpDndDragViewableFunc) gimp_dnd_get_drag_data,
|
|
|
|
NULL);
|
|
|
|
|
2004-07-10 18:08:19 +08:00
|
|
|
label = gtk_label_new (_("If you quit GIMP now, "
|
2004-07-10 06:28:27 +08:00
|
|
|
"these changes will be lost."));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2004-07-10 18:08:19 +08:00
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
|
2004-08-25 05:42:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
|
2004-07-10 06:28:27 +08:00
|
|
|
gtk_widget_show (label);
|
2004-07-10 04:38:35 +08:00
|
|
|
|
2004-10-13 09:39:57 +08:00
|
|
|
g_object_set_data (G_OBJECT (box), "lost-label", label);
|
|
|
|
|
2004-10-13 22:35:28 +08:00
|
|
|
quit_dialog_container_changed (images, NULL,
|
|
|
|
GIMP_MESSAGE_DIALOG (dialog)->box);
|
2004-10-13 09:39:57 +08:00
|
|
|
|
2004-07-10 04:38:35 +08:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-10 06:28:27 +08:00
|
|
|
quit_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp)
|
2004-07-10 04:38:35 +08:00
|
|
|
{
|
2004-07-10 06:28:27 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
gimp_exit (gimp, TRUE);
|
2004-07-10 04:38:35 +08:00
|
|
|
}
|
2004-07-12 19:12:19 +08:00
|
|
|
|
|
|
|
static void
|
2004-08-25 05:42:29 +08:00
|
|
|
quit_dialog_container_changed (GimpContainer *images,
|
|
|
|
GimpObject *image,
|
|
|
|
GimpMessageBox *box)
|
2004-07-12 19:12:19 +08:00
|
|
|
{
|
2004-10-13 09:39:57 +08:00
|
|
|
gint num_images = gimp_container_num_children (images);
|
|
|
|
GtkWidget *label = g_object_get_data (G_OBJECT (box), "lost-label");
|
2004-10-26 04:11:50 +08:00
|
|
|
GtkWidget *button = g_object_get_data (G_OBJECT (box), "ok-button");
|
2004-10-26 20:59:58 +08:00
|
|
|
GtkWidget *dialog = gtk_widget_get_toplevel (button);
|
2004-07-12 19:12:19 +08:00
|
|
|
|
|
|
|
if (num_images == 1)
|
2004-08-25 05:42:29 +08:00
|
|
|
gimp_message_box_set_primary_text (box,
|
|
|
|
_("There is one image with unsaved changes:"));
|
2004-07-12 19:12:19 +08:00
|
|
|
else
|
2004-08-25 05:42:29 +08:00
|
|
|
gimp_message_box_set_primary_text (box,
|
|
|
|
_("There are %d images with unsaved changes:"),
|
|
|
|
num_images);
|
2004-07-12 19:12:19 +08:00
|
|
|
|
2004-10-13 09:39:57 +08:00
|
|
|
if (num_images == 0)
|
2004-10-26 04:11:50 +08:00
|
|
|
{
|
|
|
|
gtk_widget_hide (label);
|
|
|
|
g_object_set (button,
|
|
|
|
"label", GTK_STOCK_QUIT,
|
|
|
|
"use-stock", TRUE,
|
2005-03-31 16:14:15 +08:00
|
|
|
"image", NULL,
|
2004-10-26 04:11:50 +08:00
|
|
|
NULL);
|
2004-10-26 20:59:58 +08:00
|
|
|
gtk_widget_grab_default (button);
|
2004-10-26 04:11:50 +08:00
|
|
|
}
|
2004-10-13 09:39:57 +08:00
|
|
|
else
|
2004-10-26 04:11:50 +08:00
|
|
|
{
|
2005-03-31 16:14:15 +08:00
|
|
|
GtkWidget *icon = gtk_image_new_from_stock (GTK_STOCK_DELETE,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
2004-10-26 04:11:50 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
g_object_set (button,
|
2004-12-18 18:35:35 +08:00
|
|
|
"label", _("_Discard Changes"),
|
2004-10-26 04:11:50 +08:00
|
|
|
"use-stock", FALSE,
|
2005-03-31 16:14:15 +08:00
|
|
|
"image", icon,
|
2004-10-26 04:11:50 +08:00
|
|
|
NULL);
|
2004-10-26 20:59:58 +08:00
|
|
|
gtk_window_set_default (GTK_WINDOW (dialog), NULL);
|
2004-10-26 04:11:50 +08:00
|
|
|
}
|
2004-10-13 09:39:57 +08:00
|
|
|
}
|
2004-10-15 22:34:34 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
quit_dialog_image_activated (GimpContainerView *view,
|
|
|
|
GimpImage *image,
|
|
|
|
gpointer insert_data,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = GIMP_LIST (gimp->displays)->list;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpDisplay *display = list->data;
|
|
|
|
|
|
|
|
if (display->gimage == image)
|
|
|
|
gtk_window_present (GTK_WINDOW (display->shell));
|
|
|
|
}
|
|
|
|
}
|