vectors-actions.c 10.2 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 26 27 28 29 30 31 32
/* 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 "actions-types.h"

#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "core/gimplist.h"

#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
33

34
#include "actions.h"
35
#include "vectors-actions.h"
Michael Natterer's avatar
Michael Natterer committed
36
#include "vectors-commands.h"
37 38 39 40 41 42

#include "gimp-intl.h"


static GimpActionEntry vectors_actions[] =
{
43 44
  { "vectors-popup", GIMP_STOCK_PATHS,
    N_("Paths Menu"), NULL, NULL, NULL,
45
    GIMP_HELP_PATH_DIALOG },
46

47 48 49 50 51 52
  { "vectors-path-tool", GIMP_STOCK_TOOL_PATH,
    N_("Path _Tool"), NULL, NULL,
    G_CALLBACK (vectors_vectors_tool_cmd_callback),
    GIMP_HELP_TOOL_VECTORS },

  { "vectors-edit-attributes", GIMP_STOCK_EDIT,
53 54
    N_("_Edit Path Attributes..."), NULL,
    N_("Edit path attributes"),
55 56 57 58
    G_CALLBACK (vectors_edit_attributes_cmd_callback),
    GIMP_HELP_PATH_EDIT },

  { "vectors-new", GTK_STOCK_NEW,
59
    N_("_New Path..."), "",
60
    N_("New path..."),
61 62 63
    G_CALLBACK (vectors_new_cmd_callback),
    GIMP_HELP_PATH_NEW },

64
  { "vectors-new-last-values", GTK_STOCK_NEW,
65
    N_("_New Path"), "",
66 67
    N_("New path with last values"),
    G_CALLBACK (vectors_new_last_vals_cmd_callback),
68 69
    GIMP_HELP_PATH_NEW },

70
  { "vectors-duplicate", GIMP_STOCK_DUPLICATE,
71 72
    N_("D_uplicate Path"), NULL,
    N_("Duplicate path"),
73 74 75 76
    G_CALLBACK (vectors_duplicate_cmd_callback),
    GIMP_HELP_PATH_DUPLICATE },

  { "vectors-delete", GTK_STOCK_DELETE,
77 78
    N_("_Delete Path"), "",
    N_("Delete path"),
79 80 81 82 83 84 85 86 87
    G_CALLBACK (vectors_delete_cmd_callback),
    GIMP_HELP_PATH_DELETE },

  { "vectors-merge-visible", NULL,
    N_("Merge _Visible Paths"), NULL, NULL,
    G_CALLBACK (vectors_merge_visible_cmd_callback),
    GIMP_HELP_PATH_MERGE_VISIBLE },

  { "vectors-raise", GTK_STOCK_GO_UP,
88 89
    N_("_Raise Path"), "",
    N_("Raise path"),
90 91 92 93
    G_CALLBACK (vectors_raise_cmd_callback),
    GIMP_HELP_PATH_RAISE },

  { "vectors-raise-to-top", GTK_STOCK_GOTO_TOP,
94 95
    N_("Raise Path to _Top"), "",
    N_("Raise path to top"),
96 97 98 99
    G_CALLBACK (vectors_raise_to_top_cmd_callback),
    GIMP_HELP_PATH_RAISE_TO_TOP },

  { "vectors-lower", GTK_STOCK_GO_DOWN,
100 101
    N_("_Lower Path"), "",
    N_("Lower path"),
102 103 104 105
    G_CALLBACK (vectors_lower_cmd_callback),
    GIMP_HELP_PATH_LOWER },

  { "vectors-lower-to-bottom", GTK_STOCK_GOTO_BOTTOM,
106 107
    N_("Lower Path to _Bottom"), "",
    N_("Lower path to bottom"),
108 109 110 111
    G_CALLBACK (vectors_lower_to_bottom_cmd_callback),
    GIMP_HELP_PATH_LOWER_TO_BOTTOM },

  { "vectors-stroke", GIMP_STOCK_PATH_STROKE,
112
    N_("Stro_ke Path..."), NULL,
113
    N_("Stroke path..."),
114 115 116
    G_CALLBACK (vectors_stroke_cmd_callback),
    GIMP_HELP_PATH_STROKE },

117 118 119
  { "vectors-stroke-last-values", GIMP_STOCK_PATH_STROKE,
    N_("Stro_ke Path"), NULL,
    N_("Stroke path with last values"),
120 121 122
    G_CALLBACK (vectors_stroke_last_vals_cmd_callback),
    GIMP_HELP_PATH_STROKE },

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
  { "vectors-copy", GTK_STOCK_COPY,
    N_("Co_py Path"), "", NULL,
    G_CALLBACK (vectors_copy_cmd_callback),
    GIMP_HELP_PATH_COPY },

  { "vectors-paste", GTK_STOCK_PASTE,
    N_("Paste Pat_h"), "", NULL,
    G_CALLBACK (vectors_paste_cmd_callback),
    GIMP_HELP_PATH_PASTE },

  { "vectors-import", GTK_STOCK_OPEN,
    N_("I_mport Path..."), "", NULL,
    G_CALLBACK (vectors_import_cmd_callback),
    GIMP_HELP_PATH_IMPORT },

  { "vectors-export", GTK_STOCK_SAVE,
    N_("E_xport Path..."), "", NULL,
    G_CALLBACK (vectors_export_cmd_callback),
    GIMP_HELP_PATH_EXPORT }
};

144 145 146 147 148 149
static GimpToggleActionEntry vectors_toggle_actions[] =
{
  { "vectors-visible", GIMP_STOCK_VISIBLE,
    N_("_Visible"), NULL, NULL,
    G_CALLBACK (vectors_visible_cmd_callback),
    FALSE,
150
    GIMP_HELP_PATH_VISIBLE },
151 152 153 154 155

  { "vectors-linked", GIMP_STOCK_LINKED,
    N_("_Linked"), NULL, NULL,
    G_CALLBACK (vectors_linked_cmd_callback),
    FALSE,
156
    GIMP_HELP_PATH_LINKED }
157 158
};

159 160 161
static GimpEnumActionEntry vectors_to_selection_actions[] =
{
  { "vectors-selection-replace", GIMP_STOCK_SELECTION_REPLACE,
162 163
    N_("Path to Sele_ction"), NULL,
    N_("Path to selection"),
164
    GIMP_CHANNEL_OP_REPLACE, FALSE,
165 166
    GIMP_HELP_PATH_SELECTION_REPLACE },

167 168
  { "vectors-selection-from-vectors", GIMP_STOCK_SELECTION_REPLACE,
    N_("Fr_om Path"), "<shift>V", NULL,
169
    GIMP_CHANNEL_OP_REPLACE, FALSE,
170 171
    GIMP_HELP_PATH_SELECTION_REPLACE },

172
  { "vectors-selection-add", GIMP_STOCK_SELECTION_ADD,
173 174
    N_("_Add to Selection"), NULL,
    N_("Add"),
175
    GIMP_CHANNEL_OP_ADD, FALSE,
176 177 178
    GIMP_HELP_PATH_SELECTION_ADD },

  { "vectors-selection-subtract", GIMP_STOCK_SELECTION_SUBTRACT,
179 180
    N_("_Subtract from Selection"), NULL,
    N_("Subtract"),
181
    GIMP_CHANNEL_OP_SUBTRACT, FALSE,
182 183 184
    GIMP_HELP_PATH_SELECTION_SUBTRACT },

  { "vectors-selection-intersect", GIMP_STOCK_SELECTION_INTERSECT,
185 186
    N_("_Intersect with Selection"), NULL,
    N_("Intersect"),
187
    GIMP_CHANNEL_OP_INTERSECT, FALSE,
188 189 190
    GIMP_HELP_PATH_SELECTION_INTERSECT }
};

191 192 193
static GimpEnumActionEntry vectors_selection_to_vectors_actions[] =
{
  { "vectors-selection-to-vectors", GIMP_STOCK_SELECTION_TO_PATH,
194 195
    N_("Selecti_on to Path"), NULL,
    N_("Selection to path"),
196
    FALSE, FALSE,
197 198
    GIMP_HELP_SELECTION_TO_PATH },

199 200
  { "vectors-selection-to-vectors-short", GIMP_STOCK_SELECTION_TO_PATH,
    N_("To _Path"), NULL, NULL,
201
    FALSE, FALSE,
202 203
    GIMP_HELP_SELECTION_TO_PATH },

204
  { "vectors-selection-to-vectors-advanced", GIMP_STOCK_SELECTION_TO_PATH,
205 206
    N_("Selection to Path (_Advanced)"), NULL,
    N_("Advanced options"),
207
    TRUE, FALSE,
208 209 210
    GIMP_HELP_SELECTION_TO_PATH }
};

211 212

void
213
vectors_actions_setup (GimpActionGroup *group)
214 215 216
{
  gimp_action_group_add_actions (group,
                                 vectors_actions,
217
                                 G_N_ELEMENTS (vectors_actions));
218

219 220 221 222
  gimp_action_group_add_toggle_actions (group,
                                        vectors_toggle_actions,
                                        G_N_ELEMENTS (vectors_toggle_actions));

223 224 225
  gimp_action_group_add_enum_actions (group,
                                      vectors_to_selection_actions,
                                      G_N_ELEMENTS (vectors_to_selection_actions),
226
                                      G_CALLBACK (vectors_to_selection_cmd_callback));
227 228 229 230 231

  gimp_action_group_add_enum_actions (group,
                                      vectors_selection_to_vectors_actions,
                                      G_N_ELEMENTS (vectors_selection_to_vectors_actions),
                                      G_CALLBACK (vectors_selection_to_vectors_cmd_callback));
232 233 234 235 236 237
}

void
vectors_actions_update (GimpActionGroup *group,
                        gpointer         data)
{
238
  GimpImage   *gimage     = action_data_get_image (data);
239
  GimpVectors *vectors    = NULL;
240
  gint         n_vectors  = 0;
241 242
  gboolean     mask_empty = TRUE;
  gboolean     global_buf = FALSE;
243 244
  gboolean     visible    = FALSE;
  gboolean     linked     = FALSE;
245 246 247 248 249
  GList       *next       = NULL;
  GList       *prev       = NULL;

  if (gimage)
    {
250
      n_vectors  = gimp_container_num_children (gimage->vectors);
251 252 253
      mask_empty = gimp_channel_is_empty (gimp_image_get_mask (gimage));
      global_buf = FALSE;

254 255
      vectors = gimp_image_get_active_vectors (gimage);

256 257 258
      if (vectors)
        {
          GimpItem *item = GIMP_ITEM (vectors);
259
          GList    *list;
260 261 262 263

          visible = gimp_item_get_visible (item);
          linked  = gimp_item_get_linked  (item);

264 265 266
          list = g_list_find (GIMP_LIST (gimage->vectors)->list, vectors);

          if (list)
267 268 269 270 271 272 273 274 275
            {
              prev = g_list_previous (list);
              next = g_list_next (list);
            }
        }
    }

#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
276 277
#define SET_ACTIVE(action,condition) \
        gimp_action_group_set_action_active (group, action, (condition) != 0)
278 279 280 281

  SET_SENSITIVE ("vectors-path-tool",       vectors);
  SET_SENSITIVE ("vectors-edit-attributes", vectors);

282 283 284 285 286
  SET_SENSITIVE ("vectors-new",             gimage);
  SET_SENSITIVE ("vectors-new-last-values", gimage);
  SET_SENSITIVE ("vectors-duplicate",       vectors);
  SET_SENSITIVE ("vectors-delete",          vectors);
  SET_SENSITIVE ("vectors-merge-visible",   n_vectors > 1);
287 288 289 290 291 292 293 294 295 296 297

  SET_SENSITIVE ("vectors-raise",           vectors && prev);
  SET_SENSITIVE ("vectors-raise-to-top",    vectors && prev);
  SET_SENSITIVE ("vectors-lower",           vectors && next);
  SET_SENSITIVE ("vectors-lower-to-bottom", vectors && next);

  SET_SENSITIVE ("vectors-copy",   vectors);
  SET_SENSITIVE ("vectors-paste",  global_buf);
  SET_SENSITIVE ("vectors-import", gimage);
  SET_SENSITIVE ("vectors-export", vectors);

298 299 300 301 302 303
  SET_SENSITIVE ("vectors-visible", vectors);
  SET_SENSITIVE ("vectors-linked",  vectors);

  SET_ACTIVE ("vectors-visible", visible);
  SET_ACTIVE ("vectors-linked",  linked);

Michael Natterer's avatar
Michael Natterer committed
304 305 306
  SET_SENSITIVE ("vectors-selection-to-vectors",          gimage && !mask_empty);
  SET_SENSITIVE ("vectors-selection-to-vectors-short",    gimage && !mask_empty);
  SET_SENSITIVE ("vectors-selection-to-vectors-advanced", gimage && !mask_empty);
307
  SET_SENSITIVE ("vectors-stroke",                        vectors);
308
  SET_SENSITIVE ("vectors-stroke-last-values",            vectors);
309

310 311 312 313 314
  SET_SENSITIVE ("vectors-selection-replace",      vectors);
  SET_SENSITIVE ("vectors-selection-from-vectors", vectors);
  SET_SENSITIVE ("vectors-selection-add",          vectors);
  SET_SENSITIVE ("vectors-selection-subtract",     vectors);
  SET_SENSITIVE ("vectors-selection-intersect",    vectors);
315 316

#undef SET_SENSITIVE
317
#undef SET_ACTIVE
318
}