gimp r27009 - in trunk: . plug-ins/script-fu
- From: mitch svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r27009 - in trunk: . plug-ins/script-fu
- Date: Fri, 19 Sep 2008 09:34:36 +0000 (UTC)
Author: mitch
Date: Fri Sep 19 09:34:35 2008
New Revision: 27009
URL: http://svn.gnome.org/viewvc/gimp?rev=27009&view=rev
Log:
2008-09-19 Michael Natterer <mitch gimp org>
* plug-ins/script-fu/script-fu-script.[ch]: add new functions
script_fu_script_get_title() and script_fu_script_reset().
* plug-ins/script-fu/script-fu-scripts.c (script_fu_add_script):
don't set all default values *and* values when parsing the script,
just set the defaults and call script_fu_script_reset() afterwards.
* plug-ins/script-fu/script-fu-interface.c (script_fu_interface):
use the new script_fu_script_get_title().
(script_fu_reset): call script_fu_script_reset() and then update
the UI from the current values, instead of doing slightly
different things for each arg type.
Modified:
trunk/ChangeLog
trunk/plug-ins/script-fu/script-fu-interface.c
trunk/plug-ins/script-fu/script-fu-script.c
trunk/plug-ins/script-fu/script-fu-script.h
trunk/plug-ins/script-fu/script-fu-scripts.c
Modified: trunk/plug-ins/script-fu/script-fu-interface.c
==============================================================================
--- trunk/plug-ins/script-fu/script-fu-interface.c (original)
+++ trunk/plug-ins/script-fu/script-fu-interface.c Fri Sep 19 09:34:35 2008
@@ -180,15 +180,15 @@
GtkWidget *vbox2;
GtkSizeGroup *group;
GSList *list;
- gchar *tmp;
gchar *title;
gint i;
static gboolean gtk_initted = FALSE;
- /* Simply return if there is already an interface. This is an
- ugly workaround for the fact that we can not process two
- scripts at a time. */
+ /* Simply return if there is already an interface. This is an
+ * ugly workaround for the fact that we can not process two
+ * scripts at a time.
+ */
if (sf_interface != NULL)
{
gchar *message =
@@ -219,28 +219,7 @@
sf_interface = g_slice_new0 (SFInterface);
sf_interface->widgets = g_new0 (GtkWidget *, script->n_args);
-
- /* strip mnemonics from the menupath */
- sf_interface->title = gimp_strip_uline (gettext (script->menu_path));
-
- /* if this looks like a full menu path, use only the last part */
- if (sf_interface->title[0] == '<' &&
- (tmp = strrchr (sf_interface->title, '/')) && tmp[1])
- {
- tmp = g_strdup (tmp + 1);
-
- g_free (sf_interface->title);
- sf_interface->title = tmp;
- }
-
- /* cut off ellipsis */
- tmp = (strstr (sf_interface->title, "..."));
- if (! tmp)
- /* U+2026 HORIZONTAL ELLIPSIS */
- tmp = strstr (sf_interface->title, "\342\200\246");
-
- if (tmp && tmp == (sf_interface->title + strlen (sf_interface->title) - 3))
- *tmp = '\0';
+ sf_interface->title = script_fu_script_get_title (script);
title = g_strdup_printf (_("Script-Fu: %s"), sf_interface->title);
@@ -256,7 +235,7 @@
NULL);
g_free (title);
- gtk_dialog_set_alternative_button_order (GTK_DIALOG (sf_interface->dialog),
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
RESPONSE_RESET,
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
@@ -304,7 +283,8 @@
row -= start_arg;
/* we add a colon after the label;
- some languages want an extra space here */
+ * some languages want an extra space here
+ */
label_text = g_strdup_printf (_("%s:"), gettext (arg->label));
switch (arg->type)
@@ -643,8 +623,7 @@
g_slice_free (SFInterface, sf_interface);
sf_interface = NULL;
- /*
- * We do not call gtk_main_quit() earlier to reduce the possibility
+ /* We do not call gtk_main_quit() earlier to reduce the possibility
* that script_fu_script_proc() is called from gimp_extension_process()
* while we are not finished with the current script. This sucks!
*/
@@ -861,12 +840,14 @@
{
gint i;
+ script_fu_script_reset (script, FALSE);
+
for (i = 0; i < script->n_args; i++)
{
- SFArg *arg = &script->args[i];
- GtkWidget *widget = sf_interface->widgets[i];
+ SFArgValue *value = &script->args[i].value;
+ GtkWidget *widget = sf_interface->widgets[i];
- switch (arg->type)
+ switch (script->args[i].type)
{
case SF_IMAGE:
case SF_DRAWABLE:
@@ -878,18 +859,17 @@
case SF_COLOR:
gimp_color_button_set_color (GIMP_COLOR_BUTTON (widget),
- &arg->default_value.sfa_color);
+ &value->sfa_color);
break;
case SF_TOGGLE:
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
- arg->default_value.sfa_toggle);
+ value->sfa_toggle);
break;
case SF_VALUE:
case SF_STRING:
- gtk_entry_set_text (GTK_ENTRY (widget),
- arg->default_value.sfa_value);
+ gtk_entry_set_text (GTK_ENTRY (widget), value->sfa_value);
break;
case SF_TEXT:
@@ -897,63 +877,60 @@
GtkWidget *view;
GtkTextBuffer *buffer;
- g_free (arg->value.sfa_value);
- arg->value.sfa_value = g_strdup (arg->default_value.sfa_value);
-
view = gtk_bin_get_child (GTK_BIN (widget));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- gtk_text_buffer_set_text (buffer, arg->value.sfa_value, -1);
+ gtk_text_buffer_set_text (buffer, value->sfa_value, -1);
}
break;
case SF_ADJUSTMENT:
- gtk_adjustment_set_value (arg->value.sfa_adjustment.adj,
- arg->default_value.sfa_adjustment.value);
+ gtk_adjustment_set_value (value->sfa_adjustment.adj,
+ value->sfa_adjustment.value);
break;
case SF_FILENAME:
case SF_DIRNAME:
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget),
- arg->default_value.sfa_file.filename);
+ value->sfa_file.filename);
break;
case SF_FONT:
gimp_font_select_button_set_font (GIMP_FONT_SELECT_BUTTON (widget),
- arg->default_value.sfa_font);
+ value->sfa_font);
break;
case SF_PALETTE:
gimp_palette_select_button_set_palette (GIMP_PALETTE_SELECT_BUTTON (widget),
- arg->default_value.sfa_palette);
+ value->sfa_palette);
break;
case SF_PATTERN:
gimp_pattern_select_button_set_pattern (GIMP_PATTERN_SELECT_BUTTON (widget),
- arg->default_value.sfa_pattern);
+ value->sfa_pattern);
break;
case SF_GRADIENT:
gimp_gradient_select_button_set_gradient (GIMP_GRADIENT_SELECT_BUTTON (widget),
- arg->default_value.sfa_gradient);
+ value->sfa_gradient);
break;
case SF_BRUSH:
gimp_brush_select_button_set_brush (GIMP_BRUSH_SELECT_BUTTON (widget),
- arg->default_value.sfa_brush.name,
- arg->default_value.sfa_brush.opacity,
- arg->default_value.sfa_brush.spacing,
- arg->default_value.sfa_brush.paint_mode);
+ value->sfa_brush.name,
+ value->sfa_brush.opacity,
+ value->sfa_brush.spacing,
+ value->sfa_brush.paint_mode);
break;
case SF_OPTION:
gtk_combo_box_set_active (GTK_COMBO_BOX (widget),
- arg->default_value.sfa_option.history);
+ value->sfa_option.history);
break;
case SF_ENUM:
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget),
- arg->default_value.sfa_enum.history);
+ value->sfa_enum.history);
break;
}
}
Modified: trunk/plug-ins/script-fu/script-fu-script.c
==============================================================================
--- trunk/plug-ins/script-fu/script-fu-script.c (original)
+++ trunk/plug-ins/script-fu/script-fu-script.c Fri Sep 19 09:34:35 2008
@@ -30,6 +30,8 @@
#include "script-fu-script.h"
#include "script-fu-scripts.h"
+#include "script-fu-intl.h"
+
/*
* Local Functions
@@ -324,6 +326,127 @@
gimp_uninstall_temp_proc (script->name);
}
+gchar *
+script_fu_script_get_title (SFScript *script)
+{
+ gchar *title;
+ gchar *tmp;
+
+ g_return_val_if_fail (script != NULL, NULL);
+
+ /* strip mnemonics from the menupath */
+ title = gimp_strip_uline (gettext (script->menu_path));
+
+ /* if this looks like a full menu path, use only the last part */
+ if (title[0] == '<' && (tmp = strrchr (title, '/')) && tmp[1])
+ {
+ tmp = g_strdup (tmp + 1);
+
+ g_free (title);
+ title = tmp;
+ }
+
+ /* cut off ellipsis */
+ tmp = (strstr (title, "..."));
+ if (! tmp)
+ /* U+2026 HORIZONTAL ELLIPSIS */
+ tmp = strstr (title, "\342\200\246");
+
+ if (tmp && tmp == (title + strlen (title) - 3))
+ *tmp = '\0';
+
+ return title;
+}
+
+void
+script_fu_script_reset (SFScript *script,
+ gboolean reset_ids)
+{
+ gint i;
+
+ g_return_if_fail (script != NULL);
+
+ for (i = 0; i < script->n_args; i++)
+ {
+ SFArgValue *value = &script->args[i].value;
+ SFArgValue *default_value = &script->args[i].default_value;
+
+ switch (script->args[i].type)
+ {
+ case SF_IMAGE:
+ case SF_DRAWABLE:
+ case SF_LAYER:
+ case SF_CHANNEL:
+ case SF_VECTORS:
+ case SF_DISPLAY:
+ if (reset_ids)
+ value->sfa_image = default_value->sfa_image;
+ break;
+
+ case SF_COLOR:
+ value->sfa_color = default_value->sfa_color;
+ break;
+
+ case SF_TOGGLE:
+ value->sfa_toggle = default_value->sfa_toggle;
+ break;
+
+ case SF_VALUE:
+ case SF_STRING:
+ case SF_TEXT:
+ g_free (value->sfa_value);
+ value->sfa_value = g_strdup (default_value->sfa_value);
+ break;
+
+ case SF_ADJUSTMENT:
+ value->sfa_adjustment.value = default_value->sfa_adjustment.value;
+ break;
+
+ case SF_FILENAME:
+ case SF_DIRNAME:
+ g_free (value->sfa_file.filename);
+ value->sfa_file.filename = g_strdup (default_value->sfa_file.filename);
+ break;
+
+ case SF_FONT:
+ g_free (value->sfa_font);
+ value->sfa_font = g_strdup (default_value->sfa_font);
+ break;
+
+ case SF_PALETTE:
+ g_free (value->sfa_palette);
+ value->sfa_palette = g_strdup (default_value->sfa_palette);
+ break;
+
+ case SF_PATTERN:
+ g_free (value->sfa_pattern);
+ value->sfa_pattern = g_strdup (default_value->sfa_pattern);
+ break;
+
+ case SF_GRADIENT:
+ g_free (value->sfa_gradient);
+ value->sfa_gradient = g_strdup (default_value->sfa_gradient);
+ break;
+
+ case SF_BRUSH:
+ g_free (value->sfa_brush.name);
+ value->sfa_brush.name = g_strdup (default_value->sfa_brush.name);
+ value->sfa_brush.opacity = default_value->sfa_brush.opacity;
+ value->sfa_brush.spacing = default_value->sfa_brush.spacing;
+ value->sfa_brush.paint_mode = default_value->sfa_brush.paint_mode;
+ break;
+
+ case SF_OPTION:
+ value->sfa_option.history = default_value->sfa_option.history;
+ break;
+
+ case SF_ENUM:
+ value->sfa_enum.history = default_value->sfa_enum.history;
+ break;
+ }
+ }
+}
+
gint
script_fu_script_collect_standard_args (SFScript *script,
gint n_params,
Modified: trunk/plug-ins/script-fu/script-fu-script.h
==============================================================================
--- trunk/plug-ins/script-fu/script-fu-script.h (original)
+++ trunk/plug-ins/script-fu/script-fu-script.h Fri Sep 19 09:34:35 2008
@@ -34,6 +34,10 @@
GimpRunProc run_proc);
void script_fu_script_uninstall_proc (SFScript *script);
+gchar * script_fu_script_get_title (SFScript *script);
+void script_fu_script_reset (SFScript *script,
+ gboolean reset_ids);
+
gint script_fu_script_collect_standard_args (SFScript *script,
gint n_params,
const GimpParam *params);
Modified: trunk/plug-ins/script-fu/script-fu-scripts.c
==============================================================================
--- trunk/plug-ins/script-fu/script-fu-scripts.c (original)
+++ trunk/plug-ins/script-fu/script-fu-scripts.c Fri Sep 19 09:34:35 2008
@@ -240,7 +240,6 @@
arg->default_value.sfa_image =
sc->vptr->ivalue (sc->vptr->pair_car (a));
- arg->value.sfa_image = arg->default_value.sfa_image;
break;
case SF_COLOR:
@@ -272,8 +271,6 @@
{
return foreign_error (sc, "script-fu-register: color defaults must be a list of 3 integers or a color name", 0);
}
-
- arg->value.sfa_color = arg->default_value.sfa_color;
break;
case SF_TOGGLE:
@@ -282,7 +279,6 @@
arg->default_value.sfa_toggle =
(sc->vptr->ivalue (sc->vptr->pair_car (a))) ? TRUE : FALSE;
- arg->value.sfa_toggle = arg->default_value.sfa_toggle;
break;
case SF_VALUE:
@@ -291,7 +287,6 @@
arg->default_value.sfa_value =
g_strdup (sc->vptr->string_value (sc->vptr->pair_car (a)));
- arg->value.sfa_value = g_strdup (arg->default_value.sfa_value);
break;
case SF_STRING:
@@ -301,7 +296,6 @@
arg->default_value.sfa_value =
g_strdup (sc->vptr->string_value (sc->vptr->pair_car (a)));
- arg->value.sfa_value = g_strdup (arg->default_value.sfa_value);
break;
case SF_ADJUSTMENT:
@@ -338,10 +332,6 @@
adj_list = sc->vptr->pair_cdr (adj_list);
arg->default_value.sfa_adjustment.type =
sc->vptr->ivalue (sc->vptr->pair_car (adj_list));
-
- arg->value.sfa_adjustment.adj = NULL;
- arg->value.sfa_adjustment.value =
- arg->default_value.sfa_adjustment.value;
}
break;
@@ -374,9 +364,6 @@
}
}
#endif
-
- arg->value.sfa_file.filename =
- g_strdup (arg->default_value.sfa_file.filename);
break;
case SF_FONT:
@@ -385,7 +372,6 @@
arg->default_value.sfa_font =
g_strdup (sc->vptr->string_value (sc->vptr->pair_car (a)));
- arg->value.sfa_font = g_strdup (arg->default_value.sfa_font);
break;
case SF_PALETTE:
@@ -394,8 +380,6 @@
arg->default_value.sfa_palette =
g_strdup (sc->vptr->string_value (sc->vptr->pair_car (a)));
- arg->value.sfa_palette =
- g_strdup (arg->default_value.sfa_palette);
break;
case SF_PATTERN:
@@ -404,8 +388,6 @@
arg->default_value.sfa_pattern =
g_strdup (sc->vptr->string_value (sc->vptr->pair_car (a)));
- arg->value.sfa_pattern =
- g_strdup (arg->default_value.sfa_pattern);
break;
case SF_BRUSH:
@@ -418,26 +400,18 @@
brush_list = sc->vptr->pair_car (a);
arg->default_value.sfa_brush.name =
g_strdup (sc->vptr->string_value (sc->vptr->pair_car (brush_list)));
- arg->value.sfa_brush.name =
- g_strdup (arg->default_value.sfa_brush.name);
brush_list = sc->vptr->pair_cdr (brush_list);
arg->default_value.sfa_brush.opacity =
sc->vptr->rvalue (sc->vptr->pair_car (brush_list));
- arg->value.sfa_brush.opacity =
- arg->default_value.sfa_brush.opacity;
brush_list = sc->vptr->pair_cdr (brush_list);
arg->default_value.sfa_brush.spacing =
sc->vptr->ivalue (sc->vptr->pair_car (brush_list));
- arg->value.sfa_brush.spacing =
- arg->default_value.sfa_brush.spacing;
brush_list = sc->vptr->pair_cdr (brush_list);
arg->default_value.sfa_brush.paint_mode =
sc->vptr->ivalue (sc->vptr->pair_car (brush_list));
- arg->value.sfa_brush.paint_mode =
- arg->default_value.sfa_brush.paint_mode;
}
break;
@@ -447,8 +421,6 @@
arg->default_value.sfa_gradient =
g_strdup (sc->vptr->string_value (sc->vptr->pair_car (a)));
- arg->value.sfa_gradient =
- g_strdup (arg->default_value.sfa_gradient);
break;
case SF_OPTION:
@@ -467,9 +439,6 @@
g_strdup (sc->vptr->string_value
(sc->vptr->pair_car (option_list))));
}
-
- arg->default_value.sfa_option.history = 0;
- arg->value.sfa_option.history = 0;
}
break;
@@ -512,8 +481,7 @@
g_enum_get_value_by_nick (g_type_class_peek (enum_type),
sc->vptr->string_value (sc->vptr->pair_car (option_list)));
if (enum_value)
- arg->default_value.sfa_enum.history =
- arg->value.sfa_enum.history = enum_value->value;
+ arg->default_value.sfa_enum.history = enum_value->value;
}
break;
}
@@ -526,6 +494,9 @@
}
}
+ /* fill all values from defaults */
+ script_fu_script_reset (script, TRUE);
+
script_fu_menu_map (script);
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]