[gimp] app: add GimpToolItem; derive GimpToolInfo from it
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add GimpToolItem; derive GimpToolInfo from it
- Date: Thu, 30 Jan 2020 00:57:12 +0000 (UTC)
commit 77111ba04587af5c839cdce11f6f4d5126aae57a
Author: Ell <ell_se yahoo com>
Date: Wed Jan 29 19:33:14 2020 +0200
app: add GimpToolItem; derive GimpToolInfo from it
Add GimpToolItem as a common base class for toolbox items.
Derive GimpToolInfo from GimpToolItem, representing an individual
tool. The next commits add support for tool groups, represented by
an alternative subclass of GimpToolItem.
Most of the tool-info properties remain in GimpToolInfo, however,
GimpToolItem takes care of tool-item visibility.
app/actions/tool-options-actions.c | 1 +
app/core/Makefile.am | 2 +
app/core/core-types.h | 1 +
app/core/gimptoolinfo.c | 68 +-------------
app/core/gimptoolinfo.h | 54 +++++------
app/core/gimptoolitem.c | 186 +++++++++++++++++++++++++++++++++++++
app/core/gimptoolitem.h | 63 +++++++++++++
app/core/meson.build | 1 +
app/tools/gimp-tools.c | 4 +-
app/widgets/gimptoolpalette.c | 4 +-
po/POTFILES.in | 1 -
11 files changed, 288 insertions(+), 97 deletions(-)
---
diff --git a/app/actions/tool-options-actions.c b/app/actions/tool-options-actions.c
index 8112419888..10c59eb2c8 100644
--- a/app/actions/tool-options-actions.c
+++ b/app/actions/tool-options-actions.c
@@ -28,6 +28,7 @@
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
+#include "core/gimptoolpreset.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index edf1473642..cc09265741 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -469,6 +469,8 @@ libappcore_a_sources = \
gimptilehandlerprojectable.h \
gimptoolinfo.c \
gimptoolinfo.h \
+ gimptoolitem.c \
+ gimptoolitem.h \
gimptooloptions.c \
gimptooloptions.h \
gimptoolpreset.c \
diff --git a/app/core/core-types.h b/app/core/core-types.h
index fc73cfca11..12bfd7361c 100644
--- a/app/core/core-types.h
+++ b/app/core/core-types.h
@@ -129,6 +129,7 @@ typedef struct _GimpToolOptions GimpToolOptions;
typedef struct _GimpPaintInfo GimpPaintInfo;
typedef struct _GimpToolInfo GimpToolInfo;
+typedef struct _GimpToolItem GimpToolItem;
/* data objects */
diff --git a/app/core/gimptoolinfo.c b/app/core/gimptoolinfo.c
index 1cfd9d777d..b5e1ae90a7 100644
--- a/app/core/gimptoolinfo.c
+++ b/app/core/gimptoolinfo.c
@@ -23,7 +23,6 @@
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
-#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
@@ -35,31 +34,15 @@
#include "gimptooloptions.h"
#include "gimptoolpreset.h"
-#include "gimp-intl.h"
-
-
-enum
-{
- PROP_0,
- PROP_VISIBLE
-};
-
static void gimp_tool_info_dispose (GObject *object);
static void gimp_tool_info_finalize (GObject *object);
-static void gimp_tool_info_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
-static void gimp_tool_info_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
+
static gchar * gimp_tool_info_get_description (GimpViewable *viewable,
gchar **tooltip);
-G_DEFINE_TYPE (GimpToolInfo, gimp_tool_info, GIMP_TYPE_VIEWABLE)
+G_DEFINE_TYPE (GimpToolInfo, gimp_tool_info, GIMP_TYPE_TOOL_ITEM)
#define parent_class gimp_tool_info_parent_class
@@ -72,17 +55,8 @@ gimp_tool_info_class_init (GimpToolInfoClass *klass)
object_class->dispose = gimp_tool_info_dispose;
object_class->finalize = gimp_tool_info_finalize;
- object_class->get_property = gimp_tool_info_get_property;
- object_class->set_property = gimp_tool_info_set_property;
viewable_class->get_description = gimp_tool_info_get_description;
-
- GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_VISIBLE,
- "visible",
- _("Visible"),
- NULL,
- TRUE,
- GIMP_PARAM_STATIC_STRINGS);
}
static void
@@ -121,44 +95,6 @@ gimp_tool_info_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-static void
-gimp_tool_info_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GimpToolInfo *tool_info = GIMP_TOOL_INFO (object);
-
- switch (property_id)
- {
- case PROP_VISIBLE:
- g_value_set_boolean (value, tool_info->visible);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
-static void
-gimp_tool_info_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GimpToolInfo *tool_info = GIMP_TOOL_INFO (object);
-
- switch (property_id)
- {
- case PROP_VISIBLE:
- tool_info->visible = (g_value_get_boolean (value) && ! tool_info->hidden);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
static gchar *
gimp_tool_info_get_description (GimpViewable *viewable,
gchar **tooltip)
diff --git a/app/core/gimptoolinfo.h b/app/core/gimptoolinfo.h
index ebee1fb908..2b3f73098e 100644
--- a/app/core/gimptoolinfo.h
+++ b/app/core/gimptoolinfo.h
@@ -19,7 +19,7 @@
#define __GIMP_TOOL_INFO_H__
-#include "gimpdata.h"
+#include "gimptoolitem.h"
#define GIMP_TYPE_TOOL_INFO (gimp_tool_info_get_type ())
@@ -34,7 +34,7 @@ typedef struct _GimpToolInfoClass GimpToolInfoClass;
struct _GimpToolInfo
{
- GimpViewable parent_instance;
+ GimpToolItem parent_instance;
Gimp *gimp;
@@ -51,8 +51,8 @@ struct _GimpToolInfo
gchar *help_domain;
gchar *help_id;
- gboolean hidden; /* can't be made visible */
- gboolean visible;
+ gboolean hidden;
+
GimpToolOptions *tool_options;
GimpPaintInfo *paint_info;
@@ -61,32 +61,32 @@ struct _GimpToolInfo
struct _GimpToolInfoClass
{
- GimpViewableClass parent_class;
+ GimpToolItemClass parent_class;
};
-GType gimp_tool_info_get_type (void) G_GNUC_CONST;
-
-GimpToolInfo * gimp_tool_info_new (Gimp *gimp,
- GType tool_type,
- GType tool_options_type,
- GimpContextPropMask context_props,
- const gchar *identifier,
- const gchar *label,
- const gchar *tooltip,
- const gchar *menu_label,
- const gchar *menu_accel,
- const gchar *help_domain,
- const gchar *help_id,
- const gchar *paint_core_name,
- const gchar *icon_name);
-
-void gimp_tool_info_set_standard (Gimp *gimp,
- GimpToolInfo *tool_info);
-GimpToolInfo * gimp_tool_info_get_standard (Gimp *gimp);
-
-GFile * gimp_tool_info_get_options_file (GimpToolInfo *tool_info,
- const gchar *suffix);
+GType gimp_tool_info_get_type (void) G_GNUC_CONST;
+
+GimpToolInfo * gimp_tool_info_new (Gimp *gimp,
+ GType tool_type,
+ GType tool_options_type,
+ GimpContextPropMask context_props,
+ const gchar *identifier,
+ const gchar *label,
+ const gchar *tooltip,
+ const gchar *menu_label,
+ const gchar *menu_accel,
+ const gchar *help_domain,
+ const gchar *help_id,
+ const gchar *paint_core_name,
+ const gchar *icon_name);
+
+void gimp_tool_info_set_standard (Gimp *gimp,
+ GimpToolInfo *tool_info);
+GimpToolInfo * gimp_tool_info_get_standard (Gimp *gimp);
+
+GFile * gimp_tool_info_get_options_file (GimpToolInfo *tool_info,
+ const gchar *suffix);
#endif /* __GIMP_TOOL_INFO_H__ */
diff --git a/app/core/gimptoolitem.c b/app/core/gimptoolitem.c
new file mode 100644
index 0000000000..5252cb091c
--- /dev/null
+++ b/app/core/gimptoolitem.c
@@ -0,0 +1,186 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimptoolitem.c
+ * Copyright (C) 2020 Ell
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (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
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
+
+#include "libgimpbase/gimpbase.h"
+#include "libgimpconfig/gimpconfig.h"
+
+#include "core-types.h"
+
+#include "core/gimpmarshal.h"
+
+#include "gimptoolitem.h"
+
+
+enum
+{
+ VISIBLE_CHANGED,
+ LAST_SIGNAL
+};
+
+enum
+{
+ PROP_0,
+ PROP_VISIBLE
+};
+
+
+struct _GimpToolItemPrivate
+{
+ gboolean visible;
+};
+
+
+/* local function prototypes */
+
+static void gimp_tool_item_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gimp_tool_item_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (GimpToolItem, gimp_tool_item, GIMP_TYPE_VIEWABLE)
+
+#define parent_class gimp_tool_item_parent_class
+
+static guint gimp_tool_item_signals[LAST_SIGNAL] = { 0 };
+
+
+/* private functions */
+
+static void
+gimp_tool_item_class_init (GimpToolItemClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ gimp_tool_item_signals[VISIBLE_CHANGED] =
+ g_signal_new ("visible-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpToolItemClass, visible_changed),
+ NULL, NULL,
+ gimp_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ object_class->get_property = gimp_tool_item_get_property;
+ object_class->set_property = gimp_tool_item_set_property;
+
+ GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_VISIBLE,
+ "visible", NULL, NULL,
+ TRUE,
+ GIMP_PARAM_STATIC_STRINGS);
+}
+
+static void
+gimp_tool_item_init (GimpToolItem *tool_item)
+{
+ tool_item->priv = gimp_tool_item_get_instance_private (tool_item);
+}
+
+static void
+gimp_tool_item_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GimpToolItem *tool_item = GIMP_TOOL_ITEM (object);
+
+ switch (property_id)
+ {
+ case PROP_VISIBLE:
+ g_value_set_boolean (value, tool_item->priv->visible);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gimp_tool_item_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GimpToolItem *tool_item = GIMP_TOOL_ITEM (object);
+
+ switch (property_id)
+ {
+ case PROP_VISIBLE:
+ gimp_tool_item_set_visible (tool_item, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+/* public functions */
+
+void
+gimp_tool_item_set_visible (GimpToolItem *tool_item,
+ gboolean visible)
+{
+ g_return_if_fail (GIMP_IS_TOOL_ITEM (tool_item));
+
+ if (visible != tool_item->priv->visible)
+ {
+ tool_item->priv->visible = visible;
+
+ g_signal_emit (tool_item, gimp_tool_item_signals[VISIBLE_CHANGED], 0);
+
+ g_object_notify (G_OBJECT (tool_item), "visible");
+ }
+}
+
+gboolean
+gimp_tool_item_get_visible (GimpToolItem *tool_item)
+{
+ g_return_val_if_fail (GIMP_IS_TOOL_ITEM (tool_item), FALSE);
+
+ return tool_item->priv->visible;
+}
+
+gboolean
+gimp_tool_item_is_visible (GimpToolItem *tool_item)
+{
+ GimpToolItem *parent;
+
+ g_return_val_if_fail (GIMP_IS_TOOL_ITEM (tool_item), FALSE);
+
+ parent = GIMP_TOOL_ITEM (
+ gimp_viewable_get_parent (GIMP_VIEWABLE (tool_item)));
+
+ return tool_item->priv->visible &&
+ (! parent || gimp_tool_item_is_visible (parent));
+}
diff --git a/app/core/gimptoolitem.h b/app/core/gimptoolitem.h
new file mode 100644
index 0000000000..9568bb98ec
--- /dev/null
+++ b/app/core/gimptoolitem.h
@@ -0,0 +1,63 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimptoolitem.h
+ * Copyright (C) 2020 Ell
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (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
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_TOOL_ITEM_H__
+#define __GIMP_TOOL_ITEM_H__
+
+
+#include "gimpviewable.h"
+
+
+#define GIMP_TYPE_TOOL_ITEM (gimp_tool_item_get_type ())
+#define GIMP_TOOL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_ITEM,
GimpToolItem))
+#define GIMP_TOOL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_ITEM,
GimpToolItemClass))
+#define GIMP_IS_TOOL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TOOL_ITEM))
+#define GIMP_IS_TOOL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_ITEM))
+#define GIMP_TOOL_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TOOL_ITEM,
GimpToolItemClass))
+
+
+typedef struct _GimpToolItemPrivate GimpToolItemPrivate;
+typedef struct _GimpToolItemClass GimpToolItemClass;
+
+struct _GimpToolItem
+{
+ GimpViewable parent_instance;
+
+ GimpToolItemPrivate *priv;
+};
+
+struct _GimpToolItemClass
+{
+ GimpViewableClass parent_class;
+
+ /* signals */
+ void (* visible_changed) (GimpToolItem *tool_item);
+};
+
+
+GType gimp_tool_item_get_type (void) G_GNUC_CONST;
+
+void gimp_tool_item_set_visible (GimpToolItem *tool_item,
+ gboolean visible);
+gboolean gimp_tool_item_get_visible (GimpToolItem *tool_item);
+gboolean gimp_tool_item_is_visible (GimpToolItem *tool_item);
+
+
+#endif /* __GIMP_TOOL_ITEM_H__ */
diff --git a/app/core/meson.build b/app/core/meson.build
index 851a576e4e..5d6a75d43e 100644
--- a/app/core/meson.build
+++ b/app/core/meson.build
@@ -234,6 +234,7 @@ libappcore_sources = [
'gimptemplate.c',
'gimptilehandlerprojectable.c',
'gimptoolinfo.c',
+ 'gimptoolitem.c',
'gimptooloptions.c',
'gimptoolpreset-load.c',
'gimptoolpreset-save.c',
diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c
index 7ee6f7f2a2..32c85353f4 100644
--- a/app/tools/gimp-tools.c
+++ b/app/tools/gimp-tools.c
@@ -288,6 +288,8 @@ gimp_tools_restore (Gimp *gimp)
if (object)
{
+ GimpToolItem *tool_item = list->data;
+
while (! gimp_container_get_child_by_name (
gimp_list,
gimp_object_get_name (
@@ -298,7 +300,7 @@ gimp_tools_restore (Gimp *gimp)
}
g_object_set (object,
- "visible", GIMP_TOOL_INFO (list->data)->visible,
+ "visible", gimp_tool_item_is_visible (tool_item),
NULL);
gimp_container_reorder (gimp->tool_info_list,
diff --git a/app/widgets/gimptoolpalette.c b/app/widgets/gimptoolpalette.c
index 3c083d9c73..0b636a3c2a 100644
--- a/app/widgets/gimptoolpalette.c
+++ b/app/widgets/gimptoolpalette.c
@@ -165,9 +165,9 @@ gimp_tool_palette_get_n_tools (GimpToolPalette *palette,
list;
list = list->next)
{
- GimpToolInfo *tool_info = list->data;
+ GimpToolItem *tool_item = list->data;
- if (tool_info->visible)
+ if (gimp_tool_item_get_visible (tool_item))
n_tools++;
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f3a5e5c906..18aeb7f458 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -197,7 +197,6 @@ app/core/gimpsymmetry-mirror.c
app/core/gimpsymmetry-tiling.c
app/core/gimptagcache.c
app/core/gimptemplate.c
-app/core/gimptoolinfo.c
app/core/gimptooloptions.c
app/core/gimptoolpreset.c
app/core/gimptoolpreset-load.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]