2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-05-20 04:56:37 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpaction.c
|
2019-07-02 09:54:38 +08:00
|
|
|
* Copyright (C) 2004-2019 Michael Natterer <mitch@gimp.org>
|
2004-05-20 04:56:37 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-05-20 04:56:37 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-05-20 04:56:37 +08: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-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2004-05-20 04:56:37 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2004-05-20 04:56:37 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2019-07-04 07:11:48 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
|
|
|
|
2004-05-20 04:56:37 +08:00
|
|
|
#include "gimpaction.h"
|
|
|
|
|
|
|
|
|
2019-07-04 07:11:48 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ACTIVATE,
|
|
|
|
CHANGE_STATE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-17 20:53:07 +08:00
|
|
|
static void gimp_action_set_proxy_tooltip (GimpAction *action,
|
|
|
|
GtkWidget *proxy);
|
2019-05-05 22:17:50 +08:00
|
|
|
static void gimp_action_label_notify (GimpAction *action,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
gpointer data);
|
2008-05-17 20:53:07 +08:00
|
|
|
static void gimp_action_tooltip_notify (GimpAction *action,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
gpointer data);
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-04 07:11:48 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
G_DEFINE_INTERFACE (GimpAction, gimp_action, GTK_TYPE_ACTION)
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-04 07:11:48 +08:00
|
|
|
static guint action_signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
|
2004-05-20 04:56:37 +08:00
|
|
|
static void
|
2019-07-02 09:54:38 +08:00
|
|
|
gimp_action_default_init (GimpActionInterface *iface)
|
2004-05-20 04:56:37 +08:00
|
|
|
{
|
2019-07-04 07:11:48 +08:00
|
|
|
action_signals[ACTIVATE] =
|
|
|
|
g_signal_new ("gimp-activate",
|
|
|
|
G_TYPE_FROM_INTERFACE (iface),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpActionInterface, activate),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VARIANT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_VARIANT);
|
|
|
|
|
|
|
|
action_signals[CHANGE_STATE] =
|
|
|
|
g_signal_new ("gimp-change-state",
|
|
|
|
G_TYPE_FROM_INTERFACE (iface),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpActionInterface, change_state),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VARIANT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_VARIANT);
|
2004-05-20 04:56:37 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
2004-05-20 04:56:37 +08:00
|
|
|
gimp_action_init (GimpAction *action)
|
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
g_return_if_fail (GIMP_IS_ACTION (action));
|
2008-05-17 20:53:07 +08:00
|
|
|
|
2019-05-05 22:17:50 +08:00
|
|
|
g_signal_connect (action, "notify::label",
|
|
|
|
G_CALLBACK (gimp_action_label_notify),
|
|
|
|
NULL);
|
2008-05-17 20:53:07 +08:00
|
|
|
g_signal_connect (action, "notify::tooltip",
|
|
|
|
G_CALLBACK (gimp_action_tooltip_notify),
|
|
|
|
NULL);
|
2004-05-20 04:56:37 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2019-07-04 07:11:48 +08:00
|
|
|
void
|
|
|
|
gimp_action_emit_activate (GimpAction *action,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_ACTION (action));
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
g_variant_ref_sink (value);
|
|
|
|
|
|
|
|
g_signal_emit (action, action_signals[ACTIVATE], 0, value);
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
g_variant_unref (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_action_emit_change_state (GimpAction *action,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_ACTION (action));
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
g_variant_ref_sink (value);
|
|
|
|
|
|
|
|
g_signal_emit (action, action_signals[CHANGE_STATE], 0, value);
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
g_variant_unref (value);
|
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_proxy (GimpAction *action,
|
|
|
|
GtkWidget *proxy)
|
2004-05-20 04:56:37 +08:00
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
g_return_if_fail (GIMP_IS_ACTION (action));
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (proxy));
|
|
|
|
|
|
|
|
gimp_action_set_proxy_tooltip (action, proxy);
|
|
|
|
}
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_action_get_name (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_name ((GtkAction *) action);
|
2004-05-20 04:56:37 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_label (GimpAction *action,
|
|
|
|
const gchar *label)
|
2004-05-20 04:56:37 +08:00
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
gtk_action_set_label ((GtkAction *) action, label);
|
|
|
|
}
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_action_get_label (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_label ((GtkAction *) action);
|
|
|
|
}
|
2008-07-23 14:47:23 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_tooltip (GimpAction *action,
|
|
|
|
const gchar *tooltip)
|
|
|
|
{
|
|
|
|
gtk_action_set_tooltip ((GtkAction *) action, tooltip);
|
|
|
|
}
|
2008-07-23 14:47:23 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_action_get_tooltip (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_tooltip ((GtkAction *) action);
|
|
|
|
}
|
2008-07-23 14:47:23 +08:00
|
|
|
|
2019-07-05 18:32:36 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_icon_name (GimpAction *action,
|
|
|
|
const gchar *icon_name)
|
|
|
|
{
|
|
|
|
gtk_action_set_icon_name ((GtkAction *) action, icon_name);
|
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_action_get_icon_name (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_icon_name ((GtkAction *) action);
|
|
|
|
}
|
2008-07-23 14:47:23 +08:00
|
|
|
|
2019-07-05 18:32:36 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_gicon (GimpAction *action,
|
|
|
|
GIcon *icon)
|
|
|
|
{
|
|
|
|
gtk_action_set_gicon ((GtkAction *) action, icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
GIcon *
|
|
|
|
gimp_action_get_gicon (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_gicon ((GtkAction *) action);
|
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_help_id (GimpAction *action,
|
|
|
|
const gchar *help_id)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_ACTION (action));
|
2008-05-11 17:26:17 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
|
|
|
|
g_strdup (help_id),
|
|
|
|
(GDestroyNotify) g_free);
|
2004-05-20 04:56:37 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_action_get_help_id (GimpAction *action)
|
2004-05-20 04:56:37 +08:00
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_ACTION (action), NULL);
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
return g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID);
|
|
|
|
}
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_visible (GimpAction *action,
|
|
|
|
gboolean visible)
|
|
|
|
{
|
|
|
|
gtk_action_set_visible ((GtkAction *) action, visible);
|
2004-05-20 04:56:37 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
gboolean
|
|
|
|
gimp_action_get_visible (GimpAction *action)
|
2018-07-06 12:00:16 +08:00
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
return gtk_action_get_visible ((GtkAction *) action);
|
|
|
|
}
|
2018-07-06 12:00:16 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
gboolean
|
|
|
|
gimp_action_is_visible (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_is_visible ((GtkAction *) action);
|
2018-07-06 12:00:16 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_sensitive (GimpAction *action,
|
|
|
|
gboolean sensitive)
|
2004-05-20 04:56:37 +08:00
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
gtk_action_set_sensitive ((GtkAction *) action, sensitive);
|
|
|
|
}
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
gboolean
|
|
|
|
gimp_action_get_sensitive (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_sensitive ((GtkAction *) action);
|
2004-05-20 04:56:37 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
gboolean
|
|
|
|
gimp_action_is_sensitive (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_is_sensitive ((GtkAction *) action);
|
|
|
|
}
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
GClosure *
|
|
|
|
gimp_action_get_accel_closure (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_accel_closure ((GtkAction *) action);
|
|
|
|
}
|
2004-05-20 04:56:37 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_accel_path (GimpAction *action,
|
|
|
|
const gchar *accel_path)
|
2004-05-20 04:56:37 +08:00
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
gtk_action_set_accel_path ((GtkAction *) action, accel_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_action_get_accel_path (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_accel_path ((GtkAction *) action);
|
|
|
|
}
|
2008-08-22 16:57:11 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_set_accel_group (GimpAction *action,
|
|
|
|
GtkAccelGroup *accel_group)
|
|
|
|
{
|
|
|
|
gtk_action_set_accel_group ((GtkAction *) action, accel_group);
|
|
|
|
}
|
2008-08-22 16:57:11 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_connect_accelerator (GimpAction *action)
|
|
|
|
{
|
|
|
|
gtk_action_connect_accelerator ((GtkAction *) action);
|
|
|
|
}
|
|
|
|
|
2019-07-05 18:32:36 +08:00
|
|
|
GSList *
|
|
|
|
gimp_action_get_proxies (GimpAction *action)
|
|
|
|
{
|
|
|
|
return gtk_action_get_proxies ((GtkAction *) action);
|
|
|
|
}
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
void
|
|
|
|
gimp_action_activate (GimpAction *action)
|
|
|
|
{
|
|
|
|
gtk_action_activate ((GtkAction *) action);
|
2004-05-20 04:56:37 +08:00
|
|
|
}
|
|
|
|
|
2004-07-21 02:50:20 +08:00
|
|
|
gint
|
|
|
|
gimp_action_name_compare (GimpAction *action1,
|
|
|
|
GimpAction *action2)
|
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
return strcmp (gimp_action_get_name (action1),
|
|
|
|
gimp_action_get_name (action2));
|
2004-07-21 02:50:20 +08:00
|
|
|
}
|
|
|
|
|
2014-04-20 21:57:57 +08:00
|
|
|
gboolean
|
|
|
|
gimp_action_is_gui_blacklisted (const gchar *action_name)
|
|
|
|
{
|
|
|
|
static const gchar *suffixes[] =
|
|
|
|
{
|
|
|
|
"-menu",
|
|
|
|
"-popup"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *prefixes[] =
|
|
|
|
{
|
|
|
|
"<",
|
|
|
|
"tools-color-average-radius-",
|
2014-05-04 04:55:05 +08:00
|
|
|
"tools-paintbrush-size-",
|
|
|
|
"tools-paintbrush-aspect-ratio-",
|
2016-03-23 06:51:32 +08:00
|
|
|
"tools-paintbrush-angle-",
|
|
|
|
"tools-paintbrush-spacing-",
|
|
|
|
"tools-paintbrush-hardness-",
|
|
|
|
"tools-paintbrush-force-",
|
2014-04-20 21:57:57 +08:00
|
|
|
"tools-ink-blob-size-",
|
|
|
|
"tools-ink-blob-aspect-",
|
|
|
|
"tools-ink-blob-angle-",
|
2015-12-23 02:39:11 +08:00
|
|
|
"tools-mypaint-brush-radius-",
|
2016-03-23 06:51:32 +08:00
|
|
|
"tools-mypaint-brush-hardness-",
|
2014-04-20 21:57:57 +08:00
|
|
|
"tools-foreground-select-brush-size-",
|
2014-05-04 04:56:46 +08:00
|
|
|
"tools-transform-preview-opacity-",
|
2018-02-17 17:21:06 +08:00
|
|
|
"tools-warp-effect-size-",
|
2016-03-23 06:51:32 +08:00
|
|
|
"tools-warp-effect-hardness-"
|
2014-04-20 21:57:57 +08:00
|
|
|
};
|
|
|
|
|
2018-01-14 22:42:29 +08:00
|
|
|
static const gchar *actions[] =
|
|
|
|
{
|
|
|
|
"tools-brightness-contrast",
|
|
|
|
"tools-curves",
|
|
|
|
"tools-levels",
|
2019-06-06 16:47:46 +08:00
|
|
|
"tools-offset",
|
2018-01-14 22:42:29 +08:00
|
|
|
"tools-threshold"
|
|
|
|
};
|
|
|
|
|
2014-04-20 21:57:57 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (! (action_name && *action_name))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (suffixes); i++)
|
|
|
|
{
|
|
|
|
if (g_str_has_suffix (action_name, suffixes[i]))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (prefixes); i++)
|
|
|
|
{
|
|
|
|
if (g_str_has_prefix (action_name, prefixes[i]))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-01-14 22:42:29 +08:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (actions); i++)
|
|
|
|
{
|
|
|
|
if (! strcmp (action_name, actions[i]))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-20 21:57:57 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-05-20 04:56:37 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2008-05-17 20:53:07 +08:00
|
|
|
static void
|
|
|
|
gimp_action_set_proxy_tooltip (GimpAction *action,
|
|
|
|
GtkWidget *proxy)
|
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
const gchar *tooltip = gimp_action_get_tooltip (action);
|
2008-05-17 20:53:07 +08:00
|
|
|
|
|
|
|
if (tooltip)
|
2009-05-25 04:29:18 +08:00
|
|
|
gimp_help_set_help_data (proxy, tooltip,
|
|
|
|
g_object_get_qdata (G_OBJECT (proxy),
|
|
|
|
GIMP_HELP_ID));
|
2008-05-17 20:53:07 +08:00
|
|
|
}
|
|
|
|
|
2019-05-05 22:17:50 +08:00
|
|
|
static void
|
|
|
|
gimp_action_label_notify (GimpAction *action,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
|
2019-07-05 18:32:36 +08:00
|
|
|
for (list = gimp_action_get_proxies (action);
|
2019-05-05 22:17:50 +08:00
|
|
|
list;
|
|
|
|
list = g_slist_next (list))
|
|
|
|
{
|
|
|
|
if (GTK_IS_MENU_ITEM (list->data))
|
|
|
|
{
|
|
|
|
GtkWidget *child = gtk_bin_get_child (GTK_BIN (list->data));
|
|
|
|
|
|
|
|
if (GTK_IS_BOX (child))
|
|
|
|
{
|
|
|
|
child = g_object_get_data (G_OBJECT (list->data),
|
|
|
|
"gimp-menu-item-label");
|
|
|
|
|
|
|
|
if (GTK_IS_LABEL (child))
|
|
|
|
gtk_label_set_text (GTK_LABEL (child),
|
2019-07-05 18:32:36 +08:00
|
|
|
gimp_action_get_label (action));
|
2019-05-05 22:17:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-17 20:53:07 +08:00
|
|
|
static void
|
|
|
|
gimp_action_tooltip_notify (GimpAction *action,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
|
2019-07-05 18:32:36 +08:00
|
|
|
for (list = gimp_action_get_proxies (action);
|
2008-05-17 20:53:07 +08:00
|
|
|
list;
|
|
|
|
list = g_slist_next (list))
|
|
|
|
{
|
|
|
|
gimp_action_set_proxy_tooltip (action, list->data);
|
|
|
|
}
|
|
|
|
}
|