1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
8 * (C) Copyright 2010 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
24 #include <gnumeric-config.h>
28 #include "sheet-view.h"
29 #include "sheet-control-gui.h"
31 #include "wbc-gtk-impl.h"
34 #include <gsf/gsf-impl-utils.h>
35 #include <glib/gi18n-lib.h>
37 /* ------------------------------------------------------------------------- */
39 static GObjectClass
*gnm_undo_colrow_restore_state_group_parent_class
;
42 gnm_undo_colrow_restore_state_group_finalize (GObject
*o
)
44 GnmUndoColrowRestoreStateGroup
*ua
= (GnmUndoColrowRestoreStateGroup
*)o
;
46 colrow_state_group_destroy (ua
->saved_state
);
47 ua
->saved_state
= NULL
;
48 colrow_index_list_destroy (ua
->selection
);
51 G_OBJECT_CLASS (gnm_undo_colrow_restore_state_group_parent_class
)->finalize (o
);
55 gnm_undo_colrow_restore_state_group_undo (GOUndo
*u
, G_GNUC_UNUSED gpointer data
)
57 GnmUndoColrowRestoreStateGroup
*ua
= (GnmUndoColrowRestoreStateGroup
*)u
;
59 colrow_restore_state_group (ua
->sheet
, ua
->is_cols
, ua
->selection
, ua
->saved_state
);
63 gnm_undo_colrow_restore_state_group_class_init (GObjectClass
*gobject_class
)
65 GOUndoClass
*uclass
= (GOUndoClass
*)gobject_class
;
67 gnm_undo_colrow_restore_state_group_parent_class
= g_type_class_peek_parent (gobject_class
);
69 gobject_class
->finalize
= gnm_undo_colrow_restore_state_group_finalize
;
70 uclass
->undo
= gnm_undo_colrow_restore_state_group_undo
;
74 GSF_CLASS (GnmUndoColrowRestoreStateGroup
, gnm_undo_colrow_restore_state_group
,
75 gnm_undo_colrow_restore_state_group_class_init
, NULL
, GO_TYPE_UNDO
)
78 * gnm_undo_colrow_restore_state_group_new:
80 * Returns: a new undo object.
84 gnm_undo_colrow_restore_state_group_new (Sheet
*sheet
, gboolean is_cols
,
85 ColRowIndexList
*selection
,
86 ColRowStateGroup
*saved_state
)
88 GnmUndoColrowRestoreStateGroup
*ua
= g_object_new (GNM_TYPE_UNDO_COLROW_RESTORE_STATE_GROUP
, NULL
);
91 ua
->is_cols
= is_cols
;
92 ua
->selection
= selection
;
93 ua
->saved_state
= saved_state
;
98 /* ------------------------------------------------------------------------- */
100 static GObjectClass
*gnm_undo_colrow_set_sizes_parent_class
;
103 gnm_undo_colrow_set_sizes_finalize (GObject
*o
)
105 GnmUndoColrowSetSizes
*ua
= (GnmUndoColrowSetSizes
*)o
;
107 colrow_index_list_destroy (ua
->selection
);
108 ua
->selection
= NULL
;
110 G_OBJECT_CLASS (gnm_undo_colrow_set_sizes_parent_class
)->finalize (o
);
114 gnm_undo_colrow_set_sizes_undo (GOUndo
*u
, G_GNUC_UNUSED gpointer data
)
116 GnmUndoColrowSetSizes
*ua
= (GnmUndoColrowSetSizes
*)u
;
117 ColRowStateGroup
*group
;
119 group
= colrow_set_sizes (ua
->sheet
, ua
->is_cols
, ua
->selection
, ua
->new_size
,
121 colrow_state_group_destroy (group
);
125 gnm_undo_colrow_set_sizes_class_init (GObjectClass
*gobject_class
)
127 GOUndoClass
*uclass
= (GOUndoClass
*)gobject_class
;
129 gnm_undo_colrow_set_sizes_parent_class
= g_type_class_peek_parent (gobject_class
);
131 gobject_class
->finalize
= gnm_undo_colrow_set_sizes_finalize
;
132 uclass
->undo
= gnm_undo_colrow_set_sizes_undo
;
136 GSF_CLASS (GnmUndoColrowSetSizes
, gnm_undo_colrow_set_sizes
,
137 gnm_undo_colrow_set_sizes_class_init
, NULL
, GO_TYPE_UNDO
)
140 * gnm_undo_colrow_set_sizes_new:
142 * If r is non-null and new_size < 0, selection is ignored.
144 * Returns: a new undo object.
148 gnm_undo_colrow_set_sizes_new (Sheet
*sheet
, gboolean is_cols
,
149 ColRowIndexList
*selection
,
150 int new_size
, GnmRange
const *r
)
152 GnmUndoColrowSetSizes
*ua
;
154 g_return_val_if_fail (selection
!= NULL
|| (r
!= NULL
&& new_size
== -1), NULL
);
156 ua
= g_object_new (GNM_TYPE_UNDO_COLROW_SET_SIZES
, NULL
);
159 ua
->is_cols
= is_cols
;
160 ua
->new_size
= new_size
;
162 if (r
== NULL
|| new_size
>= 0) {
163 ua
->selection
= selection
;
170 first
= r
->start
.col
;
172 ua
->from
= r
->start
.row
;
175 first
= r
->start
.row
;
177 ua
->from
= r
->start
.col
;
180 ua
->selection
= colrow_get_index_list (first
, last
, NULL
);
186 /* ------------------------------------------------------------------------- */
188 static GObjectClass
*gnm_undo_filter_set_condition_parent_class
;
191 gnm_undo_filter_set_condition_finalize (GObject
*o
)
193 GnmUndoFilterSetCondition
*ua
= (GnmUndoFilterSetCondition
*)o
;
195 gnm_filter_condition_free (ua
->cond
);
198 G_OBJECT_CLASS (gnm_undo_filter_set_condition_parent_class
)->finalize (o
);
202 cb_filter_set_condition_undo (GnmColRowIter
const *iter
, gint
*count
)
204 if (iter
->cri
->visible
)
210 cb_filter_set_condition_undo_set_pb (SheetControl
*control
, char *text
)
212 SheetControlGUI
*scg
= (SheetControlGUI
*) control
;
213 WBCGtk
*wbcg
= scg_wbcg (scg
);
215 gtk_progress_bar_set_text
216 (GTK_PROGRESS_BAR (wbcg
->progress_bar
), text
);
220 gnm_undo_filter_set_condition_undo (GOUndo
*u
, G_GNUC_UNUSED gpointer data
)
222 GnmUndoFilterSetCondition
*ua
= (GnmUndoFilterSetCondition
*)u
;
227 gnm_filter_set_condition (ua
->filter
, ua
->i
,
228 gnm_filter_condition_dup (ua
->cond
), TRUE
);
229 sheet_update (ua
->filter
->sheet
);
231 col_row_collection_foreach (&ua
->filter
->sheet
->rows
,
232 ua
->filter
->r
.start
.row
+ 1,
233 ua
->filter
->r
.end
.row
,
234 (ColRowHandler
) cb_filter_set_condition_undo
,
236 if (ua
->filter
->r
.end
.row
- ua
->filter
->r
.start
.row
> 10) {
237 /* xgettext: The first %d gives the number of rows that match. */
238 /* The second %d gives the total number of rows. Assume that the */
239 /* total number of rows is always large (>10). */
240 /* Note that the english "matches" or "match" is the verb of this sentence! */
241 /* There is no explicit noun associated with the second %d in english, the */
242 /* meaning is really "%d rows of all %d rows match" */
243 /* This is input to ngettext. */
244 format
= ngettext ("%d row of %d matches",
245 "%d rows of %d match",
247 text
= g_strdup_printf (format
, count
,
248 ua
->filter
->r
.end
.row
-
249 ua
->filter
->r
.start
.row
);
251 /* xgettext: The %d gives the number of rows that match. */
252 /* This is input to ngettext. */
253 format
= ngettext ("%d row matches",
256 text
= g_strdup_printf (format
, count
);
259 SHEET_FOREACH_CONTROL (ua
->filter
->sheet
, view
, control
, cb_filter_set_condition_undo_set_pb (control
, text
););
265 gnm_undo_filter_set_condition_class_init (GObjectClass
*gobject_class
)
267 GOUndoClass
*uclass
= (GOUndoClass
*)gobject_class
;
269 gnm_undo_filter_set_condition_parent_class
= g_type_class_peek_parent
272 gobject_class
->finalize
= gnm_undo_filter_set_condition_finalize
;
273 uclass
->undo
= gnm_undo_filter_set_condition_undo
;
277 GSF_CLASS (GnmUndoFilterSetCondition
, gnm_undo_filter_set_condition
,
278 gnm_undo_filter_set_condition_class_init
, NULL
, GO_TYPE_UNDO
)
281 * gnm_undo_filter_set_condition_new:
283 * if (retrieve_from_filter), cond is ignored
285 * Returns: a new undo object.
289 gnm_undo_filter_set_condition_new (GnmFilter
*filter
, unsigned i
,
290 GnmFilterCondition
*cond
,
291 gboolean retrieve_from_filter
)
293 GnmUndoFilterSetCondition
*ua
;
295 g_return_val_if_fail (filter
!= NULL
, NULL
);
296 g_return_val_if_fail (i
< filter
->fields
->len
, NULL
);
298 ua
= g_object_new (GNM_TYPE_UNDO_FILTER_SET_CONDITION
, NULL
);
303 if (retrieve_from_filter
)
304 ua
->cond
= gnm_filter_condition_dup
305 (gnm_filter_get_condition (filter
, i
));
311 /* ------------------------------------------------------------------------- */