2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2000-02-29 18:25:05 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2007-06-06 08:44:52 +00:00
|
|
|
* This is a plug-in for GIMP.
|
2000-02-29 18:25:05 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2000-02-29 18:25:05 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2000-02-29 18:25:05 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2000-02-29 18:25:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2004-11-04 10:06:22 +00:00
|
|
|
|
2000-09-30 20:13:06 +00:00
|
|
|
#include <string.h>
|
2000-02-29 18:25:05 +00:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2002-11-29 13:57:30 +00:00
|
|
|
|
2005-08-15 22:42:34 +00:00
|
|
|
#define PLUG_IN_PROC "plug-in-unit-editor"
|
2008-03-24 15:29:55 +00:00
|
|
|
#define PLUG_IN_BINARY "unit-editor"
|
2011-04-08 20:31:34 +02:00
|
|
|
#define PLUG_IN_ROLE "gimp-unit-editor"
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2002-11-29 13:57:30 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SAVE,
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
NAME,
|
2002-11-29 13:57:30 +00:00
|
|
|
FACTOR,
|
|
|
|
DIGITS,
|
|
|
|
SYMBOL,
|
|
|
|
ABBREVIATION,
|
|
|
|
UNIT,
|
|
|
|
USER_UNIT,
|
|
|
|
NUM_COLUMNS
|
|
|
|
};
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2004-11-04 15:52:06 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const gchar *title;
|
|
|
|
const gchar *help;
|
|
|
|
|
|
|
|
} UnitColumn;
|
2000-05-01 20:22:55 +00:00
|
|
|
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
#define GIMP_UNIT_EDITOR_TYPE (gimp_unit_editor_get_type ())
|
|
|
|
G_DECLARE_FINAL_TYPE (GimpUnitEditor, gimp_unit_editor, GIMP, UNIT_EDITOR, GimpPlugIn)
|
2019-08-14 20:24:02 +02:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
struct _GimpUnitEditor
|
2019-08-14 20:24:02 +02:00
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
GtkApplication *app;
|
2019-08-14 20:24:02 +02:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
GtkWindow *window;
|
|
|
|
GtkWidget *tv;
|
|
|
|
};
|
2019-08-14 20:24:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
static GList * editor_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * editor_create_procedure (GimpPlugIn *plug_in,
|
2022-06-11 14:32:37 +02:00
|
|
|
const gchar *name);
|
2019-08-14 20:24:02 +02:00
|
|
|
|
|
|
|
static GimpValueArray * editor_run (GimpProcedure *procedure,
|
2023-06-15 16:53:54 +02:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-14 20:24:02 +02:00
|
|
|
gpointer run_data);
|
2004-11-04 15:52:06 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
static GimpUnit * new_unit_dialog (GtkWindow *main_window,
|
|
|
|
GimpUnit *template);
|
2022-10-11 21:18:48 +02:00
|
|
|
static void on_app_activate (GApplication *gapp,
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
static gboolean unit_editor_key_press_event (GtkWidget *window,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static void unit_editor_help_clicked (GtkWidget *window);
|
|
|
|
|
|
|
|
static void new_unit_action (GSimpleAction *action,
|
|
|
|
GVariant *param,
|
|
|
|
gpointer user_data);
|
|
|
|
static void duplicate_unit_action (GSimpleAction *action,
|
|
|
|
GVariant *param,
|
|
|
|
gpointer user_data);
|
|
|
|
static void refresh_action (GSimpleAction *action,
|
|
|
|
GVariant *param,
|
|
|
|
gpointer user_data);
|
|
|
|
static void saved_toggled_callback (GtkCellRendererToggle *celltoggle,
|
|
|
|
gchar *path_string,
|
|
|
|
GtkListStore *list_store);
|
|
|
|
static void unit_list_init (GtkTreeView *tv);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2001-08-03 19:52:08 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
G_DEFINE_TYPE (GimpUnitEditor, gimp_unit_editor, GIMP_TYPE_PLUG_IN)
|
2019-08-14 20:24:02 +02:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
GIMP_MAIN (GIMP_UNIT_EDITOR_TYPE)
|
2022-05-26 00:59:36 +02:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-14 20:24:02 +02:00
|
|
|
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2003-02-11 11:49:33 +00:00
|
|
|
static const UnitColumn columns[] =
|
|
|
|
{
|
|
|
|
{ N_("Saved"), N_("A unit definition will only be saved before "
|
|
|
|
"GIMP exits if this column is checked.") },
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
{ N_("Name"), N_("The name to be used to identify this unit in "
|
|
|
|
"the graphical interface") },
|
2003-02-11 11:49:33 +00:00
|
|
|
{ N_("Factor"), N_("How many units make up an inch.") },
|
|
|
|
{ N_("Digits"), N_("This field is a hint for numerical input "
|
|
|
|
"fields. It specifies how many decimal digits "
|
|
|
|
"the input field should provide to get "
|
2003-02-19 18:51:17 +00:00
|
|
|
"approximately the same accuracy as an "
|
2003-02-11 11:49:33 +00:00
|
|
|
"\"inch\" input field with two decimal digits.") },
|
2008-11-18 12:49:01 +00:00
|
|
|
{ N_("Symbol"), N_("The unit's symbol if it has one (e.g. \" "
|
2003-02-11 11:49:33 +00:00
|
|
|
"for inches). The unit's abbreviation is used "
|
|
|
|
"if doesn't have a symbol.") },
|
|
|
|
{ N_("Abbreviation"), N_("The unit's abbreviation (e.g. \"cm\" for "
|
|
|
|
"centimeters).") },
|
2002-11-29 13:57:30 +00:00
|
|
|
};
|
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
static GActionEntry ACTIONS[] =
|
2004-11-04 15:52:06 +00:00
|
|
|
{
|
2022-06-11 14:32:37 +02:00
|
|
|
{ "new-unit", new_unit_action },
|
|
|
|
{ "duplicate-unit", duplicate_unit_action },
|
|
|
|
{ "refresh", refresh_action },
|
2004-11-04 15:52:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-14 20:24:02 +02:00
|
|
|
static void
|
2022-06-11 14:32:37 +02:00
|
|
|
gimp_unit_editor_class_init (GimpUnitEditorClass *klass)
|
2019-08-14 20:24:02 +02:00
|
|
|
{
|
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
2004-11-04 15:52:06 +00:00
|
|
|
|
2019-08-14 20:24:02 +02:00
|
|
|
plug_in_class->query_procedures = editor_query_procedures;
|
|
|
|
plug_in_class->create_procedure = editor_create_procedure;
|
2022-05-26 00:59:36 +02:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2019-08-14 20:24:02 +02:00
|
|
|
}
|
2002-11-29 13:57:30 +00:00
|
|
|
|
2000-02-29 18:25:05 +00:00
|
|
|
static void
|
2022-06-11 14:32:37 +02:00
|
|
|
gimp_unit_editor_init (GimpUnitEditor *self)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-14 20:24:02 +02:00
|
|
|
static GList *
|
|
|
|
editor_query_procedures (GimpPlugIn *plug_in)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2019-08-14 20:24:02 +02:00
|
|
|
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
|
|
|
|
}
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2019-08-14 20:24:02 +02:00
|
|
|
static GimpProcedure *
|
|
|
|
editor_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
2003-03-25 16:38:19 +00:00
|
|
|
|
2019-08-14 20:24:02 +02:00
|
|
|
if (! strcmp (name, PLUG_IN_PROC))
|
|
|
|
{
|
2023-06-16 18:34:53 +02:00
|
|
|
procedure = gimp_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
editor_run, plug_in, NULL);
|
2019-08-14 20:24:02 +02:00
|
|
|
|
2022-07-04 22:50:53 +02:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("U_nits"));
|
2019-08-18 13:45:58 +02:00
|
|
|
gimp_procedure_set_icon_name (procedure, GIMP_ICON_TOOL_MEASURE);
|
2023-07-13 15:34:40 +02:00
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/Edit/[Preferences]");
|
2019-08-14 20:24:02 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2022-07-04 22:50:53 +02:00
|
|
|
_("Create or alter units used in GIMP"),
|
2019-08-14 20:24:02 +02:00
|
|
|
"The GIMP unit editor",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Michael Natterer <mitch@gimp.org>",
|
|
|
|
"Michael Natterer <mitch@gimp.org>",
|
|
|
|
"2000");
|
|
|
|
|
2024-06-12 16:53:12 +00:00
|
|
|
gimp_procedure_add_enum_argument (procedure, "run-mode",
|
|
|
|
"Run mode",
|
|
|
|
"The run mode",
|
|
|
|
GIMP_TYPE_RUN_MODE,
|
|
|
|
GIMP_RUN_INTERACTIVE,
|
|
|
|
G_PARAM_READWRITE);
|
2019-08-14 20:24:02 +02:00
|
|
|
}
|
2001-11-28 01:14:06 +00:00
|
|
|
|
2019-08-14 20:24:02 +02:00
|
|
|
return procedure;
|
|
|
|
}
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
static void
|
|
|
|
on_app_activate (GApplication *gapp, gpointer user_data)
|
|
|
|
{
|
|
|
|
GimpUnitEditor *self = GIMP_UNIT_EDITOR (user_data);
|
|
|
|
GtkWidget *headerbar;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *button_box;
|
|
|
|
GtkWidget *scrolled_win;
|
|
|
|
GtkListStore *list_store;
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
GtkWidget *col_widget;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkCellRenderer *rend;
|
|
|
|
|
|
|
|
list_store = gtk_list_store_new (NUM_COLUMNS,
|
|
|
|
G_TYPE_BOOLEAN, /* SAVE */
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
G_TYPE_STRING, /* NAME */
|
2022-06-11 14:32:37 +02:00
|
|
|
G_TYPE_DOUBLE, /* FACTOR */
|
|
|
|
G_TYPE_INT, /* DIGITS */
|
|
|
|
G_TYPE_STRING, /* SYMBOL */
|
|
|
|
G_TYPE_STRING, /* ABBREVIATION */
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
G_TYPE_OBJECT, /* UNIT */
|
2023-09-14 15:05:32 +02:00
|
|
|
G_TYPE_BOOLEAN); /* USER_UNIT */
|
2022-06-11 14:32:37 +02:00
|
|
|
|
|
|
|
self->tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
|
|
|
|
g_object_unref (list_store);
|
|
|
|
|
|
|
|
self->window = GTK_WINDOW (gtk_application_window_new (self->app));
|
|
|
|
gtk_window_set_title (self->window, _("Unit Editor"));
|
|
|
|
gtk_window_set_role (self->window, PLUG_IN_ROLE);
|
|
|
|
gimp_help_connect (GTK_WIDGET (self->window),
|
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
|
|
|
self->window, NULL);
|
|
|
|
|
|
|
|
/* Actions */
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (self->window),
|
|
|
|
ACTIONS, G_N_ELEMENTS (ACTIONS),
|
|
|
|
self);
|
|
|
|
gtk_application_set_accels_for_action (self->app, "win.new-unit",
|
|
|
|
(const char*[]) { "<Ctrl>N", NULL });
|
|
|
|
gtk_application_set_accels_for_action (self->app, "win.duplicate-unit",
|
|
|
|
(const char*[]) { "<ctrl>D", NULL });
|
|
|
|
gtk_application_set_accels_for_action (self->app, "win.refresh",
|
|
|
|
(const char*[]) { "<ctrl>R", NULL });
|
|
|
|
|
|
|
|
/* Titlebar */
|
|
|
|
headerbar = gtk_header_bar_new ();
|
|
|
|
gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), _("Unit Editor"));
|
|
|
|
gtk_header_bar_set_has_subtitle (GTK_HEADER_BAR (headerbar), FALSE);
|
|
|
|
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), TRUE);
|
|
|
|
|
2022-10-11 21:18:48 +02:00
|
|
|
button = gtk_button_new_with_mnemonic (_("_Refresh"));
|
2022-06-11 14:32:37 +02:00
|
|
|
gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.refresh");
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), button);
|
|
|
|
|
|
|
|
if (gimp_show_help_button ())
|
|
|
|
{
|
2022-10-11 21:18:48 +02:00
|
|
|
button = gtk_button_new_with_mnemonic (_("_Help"));
|
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (unit_editor_help_clicked),
|
|
|
|
self->window);
|
2022-06-11 14:32:37 +02:00
|
|
|
gtk_widget_show (button);
|
2022-10-11 21:18:48 +02:00
|
|
|
gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), button);
|
2022-06-11 14:32:37 +02:00
|
|
|
}
|
|
|
|
|
2022-10-11 21:18:48 +02:00
|
|
|
button = gtk_button_new_with_mnemonic (_("_OK"));
|
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
self->window);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), button);
|
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
gtk_window_set_titlebar (self->window, headerbar);
|
|
|
|
gtk_widget_show (headerbar);
|
|
|
|
|
|
|
|
/* Content */
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
gtk_container_add (GTK_CONTAINER (self->window), vbox);
|
|
|
|
|
|
|
|
button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
|
|
|
gtk_widget_show (button_box);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), button_box);
|
|
|
|
|
|
|
|
button = gtk_button_new_from_icon_name (GIMP_ICON_DOCUMENT_NEW,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.new-unit");
|
|
|
|
gtk_widget_set_tooltip_text (button, _("Create a new unit from scratch"));
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gtk_container_add (GTK_CONTAINER (button_box), button);
|
|
|
|
|
|
|
|
button = gtk_button_new_from_icon_name (GIMP_ICON_OBJECT_DUPLICATE,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.duplicate-unit");
|
|
|
|
gtk_widget_set_tooltip_text (button, _("Create a new unit using the currently selected unit as template"));
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gtk_container_add (GTK_CONTAINER (button_box), button);
|
|
|
|
|
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_widget_set_size_request (scrolled_win, -1, 200);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_ALWAYS);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), scrolled_win);
|
|
|
|
gtk_widget_show (scrolled_win);
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (self->tv, -1, 220);
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_win), self->tv);
|
2022-10-11 21:18:48 +02:00
|
|
|
gtk_widget_set_vexpand (self->tv, TRUE);
|
2022-06-11 14:32:37 +02:00
|
|
|
gtk_widget_show (self->tv);
|
|
|
|
|
|
|
|
rend = gtk_cell_renderer_toggle_new ();
|
|
|
|
col =
|
|
|
|
gtk_tree_view_column_new_with_attributes (gettext (columns[SAVE].title),
|
|
|
|
rend,
|
2023-09-14 15:05:32 +02:00
|
|
|
"active", SAVE,
|
|
|
|
"activatable", USER_UNIT,
|
2022-06-11 14:32:37 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (self->tv), col);
|
|
|
|
|
|
|
|
col_widget = gtk_tree_view_column_get_widget (col);
|
|
|
|
if (col_widget)
|
|
|
|
{
|
|
|
|
button = gtk_widget_get_ancestor (col_widget, GTK_TYPE_BUTTON);
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
gimp_help_set_help_data (button,
|
|
|
|
gettext (columns[SAVE].help), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (rend, "toggled",
|
|
|
|
G_CALLBACK (saved_toggled_callback),
|
|
|
|
list_store);
|
|
|
|
|
|
|
|
for (int i = 0; i < G_N_ELEMENTS (columns); i++)
|
|
|
|
{
|
|
|
|
if (i == SAVE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
col =
|
|
|
|
gtk_tree_view_column_new_with_attributes (gettext (columns[i].title),
|
|
|
|
gtk_cell_renderer_text_new (),
|
2023-09-14 15:05:32 +02:00
|
|
|
"text", i,
|
2022-06-11 14:32:37 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (self->tv), col);
|
|
|
|
|
|
|
|
col_widget = gtk_tree_view_column_get_widget (col);
|
|
|
|
if (col_widget)
|
|
|
|
{
|
|
|
|
button = gtk_widget_get_ancestor (col_widget, GTK_TYPE_BUTTON);
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
gimp_help_set_help_data (button, gettext (columns[i].help), NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unit_list_init (GTK_TREE_VIEW (self->tv));
|
|
|
|
|
2022-10-11 21:18:48 +02:00
|
|
|
g_signal_connect (self->window, "key-press-event",
|
|
|
|
G_CALLBACK (unit_editor_key_press_event),
|
|
|
|
NULL);
|
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
gtk_widget_show (GTK_WIDGET (self->window));
|
|
|
|
}
|
|
|
|
|
2022-10-11 21:18:48 +02:00
|
|
|
static gboolean
|
|
|
|
unit_editor_key_press_event (GtkWidget *window,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (event->state == 0 &&
|
|
|
|
event->keyval == GDK_KEY_Escape)
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (window));
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unit_editor_help_clicked (GtkWidget *window)
|
|
|
|
{
|
|
|
|
gimp_standard_help_func (PLUG_IN_PROC, window);
|
|
|
|
}
|
|
|
|
|
2019-08-14 20:24:02 +02:00
|
|
|
static GimpValueArray *
|
|
|
|
editor_run (GimpProcedure *procedure,
|
2023-06-15 16:53:54 +02:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-14 20:24:02 +02:00
|
|
|
gpointer run_data)
|
|
|
|
{
|
2022-06-11 14:32:37 +02:00
|
|
|
GimpUnitEditor *editor = GIMP_UNIT_EDITOR (run_data);
|
|
|
|
|
2022-10-11 21:18:48 +02:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
|
|
|
|
2023-05-20 21:46:17 +02:00
|
|
|
#if GLIB_CHECK_VERSION(2,74,0)
|
|
|
|
editor->app = gtk_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
|
|
|
|
#else
|
2022-06-11 14:32:37 +02:00
|
|
|
editor->app = gtk_application_new (NULL, G_APPLICATION_FLAGS_NONE);
|
2023-05-20 21:46:17 +02:00
|
|
|
#endif
|
2022-06-11 14:32:37 +02:00
|
|
|
g_signal_connect (editor->app, "activate", G_CALLBACK (on_app_activate), editor);
|
|
|
|
|
|
|
|
g_application_run (G_APPLICATION (editor->app), 0, NULL);
|
|
|
|
|
|
|
|
g_clear_object (&editor->app);
|
2019-08-14 20:24:02 +02:00
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
static GimpUnit *
|
2022-06-11 14:32:37 +02:00
|
|
|
new_unit_dialog (GtkWindow *main_window,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *template)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2014-06-22 23:01:31 +02:00
|
|
|
GtkWidget *dialog;
|
2018-05-11 12:30:03 +02:00
|
|
|
GtkWidget *grid;
|
2014-06-22 23:01:31 +02:00
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *spinbutton;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
GtkWidget *name_entry;
|
2014-06-22 23:01:31 +02:00
|
|
|
GtkAdjustment *factor_adj;
|
|
|
|
GtkAdjustment *digits_adj;
|
|
|
|
GtkWidget *symbol_entry;
|
|
|
|
GtkWidget *abbreviation_entry;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit = NULL;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2011-04-08 20:31:34 +02:00
|
|
|
dialog = gimp_dialog_new (_("Add a New Unit"), PLUG_IN_ROLE,
|
2022-06-11 14:32:37 +02:00
|
|
|
GTK_WIDGET (main_window), GTK_DIALOG_MODAL,
|
2008-10-20 06:04:39 +00:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2001-12-31 01:22:47 +00:00
|
|
|
|
2017-02-12 16:18:24 +01:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Add"), GTK_RESPONSE_OK,
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
NULL);
|
2002-11-29 13:57:30 +00:00
|
|
|
|
2018-05-10 17:04:37 +02:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2022-10-11 21:18:48 +02:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-08 20:40:33 +00:00
|
|
|
|
2018-05-11 12:30:03 +02:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (grid), 12);
|
2009-07-15 18:57:12 +02:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
2018-05-11 12:30:03 +02:00
|
|
|
grid, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (grid);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
entry = name_entry = gtk_entry_new ();
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
if (template != gimp_unit_pixel ())
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2003-11-06 15:27:05 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry),
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
gimp_unit_get_name (template));
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
2018-05-11 12:30:03 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
|
2024-08-10 17:51:16 -04:00
|
|
|
_("_Name:"), 0.0, 0.5,
|
2018-05-11 12:30:03 +02:00
|
|
|
entry, 1);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
gimp_help_set_help_data (entry, gettext (columns[NAME].help), NULL);
|
2000-03-04 00:24:39 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
factor_adj = gtk_adjustment_new ((template != gimp_unit_pixel ()) ?
|
2018-06-24 18:15:16 +02:00
|
|
|
gimp_unit_get_factor (template) : 1.0,
|
|
|
|
GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION,
|
|
|
|
0.01, 0.1, 0.0);
|
2019-03-09 07:25:19 -05:00
|
|
|
spinbutton = gimp_spin_button_new (factor_adj, 0.01, 5);
|
2014-06-22 23:01:31 +02:00
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
|
2018-05-11 12:30:03 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
|
|
|
|
_("_Factor:"), 0.0, 0.5,
|
|
|
|
spinbutton, 1);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2003-02-11 11:49:33 +00:00
|
|
|
gimp_help_set_help_data (spinbutton, gettext (columns[FACTOR].help), NULL);
|
2000-03-04 00:24:39 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
digits_adj = gtk_adjustment_new ((template != gimp_unit_pixel ()) ?
|
2018-06-24 18:15:16 +02:00
|
|
|
gimp_unit_get_digits (template) : 2.0,
|
|
|
|
0, 5, 1, 1, 0);
|
2019-03-09 07:25:19 -05:00
|
|
|
spinbutton = gimp_spin_button_new (digits_adj, 0, 0);
|
2014-06-22 23:01:31 +02:00
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
|
2018-05-11 12:30:03 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 2,
|
|
|
|
_("_Digits:"), 0.0, 0.5,
|
|
|
|
spinbutton, 1);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2003-02-11 11:49:33 +00:00
|
|
|
gimp_help_set_help_data (spinbutton, gettext (columns[DIGITS].help), NULL);
|
2000-03-04 00:24:39 +00:00
|
|
|
|
2000-02-29 18:25:05 +00:00
|
|
|
entry = symbol_entry = gtk_entry_new ();
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
if (template != gimp_unit_pixel ())
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2003-11-06 15:27:05 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry),
|
2001-12-31 01:22:47 +00:00
|
|
|
gimp_unit_get_symbol (template));
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
2018-05-11 12:30:03 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 3,
|
|
|
|
_("_Symbol:"), 0.0, 0.5,
|
|
|
|
entry, 1);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2003-02-11 11:49:33 +00:00
|
|
|
gimp_help_set_help_data (entry, gettext (columns[SYMBOL].help), NULL);
|
2000-03-04 00:24:39 +00:00
|
|
|
|
2000-02-29 18:25:05 +00:00
|
|
|
entry = abbreviation_entry = gtk_entry_new ();
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
if (template != gimp_unit_pixel ())
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2003-11-06 15:27:05 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry),
|
2001-12-31 01:22:47 +00:00
|
|
|
gimp_unit_get_abbreviation (template));
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
2018-05-11 12:30:03 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 4,
|
|
|
|
_("_Abbreviation:"), 0.0, 0.5,
|
|
|
|
entry, 1);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2003-02-11 11:49:33 +00:00
|
|
|
gimp_help_set_help_data (entry, gettext (columns[ABBREVIATION].help), NULL);
|
2000-03-04 00:24:39 +00:00
|
|
|
|
2000-02-29 18:25:05 +00:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
2001-08-29 17:48:28 +00:00
|
|
|
while (TRUE)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
gchar *name;
|
2003-11-06 15:27:05 +00:00
|
|
|
gdouble factor;
|
|
|
|
gint digits;
|
|
|
|
gchar *symbol;
|
|
|
|
gchar *abbreviation;
|
|
|
|
|
2003-11-11 18:11:56 +00:00
|
|
|
if (gimp_dialog_run (GIMP_DIALOG (dialog)) != GTK_RESPONSE_OK)
|
2003-11-06 15:27:05 +00:00
|
|
|
break;
|
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
name = g_strdup (gtk_entry_get_text (GTK_ENTRY (name_entry)));
|
2010-10-25 01:26:00 +02:00
|
|
|
factor = gtk_adjustment_get_value (factor_adj);
|
|
|
|
digits = gtk_adjustment_get_value (digits_adj);
|
2003-11-06 15:27:05 +00:00
|
|
|
symbol = g_strdup (gtk_entry_get_text (GTK_ENTRY (symbol_entry)));
|
|
|
|
abbreviation = g_strdup (gtk_entry_get_text (GTK_ENTRY (abbreviation_entry)));
|
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
name = g_strstrip (name);
|
2003-11-06 15:27:05 +00:00
|
|
|
symbol = g_strstrip (symbol);
|
|
|
|
abbreviation = g_strstrip (abbreviation);
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
|
|
|
|
if (! strlen (name) ||
|
|
|
|
! strlen (symbol) ||
|
|
|
|
! strlen (abbreviation))
|
2003-11-06 15:27:05 +00:00
|
|
|
{
|
2005-11-05 21:56:33 +00:00
|
|
|
GtkWidget *msg = gtk_message_dialog_new (GTK_WINDOW (dialog), 0,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
_("Incomplete input"));
|
|
|
|
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msg),
|
|
|
|
_("Please fill in all text fields."));
|
|
|
|
gtk_dialog_run (GTK_DIALOG (msg));
|
|
|
|
gtk_widget_destroy (msg);
|
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
unit = gimp_unit_new (name, factor, digits, symbol, abbreviation);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
g_free (name);
|
2003-11-06 15:27:05 +00:00
|
|
|
g_free (symbol);
|
|
|
|
g_free (abbreviation);
|
|
|
|
|
|
|
|
break;
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-06-11 14:32:37 +02:00
|
|
|
new_unit_action (GSimpleAction *action,
|
|
|
|
GVariant *param,
|
|
|
|
gpointer user_data)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2022-06-11 14:32:37 +02:00
|
|
|
GimpUnitEditor *self = GIMP_UNIT_EDITOR (user_data);
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit;
|
2002-11-29 13:57:30 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
unit = new_unit_dialog (self->window, gimp_unit_pixel ());
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2024-08-10 23:21:36 +00:00
|
|
|
if (unit != NULL)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2003-02-25 14:48:24 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
2002-11-29 13:57:30 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
unit_list_init (GTK_TREE_VIEW (self->tv));
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->tv));
|
2003-02-25 14:48:24 +00:00
|
|
|
|
2004-11-04 10:06:22 +00:00
|
|
|
if (gtk_tree_model_get_iter_first (model, &iter) &&
|
2003-02-25 14:48:24 +00:00
|
|
|
gtk_tree_model_iter_nth_child (model, &iter,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
NULL, gimp_unit_get_id (unit) - GIMP_UNIT_INCH))
|
2002-11-29 13:57:30 +00:00
|
|
|
{
|
2022-06-11 14:32:37 +02:00
|
|
|
GtkTreeSelection *selection;
|
2002-11-29 13:57:30 +00:00
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->tv));
|
|
|
|
gtk_tree_selection_select_iter (selection, &iter);
|
2002-11-29 13:57:30 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (self->tv));
|
2009-10-10 15:10:14 +02:00
|
|
|
gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));
|
2002-11-29 13:57:30 +00:00
|
|
|
}
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-06-11 14:32:37 +02:00
|
|
|
duplicate_unit_action (GSimpleAction *action,
|
|
|
|
GVariant *param,
|
|
|
|
gpointer user_data)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2022-06-11 14:32:37 +02:00
|
|
|
GimpUnitEditor *self = GIMP_UNIT_EDITOR (user_data);
|
2003-02-25 14:48:24 +00:00
|
|
|
GtkTreeModel *model;
|
2002-11-29 13:57:30 +00:00
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreeIter iter;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->tv));
|
|
|
|
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->tv));
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2002-11-29 13:57:30 +00:00
|
|
|
if (gtk_tree_selection_get_selected (sel, NULL, &iter))
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2003-02-25 14:48:24 +00:00
|
|
|
gtk_tree_model_get (model, &iter,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
UNIT, &unit,
|
2002-11-29 13:57:30 +00:00
|
|
|
-1);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
unit = new_unit_dialog (self->window, unit);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
if (unit != NULL)
|
2002-11-29 13:57:30 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
unit_list_init (GTK_TREE_VIEW (self->tv));
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2004-11-04 10:06:22 +00:00
|
|
|
if (gtk_tree_model_get_iter_first (model, &iter) &&
|
2003-02-25 14:48:24 +00:00
|
|
|
gtk_tree_model_iter_nth_child (model, &iter,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
NULL, gimp_unit_get_id (unit) - GIMP_UNIT_INCH))
|
2002-11-29 13:57:30 +00:00
|
|
|
{
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
|
|
|
gtk_tree_selection_select_iter (sel, &iter);
|
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (self->tv));
|
2009-10-10 15:10:14 +02:00
|
|
|
gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));
|
2002-11-29 13:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 14:32:37 +02:00
|
|
|
static void
|
|
|
|
refresh_action (GSimpleAction *action,
|
|
|
|
GVariant *param,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GimpUnitEditor *self = GIMP_UNIT_EDITOR (user_data);
|
|
|
|
|
|
|
|
unit_list_init (GTK_TREE_VIEW (self->tv));
|
|
|
|
}
|
|
|
|
|
2000-02-29 18:25:05 +00:00
|
|
|
static void
|
2002-11-29 13:57:30 +00:00
|
|
|
saved_toggled_callback (GtkCellRendererToggle *celltoggle,
|
|
|
|
gchar *path_string,
|
|
|
|
GtkListStore *list_store)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2002-11-29 13:57:30 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean saved;
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2002-11-29 13:57:30 +00:00
|
|
|
path = gtk_tree_path_new_from_string (path_string);
|
2005-11-05 21:56:33 +00:00
|
|
|
|
2002-11-29 13:57:30 +00:00
|
|
|
if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, path))
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2002-11-29 13:57:30 +00:00
|
|
|
g_warning ("%s: bad tree path?", G_STRLOC);
|
|
|
|
return;
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
2002-11-29 13:57:30 +00:00
|
|
|
gtk_tree_path_free (path);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2002-11-29 13:57:30 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
|
|
|
|
SAVE, &saved,
|
|
|
|
UNIT, &unit,
|
|
|
|
-1);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
if (! gimp_unit_is_built_in (unit))
|
2002-11-29 13:57:30 +00:00
|
|
|
{
|
|
|
|
gimp_unit_set_deletion_flag (unit, saved);
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (list_store), &iter,
|
|
|
|
SAVE, ! saved,
|
|
|
|
-1);
|
|
|
|
}
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
static void
|
2004-11-04 15:52:06 +00:00
|
|
|
unit_list_init (GtkTreeView *tv)
|
2000-02-29 18:25:05 +00:00
|
|
|
{
|
2004-11-04 15:52:06 +00:00
|
|
|
GtkListStore *list_store;
|
|
|
|
GtkTreeIter iter;
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit = gimp_unit_get_by_id (GIMP_UNIT_INCH);
|
|
|
|
gint i = GIMP_UNIT_INCH + 1;
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2004-11-04 15:52:06 +00:00
|
|
|
list_store = GTK_LIST_STORE (gtk_tree_view_get_model (tv));
|
2003-02-11 11:49:33 +00:00
|
|
|
|
2004-11-04 15:52:06 +00:00
|
|
|
gtk_list_store_clear (list_store);
|
2000-02-29 18:25:05 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
while (unit != NULL)
|
2003-02-11 11:49:33 +00:00
|
|
|
{
|
2004-11-04 15:52:06 +00:00
|
|
|
gtk_list_store_append (list_store, &iter);
|
|
|
|
gtk_list_store_set (list_store, &iter,
|
|
|
|
SAVE, ! gimp_unit_get_deletion_flag (unit),
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
NAME, gimp_unit_get_name (unit),
|
2004-11-04 15:52:06 +00:00
|
|
|
FACTOR, gimp_unit_get_factor (unit),
|
|
|
|
DIGITS, gimp_unit_get_digits (unit),
|
|
|
|
SYMBOL, gimp_unit_get_symbol (unit),
|
|
|
|
ABBREVIATION, gimp_unit_get_abbreviation (unit),
|
|
|
|
UNIT, unit,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
USER_UNIT, ! gimp_unit_is_built_in (unit),
|
2004-11-04 15:52:06 +00:00
|
|
|
-1);
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
|
|
|
|
unit = gimp_unit_get_by_id (i++);
|
2004-11-04 15:52:06 +00:00
|
|
|
}
|
2000-02-29 18:25:05 +00:00
|
|
|
|
2004-11-04 15:52:06 +00:00
|
|
|
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
|
|
|
|
gtk_tree_selection_select_iter (gtk_tree_view_get_selection (tv), &iter);
|
2000-02-29 18:25:05 +00:00
|
|
|
}
|