Commit 8d50adf1 authored by Andreas J. Guelzow's avatar Andreas J. Guelzow Committed by Andreas J. Guelzow

Add `add' entry code extracted from load_model_data (load_model_data) :

2002-02-23  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* cell-sort.glade : Add `add' entry
	* dialog-cell-sort.c (append_data) : code extracted from
	  load_model_data
	(load_model_data) : use append_data
	(value_to_global_range) : utility for cb_update_add_sensitivity
	(cb_update_add_sensitivity) : update add button sensitivity
	(cb_update_sensitivity) : call cb_update_add_sensitivity
	(cb_ok_clicked) : adjust base (the tree widget now stores
	  row and col numbers rather than offset)
	(cb_add_clicked) : new
	(dialog_init) : set up add-entry
parent 15028d47
......@@ -20,6 +20,7 @@ Andreas:
* Port the plugin manager dialog to gnome2
* Improve numerical precision in single factor ANOVA
* Correct regression analysis tool (intercept == 0 case)
* Port and redesign sort dialog
Jody:
* Initial port to gnome2.
......
2002-02-23 Andreas J. Guelzow <aguelzow@taliesin.ca>
* cell-sort.glade : Add `add' entry
* dialog-cell-sort.c (append_data) : code extracted from
load_model_data
(load_model_data) : use append_data
(value_to_global_range) : utility for cb_update_add_sensitivity
(cb_update_add_sensitivity) : update add button sensitivity
(cb_update_sensitivity) : call cb_update_add_sensitivity
(cb_ok_clicked) : adjust base (the tree widget now stores
row and col numbers rather than offset)
(cb_add_clicked) : new
(dialog_init) : set up add-entry
2002-02-23 Andreas J. Guelzow <aguelzow@taliesin.ca>
* dialog-analysis-tools.c (tool_set_focus) : the focus widget
......
......@@ -132,18 +132,14 @@
</child>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">1</property>
<property name="xscale">1</property>
<property name="yscale">0</property>
<widget class="GtkTable" id="cell_sort_buttons_table">
<property name="border_width">5</property>
<property name="homogeneous">no</property>
<property name="row_spacing">4</property>
<property name="column_spacing">4</property>
<property name="n-rows">4</property>
<property name="n-columns">2</property>
<property name="visible">yes</property>
<child>
<widget class="GtkButton" id="up_button">
......@@ -154,22 +150,17 @@
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_padding">0</property>
<property name="y_padding">0</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xscale">1</property>
<property name="yscale">0</property>
<child>
<widget class="GtkButton" id="down_button">
......@@ -180,75 +171,62 @@
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_padding">0</property>
<property name="y_padding">0</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">1</property>
<property name="xscale">1</property>
<property name="yscale">0</property>
<child>
<widget class="GtkButton" id="add_button">
<widget class="GtkButton" id="delete_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-add</property>
<property name="label">gtk-delete</property>
<property name="use_stock">True</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_padding">0</property>
<property name="y_padding">0</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xscale">1</property>
<property name="yscale">0</property>
<child>
<widget class="GtkButton" id="delete_button">
<widget class="GtkButton" id="add_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-delete</property>
<property name="label">gtk-add</property>
<property name="use_stock">True</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_padding">0</property>
<property name="y_padding">0</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
......@@ -292,7 +270,7 @@
<property name="x_padding">0</property>
<property name="y_padding">0</property>
<property name="x_options">expand|fill</property>
<property name="y_options">expand|fill</property>
<property name="y_options">fill</property>
</packing>
</child>
......@@ -353,7 +331,7 @@
<property name="x_padding">0</property>
<property name="y_padding">0</property>
<property name="x_options">expand|fill</property>
<property name="y_options">expand|fill</property>
<property name="y_options">fill</property>
</packing>
</child>
......
......@@ -37,7 +37,6 @@
#define CELL_SORT_KEY "cell-sort-dialog"
#define MAX_INITIAL_CLAUSES 32
#warning we need to add a way to add clauses
typedef struct {
Sheet *sheet;
......@@ -54,6 +53,7 @@ typedef struct {
GtkWidget *add_button;
GtkWidget *delete_button;
GnumericExprEntry *range_entry;
GnumericExprEntry *add_entry;
GtkListStore *model;
GtkTreeView *treeview;
GtkTreeSelection *selection;
......@@ -148,6 +148,30 @@ translate_range (Value *range, SortFlowState *state)
}
}
static void
append_data (SortFlowState *state, int i, int index)
{
gchar *str;
GtkTreeIter iter;
Sheet *sheet = state->sel->v_range.cell.a.sheet;
str = state->is_cols
? col_row_name (sheet, i, index, state->header, TRUE)
: col_row_name (sheet, index, i, state->header, FALSE);
gtk_list_store_append (state->model, &iter);
gtk_list_store_set (state->model, &iter,
ITEM_IN_USE, TRUE,
ITEM_NAME, str,
ITEM_DESCENDING, FALSE,
ITEM_CASE_SENSITIVE, FALSE,
ITEM_SORT_BY_VALUE, TRUE,
ITEM_MOVE_FORMAT, TRUE,
ITEM_NUMBER, i,
-1);
state->sort_items++;
g_free (str);
}
static void
load_model_data (SortFlowState *state)
{
......@@ -155,10 +179,6 @@ load_model_data (SortFlowState *state)
int end;
int index;
int i;
int offset = 0;
gchar *str;
GtkTreeIter iter;
Sheet *sheet = state->sel->v_range.cell.a.sheet;
if (state->is_cols) {
start = state->sel->v_range.cell.a.col;
......@@ -176,24 +196,53 @@ load_model_data (SortFlowState *state)
if (end >= start + MAX_INITIAL_CLAUSES)
end = start + MAX_INITIAL_CLAUSES - 1;
for (i = start; i <= end; i++) {
str = state->is_cols
? col_row_name (sheet, i, index, state->header, TRUE)
: col_row_name (sheet, index, i, state->header, FALSE);
gtk_list_store_append (state->model, &iter);
gtk_list_store_set (state->model, &iter,
ITEM_IN_USE, TRUE,
ITEM_NAME, str,
ITEM_DESCENDING, FALSE,
ITEM_CASE_SENSITIVE, FALSE,
ITEM_SORT_BY_VALUE, TRUE,
ITEM_MOVE_FORMAT, TRUE,
ITEM_NUMBER, offset,
-1);
state->sort_items++;
offset++;
g_free (str);
for (i = start; i <= end; i++)
append_data (state, i, index);
}
static GlobalRange *
value_to_global_range ( Value *value)
{
GlobalRange *gr;
g_return_val_if_fail (value->type == VALUE_CELLRANGE, NULL);
gr = g_new0 (GlobalRange, 1);
gr->sheet = value->v_range.cell.a.sheet;
gr->range.start.row = value->v_range.cell.a.row;
gr->range.start.col = value->v_range.cell.a.col;
gr->range.end.row = value->v_range.cell.b.row;
gr->range.end.col = value->v_range.cell.b.col;
return gr;
}
/**
* cb_update_add_sensitivity:
* @dummy:
* @state:
*
**/
static void
cb_update_add_sensitivity (GtkWidget *dummy, SortFlowState *state)
{
Value *range_add;
range_add = gnm_expr_entry_parse_as_value
(GNUMERIC_EXPR_ENTRY (state->add_entry), state->sheet);
if (state->sel == NULL || range_add == NULL) {
gtk_widget_set_sensitive (state->add_button, FALSE);
} else {
GlobalRange *a = value_to_global_range (state->sel);
GlobalRange *b = value_to_global_range (range_add);
gtk_widget_set_sensitive (state->add_button,
global_range_overlap (a, b));
global_range_free (a);
global_range_free (b);
}
if (range_add != NULL)
value_release (range_add);
}
/**
......@@ -201,9 +250,6 @@ load_model_data (SortFlowState *state)
* @dummy:
* @state:
*
* Update the dialog widgets sensitivity if the only items of interest
* are one or two standard input and and one output item, permitting multiple
* areas as first input.
**/
static void
cb_update_sensitivity (GtkWidget *dummy, SortFlowState *state)
......@@ -221,6 +267,7 @@ cb_update_sensitivity (GtkWidget *dummy, SortFlowState *state)
state->sort_items = 0;
}
gtk_widget_set_sensitive (state->ok_button, FALSE);
gtk_widget_set_sensitive (state->add_button, FALSE);
} else {
if (translate_range (range, state))
load_model_data (state);
......@@ -233,6 +280,7 @@ cb_update_sensitivity (GtkWidget *dummy, SortFlowState *state)
gtk_widget_set_sensitive (state->ok_button,
(state->sort_items != 0) &&
(items > 1));
cb_update_add_sensitivity (dummy, state);
}
}
......@@ -283,9 +331,11 @@ cb_dialog_ok_clicked (GtkWidget *button, SortFlowState *state)
GtkTreeIter iter;
gboolean in_use, descending, case_sensitive, sort_by_value, move_format;
gint number;
gint base;
array = g_new (SortClause, state->sort_items);
this_array_item = array;
base = (state->is_cols ? state->sel->v_range.cell.a.col : state->sel->v_range.cell.a.row);
while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model),
&iter, NULL, item)) {
......@@ -299,7 +349,7 @@ cb_dialog_ok_clicked (GtkWidget *button, SortFlowState *state)
-1);
item++;
if (in_use) {
this_array_item->offset = number;
this_array_item->offset = number - base;
this_array_item->asc = descending ? 1 : 0;
this_array_item->cs = case_sensitive;
this_array_item->val = sort_by_value;
......@@ -490,6 +540,67 @@ static void cb_delete_clicked (GtkWidget *w, SortFlowState *state)
cb_update_sensitivity (NULL, state);
}
static void cb_add_clicked (GtkWidget *w, SortFlowState *state)
{
Value *range_add;
GlobalRange *grange_sort;
GlobalRange *grange_add;
Range intersection;
int start;
int end;
int index;
int i;
range_add = gnm_expr_entry_parse_as_value
(GNUMERIC_EXPR_ENTRY (state->add_entry), state->sheet);
g_return_if_fail (range_add != NULL && state->sel != NULL);
grange_sort = value_to_global_range (state->sel);
grange_add = value_to_global_range (range_add);
if (range_intersection (&intersection, &grange_sort->range, &grange_add->range)) {
if (state->is_cols) {
start = intersection.start.col;
end = intersection.end.col;
index = intersection.start.row;
} else {
start = intersection.start.row;
end = intersection.end.row;
index = intersection.start.col;
}
for (i = start; i <= end; i++) {
int item = 0;
GtkTreeIter iter;
gboolean found = FALSE;
gint number;
while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model),
&iter, NULL, item)) {
gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
ITEM_NUMBER, &number,
-1);
item++;
if (number == i) {
found = TRUE;
break;
}
}
if (!found) {
append_data (state, i, index);
break;
}
}
}
global_range_free (grange_sort);
global_range_free (grange_add);
}
static void
cb_toggled_in_use (GtkCellRendererToggle *cell,
gchar *path_string,
......@@ -573,6 +684,25 @@ dialog_init (SortFlowState *state)
"update",
G_CALLBACK (cb_update_sensitivity), state);
table = GTK_TABLE (glade_xml_get_widget (state->gui, "cell_sort_buttons_table"));
/* setup add entry */
state->add_entry = gnumeric_expr_entry_new (state->wbcg, TRUE);
gnm_expr_entry_set_flags (state->add_entry,
GNUM_EE_SINGLE_RANGE,
GNUM_EE_MASK);
gnm_expr_entry_set_scg (state->add_entry, wbcg_cur_scg (state->wbcg));
gtk_table_attach (table, GTK_WIDGET (state->add_entry),
0, 2, 1, 2,
GTK_EXPAND | GTK_FILL, 0,
0, 0);
gnumeric_editable_enters (GTK_WINDOW (state->dialog),
GTK_WIDGET (state->add_entry));
gtk_widget_show (GTK_WIDGET (state->add_entry));
g_signal_connect (G_OBJECT (state->add_entry),
"changed",
G_CALLBACK (cb_update_add_sensitivity), state);
/* Set-up tree view */
scrolled = glade_xml_get_widget (state->gui, "scrolled_cell_sort_list");
state->model = gtk_list_store_new (NUM_COLMNS, G_TYPE_BOOLEAN, G_TYPE_STRING,
......@@ -655,6 +785,9 @@ dialog_init (SortFlowState *state)
"clicked",
G_CALLBACK (cb_down), state);
state->add_button = glade_xml_get_widget (state->gui, "add_button");
g_signal_connect (GTK_OBJECT (state->add_button),
"clicked",
G_CALLBACK (cb_add_clicked), state);
gtk_widget_set_sensitive (state->add_button, FALSE);
state->delete_button = glade_xml_get_widget (state->gui, "delete_button");
g_signal_connect (GTK_OBJECT (state->delete_button),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment