[gnumeric] fix crash and save sort-setups
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] fix crash and save sort-setups
- Date: Sat, 14 Nov 2009 20:29:15 +0000 (UTC)
commit 4f7a000fcda02f36362cafc3de2b59ada6abf894
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Sat Nov 14 13:28:26 2009 -0700
fix crash and save sort-setups
2009-11-14 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/sheet.h (gnm_sheet_get_sort_setups): new
(gnm_sheet_add_sort_setup): new
(gnm_sheet_find_sort_setup): new
* src/sheet.c (gnm_sheet_add_sort_setup): new
(gnm_sheet_get_sort_setups): new
(gnm_sheet_find_sort_setup): new
(gnm_sheet_init): initialize new field sort_setups
(gnm_sheet_finalize): and free them
* src/sort.c (gnm_sort_data_copy): new
* src/sort.h (gnm_sort_data_copy): new
2009-11-14 Andreas J. Guelzow <aguelzow pyrshep ca>
* dialog-cell-sort.c (set_ok_button_sensitivity): check whether
state->sel is NULL
(cb_dialog_ok_clicked): store a copy of the setup.
(dialog_cell_sort_load_sort_setup): new stub
(dialog_load_selection): do more
(dialog_init): move some code into dialog_load_selection
ChangeLog | 13 +++++++++
src/dialogs/ChangeLog | 9 ++++++
src/dialogs/dialog-cell-sort.c | 55 ++++++++++++++++++++++++++++++++++++---
src/sheet.c | 35 +++++++++++++++++++++++++
src/sheet.h | 4 +++
src/sort.c | 17 ++++++++++++
src/sort.h | 1 +
7 files changed, 129 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8ddccaf..46069b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-11-14 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/sheet.h (gnm_sheet_get_sort_setups): new
+ (gnm_sheet_add_sort_setup): new
+ (gnm_sheet_find_sort_setup): new
+ * src/sheet.c (gnm_sheet_add_sort_setup): new
+ (gnm_sheet_get_sort_setups): new
+ (gnm_sheet_find_sort_setup): new
+ (gnm_sheet_init): initialize new field sort_setups
+ (gnm_sheet_finalize): and free them
+ * src/sort.c (gnm_sort_data_copy): new
+ * src/sort.h (gnm_sort_data_copy): new
+
2009-11-13 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/func-builtin.c: add some translator comments
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index a1d2bb7..740bbab 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,12 @@
+2009-11-14 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * dialog-cell-sort.c (set_ok_button_sensitivity): check whether
+ state->sel is NULL
+ (cb_dialog_ok_clicked): store a copy of the setup.
+ (dialog_cell_sort_load_sort_setup): new stub
+ (dialog_load_selection): do more
+ (dialog_init): move some code into dialog_load_selection
+
2009-11-12 Morten Welinder <terra gnome org>
* dialog-solver.c (dialog_init): Set GNM_EE_CONSTANT_ALLOWED for
diff --git a/src/dialogs/dialog-cell-sort.c b/src/dialogs/dialog-cell-sort.c
index 475fbaa..7de64d7 100644
--- a/src/dialogs/dialog-cell-sort.c
+++ b/src/dialogs/dialog-cell-sort.c
@@ -212,6 +212,12 @@ static void
set_ok_button_sensitivity(SortFlowState *state)
{
int items;
+
+ if (state->sel == NULL) {
+ gtk_widget_set_sensitive (state->ok_button, FALSE);
+ return;
+ }
+
items = state->is_cols ? (state->sel->v_range.cell.b.row -
state->sel->v_range.cell.a.row + 1) :
(state->sel->v_range.cell.b.col -
@@ -453,13 +459,14 @@ cb_dialog_destroy (SortFlowState *state)
static void
cb_dialog_ok_clicked (SortFlowState *state)
{
- GnmSortData *data;
+ GnmSortData *data, *data_copy;
GnmSortClause *array, *this_array_item;
int item = 0;
GtkTreeIter iter;
gboolean descending, case_sensitive, sort_by_value, move_format;
gint number;
gint base;
+ char const *text;
array = g_new (GnmSortClause, state->sort_items);
this_array_item = array;
@@ -498,7 +505,14 @@ cb_dialog_ok_clicked (SortFlowState *state)
data->retain_formats = gtk_toggle_button_get_active (
GTK_TOGGLE_BUTTON (state->retain_format_check));
data->locale = go_locale_sel_get_locale (state->locale_selector);
-
+
+ data_copy = gnm_sort_data_copy (data);
+ text = gnm_expr_entry_get_text (state->range_entry);
+ gnm_sheet_add_sort_setup
+ (data->sheet,
+ g_strdup((text != NULL && text[0] != '\0') ? text : "Other"),
+ data_copy);
+
cmd_sort (WORKBOOK_CONTROL (state->wbcg), data);
gtk_widget_destroy (state->dialog);
@@ -512,10 +526,32 @@ cb_dialog_cancel_clicked (G_GNUC_UNUSED GtkWidget *button,
gtk_widget_destroy (state->dialog);
}
+static void
+dialog_cell_sort_load_sort_setup (SortFlowState *state, GnmSortData const *data)
+{
+/* int i; */
+/* GnmSortClause *this = data->clauses; */
+
+/* g_print ("Found a matching sort setup!\n"); */
+/* go_locale_sel_set_locale (state->locale_selector, data->locale); */
+/* gtk_toggle_button_set_active ( */
+/* GTK_TOGGLE_BUTTON (state->retain_format_check), data->retain_formats); */
+
+/* for (i = 0; i < data->num_clause; i++) { */
+
+
+
+
+
+/* this++; */
+/* } */
+}
+
static GnmRange const *
dialog_load_selection (SortFlowState *state, gboolean *col_rb)
{
GnmRange const *first;
+ GnmSortData const *data;
first = selection_first_range (state->sv, NULL, NULL);
@@ -529,6 +565,17 @@ dialog_load_selection (SortFlowState *state, gboolean *col_rb)
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON (state->cell_sort_col_rb),
(*col_rb = TRUE));
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->cell_sort_header_check),
+ sheet_range_has_heading
+ (state->sheet, first, *col_rb, FALSE));
+ cb_sort_header_check (state);
+
+ data = gnm_sheet_find_sort_setup (state->sheet,
+ gnm_expr_entry_get_text (state->range_entry));
+ if (data != NULL)
+ dialog_cell_sort_load_sort_setup (state, data);
+
return first;
}
@@ -1060,9 +1107,7 @@ dialog_init (SortFlowState *state)
cb_sort_selection_changed (state);
range = dialog_load_selection (state, &col_rb);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->cell_sort_header_check),
- sheet_range_has_heading (state->sheet, range, col_rb, FALSE));
- cb_sort_header_check (state);
+
cb_update_sensitivity (state);
gnm_expr_entry_grab_focus(GNM_EXPR_ENTRY (state->add_entry), TRUE);
diff --git a/src/sheet.c b/src/sheet.c
index e47706a..d13dd6e 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -62,6 +62,7 @@
#include "gnm-sheet-slicer.h"
#include "scenarios.h"
#include "cell-draw.h"
+#include "sort.h"
#include <goffice/goffice.h>
#include <glib/gi18n-lib.h>
@@ -769,6 +770,7 @@ gnm_sheet_init (Sheet *sheet)
sheet->filters = NULL;
sheet->scenarios = NULL;
+ sheet->sort_setups = NULL;
sheet->list_merged = NULL;
sheet->hash_merged = g_hash_table_new ((GHashFunc)&gnm_cellpos_hash,
(GCompareFunc)&gnm_cellpos_equal);
@@ -3968,6 +3970,8 @@ gnm_sheet_finalize (GObject *obj)
g_object_unref (sheet->solver_parameters);
scenarios_free (sheet->scenarios);
+ if (sheet->sort_setups != NULL)
+ g_hash_table_unref (sheet->sort_setups);
dependents_invalidate_sheet (sheet, TRUE);
@@ -5763,3 +5767,34 @@ gnm_sheet_get_size2 (Sheet const *sheet, Workbook const *wb)
? gnm_sheet_get_size (sheet)
: workbook_get_sheet_size (wb);
}
+
+
+GHashTable *
+gnm_sheet_get_sort_setups (Sheet *sheet)
+{
+ GHashTable *hash = sheet->sort_setups;
+
+ if (hash == NULL)
+ hash = sheet->sort_setups =
+ g_hash_table_new_full
+ (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify)gnm_sort_data_destroy);
+
+ return hash;
+}
+
+void
+gnm_sheet_add_sort_setup (Sheet *sheet, char *key, gpointer setup)
+{
+ GHashTable *hash = gnm_sheet_get_sort_setups (sheet);
+
+ g_hash_table_insert (hash, key, setup);
+}
+
+gconstpointer
+gnm_sheet_find_sort_setup (Sheet *sheet, char const *key)
+{
+ if (sheet->sort_setups == NULL)
+ return NULL;
+ return g_hash_table_lookup (sheet->sort_setups, key);
+}
diff --git a/src/sheet.h b/src/sheet.h
index 78181f1..90814d0 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -96,6 +96,7 @@ struct _Sheet {
GnmSolverParameters *solver_parameters;
GList *scenarios;
+ GHashTable *sort_setups;
gint simulation_round;
@@ -278,6 +279,9 @@ gboolean sheet_range_has_heading (Sheet const *sheet, GnmRange const *src,
void gnm_sheet_foreach_name (Sheet const *sheet, GHFunc func, gpointer data);
+GHashTable *gnm_sheet_get_sort_setups (Sheet *sheet);
+void gnm_sheet_add_sort_setup (Sheet *sheet, char *key, gpointer setup);
+gconstpointer gnm_sheet_find_sort_setup (Sheet *sheet, char const *key);
/* Redraw */
#define sheet_is_visible(_sheet) ((_sheet)->visibility == GNM_SHEET_VISIBILITY_VISIBLE)
diff --git a/src/sort.c b/src/sort.c
index a64ac47..bda9bd1 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -324,3 +324,20 @@ gnm_sort_contents (GnmSortData *data, GOCmdContext *cc)
return iperm;
}
+
+
+GnmSortData *
+gnm_sort_data_copy (GnmSortData *data)
+{
+ GnmSortData *result;
+
+ g_return_val_if_fail (data != NULL, NULL);
+
+ result = g_memdup (data, sizeof (GnmSortData));
+ result->range = g_memdup (result->range, sizeof (GnmRange));
+ result->clauses = g_memdup (result->clauses,
+ result->num_clause * sizeof (GnmSortClause));
+ result->locale = g_strdup (result->locale);
+
+ return result;
+}
diff --git a/src/sort.h b/src/sort.h
index 190daeb..24054a4 100644
--- a/src/sort.h
+++ b/src/sort.h
@@ -24,6 +24,7 @@ struct _GnmSortData {
};
void gnm_sort_data_destroy (GnmSortData *data);
+GnmSortData *gnm_sort_data_copy (GnmSortData *data);
void gnm_sort_position (GnmSortData *data, int *perm, GOCmdContext *cc);
int *gnm_sort_contents (GnmSortData *data, GOCmdContext *cc);
int gnm_sort_data_length (GnmSortData const *data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]