2 * dialog-insert-cells.c: Insert a number of cells.
5 * Miguel de Icaza (miguel@gnu.org)
6 * Copyright (C) Andreas J. Guelzow (aguelzow@taliesin.ca)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 #include <gnumeric-config.h>
22 #include <glib/gi18n-lib.h>
28 #include <selection.h>
31 #include <sheet-view.h>
36 #include <command-context.h>
40 #define DELETE_CELL_DIALOG_KEY "delete-cells-dialog"
46 GtkWidget
*cancel_button
;
53 cb_delete_cell_destroy (DeleteCellState
*state
)
55 if (state
->gui
!= NULL
)
56 g_object_unref (state
->gui
);
61 cb_delete_cell_ok_clicked (DeleteCellState
*state
)
63 WorkbookControl
*wbc
= GNM_WBC (state
->wbcg
);
68 radio_0
= go_gtk_builder_get_widget (state
->gui
, "radio_0");
69 g_return_if_fail (radio_0
!= NULL
);
71 i
= gnm_gtk_radio_group_get_selected
72 (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_0
)));
74 cols
= state
->sel
->end
.col
- state
->sel
->start
.col
+ 1;
75 rows
= state
->sel
->end
.row
- state
->sel
->start
.row
+ 1;
79 cmd_shift_rows (wbc
, state
->sheet
,
80 state
->sel
->end
.col
+ 1,
81 state
->sel
->start
.row
,
82 state
->sel
->end
.row
, - cols
);
85 cmd_shift_cols (wbc
, state
->sheet
,
86 state
->sel
->start
.col
,
88 state
->sel
->end
.row
+ 1, - rows
);
91 cmd_delete_rows (wbc
, state
->sheet
,
92 state
->sel
->start
.row
, rows
);
95 cmd_delete_cols (wbc
, state
->sheet
,
96 state
->sel
->start
.col
, cols
);
99 gtk_widget_destroy (state
->dialog
);
103 cb_delete_cell_cancel_clicked (G_GNUC_UNUSED GtkWidget
*button
,
104 DeleteCellState
*state
)
106 gtk_widget_destroy (state
->dialog
);
110 dialog_delete_cells (WBCGtk
*wbcg
)
112 DeleteCellState
*state
;
113 WorkbookControl
*wbc
= GNM_WBC (wbcg
);
114 SheetView
*sv
= wb_control_cur_sheet_view (wbc
);
115 Sheet
*sheet
= sv_sheet (sv
);
121 g_return_if_fail (wbcg
!= NULL
);
123 if (!(sel
= selection_first_range (sv
, GO_CMD_CONTEXT (wbc
), _("Delete"))))
125 cols
= sel
->end
.col
- sel
->start
.col
+ 1;
126 rows
= sel
->end
.row
- sel
->start
.row
+ 1;
128 if (range_is_full (sel
, sheet
, FALSE
)) {
129 cmd_delete_cols (wbc
, sheet
, sel
->start
.col
, cols
);
132 if (range_is_full (sel
, sheet
, TRUE
)) {
133 cmd_delete_rows (wbc
, sheet
, sel
->start
.row
, rows
);
137 if (gnm_dialog_raise_if_exists (wbcg
, DELETE_CELL_DIALOG_KEY
))
139 gui
= gnm_gtk_builder_load ("res:ui/delete-cells.ui", NULL
, GO_CMD_CONTEXT (wbcg
));
143 state
= g_new (DeleteCellState
, 1);
147 state
->sheet
= sv_sheet (sv
);
149 state
->dialog
= go_gtk_builder_get_widget (state
->gui
, "Delete_cells");
150 if (state
->dialog
== NULL
) {
151 go_gtk_notice_dialog (wbcg_toplevel (wbcg
), GTK_MESSAGE_ERROR
,
152 _("Could not create the Delete Cell dialog."));
157 w
= go_gtk_builder_get_widget (state
->gui
, "okbutton");
158 g_signal_connect_swapped (G_OBJECT (w
), "clicked",
159 G_CALLBACK (cb_delete_cell_ok_clicked
), state
);
160 w
= go_gtk_builder_get_widget (state
->gui
, "cancelbutton");
161 g_signal_connect (G_OBJECT (w
), "clicked",
162 G_CALLBACK (cb_delete_cell_cancel_clicked
), state
);
164 gnm_dialog_setup_destroy_handlers (GTK_DIALOG (state
->dialog
),
166 GNM_DIALOG_DESTROY_CURRENT_SHEET_REMOVED
);
168 gnm_init_help_button (
169 go_gtk_builder_get_widget (state
->gui
, "helpbutton"),
170 GNUMERIC_HELP_LINK_DELETE_CELLS
);
172 gtk_toggle_button_set_active
173 (GTK_TOGGLE_BUTTON (go_gtk_builder_get_widget
174 (state
->gui
, cols
< rows
175 ? "radio_0" : "radio_1")),
178 wbc_gtk_attach_guru (state
->wbcg
, state
->dialog
);
179 g_object_set_data_full (G_OBJECT (state
->dialog
),
180 "state", state
, (GDestroyNotify
) cb_delete_cell_destroy
);
182 gnm_keyed_dialog (wbcg
, GTK_WINDOW (state
->dialog
),
183 DELETE_CELL_DIALOG_KEY
);
184 gtk_widget_show (state
->dialog
);