channels-commands.c 18.8 KB
Newer Older
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
/* 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 "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"

26
#include "gui-types.h"
27

Michael Natterer's avatar
Michael Natterer committed
28
#include "core/gimp.h"
29 30 31 32 33
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimplist.h"

34
#include "display/gimpdisplay-foreach.h"
35

36
#include "widgets/gimpcolorpanel.h"
37
#include "widgets/gimpitemfactory.h"
Michael Natterer's avatar
Michael Natterer committed
38
#include "widgets/gimpwidgets-utils.h"
39 40 41

#include "channels-commands.h"

42 43
#include "undo.h"

44 45 46
#include "libgimp/gimpintl.h"


47 48
/*  public functions  */

49 50 51 52 53 54 55 56 57 58 59
void
channels_new_channel_cmd_callback (GtkWidget *widget,
				   gpointer   data)
{
  GimpImage *gimage;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

60
  channels_new_channel_query (gimage, NULL);
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
}

void
channels_raise_channel_cmd_callback (GtkWidget *widget,
				     gpointer   data)
{
  GimpImage *gimage;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if (gimp_image_get_active_channel (gimage))
    {
      gimp_image_raise_channel (gimage, gimp_image_get_active_channel (gimage));
      gdisplays_flush ();
    }
}

void
channels_lower_channel_cmd_callback (GtkWidget *widget,
				     gpointer   data)
{
  GimpImage *gimage;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if (gimp_image_get_active_channel (gimage))
    {
      gimp_image_lower_channel (gimage, gimp_image_get_active_channel (gimage));
      gdisplays_flush ();
    }
}

void
channels_duplicate_channel_cmd_callback (GtkWidget *widget,
					 gpointer   data)
{
  GimpImage   *gimage;
  GimpChannel *active_channel;
  GimpChannel *new_channel;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if ((active_channel = gimp_image_get_active_channel (gimage)))
    {
114 115 116
      new_channel = gimp_channel_copy (active_channel,
                                       G_TYPE_FROM_INSTANCE (active_channel),
                                       TRUE);
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
      gimp_image_add_channel (gimage, new_channel, -1);
      gdisplays_flush ();
    }
}

void
channels_delete_channel_cmd_callback (GtkWidget *widget,
				      gpointer   data)
{
  GimpImage   *gimage;
  GimpChannel *active_channel;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if ((active_channel = gimp_image_get_active_channel (gimage)))
    {
      gimp_image_remove_channel (gimage, active_channel);
      gdisplays_flush ();
    }
}

void
channels_channel_to_sel_cmd_callback (GtkWidget *widget,
				      gpointer   data)
{
  GimpImage   *gimage;
  GimpChannel *active_channel;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if ((active_channel = gimp_image_get_active_channel (gimage)))
    {
155
      gimp_image_mask_load (gimage, active_channel);
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
      gdisplays_flush ();
    }
}

void
channels_add_channel_to_sel_cmd_callback (GtkWidget *widget,
					  gpointer   data)
{
  GimpImage   *gimage;
  GimpChannel *active_channel;
  GimpChannel *new_channel;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if ((active_channel = gimp_image_get_active_channel (gimage)))
    {
175 176 177
      new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
                                       G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
                                       TRUE);
178 179 180 181
      gimp_channel_combine_mask (new_channel,
				 active_channel,
				 CHANNEL_OP_ADD, 
				 0, 0);  /* off x/y */
182
      gimp_image_mask_load (gimage, new_channel);
183
      g_object_unref (G_OBJECT (new_channel));
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
      gdisplays_flush ();
    }
}

void
channels_sub_channel_from_sel_cmd_callback (GtkWidget *widget,
					    gpointer   data)
{
  GimpImage   *gimage;
  GimpChannel *active_channel;
  GimpChannel *new_channel;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if ((active_channel = gimp_image_get_active_channel (gimage)))
    {
203 204 205
       new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
                                        G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
                                        TRUE);
206 207 208 209
       gimp_channel_combine_mask (new_channel,
				  active_channel,
				  CHANNEL_OP_SUB, 
				  0, 0);  /* off x/y */
210
      gimp_image_mask_load (gimage, new_channel);
211
      g_object_unref (G_OBJECT (new_channel));
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
      gdisplays_flush ();
    }
}

void
channels_intersect_channel_with_sel_cmd_callback (GtkWidget *widget,
						  gpointer   data)
{
  GimpImage   *gimage;
  GimpChannel *active_channel;
  GimpChannel *new_channel;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if ((active_channel = gimp_image_get_active_channel (gimage)))
    {
231 232 233
      new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
                                       G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
                                       TRUE);
234 235 236 237
      gimp_channel_combine_mask (new_channel,
				 active_channel,
				 CHANNEL_OP_INTERSECT, 
				 0, 0);  /* off x/y */
238
      gimp_image_mask_load (gimage, new_channel);
239
      g_object_unref (G_OBJECT (new_channel));
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
      gdisplays_flush ();
    }
}

void
channels_edit_channel_attributes_cmd_callback (GtkWidget *widget,
					       gpointer   data)
{
  GimpImage   *gimage;
  GimpChannel *active_channel;

  gimage = (GimpImage *) gimp_widget_get_callback_context (widget);

  if (! gimage)
    return;

  if ((active_channel = gimp_image_get_active_channel (gimage)))
    {
      channels_edit_channel_query (active_channel);
    }
}


static void
channels_opacity_update (GtkAdjustment *adjustment,
			 gpointer       data)
{
  GimpRGB  color;

  gimp_color_button_get_color (GIMP_COLOR_BUTTON (data), &color);
  gimp_rgb_set_alpha (&color, adjustment->value / 100.0);
  gimp_color_button_set_color (GIMP_COLOR_BUTTON (data), &color);
}

static void
channels_color_changed (GimpColorButton *button,
			gpointer         data)
{
  GtkAdjustment *adj = GTK_ADJUSTMENT (data);
  GimpRGB        color;

  gimp_color_button_get_color (button, &color);
  gtk_adjustment_set_value (adj, color.a * 100.0);
}

/**********************************/
/*  The new channel query dialog  */
/**********************************/

typedef struct _NewChannelOptions NewChannelOptions;

struct _NewChannelOptions
{
  GtkWidget  *query_box;
  GtkWidget  *name_entry;
  GtkWidget  *color_panel;

  GimpImage  *gimage;
};

static gchar   *channel_name  = NULL;
static GimpRGB  channel_color = { 0.0, 0.0, 0.0, 0.5 };


static void
new_channel_query_ok_callback (GtkWidget *widget,
			       gpointer   data)
{
  NewChannelOptions *options;
  GimpChannel       *new_channel;
  GimpImage         *gimage;

  options = (NewChannelOptions *) data;

  if (channel_name)
    g_free (channel_name);
  channel_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));

  if ((gimage = options->gimage))
    {
      gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
				   &channel_color);
      new_channel = gimp_channel_new (gimage, gimage->width, gimage->height,
				      channel_name,
				      &channel_color);

Michael Natterer's avatar
Michael Natterer committed
326
      gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
Michael Natterer's avatar
Michael Natterer committed
327
				  gimp_get_user_context (gimage->gimp),
Michael Natterer's avatar
Michael Natterer committed
328
				  TRANSPARENT_FILL);
329 330 331 332 333 334 335 336 337

      gimp_image_add_channel (gimage, new_channel, -1);
      gdisplays_flush ();
    }

  gtk_widget_destroy (options->query_box);
}

void
338 339
channels_new_channel_query (GimpImage   *gimage,
                            GimpChannel *template)
340 341 342 343 344 345 346 347 348
{
  NewChannelOptions *options;
  GtkWidget         *hbox;
  GtkWidget         *vbox;
  GtkWidget         *table;
  GtkWidget         *label;
  GtkWidget         *opacity_scale;
  GtkObject         *opacity_scale_data;

349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
  g_return_if_fail (! template || GIMP_IS_CHANNEL (template));

  if (template)
    {
      GimpChannel *new_channel;
      gint         width, height;
      gint         off_x, off_y;

      width  = gimp_drawable_width  (GIMP_DRAWABLE (template));
      height = gimp_drawable_height (GIMP_DRAWABLE (template));
      gimp_drawable_offsets (GIMP_DRAWABLE (template), &off_x, &off_y);

      undo_push_group_start (gimage, EDIT_PASTE_UNDO);

      new_channel = gimp_channel_new (gimage,
                                      width, height,
                                      _("Empty Channel Copy"),
                                      &template->color);

      gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
                                  gimp_get_user_context (gimage->gimp),
                                  TRANSPARENT_FILL);
      gimp_channel_translate (new_channel, off_x, off_y);
      gimp_image_add_channel (gimage, new_channel, -1);

      undo_push_group_end (gimage);

      gdisplays_flush ();
      return;
    }

381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
  /*  the new options structure  */
  options = g_new (NewChannelOptions, 1);
  options->gimage      = gimage;
  options->color_panel = gimp_color_panel_new (_("New Channel Color"),
					       &channel_color,
					       GIMP_COLOR_AREA_LARGE_CHECKS,
					       48, 64);
  
  /*  The dialog  */
  options->query_box =
    gimp_dialog_new (_("New Channel Options"), "new_channel_options",
		     gimp_standard_help_func,
		     "dialogs/channels/new_channel.html",
		     GTK_WIN_POS_MOUSE,
		     FALSE, TRUE, FALSE,

397
		     GTK_STOCK_CANCEL, gtk_widget_destroy,
398 399
		     NULL, 1, NULL, FALSE, TRUE,

400 401 402
		     GTK_STOCK_OK, new_channel_query_ok_callback,
		     options, NULL, NULL, TRUE, FALSE,

403 404
		     NULL);

405 406 407
  g_object_weak_ref (G_OBJECT (options->query_box),
		     (GWeakNotify) g_free,
		     options);
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432

  /*  The main hbox  */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
		     hbox);

  /*  The vbox  */
  vbox = gtk_vbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);

  /*  The table  */
  table = gtk_table_new (2, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);

  /*  The name entry hbox, label and entry  */
  label = gtk_label_new (_("Channel name:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  options->name_entry = gtk_entry_new ();
433
  gtk_widget_set_size_request (options->name_entry, 150, -1);
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
  gtk_table_attach_defaults (GTK_TABLE (table), options->name_entry,
			     1, 2, 0, 1);
  gtk_entry_set_text (GTK_ENTRY (options->name_entry),
		      (channel_name ? channel_name : _("New Channel")));
  gtk_widget_show (options->name_entry);

  /*  The opacity scale  */
  label = gtk_label_new (_("Fill Opacity:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  opacity_scale_data =
    gtk_adjustment_new (channel_color.a * 100.0, 0.0, 100.0, 1.0, 1.0, 0.0);
  opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
  gtk_table_attach_defaults (GTK_TABLE (table), opacity_scale, 1, 2, 1, 2);
  gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
  gtk_widget_show (opacity_scale);

454 455 456 457
  g_signal_connect (G_OBJECT (opacity_scale_data), "value_changed",
		    G_CALLBACK (channels_opacity_update),
		    options->color_panel);

458 459 460 461 462
  /*  The color panel  */
  gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
		      TRUE, TRUE, 0);
  gtk_widget_show (options->color_panel);

463 464 465 466
  g_signal_connect (G_OBJECT (options->color_panel), "color_changed",
		    G_CALLBACK (channels_color_changed),
		    opacity_scale_data);

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
  gtk_widget_show (table);
  gtk_widget_show (vbox);
  gtk_widget_show (hbox);
  gtk_widget_show (options->query_box);
}

/****************************************/
/*  The edit channel attributes dialog  */
/****************************************/

typedef struct _EditChannelOptions EditChannelOptions;

struct _EditChannelOptions
{
  GtkWidget     *query_box;
  GtkWidget     *name_entry;
  GtkWidget     *color_panel;

  GimpChannel   *channel;
  GimpImage     *gimage;
};

static void
edit_channel_query_ok_callback (GtkWidget *widget,
				gpointer   data)
{
  EditChannelOptions *options;
  GimpChannel        *channel;
  GimpRGB             color;

  options = (EditChannelOptions *) data;
  channel = options->channel;

  if (options->gimage)
    {
      /*  Set the new channel name  */
      gimp_object_set_name (GIMP_OBJECT (channel),
			    gtk_entry_get_text (GTK_ENTRY (options->name_entry)));

      gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
				   &color);

      if (gimp_rgba_distance (&color, &channel->color) > 0.0001)
	{
Michael Natterer's avatar
Michael Natterer committed
511
	  gimp_channel_set_color (channel, &color);
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550

	  gdisplays_flush ();
	}
    }

  gtk_widget_destroy (options->query_box);
}

void
channels_edit_channel_query (GimpChannel *channel)
{
  EditChannelOptions *options;
  GtkWidget          *hbox;
  GtkWidget          *vbox;
  GtkWidget          *table;
  GtkWidget          *label;
  GtkWidget          *opacity_scale;
  GtkObject          *opacity_scale_data;

  options = g_new0 (EditChannelOptions, 1);

  options->channel = channel;
  options->gimage  = gimp_drawable_gimage (GIMP_DRAWABLE (channel));

  channel_color = channel->color;

  options->color_panel = gimp_color_panel_new (_("Edit Channel Color"),
					       &channel_color,
					       GIMP_COLOR_AREA_LARGE_CHECKS,
					       48, 64);

  /*  The dialog  */
  options->query_box =
    gimp_dialog_new (_("Edit Channel Attributes"), "edit_channel_attributes",
		     gimp_standard_help_func,
		     "dialogs/channels/edit_channel_attributes.html",
		     GTK_WIN_POS_MOUSE,
		     FALSE, TRUE, FALSE,

551
		     GTK_STOCK_CANCEL, gtk_widget_destroy,
552 553
		     NULL, 1, NULL, FALSE, TRUE,

554 555 556
		     GTK_STOCK_OK, edit_channel_query_ok_callback,
		     options, NULL, NULL, TRUE, FALSE,

557 558
		     NULL);

559 560 561
  g_object_weak_ref (G_OBJECT (options->query_box),
		     (GWeakNotify) g_free,
		     options);
562

563 564 565 566
  g_signal_connect_object (G_OBJECT (channel), "removed",
			   G_CALLBACK (gtk_widget_destroy),
			   G_OBJECT (options->query_box),
			   G_CONNECT_SWAPPED);
567

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
  /*  The main hbox  */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
		     hbox);

  /*  The vbox  */
  vbox = gtk_vbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);

  /*  The table  */
  table = gtk_table_new (2, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);

  /*  The name entry  */
  label = gtk_label_new (_("Channel name:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
		    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  options->name_entry = gtk_entry_new ();
592
  gtk_widget_set_size_request (options->name_entry, 150, -1);
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
  gtk_table_attach_defaults (GTK_TABLE (table), options->name_entry,
			     1, 2, 0, 1);
  gtk_entry_set_text (GTK_ENTRY (options->name_entry),
		      gimp_object_get_name (GIMP_OBJECT (channel)));
  gtk_widget_show (options->name_entry);

  /*  The opacity scale  */
  label = gtk_label_new (_("Fill Opacity:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
		    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  opacity_scale_data =
    gtk_adjustment_new (channel_color.a * 100.0, 0.0, 100.0, 1.0, 1.0, 0.0);
  opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
  gtk_table_attach_defaults (GTK_TABLE (table), opacity_scale, 1, 2, 1, 2);
  gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
  gtk_widget_show (opacity_scale);

613 614 615 616
  g_signal_connect (G_OBJECT (opacity_scale_data), "value_changed",
		    G_CALLBACK (channels_opacity_update),
		    options->color_panel);

617 618 619 620 621
  /*  The color panel  */
  gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
		      TRUE, TRUE, 0);
  gtk_widget_show (options->color_panel);

622 623 624 625
  g_signal_connect (G_OBJECT (options->color_panel), "color_changed",
		    G_CALLBACK (channels_color_changed),
		    opacity_scale_data);		      

626 627 628 629 630
  gtk_widget_show (table);
  gtk_widget_show (vbox);
  gtk_widget_show (hbox);
  gtk_widget_show (options->query_box);
}
631 632

void
633 634
channels_menu_update (GtkItemFactory *factory,
                      gpointer        data)
635
{
636
  GimpImage   *gimage;
637 638 639 640 641 642
  GimpChannel *channel;
  gboolean     fs;
  GList       *list;
  GList       *next = NULL;
  GList       *prev = NULL;

643
  gimage = GIMP_IMAGE (data);
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661

  channel = gimp_image_get_active_channel (gimage);

  fs = (gimp_image_floating_sel (gimage) != NULL);

  for (list = GIMP_LIST (gimage->channels)->list;
       list;
       list = g_list_next (list))
    {
      if (channel == (GimpChannel *) list->data)
	{
	  prev = g_list_previous (list);
	  next = g_list_next (list);
	  break;
	}
    }

#define SET_SENSITIVE(menu,condition) \
662 663 664 665 666 667 668 669 670 671 672 673
        gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)

  SET_SENSITIVE ("/New Channel...",             !fs);
  SET_SENSITIVE ("/Raise Channel",              !fs && channel && prev);
  SET_SENSITIVE ("/Lower Channel",              !fs && channel && next);
  SET_SENSITIVE ("/Duplicate Channel",          !fs && channel);
  SET_SENSITIVE ("/Channel to Selection",       !fs && channel);
  SET_SENSITIVE ("/Add to Selection",           !fs && channel);
  SET_SENSITIVE ("/Subtract from Selection",    !fs && channel);
  SET_SENSITIVE ("/Intersect with Selection",   !fs && channel);
  SET_SENSITIVE ("/Delete Channel",             !fs && channel);
  SET_SENSITIVE ("/Edit Channel Attributes...", !fs && channel);
674 675 676

#undef SET_OPS_SENSITIVE
}