Commit 32cc07b9 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Warn the user if he overwrites something accidentally by dropping cells in

1999-02-12  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/item-cursor.c (item_cursor_target_region_ok): Warn the user
	if he overwrites something accidentally by dropping cells in the
	target location.

	* src/sheet.c (sheet_is_region_empty): New function.
parent 35cf24d8
1999-02-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_target_region_ok): Warn the user
if he overwrites something accidentally by dropping cells in the
target location.
* src/sheet.c (sheet_is_region_empty): New function.
1999-02-12 Michael Meeks <sca20@cam.ac.uk>
* plugins/excel/ms-excel.c (biff_get_global_string):
......
1999-02-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_target_region_ok): Warn the user
if he overwrites something accidentally by dropping cells in the
target location.
* src/sheet.c (sheet_is_region_empty): New function.
1999-02-12 Michael Meeks <sca20@cam.ac.uk>
* plugins/excel/ms-excel.c (biff_get_global_string):
......
1999-02-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_target_region_ok): Warn the user
if he overwrites something accidentally by dropping cells in the
target location.
* src/sheet.c (sheet_is_region_empty): New function.
1999-02-12 Michael Meeks <sca20@cam.ac.uk>
* plugins/excel/ms-excel.c (biff_get_global_string):
......
1999-02-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_target_region_ok): Warn the user
if he overwrites something accidentally by dropping cells in the
target location.
* src/sheet.c (sheet_is_region_empty): New function.
1999-02-12 Michael Meeks <sca20@cam.ac.uk>
* plugins/excel/ms-excel.c (biff_get_global_string):
......
......@@ -481,10 +481,34 @@ item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
static gboolean
item_cursor_target_region_ok (ItemCursor *item_cursor)
{
/* FIXME: check the destination range and if any cell
* has values, ask for confirmation
*/
return TRUE;
GtkWidget *message;
GnomeCanvas *canvas = GNOME_CANVAS_ITEM (item_cursor)->canvas;
GtkWidget *window;
int v;
v = sheet_is_region_empty (
item_cursor->sheet,
item_cursor->start_col, item_cursor->start_row,
item_cursor->end_col, item_cursor->end_row);
if (v)
return TRUE;
message = gnome_message_box_new (
_("The cells dragged will overwrite the contents of the\n"
"existing cells in that range. Do you want me to replace\n"
"the contents in this region?"),
GNOME_MESSAGE_BOX_WARNING,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
window = gtk_widget_get_toplevel (GTK_WIDGET (canvas));
gnome_dialog_set_parent (GNOME_DIALOG (message), window);
v = gnome_dialog_run (GNOME_DIALOG (message));
if (v == 0)
return TRUE;
return FALSE;
}
typedef enum {
......@@ -511,8 +535,9 @@ item_cursor_do_action (ItemCursor *item_cursor, ActionType action, guint32 time)
return;
case ACTION_COPY_CELLS:
if (!item_cursor_target_region_ok (item_cursor))
if (!item_cursor_target_region_ok (item_cursor)){
return;
}
if (!sheet_selection_copy (sheet))
return;
sheet_selection_paste (sheet, col, row, PASTE_ALL_TYPES, time);
......
......@@ -1868,6 +1868,40 @@ sheet_cell_foreach_range (Sheet *sheet, int only_existing,
return TRUE;
}
static gboolean
fail_if_found (Sheet *sheet, int col, int row, Cell *cell, void *user_data)
{
return FALSE;
}
/**
* sheet_is_region_empty:
* @sheet: sheet to check
* @start_col: starting column
* @start_row: starting row
* @end_col: end column
* @end_row: end row
*
* Returns TRUE if the specified region of the @sheet does not
* contain any cells.
*
* FIXME: Perhaps this routine should be extended to allow testing for specific
* features of a cell rather than just the existance of the cell.
*/
gboolean
sheet_is_region_empty (Sheet *sheet, int start_col, int start_row, int end_col, int end_row)
{
g_return_val_if_fail (sheet != NULL, TRUE);
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
g_return_val_if_fail (start_col <= end_col, TRUE);
g_return_val_if_fail (start_row <= end_row, TRUE);
return sheet_cell_foreach_range (
sheet, TRUE, start_col, start_row, end_col, end_row,
fail_if_found, NULL);
}
static gint
CRowSort (gconstpointer a, gconstpointer b)
{
......
......@@ -220,6 +220,8 @@ void sheet_cell_comment_unlink (Cell *cell);
void sheet_cell_formula_link (Cell *cell);
void sheet_cell_formula_unlink (Cell *cell);
gboolean sheet_is_region_empty (Sheet *sheet, int start_col, int start_row,
int end_col, int end_row);
/* Create new ColRowInfos from the default sheet style */
ColRowInfo *sheet_col_new (Sheet *sheet);
......
......@@ -9,6 +9,7 @@
#include <gnome.h>
#include <gdk/gdkkeysyms.h>
#include "gnumeric.h"
#include "eval.h"
#include "gnumeric-util.h"
#include "gnumeric-sheet.h"
#include "sheet-object.h"
......
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