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