1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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/>.
25 #include <gnumeric-config.h>
26 #include <glib/gi18n-lib.h>
35 #include <dialogs/tool-dialogs.h>
36 #include <dialogs/dao-gui-utils.h>
40 #include <selection.h>
43 #include <widgets/gnumeric-expr-entry.h>
44 #include <tools/data-shuffling.h>
47 #define SHUFFLE_KEY "shuffle-dialog"
49 typedef GnmGenericToolState ShuffleState
;
51 static char const * const shuffle_by
[] = {
59 * shuffle_update_sensitivity_cb:
63 * Update the dialog widgets sensitivity
66 shuffle_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget
*dummy
,
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
);
76 value_release (input_range
);
77 gtk_label_set_text (GTK_LABEL (state
->warning
), "");
78 gtk_widget_set_sensitive (state
->ok_button
, TRUE
);
83 * shuffle_ok_clicked_cb:
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.
92 shuffle_ok_clicked_cb (G_GNUC_UNUSED GtkWidget
*button
, ShuffleState
*state
)
94 data_analysis_output_t
*dao
;
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
);
126 * Show the dialog (guru).
129 dialog_shuffle (WBCGtk
*wbcg
)
132 WorkbookControl
*wbc
;
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
))
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."),
152 G_CALLBACK (shuffle_ok_clicked_cb
), NULL
,
153 G_CALLBACK (shuffle_update_sensitivity_cb
),
157 shuffle_update_sensitivity_cb (NULL
, state
);
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";
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
);