1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimppalette.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimpdatafactoryview.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpview.h"
#include "widgets/gimpwidgets-utils.h"
#include "dialogs/dialogs.h"
#include "actions.h"
#include "palettes-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void palettes_merge_callback (GtkWidget *widget,
const gchar *palette_name,
gpointer data);
/* public functions */
void
palettes_import_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GtkWidget *widget;
return_if_no_widget (widget, data);
gimp_dialog_factory_dialog_new (gimp_dialog_factory_get_singleton (),
gtk_widget_get_screen (widget),
gimp_widget_get_monitor (widget),
NULL /*ui_manager*/,
"gimp-palette-import-dialog", -1, TRUE);
}
void
palettes_merge_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
GtkWidget *dialog;
#define MERGE_DIALOG_KEY "gimp-palettes-merge-dialog"
dialog = dialogs_get_dialog (G_OBJECT (editor), MERGE_DIALOG_KEY);
if (! dialog)
{
dialog = gimp_query_string_box (_("Merge Palettes"),
GTK_WIDGET (editor),
gimp_standard_help_func,
GIMP_HELP_PALETTE_MERGE,
_("Enter a name for the merged palette"),
NULL,
G_OBJECT (editor), "destroy",
palettes_merge_callback, editor);
dialogs_attach_dialog (G_OBJECT (editor), MERGE_DIALOG_KEY, dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
}
/* private functions */
static void
palettes_merge_callback (GtkWidget *widget,
const gchar *palette_name,
gpointer data)
{
GimpContainerEditor *editor = data;
GimpDataFactoryView *view = data;
GimpDataFactory *factory;
GimpContext *context;
GimpPalette *new_palette;
GList *selected = NULL;
GList *list;
context = gimp_container_view_get_context (editor->view);
factory = gimp_data_factory_view_get_data_factory (view);
gimp_container_view_get_selected (editor->view, &selected);
if (g_list_length (selected) < 2)
{
gimp_message_literal (context->gimp,
G_OBJECT (editor), GIMP_MESSAGE_WARNING,
_("There must be at least two palettes selected "
"to merge."));
g_list_free (selected);
return;
}
new_palette = GIMP_PALETTE (gimp_data_factory_data_new (factory, context,
palette_name));
for (list = selected; list; list = g_list_next (list))
{
GimpPalette *palette = list->data;
GList *cols;
for (cols = gimp_palette_get_colors (palette);
cols;
cols = g_list_next (cols))
{
GimpPaletteEntry *entry = cols->data;
gimp_palette_add_entry (new_palette, -1,
entry->name,
&entry->color);
}
}
g_list_free (selected);
}
|