Commit 7bbc3e9f authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

detach guru. (get_selected_sheet) : new util. (cb_selection_changed) :

2002-01-28  Jody Goldberg <jody@gnome.org>

	* dialog-sheet-order.c (cb_sheet_order_destroy) : detach guru.
	(get_selected_sheet) : new util.
	(cb_selection_changed) : rework.
	(populate_sheet_list) : simplify.
	(move_cb) : implement.

2002-01-28  Jody Goldberg <jody@gnome.org>

	* src/workbook.c (workbook_sheet_move) : flag if the move did
	  anything.
parent 56273a9c
2002-01-28 Jody Goldberg <jody@gnome.org>
* src/workbook.c (workbook_sheet_move) : flag if the move did
anything.
* src/workbook-object-toolbar.c : adjust to the new creation format.
* src/workbook-edit.c (wbcg_edit_has_guru) : return the actual guru.
......@@ -31,7 +34,6 @@
parameters
(consolidate_add_source) : ditto
>>>>>>> 1.1833
2002-01-27 Seth Nickell <snickell@stanford.edu>
* Makefile.am:
......
2002-01-28 Jody Goldberg <jody@gnome.org>
* src/workbook.c (workbook_sheet_move) : flag if the move did
anything.
* src/workbook-object-toolbar.c : adjust to the new creation format.
* src/workbook-edit.c (wbcg_edit_has_guru) : return the actual guru.
......@@ -31,7 +34,6 @@
parameters
(consolidate_add_source) : ditto
>>>>>>> 1.1833
2002-01-27 Seth Nickell <snickell@stanford.edu>
* Makefile.am:
......
2002-01-28 Jody Goldberg <jody@gnome.org>
* src/workbook.c (workbook_sheet_move) : flag if the move did
anything.
* src/workbook-object-toolbar.c : adjust to the new creation format.
* src/workbook-edit.c (wbcg_edit_has_guru) : return the actual guru.
......@@ -31,7 +34,6 @@
parameters
(consolidate_add_source) : ditto
>>>>>>> 1.1833
2002-01-27 Seth Nickell <snickell@stanford.edu>
* Makefile.am:
......
2002-01-28 Jody Goldberg <jody@gnome.org>
* src/workbook.c (workbook_sheet_move) : flag if the move did
anything.
* src/workbook-object-toolbar.c : adjust to the new creation format.
* src/workbook-edit.c (wbcg_edit_has_guru) : return the actual guru.
......@@ -31,7 +34,6 @@
parameters
(consolidate_add_source) : ditto
>>>>>>> 1.1833
2002-01-27 Seth Nickell <snickell@stanford.edu>
* Makefile.am:
......
2002-01-28 Jody Goldberg <jody@gnome.org>
* dialog-sheet-order.c (cb_sheet_order_destroy) : detach guru.
(get_selected_sheet) : new util.
(cb_selection_changed) : rework.
(populate_sheet_list) : simplify.
(move_cb) : implement.
2002-01-28 Jody Goldberg <jody@gnome.org>
* sheet-order.glade : rewrite.
......
......@@ -27,34 +27,60 @@ typedef struct {
GladeXML *gui;
GtkWidget *dialog;
GtkTreeView *sheet_list;
GtkListStore *model;
GtkWidget *up_btn;
GtkWidget *down_btn;
GtkWidget *close_btn;
gint current_row;
} SheetManager;
enum {
SHEET_NAME,
SHEET_POINTER,
NUM_COLMNS
};
static Sheet *
get_selected_sheet (SheetManager *state)
{
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);
}
return sheet;
}
/**
* Refreshes the buttons on a row (un)selection
* And moves the representative page/sheet in the notebook
* To the foreground
* Refreshes the buttons on a row (un)selection and selects the chosen sheet
* for this view.
*/
void
cb_row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
SheetManager *state)
cb_selection_changed (GtkTreeSelection *ignored, SheetManager *state)
{
#if 0
state->current_row = row;
gtk_widget_set_sensitive (state->up_btn, row > 0);
gtk_widget_set_sensitive (state->down_btn, can_go);
can_go = !(row >= (numrows - 1)); /* bottom row test */
gint numrows = state->sheet_list->rows;
/* Display/focus on the selected sheet underneath us */
wb_control_sheet_focus (WORKBOOK_CONTROL (state->wbcg), sheet);
gtk_clist_get_row_data (GTK_CLIST (state->sheet_list), row);
#endif
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));
}
}
/* Add all of the sheets to the sheet_list */
......@@ -62,56 +88,75 @@ static void
populate_sheet_list (SheetManager *state)
{
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
GtkTreeIter iter;
GtkWidget *scrolled = glade_xml_get_widget (state->gui, "scrolled");
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
Sheet *cur_sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg));
int i, n = workbook_sheet_count (state->wb);
state->model = gtk_list_store_new (NUM_COLMNS,
G_TYPE_STRING, G_TYPE_POINTER);
state->sheet_list = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL (state->model)));
selection = gtk_tree_view_get_selection (state->sheet_list);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
for (i = 0 ; i < n ; i++) {
Sheet *sheet = workbook_sheet_by_index (state->wb, i);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, sheet->name_unquoted,
gtk_list_store_append (state->model, &iter);
gtk_list_store_set (state->model, &iter,
SHEET_NAME, sheet->name_unquoted,
SHEET_POINTER, sheet,
-1);
if (sheet == cur_sheet)
gtk_tree_selection_select_iter (selection, &iter);
}
state->sheet_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
column = gtk_tree_view_column_new_with_attributes ("Sheets",
gtk_cell_renderer_text_new (),
"text", 0, NULL);
"text", SHEET_NAME, NULL);
gtk_tree_view_column_set_sort_column_id (column, 0);
gtk_tree_view_append_column (GTK_TREE_VIEW (state->sheet_list), column);
gtk_widget_show_all (GTK_WIDGET (state->sheet_list));
gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (state->sheet_list));
gtk_tree_view_append_column (state->sheet_list, column);
gtk_tree_view_set_reorderable (state->sheet_list, TRUE);
/* Init the buttons & selection */
cb_row_activated (state->sheet_list, NULL, state);
cb_selection_changed (NULL, state);
g_signal_connect (selection,
"changed",
G_CALLBACK (cb_selection_changed), 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)
{
gint numrows = 0;
Sheet *sheet = get_selected_sheet (state);
if (sheet != NULL) {
GtkTreeIter iter;
GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list);
#if 0
if (numrows && state->current_row >= 0) {
GList *selection = GTK_CLIST (state->sheet_list)->selection;
Sheet *sheet = gtk_clist_get_row_data (GTK_CLIST (state->sheet_list), state->current_row);
gint source = GPOINTER_TO_INT (g_list_nth_data (selection, 0));
gint dest = source + direction;
WorkbookView *view = wb_control_view (
WORKBOOK_CONTROL (state->wbcg));
workbook_sheet_move (sheet, direction);
gtk_clist_row_move (GTK_CLIST (state->sheet_list), source, dest);
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
workbook_sheet_move (sheet, direction);
wb_view_sheet_focus (view, sheet);
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);
/* this is a little hack-ish, but we need to refresh the buttons */
cb_row_activated (state->sheet_list, NULL, state);
cb_selection_changed (NULL, state);
}
#endif
}
static void cb_up (GtkWidget *w, SheetManager *state) { move_cb (state, -1); }
......@@ -126,6 +171,7 @@ close_clicked_cb (GtkWidget *ignore, SheetManager *state)
static void
cb_sheet_order_destroy (GtkWidget *ignored, SheetManager *state)
{
wbcg_edit_detach_guru (state->wbcg);
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
g_free (state);
......@@ -152,13 +198,8 @@ dialog_sheet_order (WorkbookControlGUI *wbcg)
state->down_btn = glade_xml_get_widget (gui, "down_button");
state->close_btn = glade_xml_get_widget (gui, "close_button");
state->current_row = -1;
populate_sheet_list (state);
gtk_signal_connect (GTK_OBJECT (state->sheet_list),
"row_activated",
GTK_SIGNAL_FUNC (cb_row_activated), state);
gtk_signal_connect (GTK_OBJECT (state->up_btn),
"clicked",
GTK_SIGNAL_FUNC (cb_up), state);
......@@ -174,5 +215,5 @@ dialog_sheet_order (WorkbookControlGUI *wbcg)
gnumeric_non_modal_dialog (state->wbcg, GTK_WINDOW (state->dialog));
wbcg_edit_attach_guru (state->wbcg, GTK_WIDGET (state->dialog));
gtk_widget_show (GTK_WIDGET (state->dialog));
gtk_widget_show_all (GTK_WIDGET (state->dialog));
}
......@@ -81,7 +81,7 @@ Sheet *workbook_sheet_add (Workbook *wb,
Sheet const *insert_after,
gboolean make_dirty);
void workbook_sheet_delete (Sheet *sheet);
void workbook_sheet_move (Sheet *sheet, int direction);
gboolean workbook_sheet_move (Sheet *sheet, int direction);
char *workbook_sheet_get_free_name (Workbook *wb,
const char *base,
gboolean always_suffix,
......
......@@ -1083,17 +1083,17 @@ workbook_sheet_delete (Sheet *sheet)
workbook_sheet_detach (wb, sheet);
}
/*
/**
* Moves the sheet up or down @direction spots in the sheet list
* If @direction is positive, move left. If positive, move right.
*/
void
gboolean
workbook_sheet_move (Sheet *sheet, int direction)
{
Workbook *wb;
gint old_pos, new_pos;
g_return_if_fail (IS_SHEET (sheet));
g_return_val_if_fail (IS_SHEET (sheet), FALSE);
wb = sheet->workbook;
old_pos = workbook_sheet_index_get (wb, sheet);
......@@ -1105,7 +1105,9 @@ workbook_sheet_move (Sheet *sheet, int direction)
WORKBOOK_FOREACH_CONTROL (wb, view, control,
wb_control_sheet_move (control, sheet, new_pos););
sheet_set_dirty (sheet, TRUE);
return TRUE;
}
return FALSE;
}
/**
......
......@@ -81,7 +81,7 @@ Sheet *workbook_sheet_add (Workbook *wb,
Sheet const *insert_after,
gboolean make_dirty);
void workbook_sheet_delete (Sheet *sheet);
void workbook_sheet_move (Sheet *sheet, int direction);
gboolean workbook_sheet_move (Sheet *sheet, int direction);
char *workbook_sheet_get_free_name (Workbook *wb,
const char *base,
gboolean always_suffix,
......
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