Compilation: don't compile dialogs separately.
[gnumeric.git] / src / dialogs / dialog-shuffle.c
blobb2c486c209d1f9bd98c1be5d04da738af7db2a79
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * dialog-shuffle.c:
5 * Authors:
6 * Jukka-Pekka Iivonen <iivonen@iki.fi>
7 * Andreas J. Guelzow <aguelzow@taliesin.ca>
9 * (C) Copyright 2000-2003 by Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
10 * (C) Copyright 2002 by Andreas J. Guelzow <aguelzow@taliesin.ca>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses/>.
24 **/
25 #include <gnumeric-config.h>
26 #include <glib/gi18n-lib.h>
27 #include <gnumeric.h>
28 #include "dialogs.h"
29 #include "help.h"
31 #include <sheet.h>
32 #include <cell.h>
33 #include <ranges.h>
34 #include <gui-util.h>
35 #include <tool-dialogs.h>
36 #include <dao-gui-utils.h>
37 #include <value.h>
38 #include <wbc-gtk.h>
39 #include <commands.h>
40 #include <selection.h>
42 #include <gtk/gtk.h>
43 #include <widgets/gnumeric-expr-entry.h>
44 #include "data-shuffling.h"
47 #define SHUFFLE_KEY "shuffle-dialog"
49 typedef GnmGenericToolState ShuffleState;
51 static char const * const shuffle_by[] = {
52 "shuffle_cols",
53 "shuffle_rows",
54 "shuffle_area",
55 NULL
58 /**
59 * shuffle_update_sensitivity_cb:
60 * @dummy:
61 * @state:
63 * Update the dialog widgets sensitivity
64 **/
65 static void
66 shuffle_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
67 ShuffleState *state)
69 GnmValue *input_range = gnm_expr_entry_parse_as_value (
70 GNM_EXPR_ENTRY (state->input_entry), state->sheet);
71 if (input_range == NULL) {
72 gtk_label_set_text (GTK_LABEL (state->warning),
73 _("The input range is invalid."));
74 gtk_widget_set_sensitive (state->ok_button, FALSE);
75 } else {
76 value_release (input_range);
77 gtk_label_set_text (GTK_LABEL (state->warning), "");
78 gtk_widget_set_sensitive (state->ok_button, TRUE);
82 /**
83 * shuffle_ok_clicked_cb:
84 * @button:
85 * @state:
87 * Retrieve the information from the dialog and call the data_shuffling.
88 * Note that we assume that the ok_button is only active if the entry fields
89 * contain sensible data.
90 **/
91 static void
92 shuffle_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button, ShuffleState *state)
94 data_analysis_output_t *dao;
95 data_shuffling_t *ds;
96 WorkbookControl *wbc;
97 GnmValue *input;
98 int type;
100 /* This is free'ed by data_shuffling_free. */
101 /* We later want to extend this to shuffle to other locations */
102 dao = dao_init (NULL, InPlaceOutput);
104 input = gnm_expr_entry_parse_as_value (
105 GNM_EXPR_ENTRY (state->input_entry), state->sheet);
107 if (dao->type == InPlaceOutput)
108 dao_load_from_value (dao, input);
110 type = gnm_gui_group_value (state->gui, shuffle_by);
112 ds = data_shuffling (GNM_WBC (state->wbcg), dao,
113 state->sheet, input, type);
115 wbc = GNM_WBC (state->wbcg);
116 cmd_data_shuffle (wbc, ds, state->sheet);
118 value_release (input);
119 gtk_widget_destroy (state->dialog);
123 * dialog_shuffle:
124 * @wbcg:
126 * Show the dialog (guru).
128 void
129 dialog_shuffle (WBCGtk *wbcg)
131 ShuffleState *state;
132 WorkbookControl *wbc;
133 GtkWidget *w;
134 char const *type;
135 GnmRange const *r;
137 g_return_if_fail (wbcg != NULL);
139 wbc = GNM_WBC (wbcg);
141 /* Only pop up one copy per workbook */
142 if (gnm_dialog_raise_if_exists (wbcg, SHUFFLE_KEY))
143 return;
145 state = g_new (ShuffleState, 1);
147 if (dialog_tool_init (state, wbcg, wb_control_cur_sheet (wbc),
148 GNUMERIC_HELP_LINK_DATA_SHUFFLE,
149 "res:ui/shuffle.ui", "Shuffling",
150 _("Could not create the Data Shuffling dialog."),
151 SHUFFLE_KEY,
152 G_CALLBACK (shuffle_ok_clicked_cb), NULL,
153 G_CALLBACK (shuffle_update_sensitivity_cb),
155 return;
157 shuffle_update_sensitivity_cb (NULL, state);
158 state->gdao = NULL;
159 tool_load_selection ((GnmGenericToolState *)state, FALSE);
161 r = selection_first_range (state->sv, NULL, NULL);
162 if (range_width (r) == 1)
163 type = "shuffle_cols";
164 else if (range_height (r) == 1)
165 type = "shuffle_rows";
166 else
167 type = "shuffle_area";
168 w = go_gtk_builder_get_widget (state->gui, type);
169 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
171 gtk_widget_show (state->dialog);
173 return;