app: move more of GimpActionImpl code into GimpAction.
This commit is contained in:
parent
453f5670b3
commit
c8845c95ec
9 changed files with 380 additions and 294 deletions
|
|
@ -366,7 +366,7 @@ file_actions_last_opened_update (GimpContainer *container,
|
|||
GimpImagefile *imagefile = (GimpImagefile *)
|
||||
gimp_container_get_child_by_index (container, i);
|
||||
|
||||
if (GIMP_ACTION_IMPL (action)->viewable != (GimpViewable *) imagefile)
|
||||
if (gimp_action_get_viewable (action) != (GimpViewable *) imagefile)
|
||||
{
|
||||
GFile *file;
|
||||
const gchar *name;
|
||||
|
|
|
|||
|
|
@ -103,16 +103,15 @@ file_menu_open_recent_query_tooltip (GtkWidget *widget,
|
|||
GtkTooltip *tooltip,
|
||||
GimpAction *action)
|
||||
{
|
||||
GimpActionImpl *impl = GIMP_ACTION_IMPL (action);
|
||||
gchar *text;
|
||||
gchar *text;
|
||||
|
||||
text = gtk_widget_get_tooltip_text (widget);
|
||||
gtk_tooltip_set_text (tooltip, text);
|
||||
g_free (text);
|
||||
|
||||
gtk_tooltip_set_icon (tooltip,
|
||||
gimp_viewable_get_pixbuf (impl->viewable,
|
||||
impl->context,
|
||||
gimp_viewable_get_pixbuf (gimp_action_get_viewable (action),
|
||||
gimp_action_get_context (action),
|
||||
GIMP_THUMB_SIZE_NORMAL,
|
||||
GIMP_THUMB_SIZE_NORMAL));
|
||||
|
||||
|
|
|
|||
|
|
@ -408,17 +408,19 @@ windows_menu_display_query_tooltip (GtkWidget *widget,
|
|||
GtkTooltip *tooltip,
|
||||
GimpAction *action)
|
||||
{
|
||||
GimpActionImpl *impl = GIMP_ACTION_IMPL (action);
|
||||
GimpImage *image = GIMP_IMAGE (impl->viewable);
|
||||
gchar *text;
|
||||
gdouble xres;
|
||||
gdouble yres;
|
||||
gint width;
|
||||
gint height;
|
||||
GimpViewable *viewable = gimp_action_get_viewable (action);
|
||||
GimpImage *image;
|
||||
gchar *text;
|
||||
gdouble xres;
|
||||
gdouble yres;
|
||||
gint width;
|
||||
gint height;
|
||||
|
||||
if (! image)
|
||||
if (! viewable)
|
||||
return FALSE;
|
||||
|
||||
image = GIMP_IMAGE (viewable);
|
||||
|
||||
text = gtk_widget_get_tooltip_text (widget);
|
||||
gtk_tooltip_set_text (tooltip, text);
|
||||
g_free (text);
|
||||
|
|
@ -432,8 +434,8 @@ windows_menu_display_query_tooltip (GtkWidget *widget,
|
|||
&width, &height, NULL);
|
||||
|
||||
gtk_tooltip_set_icon (tooltip,
|
||||
gimp_viewable_get_pixbuf (impl->viewable,
|
||||
impl->context,
|
||||
gimp_viewable_get_pixbuf (viewable,
|
||||
gimp_action_get_context (action),
|
||||
width, height));
|
||||
|
||||
return TRUE;
|
||||
|
|
|
|||
|
|
@ -23,11 +23,22 @@
|
|||
#include <gegl.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "widgets-types.h"
|
||||
|
||||
#include "config/gimpcoreconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpimagefile.h" /* eek */
|
||||
|
||||
#include "gimpaction.h"
|
||||
#include "gimpview.h"
|
||||
#include "gimpviewrenderer.h"
|
||||
#include "gimpwidgets-utils.h"
|
||||
|
||||
|
||||
enum
|
||||
|
|
@ -43,7 +54,14 @@ typedef struct _GimpActionPrivate GimpActionPrivate;
|
|||
|
||||
struct _GimpActionPrivate
|
||||
{
|
||||
gchar *disable_reason;
|
||||
GimpContext *context;
|
||||
|
||||
gchar *disable_reason;
|
||||
|
||||
GimpRGB *color;
|
||||
GimpViewable *viewable;
|
||||
PangoEllipsizeMode ellipsize;
|
||||
gint max_width_chars;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -51,8 +69,6 @@ static GimpActionPrivate *
|
|||
gimp_action_get_private (GimpAction *action);
|
||||
static void gimp_action_private_finalize (GimpActionPrivate *priv);
|
||||
|
||||
static void gimp_action_set_proxy_tooltip (GimpAction *action,
|
||||
GtkWidget *proxy);
|
||||
static void gimp_action_label_notify (GimpAction *action,
|
||||
const GParamSpec *pspec,
|
||||
gpointer data);
|
||||
|
|
@ -69,6 +85,8 @@ static guint action_signals[LAST_SIGNAL];
|
|||
static void
|
||||
gimp_action_default_init (GimpActionInterface *iface)
|
||||
{
|
||||
GimpRGB black;
|
||||
|
||||
action_signals[ACTIVATE] =
|
||||
g_signal_new ("gimp-activate",
|
||||
G_TYPE_FROM_INTERFACE (iface),
|
||||
|
|
@ -86,13 +104,49 @@ gimp_action_default_init (GimpActionInterface *iface)
|
|||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_VARIANT);
|
||||
|
||||
g_object_interface_install_property (iface,
|
||||
g_param_spec_object ("context",
|
||||
NULL, NULL,
|
||||
GIMP_TYPE_CONTEXT,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
||||
g_object_interface_install_property (iface,
|
||||
gimp_param_spec_rgb ("color",
|
||||
NULL, NULL,
|
||||
TRUE, &black,
|
||||
GIMP_PARAM_READWRITE));
|
||||
g_object_interface_install_property (iface,
|
||||
g_param_spec_object ("viewable",
|
||||
NULL, NULL,
|
||||
GIMP_TYPE_VIEWABLE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_interface_install_property (iface,
|
||||
g_param_spec_enum ("ellipsize",
|
||||
NULL, NULL,
|
||||
PANGO_TYPE_ELLIPSIZE_MODE,
|
||||
PANGO_ELLIPSIZE_NONE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
g_object_interface_install_property (iface,
|
||||
g_param_spec_int ("max-width-chars",
|
||||
NULL, NULL,
|
||||
-1, G_MAXINT, -1,
|
||||
GIMP_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_init (GimpAction *action)
|
||||
{
|
||||
GimpActionPrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ACTION (action));
|
||||
|
||||
priv = GET_PRIVATE (action);
|
||||
|
||||
priv->ellipsize = PANGO_ELLIPSIZE_NONE;
|
||||
priv->max_width_chars = -1;
|
||||
|
||||
g_signal_connect (action, "notify::label",
|
||||
G_CALLBACK (gimp_action_label_notify),
|
||||
NULL);
|
||||
|
|
@ -135,15 +189,39 @@ gimp_action_emit_change_state (GimpAction *action,
|
|||
}
|
||||
|
||||
void
|
||||
gimp_action_set_proxy (GimpAction *action,
|
||||
GtkWidget *proxy)
|
||||
gimp_action_set_proxy_tooltip (GimpAction *action,
|
||||
GtkWidget *proxy)
|
||||
{
|
||||
const gchar *tooltip;
|
||||
const gchar *reason = NULL;
|
||||
gchar *escaped_reason = NULL;
|
||||
gchar *markup;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ACTION (action));
|
||||
g_return_if_fail (GTK_IS_WIDGET (proxy));
|
||||
|
||||
gimp_action_set_proxy_tooltip (action, proxy);
|
||||
tooltip = gimp_action_get_tooltip (action);
|
||||
|
||||
gimp_action_get_sensitive (action, &reason);
|
||||
if (reason)
|
||||
escaped_reason = g_markup_escape_text (reason, -1);
|
||||
|
||||
markup = g_strdup_printf ("%s%s" /* Action tooltip */
|
||||
"<i><span weight='light'>%s</span></i>", /* Inactive reason */
|
||||
tooltip,
|
||||
escaped_reason && tooltip ? "\n" : "",
|
||||
escaped_reason ? escaped_reason : "");
|
||||
|
||||
if (tooltip || escaped_reason)
|
||||
gimp_help_set_help_data_with_markup (proxy, markup,
|
||||
g_object_get_qdata (G_OBJECT (proxy),
|
||||
GIMP_HELP_ID));
|
||||
|
||||
g_free (escaped_reason);
|
||||
g_free (markup);
|
||||
}
|
||||
|
||||
|
||||
const gchar *
|
||||
gimp_action_get_name (GimpAction *action)
|
||||
{
|
||||
|
|
@ -414,8 +492,233 @@ gimp_action_is_gui_blacklisted (const gchar *action_name)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
GimpViewable *
|
||||
gimp_action_get_viewable (GimpAction *action)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_ACTION (action), NULL);
|
||||
|
||||
/* private functions */
|
||||
return GET_PRIVATE (action)->viewable;
|
||||
}
|
||||
|
||||
GimpContext *
|
||||
gimp_action_get_context (GimpAction *action)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_ACTION (action), NULL);
|
||||
|
||||
return GET_PRIVATE (action)->context;
|
||||
}
|
||||
|
||||
|
||||
/* Protected functions. */
|
||||
|
||||
/**
|
||||
* gimp_action_install_properties:
|
||||
* @klass: the class structure for a type deriving from #GObject
|
||||
*
|
||||
* Installs the necessary properties for a class implementing
|
||||
* #GimpAction. Please call this function in the *_class_init()
|
||||
* function of the child class.
|
||||
**/
|
||||
void
|
||||
gimp_action_install_properties (GObjectClass *klass)
|
||||
{
|
||||
g_object_class_override_property (klass, GIMP_ACTION_PROP_CONTEXT, "context");
|
||||
g_object_class_override_property (klass, GIMP_ACTION_PROP_COLOR, "color");
|
||||
g_object_class_override_property (klass, GIMP_ACTION_PROP_VIEWABLE, "viewable");
|
||||
|
||||
g_object_class_override_property (klass, GIMP_ACTION_PROP_ELLIPSIZE, "ellipsize");
|
||||
g_object_class_override_property (klass, GIMP_ACTION_PROP_MAX_WIDTH_CHARS, "max-width-chars");
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpActionPrivate *priv;
|
||||
|
||||
priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case GIMP_ACTION_PROP_CONTEXT:
|
||||
g_value_set_object (value, priv->context);
|
||||
break;
|
||||
case GIMP_ACTION_PROP_COLOR:
|
||||
g_value_set_boxed (value, priv->color);
|
||||
break;
|
||||
case GIMP_ACTION_PROP_VIEWABLE:
|
||||
g_value_set_object (value, priv->viewable);
|
||||
break;
|
||||
case GIMP_ACTION_PROP_ELLIPSIZE:
|
||||
g_value_set_enum (value, priv->ellipsize);
|
||||
break;
|
||||
case GIMP_ACTION_PROP_MAX_WIDTH_CHARS:
|
||||
g_value_set_int (value, priv->max_width_chars);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpActionPrivate *priv;
|
||||
gboolean set_proxy = FALSE;
|
||||
|
||||
priv = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case GIMP_ACTION_PROP_CONTEXT:
|
||||
g_set_object (&priv->context, g_value_get_object (value));
|
||||
break;
|
||||
case GIMP_ACTION_PROP_COLOR:
|
||||
g_clear_pointer (&priv->color, g_free);
|
||||
priv->color = g_value_dup_boxed (value);
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
case GIMP_ACTION_PROP_VIEWABLE:
|
||||
g_set_object (&priv->viewable, g_value_get_object (value));
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
case GIMP_ACTION_PROP_ELLIPSIZE:
|
||||
priv->ellipsize = g_value_get_enum (value);
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
case GIMP_ACTION_PROP_MAX_WIDTH_CHARS:
|
||||
priv->max_width_chars = g_value_get_int (value);
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
|
||||
if (set_proxy)
|
||||
{
|
||||
GSList *list;
|
||||
|
||||
for (list = gimp_action_get_proxies (GIMP_ACTION (object));
|
||||
list;
|
||||
list = g_slist_next (list))
|
||||
{
|
||||
gimp_action_set_proxy (GIMP_ACTION (object), list->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_set_proxy (GimpAction *action,
|
||||
GtkWidget *proxy)
|
||||
{
|
||||
GimpActionPrivate *priv = GET_PRIVATE (action);
|
||||
|
||||
if (! GTK_IS_MENU_ITEM (proxy))
|
||||
return;
|
||||
|
||||
if (priv->color)
|
||||
{
|
||||
GtkWidget *area;
|
||||
|
||||
area = gimp_menu_item_get_image (GTK_MENU_ITEM (proxy));
|
||||
|
||||
if (GIMP_IS_COLOR_AREA (area))
|
||||
{
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (area), priv->color);
|
||||
}
|
||||
else
|
||||
{
|
||||
gint width, height;
|
||||
|
||||
area = gimp_color_area_new (priv->color,
|
||||
GIMP_COLOR_AREA_SMALL_CHECKS, 0);
|
||||
gimp_color_area_set_draw_border (GIMP_COLOR_AREA (area), TRUE);
|
||||
|
||||
if (priv->context)
|
||||
gimp_color_area_set_color_config (GIMP_COLOR_AREA (area),
|
||||
priv->context->gimp->config->color_management);
|
||||
|
||||
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
|
||||
gtk_widget_set_size_request (area, width, height);
|
||||
gimp_menu_item_set_image (GTK_MENU_ITEM (proxy), area);
|
||||
gtk_widget_show (area);
|
||||
}
|
||||
}
|
||||
else if (priv->viewable)
|
||||
{
|
||||
GtkWidget *view;
|
||||
|
||||
view = gimp_menu_item_get_image (GTK_MENU_ITEM (proxy));
|
||||
|
||||
if (GIMP_IS_VIEW (view) &&
|
||||
g_type_is_a (G_TYPE_FROM_INSTANCE (priv->viewable),
|
||||
GIMP_VIEW (view)->renderer->viewable_type))
|
||||
{
|
||||
gimp_view_set_viewable (GIMP_VIEW (view), priv->viewable);
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkIconSize size;
|
||||
gint width, height;
|
||||
gint border_width;
|
||||
|
||||
if (GIMP_IS_IMAGEFILE (priv->viewable))
|
||||
{
|
||||
size = GTK_ICON_SIZE_LARGE_TOOLBAR;
|
||||
border_width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = GTK_ICON_SIZE_MENU;
|
||||
border_width = 1;
|
||||
}
|
||||
|
||||
gtk_icon_size_lookup (size, &width, &height);
|
||||
view = gimp_view_new_full (priv->context, priv->viewable,
|
||||
width, height, border_width,
|
||||
FALSE, FALSE, FALSE);
|
||||
gimp_menu_item_set_image (GTK_MENU_ITEM (proxy), view);
|
||||
gtk_widget_show (view);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkWidget *image;
|
||||
|
||||
image = gimp_menu_item_get_image (GTK_MENU_ITEM (proxy));
|
||||
|
||||
if (GIMP_IS_VIEW (image) || GIMP_IS_COLOR_AREA (image))
|
||||
{
|
||||
gimp_menu_item_set_image (GTK_MENU_ITEM (proxy), NULL);
|
||||
g_object_notify (G_OBJECT (action), "icon-name");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
GtkWidget *child = gtk_bin_get_child (GTK_BIN (proxy));
|
||||
|
||||
if (GTK_IS_BOX (child))
|
||||
child = g_object_get_data (G_OBJECT (proxy), "gimp-menu-item-label");
|
||||
|
||||
if (GTK_IS_LABEL (child))
|
||||
{
|
||||
GtkLabel *label = GTK_LABEL (child);
|
||||
|
||||
gtk_label_set_ellipsize (label, priv->ellipsize);
|
||||
gtk_label_set_max_width_chars (label, priv->max_width_chars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Private functions */
|
||||
|
||||
static GimpActionPrivate *
|
||||
gimp_action_get_private (GimpAction *action)
|
||||
|
|
@ -445,40 +748,13 @@ static void
|
|||
gimp_action_private_finalize (GimpActionPrivate *priv)
|
||||
{
|
||||
g_clear_pointer (&priv->disable_reason, g_free);
|
||||
g_clear_object (&priv->context);
|
||||
g_clear_pointer (&priv->color, g_free);
|
||||
g_clear_object (&priv->viewable);
|
||||
|
||||
g_slice_free (GimpActionPrivate, priv);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_action_set_proxy_tooltip (GimpAction *action,
|
||||
GtkWidget *proxy)
|
||||
{
|
||||
const gchar *tooltip;
|
||||
const gchar *reason = NULL;
|
||||
gchar *escaped_reason = NULL;
|
||||
gchar *markup;
|
||||
|
||||
tooltip = gimp_action_get_tooltip (action);
|
||||
|
||||
gimp_action_get_sensitive (action, &reason);
|
||||
if (reason)
|
||||
escaped_reason = g_markup_escape_text (reason, -1);
|
||||
|
||||
markup = g_strdup_printf ("%s%s" /* Action tooltip */
|
||||
"<i><span weight='light'>%s</span></i>", /* Inactive reason */
|
||||
tooltip,
|
||||
escaped_reason && tooltip ? "\n" : "",
|
||||
escaped_reason ? escaped_reason : "");
|
||||
|
||||
if (tooltip || escaped_reason)
|
||||
gimp_help_set_help_data_with_markup (proxy, markup,
|
||||
g_object_get_qdata (G_OBJECT (proxy),
|
||||
GIMP_HELP_ID));
|
||||
|
||||
g_free (escaped_reason);
|
||||
g_free (markup);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_action_label_notify (GimpAction *action,
|
||||
const GParamSpec *pspec,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,18 @@
|
|||
#define GIMP_ACTION_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), GIMP_TYPE_ACTION, GimpActionInterface))
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
GIMP_ACTION_PROP_0,
|
||||
GIMP_ACTION_PROP_CONTEXT,
|
||||
GIMP_ACTION_PROP_COLOR,
|
||||
GIMP_ACTION_PROP_VIEWABLE,
|
||||
GIMP_ACTION_PROP_ELLIPSIZE,
|
||||
GIMP_ACTION_PROP_MAX_WIDTH_CHARS,
|
||||
|
||||
GIMP_ACTION_PROP_LAST = GIMP_ACTION_PROP_MAX_WIDTH_CHARS,
|
||||
};
|
||||
|
||||
typedef struct _GimpActionInterface GimpActionInterface;
|
||||
|
||||
struct _GimpActionInterface
|
||||
|
|
@ -51,7 +63,7 @@ void gimp_action_emit_activate (GimpAction *action,
|
|||
void gimp_action_emit_change_state (GimpAction *action,
|
||||
GVariant *value);
|
||||
|
||||
void gimp_action_set_proxy (GimpAction *action,
|
||||
void gimp_action_set_proxy_tooltip (GimpAction *action,
|
||||
GtkWidget *proxy);
|
||||
|
||||
const gchar * gimp_action_get_name (GimpAction *action);
|
||||
|
|
@ -108,5 +120,24 @@ gint gimp_action_name_compare (GimpAction *action1,
|
|||
|
||||
gboolean gimp_action_is_gui_blacklisted (const gchar *action_name);
|
||||
|
||||
GimpContext * gimp_action_get_context (GimpAction *action);
|
||||
GimpViewable * gimp_action_get_viewable (GimpAction *action);
|
||||
|
||||
|
||||
/* Protected functions. */
|
||||
|
||||
void gimp_action_install_properties (GObjectClass *klass);
|
||||
void gimp_action_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
void gimp_action_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
void gimp_action_set_proxy (GimpAction *action,
|
||||
GtkWidget *proxy);
|
||||
|
||||
|
||||
#endif /* __GIMP_ACTION_H__ */
|
||||
|
|
|
|||
|
|
@ -24,35 +24,18 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "widgets-types.h"
|
||||
|
||||
#include "config/gimpcoreconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpimagefile.h" /* eek */
|
||||
|
||||
#include "gimpaction.h"
|
||||
#include "gimpactionimpl.h"
|
||||
#include "gimpaction-history.h"
|
||||
#include "gimpview.h"
|
||||
#include "gimpviewrenderer.h"
|
||||
#include "gimpwidgets-utils.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONTEXT,
|
||||
PROP_COLOR,
|
||||
PROP_VIEWABLE,
|
||||
PROP_ELLIPSIZE,
|
||||
PROP_MAX_WIDTH_CHARS,
|
||||
|
||||
PROP_ENABLED,
|
||||
PROP_ENABLED = GIMP_ACTION_PROP_LAST + 1,
|
||||
PROP_PARAMETER_TYPE,
|
||||
PROP_STATE_TYPE,
|
||||
PROP_STATE
|
||||
|
|
@ -105,9 +88,6 @@ static void gimp_action_impl_activate (GtkAction *action);
|
|||
static void gimp_action_impl_connect_proxy (GtkAction *action,
|
||||
GtkWidget *proxy);
|
||||
|
||||
static void gimp_action_impl_set_proxy (GimpActionImpl *impl,
|
||||
GtkWidget *proxy);
|
||||
|
||||
static void gimp_action_impl_set_state (GimpAction *gimp_action,
|
||||
GVariant *value);
|
||||
|
||||
|
|
@ -126,7 +106,6 @@ gimp_action_impl_class_init (GimpActionImplClass *klass)
|
|||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
|
||||
GimpRGB black;
|
||||
|
||||
gimp_action_impl_signals[CHANGE_STATE] =
|
||||
g_signal_new ("change-state",
|
||||
|
|
@ -144,39 +123,7 @@ gimp_action_impl_class_init (GimpActionImplClass *klass)
|
|||
action_class->activate = gimp_action_impl_activate;
|
||||
action_class->connect_proxy = gimp_action_impl_connect_proxy;
|
||||
|
||||
gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
||||
|
||||
g_object_class_install_property (object_class, PROP_CONTEXT,
|
||||
g_param_spec_object ("context",
|
||||
NULL, NULL,
|
||||
GIMP_TYPE_CONTEXT,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_COLOR,
|
||||
gimp_param_spec_rgb ("color",
|
||||
NULL, NULL,
|
||||
TRUE, &black,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_VIEWABLE,
|
||||
g_param_spec_object ("viewable",
|
||||
NULL, NULL,
|
||||
GIMP_TYPE_VIEWABLE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_ELLIPSIZE,
|
||||
g_param_spec_enum ("ellipsize",
|
||||
NULL, NULL,
|
||||
PANGO_TYPE_ELLIPSIZE_MODE,
|
||||
PANGO_ELLIPSIZE_NONE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_MAX_WIDTH_CHARS,
|
||||
g_param_spec_int ("max-width-chars",
|
||||
NULL, NULL,
|
||||
-1, G_MAXINT, -1,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
gimp_action_install_properties (object_class);
|
||||
|
||||
/**
|
||||
* GimpAction:enabled:
|
||||
|
|
@ -251,9 +198,6 @@ gimp_action_impl_init (GimpActionImpl *impl)
|
|||
impl->priv = gimp_action_impl_get_instance_private (impl);
|
||||
impl->priv->state_set_already = FALSE;
|
||||
|
||||
impl->ellipsize = PANGO_ELLIPSIZE_NONE;
|
||||
impl->max_width_chars = -1;
|
||||
|
||||
gimp_action_init (GIMP_ACTION (impl));
|
||||
}
|
||||
|
||||
|
|
@ -262,10 +206,6 @@ gimp_action_impl_finalize (GObject *object)
|
|||
{
|
||||
GimpActionImpl *impl = GIMP_ACTION_IMPL (object);
|
||||
|
||||
g_clear_object (&impl->context);
|
||||
g_clear_pointer (&impl->color, g_free);
|
||||
g_clear_object (&impl->viewable);
|
||||
|
||||
if (impl->priv->parameter_type)
|
||||
g_variant_type_free (impl->priv->parameter_type);
|
||||
if (impl->priv->state)
|
||||
|
|
@ -286,26 +226,6 @@ gimp_action_impl_get_property (GObject *object,
|
|||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_value_set_object (value, impl->context);
|
||||
break;
|
||||
|
||||
case PROP_COLOR:
|
||||
g_value_set_boxed (value, impl->color);
|
||||
break;
|
||||
|
||||
case PROP_VIEWABLE:
|
||||
g_value_set_object (value, impl->viewable);
|
||||
break;
|
||||
|
||||
case PROP_ELLIPSIZE:
|
||||
g_value_set_enum (value, impl->ellipsize);
|
||||
break;
|
||||
|
||||
case PROP_MAX_WIDTH_CHARS:
|
||||
g_value_set_int (value, impl->max_width_chars);
|
||||
break;
|
||||
|
||||
case PROP_ENABLED:
|
||||
g_value_set_boolean (value, gimp_action_impl_get_enabled (G_ACTION (impl)));
|
||||
break;
|
||||
|
|
@ -320,7 +240,7 @@ gimp_action_impl_get_property (GObject *object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
gimp_action_get_property (object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -331,36 +251,10 @@ gimp_action_impl_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpActionImpl *impl = GIMP_ACTION_IMPL (object);
|
||||
gboolean set_proxy = FALSE;
|
||||
GimpActionImpl *impl = GIMP_ACTION_IMPL (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_set_object (&impl->context, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_COLOR:
|
||||
g_clear_pointer (&impl->color, g_free);
|
||||
impl->color = g_value_dup_boxed (value);
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
|
||||
case PROP_VIEWABLE:
|
||||
g_set_object (&impl->viewable, g_value_get_object (value));
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
|
||||
case PROP_ELLIPSIZE:
|
||||
impl->ellipsize = g_value_get_enum (value);
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
|
||||
case PROP_MAX_WIDTH_CHARS:
|
||||
impl->max_width_chars = g_value_get_int (value);
|
||||
set_proxy = TRUE;
|
||||
break;
|
||||
|
||||
case PROP_ENABLED:
|
||||
gimp_action_set_sensitive (GIMP_ACTION (impl),
|
||||
g_value_get_boolean (value), NULL);
|
||||
|
|
@ -388,21 +282,9 @@ gimp_action_impl_set_property (GObject *object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
gimp_action_set_property (object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
|
||||
if (set_proxy)
|
||||
{
|
||||
GSList *list;
|
||||
|
||||
for (list = gimp_action_get_proxies (GIMP_ACTION (impl));
|
||||
list;
|
||||
list = g_slist_next (list))
|
||||
{
|
||||
gimp_action_impl_set_proxy (impl, list->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -489,9 +371,9 @@ gimp_action_impl_connect_proxy (GtkAction *action,
|
|||
{
|
||||
GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);
|
||||
|
||||
gimp_action_impl_set_proxy (GIMP_ACTION_IMPL (action), proxy);
|
||||
|
||||
gimp_action_set_proxy (GIMP_ACTION (action), proxy);
|
||||
|
||||
gimp_action_set_proxy_tooltip (GIMP_ACTION (action), proxy);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -521,107 +403,6 @@ gimp_action_impl_new (const gchar *name,
|
|||
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
gimp_action_impl_set_proxy (GimpActionImpl *impl,
|
||||
GtkWidget *proxy)
|
||||
{
|
||||
if (! GTK_IS_MENU_ITEM (proxy))
|
||||
return;
|
||||
|
||||
if (impl->color)
|
||||
{
|
||||
GtkWidget *area;
|
||||
|
||||
area = gimp_menu_item_get_image (GTK_MENU_ITEM (proxy));
|
||||
|
||||
if (GIMP_IS_COLOR_AREA (area))
|
||||
{
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (area), impl->color);
|
||||
}
|
||||
else
|
||||
{
|
||||
gint width, height;
|
||||
|
||||
area = gimp_color_area_new (impl->color,
|
||||
GIMP_COLOR_AREA_SMALL_CHECKS, 0);
|
||||
gimp_color_area_set_draw_border (GIMP_COLOR_AREA (area), TRUE);
|
||||
|
||||
if (impl->context)
|
||||
gimp_color_area_set_color_config (GIMP_COLOR_AREA (area),
|
||||
impl->context->gimp->config->color_management);
|
||||
|
||||
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
|
||||
gtk_widget_set_size_request (area, width, height);
|
||||
gimp_menu_item_set_image (GTK_MENU_ITEM (proxy), area);
|
||||
gtk_widget_show (area);
|
||||
}
|
||||
}
|
||||
else if (impl->viewable)
|
||||
{
|
||||
GtkWidget *view;
|
||||
|
||||
view = gimp_menu_item_get_image (GTK_MENU_ITEM (proxy));
|
||||
|
||||
if (GIMP_IS_VIEW (view) &&
|
||||
g_type_is_a (G_TYPE_FROM_INSTANCE (impl->viewable),
|
||||
GIMP_VIEW (view)->renderer->viewable_type))
|
||||
{
|
||||
gimp_view_set_viewable (GIMP_VIEW (view), impl->viewable);
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkIconSize size;
|
||||
gint width, height;
|
||||
gint border_width;
|
||||
|
||||
if (GIMP_IS_IMAGEFILE (impl->viewable))
|
||||
{
|
||||
size = GTK_ICON_SIZE_LARGE_TOOLBAR;
|
||||
border_width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = GTK_ICON_SIZE_MENU;
|
||||
border_width = 1;
|
||||
}
|
||||
|
||||
gtk_icon_size_lookup (size, &width, &height);
|
||||
view = gimp_view_new_full (impl->context, impl->viewable,
|
||||
width, height, border_width,
|
||||
FALSE, FALSE, FALSE);
|
||||
gimp_menu_item_set_image (GTK_MENU_ITEM (proxy), view);
|
||||
gtk_widget_show (view);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkWidget *image;
|
||||
|
||||
image = gimp_menu_item_get_image (GTK_MENU_ITEM (proxy));
|
||||
|
||||
if (GIMP_IS_VIEW (image) || GIMP_IS_COLOR_AREA (image))
|
||||
{
|
||||
gimp_menu_item_set_image (GTK_MENU_ITEM (proxy), NULL);
|
||||
g_object_notify (G_OBJECT (impl), "icon-name");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
GtkWidget *child = gtk_bin_get_child (GTK_BIN (proxy));
|
||||
|
||||
if (GTK_IS_BOX (child))
|
||||
child = g_object_get_data (G_OBJECT (proxy), "gimp-menu-item-label");
|
||||
|
||||
if (GTK_IS_LABEL (child))
|
||||
{
|
||||
GtkLabel *label = GTK_LABEL (child);
|
||||
|
||||
gtk_label_set_ellipsize (label, impl->ellipsize);
|
||||
gtk_label_set_max_width_chars (label, impl->max_width_chars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_action_impl_set_state (GimpAction *gimp_action,
|
||||
GVariant *value)
|
||||
|
|
|
|||
|
|
@ -37,13 +37,6 @@ struct _GimpActionImpl
|
|||
{
|
||||
GtkAction parent_instance;
|
||||
|
||||
GimpContext *context;
|
||||
|
||||
GimpRGB *color;
|
||||
GimpViewable *viewable;
|
||||
PangoEllipsizeMode ellipsize;
|
||||
gint max_width_chars;
|
||||
|
||||
GimpActionImplPrivate *priv;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_ENABLED,
|
||||
PROP_ENABLED = GIMP_ACTION_PROP_LAST + 1,
|
||||
PROP_PARAMETER_TYPE,
|
||||
PROP_STATE_TYPE,
|
||||
PROP_STATE
|
||||
|
|
@ -110,6 +110,8 @@ gimp_radio_action_class_init (GimpRadioActionClass *klass)
|
|||
|
||||
radio_class->changed = gimp_radio_action_changed;
|
||||
|
||||
gimp_action_install_properties (object_class);
|
||||
|
||||
/**
|
||||
* GimpRadioAction:enabled:
|
||||
*
|
||||
|
|
@ -211,7 +213,7 @@ gimp_radio_action_get_property (GObject *object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
gimp_action_get_property (object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -253,7 +255,7 @@ gimp_radio_action_set_property (GObject *object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
gimp_action_set_property (object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -356,7 +358,7 @@ gimp_radio_action_connect_proxy (GtkAction *action,
|
|||
{
|
||||
GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);
|
||||
|
||||
gimp_action_set_proxy (GIMP_ACTION (action), proxy);
|
||||
gimp_action_set_proxy_tooltip (GIMP_ACTION (action), proxy);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_ENABLED,
|
||||
PROP_ENABLED = GIMP_ACTION_PROP_LAST + 1,
|
||||
PROP_PARAMETER_TYPE,
|
||||
PROP_STATE_TYPE,
|
||||
PROP_STATE
|
||||
|
|
@ -107,6 +107,8 @@ gimp_toggle_action_class_init (GimpToggleActionClass *klass)
|
|||
|
||||
toggle_class->toggled = gimp_toggle_action_toggled;
|
||||
|
||||
gimp_action_install_properties (object_class);
|
||||
|
||||
/**
|
||||
* GimpToggleAction:enabled:
|
||||
*
|
||||
|
|
@ -207,7 +209,7 @@ gimp_toggle_action_get_property (GObject *object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
gimp_action_get_property (object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -249,7 +251,7 @@ gimp_toggle_action_set_property (GObject *object,
|
|||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
gimp_action_set_property (object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -336,7 +338,7 @@ gimp_toggle_action_connect_proxy (GtkAction *action,
|
|||
{
|
||||
GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);
|
||||
|
||||
gimp_action_set_proxy (GIMP_ACTION (action), proxy);
|
||||
gimp_action_set_proxy_tooltip (GIMP_ACTION (action), proxy);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Reference in a new issue