edit-commands.c 6.94 KB
Newer Older
Michael Natterer's avatar
Michael Natterer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* 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 <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#include "core/core-types.h"
#include "tools/tools-types.h"

28
#include "core/gimp.h"
Michael Natterer's avatar
Michael Natterer committed
29
30
31
32
#include "core/gimpbuffer.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
Michael Natterer's avatar
Michael Natterer committed
33
#include "core/gimpedit.h"
Michael Natterer's avatar
Michael Natterer committed
34
35
36
37
38
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"

#include "tools/tool_manager.h"

Michael Natterer's avatar
Michael Natterer committed
39
40
41
#include "widgets/gimpdialogfactory.h"

#include "dialogs.h"
Michael Natterer's avatar
Michael Natterer committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "edit-commands.h"

#include "gdisplay.h"
#include "undo.h"

#include "libgimp/gimpintl.h"


#define return_if_no_display(gdisp) \
        gdisp = gdisplay_active (); \
        if (!gdisp) return


/*  local function prototypes  */

static void   cut_named_buffer_callback  (GtkWidget *widget,
					  gchar     *name,
					  gpointer   data);
static void   copy_named_buffer_callback (GtkWidget *widget,
					  gchar     *name,
					  gpointer   data);


/*  public functions  */

void
edit_undo_cmd_callback (GtkWidget *widget,
			gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

  undo_pop (gdisp->gimage);
}

void
edit_redo_cmd_callback (GtkWidget *widget,
			gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

  undo_redo (gdisp->gimage);
}

void
edit_cut_cmd_callback (GtkWidget *widget,
		       gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

  /*  stop any active tool  */
95
  tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
96

Michael Natterer's avatar
Michael Natterer committed
97
98
  if (gimp_edit_cut (gdisp->gimage,
		     gimp_image_active_drawable (gdisp->gimage)))
Michael Natterer's avatar
Michael Natterer committed
99
100
101
102
103
104
105
106
107
108
109
110
    {
      gdisplays_flush ();
    }
}

void
edit_copy_cmd_callback (GtkWidget *widget,
			gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

Michael Natterer's avatar
Michael Natterer committed
111
112
  gimp_edit_copy (gdisp->gimage,
		  gimp_image_active_drawable (gdisp->gimage));
Michael Natterer's avatar
Michael Natterer committed
113
114
115
116
117
118
119
120
121
}

void
edit_paste_cmd_callback (GtkWidget *widget,
			 gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

122
  if (gdisp->gimage->gimp->global_buffer)
Michael Natterer's avatar
Michael Natterer committed
123
124
    {
      /*  stop any active tool  */
125
      tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
126

Michael Natterer's avatar
Michael Natterer committed
127
128
      if (gimp_edit_paste (gdisp->gimage,
			   gimp_image_active_drawable (gdisp->gimage), 
129
			   gdisp->gimage->gimp->global_buffer,
Michael Natterer's avatar
Michael Natterer committed
130
			   FALSE))
Michael Natterer's avatar
Michael Natterer committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	{
	  gdisplays_update_title (gdisp->gimage);
	  gdisplays_flush ();
	}
    }
}

void
edit_paste_into_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

145
  if (gdisp->gimage->gimp->global_buffer)
Michael Natterer's avatar
Michael Natterer committed
146
147
    {
      /*  stop any active tool  */
148
      tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
149

Michael Natterer's avatar
Michael Natterer committed
150
151
      if (gimp_edit_paste (gdisp->gimage,
			   gimp_image_active_drawable (gdisp->gimage), 
152
			   gdisp->gimage->gimp->global_buffer,
Michael Natterer's avatar
Michael Natterer committed
153
			   TRUE))
Michael Natterer's avatar
Michael Natterer committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
	{
	  gdisplays_update_title (gdisp->gimage);
	  gdisplays_flush ();
	}
    }
}

void
edit_paste_as_new_cmd_callback (GtkWidget *widget,
				gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

168
  if (gdisp->gimage->gimp->global_buffer)
Michael Natterer's avatar
Michael Natterer committed
169
170
    {
      /*  stop any active tool  */
171
      tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
172

173
174
175
      gimp_edit_paste_as_new (gdisp->gimage->gimp,
			      gdisp->gimage,
			      gdisp->gimage->gimp->global_buffer);
Michael Natterer's avatar
Michael Natterer committed
176
177
178
179
180
181
182
183
184
185
186
187
188
    }
}

void
edit_named_cut_cmd_callback (GtkWidget *widget,
			     gpointer   data)
{
  GDisplay  *gdisp;
  GtkWidget *qbox;

  return_if_no_display (gdisp);

  /*  stop any active tool  */
189
  tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
190
191
192
193
194
195

  qbox = gimp_query_string_box (_("Cut Named"),
				gimp_standard_help_func,
				"dialogs/cut_named.html",
				_("Enter a name for this buffer"),
				NULL,
196
				G_OBJECT (gdisp->gimage), "disconnect",
Michael Natterer's avatar
Michael Natterer committed
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
				cut_named_buffer_callback, gdisp->gimage);
  gtk_widget_show (qbox);
}

void
edit_named_copy_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
  GDisplay  *gdisp;
  GtkWidget *qbox;

  return_if_no_display (gdisp);

  qbox = gimp_query_string_box (_("Copy Named"),
				gimp_standard_help_func,
				"dialogs/copy_named.html",
				_("Enter a name for this buffer"),
				NULL,
215
				G_OBJECT (gdisp->gimage), "disconnect",
Michael Natterer's avatar
Michael Natterer committed
216
217
218
219
220
221
222
223
224
225
226
				copy_named_buffer_callback, gdisp->gimage);
  gtk_widget_show (qbox);
}

void
edit_named_paste_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

Michael Natterer's avatar
Michael Natterer committed
227
  gimp_dialog_factory_dialog_raise (global_dock_factory, "gimp:buffer-list");
Michael Natterer's avatar
Michael Natterer committed
228
229
230
231
232
233
234
235
236
}

void
edit_clear_cmd_callback (GtkWidget *widget,
			 gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

Michael Natterer's avatar
Michael Natterer committed
237
  gimp_edit_clear (gdisp->gimage, gimp_image_active_drawable (gdisp->gimage));
Michael Natterer's avatar
Michael Natterer committed
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  gdisplays_flush ();
}

void
edit_fill_cmd_callback (GtkWidget *widget,
			gpointer   data,
			guint      action)
{
  GimpFillType  fill_type;
  GDisplay     *gdisp;

  return_if_no_display (gdisp);

  fill_type = (GimpFillType) action;

Michael Natterer's avatar
Michael Natterer committed
253
254
255
256
  gimp_edit_fill (gdisp->gimage,
		  gimp_image_active_drawable (gdisp->gimage),
		  fill_type);

Michael Natterer's avatar
Michael Natterer committed
257
258
259
260
261
262
263
264
265
266
  gdisplays_flush ();
}

void
edit_stroke_cmd_callback (GtkWidget *widget,
			  gpointer   data)
{
  GDisplay *gdisp;
  return_if_no_display (gdisp);

Michael Natterer's avatar
Michael Natterer committed
267
  gimage_mask_stroke (gdisp->gimage,
268
269
		      gimp_image_active_drawable (gdisp->gimage),
		      gimp_get_current_context (gdisp->gimage->gimp));
Michael Natterer's avatar
Michael Natterer committed
270

Michael Natterer's avatar
Michael Natterer committed
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  gdisplays_flush ();
}


/*  private functions  */

static void
cut_named_buffer_callback (GtkWidget *widget,
			   gchar     *name,
			   gpointer   data)
{
  TileManager *new_tiles;
  GimpImage   *gimage;

  gimage = (GimpImage *) data;
  
Michael Natterer's avatar
Michael Natterer committed
287
288
  new_tiles = gimp_edit_cut (gimage,
			     gimp_image_active_drawable (gimage));
Michael Natterer's avatar
Michael Natterer committed
289
290
291
292
293
294

  if (new_tiles)
    {
      GimpBuffer *buffer;

      buffer = gimp_buffer_new (new_tiles, name);
295
      gimp_container_add (gimage->gimp->named_buffers, GIMP_OBJECT (buffer));
Michael Natterer's avatar
Michael Natterer committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    }

  gdisplays_flush ();
}

static void
copy_named_buffer_callback (GtkWidget *widget,
			    gchar     *name,
			    gpointer   data)
{
  TileManager *new_tiles;
  GimpImage   *gimage;

  gimage = (GimpImage *) data;
Michael Natterer's avatar
Michael Natterer committed
310
311
312

  new_tiles = gimp_edit_copy (gimage,
			      gimp_image_active_drawable (gimage));
Michael Natterer's avatar
Michael Natterer committed
313
314
315
316
317
318

  if (new_tiles)
    {
      GimpBuffer *buffer;

      buffer = gimp_buffer_new (new_tiles, name);
319
      gimp_container_add (gimage->gimp->named_buffers, GIMP_OBJECT (buffer));
Michael Natterer's avatar
Michael Natterer committed
320
321
    }
}