25
25
#include <string.h>
29
27
#include <libgimp/gimp.h>
30
28
#include <libgimp/gimpui.h>
32
30
#include "libgimp/stdplugins-intl.h"
33
#define PLUG_IN_PROC "plug-in-unit-editor"
34
#define PLUG_IN_BINARY "uniteditor"
35
35
#define RESPONSE_REFRESH 1
119
119
{ "unit-editor-new", GTK_STOCK_NEW,
121
N_("Create a new unit from scratch."),
121
N_("Create a new unit from scratch"),
122
122
G_CALLBACK (new_callback)
125
125
{ "unit-editor-duplicate", GIMP_STOCK_DUPLICATE,
127
N_("Create a new unit with the currently "
128
"selected unit as template."),
127
N_("Create a new unit using the currently selected unit as template"),
129
128
G_CALLBACK (duplicate_callback)
140
static GimpParamDef args[] =
139
static const GimpParamDef args[] =
142
{ GIMP_PDB_INT32, "run_mode", "Interactive" }
141
{ GIMP_PDB_INT32, "run-mode", "Interactive" }
145
gimp_install_procedure ("plug_in_unit_editor",
146
"The GIMP unit editor (runs in interactive mode only)",
147
"The GIMP unit editor (runs in interactive mode only)",
144
gimp_install_procedure (PLUG_IN_PROC,
145
N_("Create or alter units used in GIMP"),
146
"The GIMP unit editor",
148
147
"Michael Natterer <mitch@gimp.org>",
149
148
"Michael Natterer <mitch@gimp.org>",
154
153
G_N_ELEMENTS (args), 0,
157
gimp_plugin_menu_register ("plug_in_unit_editor",
158
"<Toolbox>/Xtns/Extensions");
159
gimp_plugin_icon_register ("plug_in_unit_editor",
160
GIMP_ICON_TYPE_STOCK_ID, GIMP_STOCK_TOOL_MEASURE);
156
gimp_plugin_menu_register (PLUG_IN_PROC, "<Toolbox>/Xtns/Extensions");
157
gimp_plugin_icon_register (PLUG_IN_PROC, GIMP_ICON_TYPE_STOCK_ID,
158
(const guint8 *) GIMP_STOCK_TOOL_MEASURE);
180
178
values[0].type = GIMP_PDB_STATUS;
181
179
values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
183
if (strcmp (name, "plug_in_unit_editor") == 0)
181
if (strcmp (name, PLUG_IN_PROC) == 0)
185
183
values[0].data.d_status = GIMP_PDB_SUCCESS;
208
206
GimpUnit unit = GIMP_UNIT_PIXEL;
210
dialog = gimp_dialog_new (_("New Unit"), "uniteditor",
208
dialog = gimp_dialog_new (_("Add a New Unit"), PLUG_IN_BINARY,
211
209
main_dialog, GTK_DIALOG_MODAL,
212
gimp_standard_help_func, "plug-in-unit-editor",
210
gimp_standard_help_func, PLUG_IN_PROC,
214
212
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
215
GTK_STOCK_OK, GTK_RESPONSE_OK,
213
GTK_STOCK_ADD, GTK_RESPONSE_OK,
217
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
219
222
table = gtk_table_new (7, 2, FALSE);
220
223
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
221
224
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
323
326
identifier = g_strdup (gtk_entry_get_text (GTK_ENTRY (identifier_entry)));
324
factor = GTK_ADJUSTMENT (factor_adj)->value;
325
digits = ROUND (GTK_ADJUSTMENT (digits_adj)->value);
327
factor = gtk_adjustment_get_value (GTK_ADJUSTMENT (factor_adj));
328
digits = gtk_adjustment_get_value (GTK_ADJUSTMENT (digits_adj));
326
329
symbol = g_strdup (gtk_entry_get_text (GTK_ENTRY (symbol_entry)));
327
330
abbreviation = g_strdup (gtk_entry_get_text (GTK_ENTRY (abbreviation_entry)));
328
331
singular = g_strdup (gtk_entry_get_text (GTK_ENTRY (singular_entry)));
334
337
singular = g_strstrip (singular);
335
338
plural = g_strstrip (plural);
337
if (factor < GIMP_MIN_RESOLUTION)
339
g_message (_("Unit factor must not be 0."));
343
340
if (!strlen (identifier) |
344
341
!strlen (symbol) |
345
342
!strlen (abbreviation) |
346
343
!strlen (singular) |
347
344
!strlen (plural))
349
g_message (_("All text fields must contain a value."));
346
GtkWidget *msg = gtk_message_dialog_new (GTK_WINDOW (dialog), 0,
349
_("Incomplete input"));
351
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msg),
352
_("Please fill in all text fields."));
353
gtk_dialog_run (GTK_DIALOG (msg));
354
gtk_widget_destroy (msg);
353
unit = gimp_unit_new (identifier, factor, digits,
354
symbol, abbreviation,
359
unit = gimp_unit_new (identifier,
361
symbol, abbreviation, singular, plural);
357
363
g_free (identifier);
382
388
GtkCellRenderer *rend;
385
gimp_ui_init ("uniteditor", FALSE);
391
gimp_ui_init (PLUG_IN_BINARY, FALSE);
387
393
list_store = gtk_list_store_new (NUM_COLUMNS,
388
394
G_TYPE_BOOLEAN, /* SAVE */
400
406
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
401
407
g_object_unref (list_store);
403
main_dialog = gimp_dialog_new (_("Unit Editor"), "uniteditor",
405
gimp_standard_help_func, "plug-in-unit-editor",
407
GTK_STOCK_REFRESH, RESPONSE_REFRESH,
408
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
412
gtk_dialog_set_default_response (GTK_DIALOG (main_dialog),
415
g_signal_connect (main_dialog, "response",
409
dialog = gimp_dialog_new (_("Unit Editor"), PLUG_IN_BINARY,
411
gimp_standard_help_func, PLUG_IN_PROC,
413
GTK_STOCK_REFRESH, RESPONSE_REFRESH,
414
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
418
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
420
g_signal_connect (dialog, "response",
416
421
G_CALLBACK (unit_editor_response),
418
g_signal_connect (main_dialog, "destroy",
423
g_signal_connect (dialog, "destroy",
419
424
G_CALLBACK (gtk_main_quit),
423
428
ui_manager = gtk_ui_manager_new ();
425
430
group = gtk_action_group_new ("unit-editor");
426
432
gtk_action_group_set_translation_domain (group, NULL);
427
433
gtk_action_group_add_actions (group, actions, G_N_ELEMENTS (actions), tv);
435
gtk_window_add_accel_group (GTK_WINDOW (dialog),
436
gtk_ui_manager_get_accel_group (ui_manager));
437
gtk_accel_group_lock (gtk_ui_manager_get_accel_group (ui_manager));
429
439
gtk_ui_manager_insert_action_group (ui_manager, group, -1);
430
440
g_object_unref (group);
442
452
toolbar = gtk_ui_manager_get_widget (ui_manager, "/unit-editor-toolbar");
443
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (main_dialog)->vbox), toolbar,
453
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), toolbar,
444
454
FALSE, FALSE, 0);
445
455
gtk_widget_show (toolbar);
451
461
GTK_POLICY_NEVER,
452
462
GTK_POLICY_ALWAYS);
453
463
gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 12);
454
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (main_dialog)->vbox),
464
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
456
466
gtk_widget_show (scrolled_win);
492
502
gtk_tree_view_append_column (GTK_TREE_VIEW (tv), col);
494
gimp_help_set_help_data (col->button,
495
gettext (columns[i].help), NULL);
504
gimp_help_set_help_data (col->button, gettext (columns[i].help), NULL);
498
507
unit_list_init (GTK_TREE_VIEW (tv));
500
gtk_widget_show (main_dialog);
509
gtk_widget_show (dialog);
608
617
path = gtk_tree_path_new_from_string (path_string);
609
619
if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, path))
611
621
g_warning ("%s: bad tree path?", G_STRLOC);
649
659
for (unit = GIMP_UNIT_INCH; unit < num_units; unit++)
653
user_unit = (unit >= gimp_unit_get_number_of_built_in_units ());
661
gboolean user_unit = (unit >= gimp_unit_get_number_of_built_in_units ());
655
663
gtk_list_store_append (list_store, &iter);
656
664
gtk_list_store_set (list_store, &iter,