Commit 74f40687 authored by Andreas J. Guelzow's avatar Andreas J. Guelzow Committed by Andreas J. Guelzow

add help button ditto deleted (location_of_iter) : new

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

	* tabulate.glade : add help button
	* dialog-tabulate.c (dialog_tabulate) : ditto
	* dialog-sheet-order.c (get_selected_sheet) : deleted
	(location_of_iter) : new
	(cb_selection_changed) : don't affect the real sheets
	(move_cb) : don't move the real sheets
	(cb_close_clicked) : replaced by cb_cancel_clicked
	(cb_ok_clicked) : new
	(cb_sheet_order_destroy) : free old_order
	(sheet_order_dialog) : set-up more buttons

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

	* commands.h (cmd_reorganize_sheets) : new
	* commands.c : implement cmd_reorganize_sheets
parent 86c39a0e
......@@ -9,7 +9,7 @@ J.H.M. Dassen (Ray), debian packaging.
Tom Dyas, plugin support.
Gergo Erdi, Gnumeric hacker.
John Gotts, rpm packaging.
Andreas J. Guelzow, statistics stuff.
Andreas J. Guelzow, Gnumeric hacker.
Jon K. Hellan, Gnumeric hacker.
Ross Ihaka, special functions.
Jukka-Pekka Iivonen, numerous functions and tools.
......
......@@ -52,7 +52,6 @@ Long term breakage
- Missing undo/redo for
- Add/duplicate sheet.
- Remove sheet.
- Reorder sheets.
- Delete Comment.
- Freeze panes.
- Changing summary info.
......
2002-02-29 Andreas J. Guelzow <aguelzow@taliesin.ca>
* commands.h (cmd_reorganize_sheets) : new
* commands.c : implement cmd_reorganize_sheets
2002-02-28 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/workbook-control-gui.c (wbcg_validation_msg) : delete
......
......@@ -26,6 +26,10 @@ Andreas:
* Port and redesign sort dialog
* Reenable the expr entry widgets in gurus
* Fix about dialog
* Convert lots of dialogs to use the new expr entry
widget correctly
* Add help buttons to various dialogs
* Make reordering of sheets undoable
Jody:
* Initial port to gnome2.
......
2002-02-29 Andreas J. Guelzow <aguelzow@taliesin.ca>
* commands.h (cmd_reorganize_sheets) : new
* commands.c : implement cmd_reorganize_sheets
2002-02-28 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/workbook-control-gui.c (wbcg_validation_msg) : delete
......
2002-02-29 Andreas J. Guelzow <aguelzow@taliesin.ca>
* commands.h (cmd_reorganize_sheets) : new
* commands.c : implement cmd_reorganize_sheets
2002-02-28 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/workbook-control-gui.c (wbcg_validation_msg) : delete
......
......@@ -4005,3 +4005,140 @@ cmd_object_move (WorkbookControl *wbc, SheetObject *so,
return command_push_undo (wbc, object);
}
/******************************************************************/
#define CMD_REORGANIZE_SHEETS_TYPE (cmd_reorganize_sheets_get_type ())
#define CMD_REORGANIZE_SHEETS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_REORGANIZE_SHEETS_TYPE, CmdReorganizeSheets))
typedef struct
{
GnumericCommand parent;
Workbook *wb;
GSList *old_order;
GSList *new_order;
GSList *old_names;
GSList *new_names;
} CmdReorganizeSheets;
GNUMERIC_MAKE_COMMAND (CmdReorganizeSheets, cmd_reorganize_sheets);
static gboolean
cmd_reorganize_sheets_apply (GSList *new_order, GSList *new_names)
{
GSList *this = new_order;
gint old_pos, new_pos = 0;
while (this) {
Sheet *sheet = this->data;
Workbook *wb = sheet->workbook;
old_pos = workbook_sheet_index_get (wb, sheet);
if (new_pos != old_pos) {
g_ptr_array_remove_index (wb->sheets, old_pos);
g_ptr_array_insert (wb->sheets, sheet, new_pos);
WORKBOOK_FOREACH_CONTROL (wb, view, control,
wb_control_sheet_move (control,
sheet, new_pos););
sheet_set_dirty (sheet, TRUE);
}
new_pos++;
this = this->next;
}
return FALSE;
}
static gboolean
cmd_reorganize_sheets_undo (GnumericCommand *cmd, WorkbookControl *wbc)
{
CmdReorganizeSheets *me = CMD_REORGANIZE_SHEETS (cmd);
g_return_val_if_fail (me != NULL, TRUE);
return cmd_reorganize_sheets_apply (me->old_order, me->old_names);
}
static gboolean
cmd_reorganize_sheets_redo (GnumericCommand *cmd, WorkbookControl *wbc)
{
CmdReorganizeSheets *me = CMD_REORGANIZE_SHEETS (cmd);
g_return_val_if_fail (me != NULL, TRUE);
return cmd_reorganize_sheets_apply (me->new_order, me->new_names);
}
static void
cmd_reorganize_free_names (gpointer data, gpointer user_data)
{
g_free (data);
}
static void
cmd_reorganize_sheets_finalize (GObject *cmd)
{
CmdReorganizeSheets *me = CMD_REORGANIZE_SHEETS (cmd);
if (me->old_order)
g_slist_free (me->old_order);
me->old_order = NULL;
if (me->new_order)
g_slist_free (me->new_order);
me->new_order = NULL;
if (me->old_names) {
g_slist_foreach (me->old_names, cmd_reorganize_free_names, NULL);
g_slist_free (me->old_names);
}
me->old_names = NULL;
if (me->new_names) {
g_slist_foreach (me->old_names, cmd_reorganize_free_names, NULL);
g_slist_free (me->new_names);
}
me->new_names = NULL;
gnumeric_command_finalize (cmd);
}
gboolean
cmd_reorganize_sheets (WorkbookControl *wbc, GSList *old_order, GSList *new_order,
GSList *old_names, GSList *new_names)
{
GObject *obj;
CmdReorganizeSheets *me;
Workbook *wb = wb_control_workbook (wbc);
obj = g_object_new (CMD_REORGANIZE_SHEETS_TYPE, NULL);
me = CMD_REORGANIZE_SHEETS (obj);
/* Store the specs for the object */
me->wb = wb;
me->old_order = old_order;
me->new_order = new_order;
me->old_names = old_names;
me->new_names = new_names;
me->parent.sheet = NULL;
me->parent.size = 1;
if (new_order == NULL ) {
if (new_names == NULL)
me->parent.cmd_descriptor = g_strdup ("Nothing to do?");
else if (new_names->next == NULL)
me->parent.cmd_descriptor = g_strdup_printf (_("Rename sheet '%s' '%s'"),
(char *)old_names->data,
(char *)new_names->data);
else
me->parent.cmd_descriptor = g_strdup (_("Renaming Sheets"));
} else {
if (new_names == NULL)
me->parent.cmd_descriptor = g_strdup (_("Reordering Sheets"));
else
me->parent.cmd_descriptor = g_strdup (_("Reorganizing Sheets"));
}
/* Register the command object */
return command_push_undo (wbc, obj);
}
/******************************************************************/
......@@ -37,9 +37,6 @@ gboolean cmd_paste_cut (WorkbookControl *wbc,
gboolean cmd_paste_copy (WorkbookControl *wbc,
PasteTarget const *pt, CellRegion *content);
gboolean cmd_rename_sheet (WorkbookControl *wbc,
char const *old_name, char const *new_name);
gboolean cmd_sort (WorkbookControl *wbc, SortData *data);
gboolean cmd_format (WorkbookControl *wbc, Sheet *sheet,
......@@ -87,4 +84,8 @@ gboolean cmd_object_move (WorkbookControl *wbc, SheetObject *so,
SheetObjectAnchor const *old_anchor,
gboolean resize);
gboolean cmd_rename_sheet (WorkbookControl *wbc, const char *old_name, const char *new_name);
gboolean cmd_reorganize_sheets (WorkbookControl *wbc, GSList *old_order, GSList *new_order,
GSList *old_names, GSList *new_names);
#endif /* GNUMERIC_COMMANDS_H */
2002-02-29 Andreas J. Guelzow <aguelzow@taliesin.ca>
* tabulate.glade : add help button
* dialog-tabulate.c (dialog_tabulate) : ditto
* dialog-sheet-order.c (get_selected_sheet) : deleted
(location_of_iter) : new
(cb_selection_changed) : don't affect the real sheets
(move_cb) : don't move the real sheets
(cb_close_clicked) : replaced by cb_cancel_clicked
(cb_ok_clicked) : new
(cb_sheet_order_destroy) : free old_order
(sheet_order_dialog) : set-up more buttons
2002-02-28 Andreas J. Guelzow <aguelzow@taliesin.ca>
* dialog-tabulate.c (ok_clicked) : lots of changes to use the new expr entry
......
......@@ -16,6 +16,7 @@
#include <workbook-view.h>
#include <workbook.h>
#include <sheet.h>
#include <commands.h>
#include <libgnome/gnome-i18n.h>
#include <glade/glade.h>
......@@ -30,7 +31,10 @@ typedef struct {
GtkListStore *model;
GtkWidget *up_btn;
GtkWidget *down_btn;
GtkWidget *close_btn;
GtkWidget *ok_btn;
GtkWidget *cancel_btn;
GSList *old_order;
} SheetManager;
enum {
......@@ -39,48 +43,54 @@ enum {
NUM_COLMNS
};
static Sheet *
get_selected_sheet (SheetManager *state)
static gint
location_of_iter (GtkTreeIter *iter, GtkListStore *model)
{
GtkTreeSelection *selection;
GtkTreeIter iter;
GValue value = {0, };
Sheet *sheet;
g_return_val_if_fail (state != NULL, NULL);
selection = gtk_tree_view_get_selection (state->sheet_list);
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return NULL;
gtk_tree_model_get_value (GTK_TREE_MODEL (state->model),
&iter, SHEET_POINTER, &value);
sheet = g_value_get_pointer (&value);
g_value_unset (&value);
if (sheet != NULL) {
g_return_val_if_fail (IS_SHEET (sheet), NULL);
Sheet *sheet, *this_sheet;
GtkTreeIter this_iter;
gint n = 0;
gtk_tree_model_get (GTK_TREE_MODEL (model), iter, SHEET_POINTER, &sheet, -1);
while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (model),
&this_iter, NULL, n)) {
gtk_tree_model_get (GTK_TREE_MODEL (model), &this_iter, SHEET_POINTER,
&this_sheet, -1);
if (this_sheet == sheet)
return n;
n++;
}
return sheet;
g_warning ("We should have never gotten to this point!\n");
return -1;
}
/**
* Refreshes the buttons on a row (un)selection and selects the chosen sheet
* for this view.
*/
void
static void
cb_selection_changed (GtkTreeSelection *ignored, SheetManager *state)
{
Sheet *sheet = get_selected_sheet (state);
if (sheet != NULL) {
int i = workbook_sheet_index_get (state->wb, sheet);
wb_control_sheet_focus (WORKBOOK_CONTROL (state->wbcg), sheet);
gtk_widget_set_sensitive (state->up_btn,
i > 0);
gtk_widget_set_sensitive (state->down_btn,
i < (workbook_sheet_count (state->wb)-1));
GtkTreeIter iter;
GtkTreeIter this_iter;
gint row;
GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list);
if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
gtk_widget_set_sensitive (state->up_btn, FALSE);
gtk_widget_set_sensitive (state->down_btn, FALSE);
return;
}
gtk_widget_set_sensitive (state->up_btn,
location_of_iter (&iter, state->model) > 0);
row = location_of_iter (&iter, state->model);
gtk_widget_set_sensitive (state->down_btn,
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model),
&this_iter, NULL, row+1));
}
static void
......@@ -128,8 +138,11 @@ populate_sheet_list (SheetManager *state)
-1);
if (sheet == cur_sheet)
gtk_tree_selection_select_iter (selection, &iter);
state->old_order = g_slist_prepend (state->old_order, sheet);
}
state->old_order = g_slist_reverse (state->old_order);
column = gtk_tree_view_column_new_with_attributes ("Sheets",
gtk_cell_renderer_text_new (),
"text", SHEET_NAME, NULL);
......@@ -149,45 +162,77 @@ populate_sheet_list (SheetManager *state)
gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (state->sheet_list));
}
/* Actual implementation of the re-ordering sheets */
static void
move_cb (SheetManager *state, gint direction)
{
Sheet *sheet = get_selected_sheet (state);
if (sheet != NULL) {
GtkTreeIter iter;
GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list);
workbook_sheet_move (sheet, direction);
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_list_store_remove (state->model, &iter);
gtk_list_store_insert (state->model, &iter,
workbook_sheet_index_get (sheet->workbook, sheet));
gtk_list_store_set (state->model, &iter,
SHEET_NAME, sheet->name_unquoted,
SHEET_POINTER, sheet,
-1);
gtk_tree_selection_select_iter (selection, &iter);
wb_view_sheet_focus (
wb_control_view (WORKBOOK_CONTROL (state->wbcg)),
sheet);
char* name;
Sheet * sheet;
GtkTreeIter iter;
gint row;
GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list);
/* this is a little hack-ish, but we need to refresh the buttons */
cb_selection_changed (NULL, state);
}
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
SHEET_NAME, &name,
SHEET_POINTER, &sheet,
-1);
row = location_of_iter (&iter, state->model);
if (row + direction < 0)
return;
gtk_list_store_remove (state->model, &iter);
gtk_list_store_insert (state->model, &iter, row + direction);
gtk_list_store_set (state->model, &iter,
SHEET_NAME, name,
SHEET_POINTER, sheet,
-1);
gtk_tree_selection_select_iter (selection, &iter);
g_free (name);
wb_view_sheet_focus (
wb_control_view (WORKBOOK_CONTROL (state->wbcg)),
sheet);
/* this is a little hack-ish, but we need to refresh the buttons */
cb_selection_changed (NULL, state);
}
static void cb_up (GtkWidget *w, SheetManager *state) { move_cb (state, -1); }
static void cb_down (GtkWidget *w, SheetManager *state) { move_cb (state, 1); }
static void
cb_close_clicked (GtkWidget *ignore, SheetManager *state)
cb_cancel_clicked (GtkWidget *ignore, SheetManager *state)
{
gtk_widget_destroy (GTK_WIDGET (state->dialog));
gtk_widget_destroy (GTK_WIDGET (state->dialog));
}
static void
cb_ok_clicked (GtkWidget *ignore, SheetManager *state)
{
GSList *new_order = NULL;
Sheet *this_sheet;
GtkTreeIter this_iter;
gint n = 0;
while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model),
&this_iter, NULL, n)) {
gtk_tree_model_get (GTK_TREE_MODEL (state->model), &this_iter, SHEET_POINTER,
&this_sheet, -1);
new_order = g_slist_prepend (new_order, this_sheet);
n++;
}
new_order = g_slist_reverse (new_order);
/* FIXME we shouldn't bother invoking cmd_reorganize_sheets unless there are changes */
if (!cmd_reorganize_sheets (WORKBOOK_CONTROL (state->wbcg), state->old_order,
new_order, NULL, NULL)) {
state->old_order = NULL;
gtk_widget_destroy (GTK_WIDGET (state->dialog));
} else
g_slist_free (new_order);
}
static void
......@@ -196,6 +241,10 @@ cb_sheet_order_destroy (GtkWidget *ignored, SheetManager *state)
wbcg_edit_detach_guru (state->wbcg);
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
if (state->old_order != NULL) {
g_slist_free (state->old_order);
state->old_order = NULL;
}
g_free (state);
}
......@@ -218,7 +267,9 @@ dialog_sheet_order (WorkbookControlGUI *wbcg)
state->dialog = glade_xml_get_widget (gui, "sheet-order-dialog");
state->up_btn = glade_xml_get_widget (gui, "up_button");
state->down_btn = glade_xml_get_widget (gui, "down_button");
state->close_btn = glade_xml_get_widget (gui, "close_button");
state->ok_btn = glade_xml_get_widget (gui, "ok_button");
state->cancel_btn = glade_xml_get_widget (gui, "cancel_button");
state->old_order = NULL;
gtk_button_stock_alignment_set (GTK_BUTTON (state->up_btn), 0., .5, 0., 0.);
gtk_button_stock_alignment_set (GTK_BUTTON (state->down_btn), 0., .5, 0., 0.);
......@@ -231,9 +282,17 @@ dialog_sheet_order (WorkbookControlGUI *wbcg)
g_signal_connect (G_OBJECT (state->down_btn),
"clicked",
G_CALLBACK (cb_down), state);
g_signal_connect (G_OBJECT (state->close_btn),
g_signal_connect (G_OBJECT (state->ok_btn),
"clicked",
G_CALLBACK (cb_close_clicked), state);
G_CALLBACK (cb_ok_clicked), state);
g_signal_connect (G_OBJECT (state->cancel_btn),
"clicked",
G_CALLBACK (cb_cancel_clicked), state);
/* FIXME: Add correct helpfile address */
gnumeric_init_help_button (
glade_xml_get_widget (state->gui, "help_button"),
"sheet-order.html");
/* a candidate for merging into attach guru */
g_signal_connect (G_OBJECT (state->dialog),
......
......@@ -574,6 +574,11 @@ dialog_tabulate (WorkbookControlGUI *wbcg, Sheet *sheet)
g_signal_connect (G_OBJECT (glade_xml_get_widget (gui, "cancel_button")),
"clicked",
G_CALLBACK (cancel_clicked), dd);
/* FIXME: Add correct helpfile address */
gnumeric_init_help_button (
glade_xml_get_widget (gui, "help_button"),
"fill-tabulate.html");
g_signal_connect (G_OBJECT (dialog),
"destroy",
G_CALLBACK (dialog_destroy), dd);
......
......@@ -3,9 +3,9 @@
<glade-interface>
<widget class="GtkWindow" id="sheet-order-dialog">
<widget class="GtkDialog" id="sheet-order-dialog">
<property name="default_width">200</property>
<property name="default_height">300</property>
<property name="default_height">200</property>
<property name="visible">no</property>
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
......@@ -14,6 +14,67 @@
<property name="allow_grow">yes</property>
<property name="window_position">GTK_WIN_POS_MOUSE</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="homogeneous">no</property>
<property name="spacing">8</property>
<property name="visible">yes</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
<property name="spacing">8</property>
<property name="visible">yes</property>
<child>
<widget class="GtkButton" id="help_button">
<property name="can_default">yes</property>
<property name="can_focus">yes</property>
<property name="visible">yes</property>
<property name="label">gtk-help</property>
<property name="use_stock">yes</property>
<property name="use_underline">yes</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="ok_button">
<property name="can_default">yes</property>
<property name="has_default">yes</property>
<property name="can_focus">yes</property>
<property name="visible">yes</property>
<property name="label">gtk-ok</property>
<property name="use_stock">yes</property>
<property name="use_underline">yes</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="cancel_button">
<property name="can_default">yes</property>
<property name="can_focus">yes</property>
<property name="visible">yes</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">yes</property>
<property name="use_underline">yes</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">no</property>
<property name="fill">yes</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="homogeneous">no</property>
<property name="spacing">0</property>
<property name="visible">yes</property>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
......@@ -22,6 +83,8 @@
<child>
<widget class="GtkScrolledWindow" id="scrolled">
<property name="width_request">100</property>
<property name="height_request">120</property>
<property name="visible">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
......@@ -37,7 +100,7 @@
</child>
<child>
<widget class="GtkVBox" id="vbox1">
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
......@@ -93,32 +156,6 @@
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment3">
<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="close_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
</widget>
</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>
......@@ -128,6 +165,21 @@
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">yes</property>
<property name="fill">yes</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">4</property>
<property name="expand">yes</property>
<property name="fill">yes</property>
</packing>
</child>
</widget>
</glade-interface>
......@@ -23,6 +23,17 @@
<property name="spacing">8</property>
<property name="visible">yes</property>
<child>
<widget class="GtkButton" id="help_button">
<property name="can_default">yes</property>
<property name="can_focus">yes</property>
<property name="visible">yes</property>
<property name="label">gtk-help</property>
<property name="use_stock">yes</property>
<property name="use_underline">yes</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="ok_button">
<property name="can_default">yes</property>
......
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