1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #include "config.h"
19 
20 #include <gegl.h>
21 #include <gtk/gtk.h>
22 
23 #include "libgimpwidgets/gimpwidgets.h"
24 
25 #include "actions-types.h"
26 
27 #include "core/gimp.h"
28 #include "core/gimpcontainer.h"
29 #include "core/gimpcontext.h"
30 #include "core/gimpimage.h"
31 
32 #include "widgets/gimpcontainerview.h"
33 #include "widgets/gimpimageview.h"
34 
35 #include "display/gimpdisplay.h"
36 #include "display/gimpdisplayshell.h"
37 
38 #include "images-commands.h"
39 
40 
41 /*  public functions */
42 
43 void
images_raise_views_cmd_callback(GimpAction * action,GVariant * value,gpointer data)44 images_raise_views_cmd_callback (GimpAction *action,
45                                  GVariant   *value,
46                                  gpointer    data)
47 {
48   GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
49   GimpContainer       *container;
50   GimpContext         *context;
51   GimpImage           *image;
52 
53   container = gimp_container_view_get_container (editor->view);
54   context   = gimp_container_view_get_context (editor->view);
55 
56   image = gimp_context_get_image (context);
57 
58   if (image && gimp_container_have (container, GIMP_OBJECT (image)))
59     {
60       GList *list;
61 
62       for (list = gimp_get_display_iter (image->gimp);
63            list;
64            list = g_list_next (list))
65         {
66           GimpDisplay *display = list->data;
67 
68           if (gimp_display_get_image (display) == image)
69             gimp_display_shell_present (gimp_display_get_shell (display));
70         }
71     }
72 }
73 
74 void
images_new_view_cmd_callback(GimpAction * action,GVariant * value,gpointer data)75 images_new_view_cmd_callback (GimpAction *action,
76                               GVariant   *value,
77                               gpointer    data)
78 {
79   GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
80   GimpContainer       *container;
81   GimpContext         *context;
82   GimpImage           *image;
83 
84   container = gimp_container_view_get_container (editor->view);
85   context   = gimp_container_view_get_context (editor->view);
86 
87   image = gimp_context_get_image (context);
88 
89   if (image && gimp_container_have (container, GIMP_OBJECT (image)))
90     {
91       gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0,
92                            G_OBJECT (gtk_widget_get_screen (GTK_WIDGET (editor))),
93                            gimp_widget_get_monitor (GTK_WIDGET (editor)));
94     }
95 }
96 
97 void
images_delete_image_cmd_callback(GimpAction * action,GVariant * value,gpointer data)98 images_delete_image_cmd_callback (GimpAction *action,
99                                   GVariant   *value,
100                                   gpointer    data)
101 {
102   GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
103   GimpContainer       *container;
104   GimpContext         *context;
105   GimpImage           *image;
106 
107   container = gimp_container_view_get_container (editor->view);
108   context   = gimp_container_view_get_context (editor->view);
109 
110   image = gimp_context_get_image (context);
111 
112   if (image && gimp_container_have (container, GIMP_OBJECT (image)))
113     {
114       if (gimp_image_get_display_count (image) == 0)
115         g_object_unref (image);
116     }
117 }
118