GUI: Move .ui files from goffice resources to glib resources
[gnumeric.git] / src / dialogs / dialog-shuffle.c
blobaf548893e988205c7829bc75dea124f1847d50a6
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 GenericToolState 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:
125 * @sheet:
127 * Show the dialog (guru).
130 void
131 dialog_shuffle (WBCGtk *wbcg)
133 ShuffleState *state;
134 WorkbookControl *wbc;
135 GtkWidget *w;
136 char const *type;
137 GnmRange const *r;
139 g_return_if_fail (wbcg != NULL);
141 wbc = GNM_WBC (wbcg);
143 /* Only pop up one copy per workbook */
144 if (gnm_dialog_raise_if_exists (wbcg, SHUFFLE_KEY))
145 return;
147 state = g_new (ShuffleState, 1);
149 if (dialog_tool_init (state, wbcg, wb_control_cur_sheet (wbc),
150 GNUMERIC_HELP_LINK_DATA_SHUFFLE,
151 "res:ui/shuffle.ui", "Shuffling",
152 _("Could not create the Data Shuffling dialog."),
153 SHUFFLE_KEY,
154 G_CALLBACK (shuffle_ok_clicked_cb), NULL,
155 G_CALLBACK (shuffle_update_sensitivity_cb),
157 return;
159 shuffle_update_sensitivity_cb (NULL, state);
160 state->gdao = NULL;
161 tool_load_selection ((GenericToolState *)state, FALSE);
163 r = selection_first_range (state->sv, NULL, NULL);
164 if (range_width (r) == 1)
165 type = "shuffle_cols";
166 else if (range_height (r) == 1)
167 type = "shuffle_rows";
168 else
169 type = "shuffle_area";
170 w = go_gtk_builder_get_widget (state->gui, type);
171 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
173 gtk_widget_show (state->dialog);
175 return;