Commit fbe12ed1 authored by Morten Welinder's avatar Morten Welinder

Introspection: copy and paste.

parent 433ca832
2018-04-12 Morten Welinder <terra@gnome.org>
* src/sheet-merge.c (gnm_sheet_merge_remove): Drop unused command
context argument. All callers changed.
2018-04-11 Morten Welinder <terra@gnome.org>
* src/workbook.c: Make Workbook a more proper object by adding a
......
......@@ -11,7 +11,6 @@ be useful in this setting and actually work.
This is incomplete. In particular, I'll have to look at
* Expressions other than via text
* File i/o
* Copy and paste
* Installing a gi override module for more pythony structure handling
-----------------------------------------------------------------------------
......@@ -81,8 +80,10 @@ Sheet: [GObject]
GnmCell: [Boxed structure] [2]
name()
get_value()
get_entered_text()
pos
GnmSheetSize: [Simple structure]
max_cols
max_rows
......@@ -133,6 +134,30 @@ GnmSheetVisibility: [Enum]
VERY_HIDDEN
PasteFlags: [Enum]
CONTENTS
AS_VALUES
FORMATS
COMMENTS
OBJECTS
OPER_ADD
OPER_SUB
OPER_MULT
OPER_DIV
TRANSPOSE
LINK
SKIP_BLANKS
DONT_MERGE
IGNORE_COMMENTS_AT_ORIGIN
UPDATE_ROW_HEIGHT
EXPR_LOCAL_RELOCATE
NO_RECALC
FLIP_H
FLIP_V
ALL_TYPES
DEFAULT
GnmStyle: [Boxed structure]
new()
new_default()
......@@ -179,6 +204,10 @@ GnmStyle: [Boxed structure]
get_effective_text_wrap()
visible_in_blank()
Gnm (i.e., not in a class):
clipboard_copy_range(sheet,range)
Footnotes:
......
......@@ -4906,8 +4906,7 @@ excel_read_MERGECELLS (BiffQuery *q, ExcelReadSheet *esheet)
/* Do this early because the _remove can kill r2. */
r = range_union (&r, r2);
gnm_sheet_merge_remove (esheet->sheet, r2,
GO_CMD_CONTEXT (esheet->container.importer->context));
gnm_sheet_merge_remove (esheet->sheet, r2);
g_slist_free (overlap);
}
gnm_sheet_merge_add (esheet->sheet, &r, FALSE,
......
......@@ -86,9 +86,7 @@ gnm_cell_copy_get_type (void)
static GnmPasteTarget *
gnm_paste_target_copy (GnmPasteTarget *pt)
{
GnmPasteTarget *res = g_new (GnmPasteTarget, 1);
memcpy (res, pt, sizeof (GnmPasteTarget));
return res;
return g_memdup (pt, sizeof (*pt));
}
GType
......@@ -104,6 +102,15 @@ gnm_paste_target_get_type (void)
return t;
}
GnmPasteTarget *
gnm_paste_target_new (Sheet *sheet, GnmRange *r, GnmPasteFlags flags)
{
GnmPasteTarget *res = g_new (GnmPasteTarget, 1);
paste_target_init (res, sheet, r, flags);
return res;
}
static gboolean
cell_has_expr_or_number_or_blank (GnmCell const * cell)
{
......@@ -403,7 +410,7 @@ range_flip_v (GnmRange *range, Sheet const *sheet, int const *data)
* clipboard_paste_region:
* @cr: The GnmCellRegion to paste.
* @pt: Where to paste the values.
* @cc: The context for error handling.
* @cc: (nullable): The context for error handling.
*
* Pastes the supplied GnmCellRegion (@cr) into the supplied
* GnmPasteTarget (@pt). This operation is not undoable. It does not auto grow
......@@ -476,9 +483,11 @@ clipboard_paste_region (GnmCellRegion const *cr,
}
if (cr->not_as_contents && (pt->paste_flags & PASTE_CONTENTS)) {
go_cmd_context_error_invalid (cc,
_("Unable to paste"),
_("Contents can only be pasted by value or by link."));
if (cc)
go_cmd_context_error_invalid
(cc,
_("Unable to paste"),
_("Contents can only be pasted by value or by link."));
return TRUE;
}
......@@ -489,7 +498,8 @@ clipboard_paste_region (GnmCellRegion const *cr,
_("destination does not have an even multiple of source columns (%d vs %d)\n\n"
"Try selecting a single cell or an area of the same shape and size."),
dst_cols, src_cols);
go_cmd_context_error_invalid (cc, _("Unable to paste"), msg);
if (cc)
go_cmd_context_error_invalid (cc, _("Unable to paste"), msg);
g_free (msg);
return TRUE;
}
......@@ -500,16 +510,19 @@ clipboard_paste_region (GnmCellRegion const *cr,
_("destination does not have an even multiple of source rows (%d vs %d)\n\n"
"Try selecting a single cell or an area of the same shape and size."),
dst_rows, src_rows);
go_cmd_context_error_invalid (cc, _("Unable to paste"), msg);
if (cc)
go_cmd_context_error_invalid (cc, _("Unable to paste"), msg);
g_free (msg);
return TRUE;
}
if ((pt->range.start.col + dst_cols) > gnm_sheet_get_max_cols (pt->sheet) ||
(pt->range.start.row + dst_rows) > gnm_sheet_get_max_rows (pt->sheet)) {
go_cmd_context_error_invalid (cc,
_("Unable to paste"),
_("result passes the sheet boundary"));
if (cc)
go_cmd_context_error_invalid
(cc,
_("Unable to paste"),
_("result passes the sheet boundary"));
return TRUE;
}
......@@ -834,9 +847,10 @@ clipboard_copy_obj (Sheet *sheet, GSList *objects)
}
GnmPasteTarget*
paste_target_init (GnmPasteTarget *pt, Sheet *sheet, GnmRange const *r, int flags)
paste_target_init (GnmPasteTarget *pt, Sheet *sheet,
GnmRange const *r, GnmPasteFlags flags)
{
pt->sheet = sheet;
pt->sheet = sheet; // No ref
pt->range = *r;
pt->paste_flags = flags;
return pt;
......
......@@ -7,7 +7,7 @@
G_BEGIN_DECLS
enum {
typedef enum {
PASTE_CONTENTS = 1 << 0, /* either CONTENTS or AS_VALUES */
PASTE_AS_VALUES = 1 << 1, /* can be applied, not both */
PASTE_FORMATS = 1 << 2,
......@@ -45,11 +45,12 @@ enum {
/* Whether the paste flips or not */
PASTE_FLIP_H = 1 << 17,
PASTE_FLIP_V = 1 << 18
};
PASTE_FLIP_V = 1 << 18,
PASTE_ALL_TYPES = (PASTE_CONTENTS | PASTE_FORMATS | PASTE_COMMENTS | PASTE_OBJECTS),
PASTE_DEFAULT = PASTE_ALL_TYPES
} GnmPasteFlags;
#define PASTE_ALL_TYPES (PASTE_CONTENTS | PASTE_FORMATS | PASTE_COMMENTS | PASTE_OBJECTS)
#define PASTE_DEFAULT PASTE_ALL_TYPES
#define PASTE_OPER_MASK (PASTE_OPER_ADD | PASTE_OPER_SUB | PASTE_OPER_MULT | PASTE_OPER_DIV)
typedef struct {
......@@ -78,11 +79,13 @@ struct _GnmCellRegion {
struct _GnmPasteTarget {
Sheet *sheet;
GnmRange range;
int paste_flags;
GnmPasteFlags paste_flags;
};
GType gnm_paste_target_get_type (void);
GnmPasteTarget *gnm_paste_target_new (Sheet *sheet, GnmRange *r, GnmPasteFlags flags);
GnmCellRegion *clipboard_copy_range (Sheet *sheet, GnmRange const *r);
GOUndo *clipboard_copy_range_undo (Sheet *sheet, GnmRange const *r);
GOUndo *clipboard_copy_ranges_undo (Sheet *sheet, GSList *ranges);
......@@ -92,7 +95,7 @@ gboolean clipboard_paste_region (GnmCellRegion const *cr,
GOCmdContext *cc);
GnmPasteTarget *paste_target_init (GnmPasteTarget *pt,
Sheet *sheet, GnmRange const *r,
int flags);
GnmPasteFlags flags);
GType gnm_cell_region_get_type (void);
GnmCellRegion *gnm_cell_region_new (Sheet *origin_sheet);
......
......@@ -3820,8 +3820,7 @@ cmd_unmerge_cells_redo (GnmCommand *cmd, WorkbookControl *wbc)
GnmRange const *pr = ptr->data;
GnmRange const tmp = *pr;
g_array_append_val (me->unmerged_regions, tmp);
gnm_sheet_merge_remove (me->cmd.sheet, &tmp,
GO_CMD_CONTEXT (wbc));
gnm_sheet_merge_remove (me->cmd.sheet, &tmp);
sheet_range_calc_spans (me->cmd.sheet, &tmp,
GNM_SPANCALC_RE_RENDER);
}
......@@ -3928,7 +3927,7 @@ cmd_merge_cells_undo (GnmCommand *cmd, WorkbookControl *wbc)
for (i = 0 ; i < me->ranges->len ; ++i) {
GnmRange const *r = &(g_array_index (me->ranges, GnmRange, i));
gnm_sheet_merge_remove (me->cmd.sheet, r, GO_CMD_CONTEXT (wbc));
gnm_sheet_merge_remove (me->cmd.sheet, r);
}
/* Avoid pasting comments that are at 0,0. Redo copies the target
......@@ -3980,7 +3979,7 @@ cmd_merge_cells_redo (GnmCommand *cmd, WorkbookControl *wbc)
me->old_contents = g_slist_prepend (me->old_contents,
clipboard_copy_range (sheet, r));
for (ptr = merged ; ptr != NULL ; ptr = ptr->next)
gnm_sheet_merge_remove (sheet, ptr->data, GO_CMD_CONTEXT (wbc));
gnm_sheet_merge_remove (sheet, ptr->data);
g_slist_free (merged);
gnm_sheet_merge_add (sheet, r, TRUE, GO_CMD_CONTEXT (wbc));
......
......@@ -52,7 +52,7 @@ range_row_cmp (GnmRange const *a, GnmRange const *b)
* @r: The region to merge
* @clear: should the non-corner content of the region be cleared and the
* style from the corner applied.
* @cc: the calling context
* @cc: (nullable): the calling context
*
* Add a range to the list of merge targets. Checks for array spliting returns
* %TRUE if there was an error. Queues a respan. Only queus a redraw if @clear
......@@ -159,7 +159,6 @@ gnm_sheet_merge_add (Sheet *sheet, GnmRange const *r, gboolean clear,
* gnm_sheet_merge_remove:
* @sheet: the sheet which will contain the region
* @r: The region
* @cc: the calling context
*
* Remove a merged range.
* Queues a redraw.
......@@ -167,7 +166,7 @@ gnm_sheet_merge_add (Sheet *sheet, GnmRange const *r, gboolean clear,
* Returns: %TRUE if there was an error.
**/
gboolean
gnm_sheet_merge_remove (Sheet *sheet, GnmRange const *r, GOCmdContext *cc)
gnm_sheet_merge_remove (Sheet *sheet, GnmRange const *r)
{
GnmRange *r_copy;
GnmCell *cell;
......@@ -317,7 +316,7 @@ cb_restore_merge (Sheet *sheet, GSList *restore)
// the old state, so we'll have to remove the merge and
// create a new.
if (r2)
gnm_sheet_merge_remove (sheet, r2, NULL);
gnm_sheet_merge_remove (sheet, r2);
gnm_sheet_merge_add (sheet, r, FALSE, NULL);
}
......@@ -356,7 +355,7 @@ gnm_sheet_merge_relocate (GnmExprRelocateInfo const *ri, GOUndo **pundo)
for (ptr = copy; ptr != NULL ; ptr = ptr->next) {
GnmRange const *r = ptr->data;
if (range_contains (&dest, r->start.col, r->start.row))
gnm_sheet_merge_remove (ri->target_sheet, r, NULL);
gnm_sheet_merge_remove (ri->target_sheet, r);
}
g_slist_free (copy);
}
......@@ -374,7 +373,7 @@ gnm_sheet_merge_relocate (GnmExprRelocateInfo const *ri, GOUndo **pundo)
ri->col_offset, ri->row_offset);
range_ensure_sanity (&r2, ri->target_sheet);
gnm_sheet_merge_remove (ri->origin_sheet, r, NULL);
gnm_sheet_merge_remove (ri->origin_sheet, r);
if (range_is_singleton (&r2))
needs_restore = TRUE;
else if (r2.start.col <= r2.end.col &&
......@@ -388,12 +387,12 @@ gnm_sheet_merge_relocate (GnmExprRelocateInfo const *ri, GOUndo **pundo)
r2.end.col += ri->col_offset;
r2.end.row += ri->row_offset;
range_ensure_sanity (&r2, ri->target_sheet);
gnm_sheet_merge_remove (ri->origin_sheet, r, NULL);
gnm_sheet_merge_remove (ri->origin_sheet, r);
needs_restore = TRUE;
needs_reapply = !range_is_singleton (&r2);
} else if (!change_sheets &&
range_contains (&dest, r->start.col, r->start.row))
gnm_sheet_merge_remove (ri->origin_sheet, r, NULL);
gnm_sheet_merge_remove (ri->origin_sheet, r);
if (needs_reapply)
reapply = g_slist_prepend (reapply,
......
......@@ -12,8 +12,7 @@ gboolean gnm_sheet_merge_add (Sheet *sheet,
gboolean clear,
GOCmdContext *cc);
gboolean gnm_sheet_merge_remove (Sheet *sheet,
GnmRange const *r,
GOCmdContext *cc);
GnmRange const *r);
GSList *gnm_sheet_merge_get_overlap (Sheet const *sheet, GnmRange const *r);
GnmRange const *gnm_sheet_merge_contains_pos (Sheet const *sheet, GnmCellPos const *pos);
GnmRange const *gnm_sheet_merge_is_corner (Sheet const *sheet, GnmCellPos const *pos);
......
......@@ -3487,9 +3487,9 @@ cb_check_array_vertical (GnmColRowIter const *iter, ArrayCheckData *data)
* sheet_range_splits_array:
* @sheet: The sheet.
* @r: The range to check
* @ignore: an optionally NULL range in which it is ok to have an array.
* @cc: an optional place to report an error.
* @cmd: an optional cmd name used with @cc.
* @ignore: (nullable): a range in which it is ok to have an array.
* @cc: (nullable): place to report an error.
* @cmd: (nullable): cmd name used with @cc.
*
* Check the outer edges of range @sheet!@r to ensure that if an array is
* within it then the entire array is within the range. @ignore is useful when
......@@ -4727,7 +4727,7 @@ cb_empty_cell (GnmCellIter const *iter, gpointer user)
* @end_col:
* @end_row:
* @clear_flags: If this is TRUE then styles are erased.
* @cc:
* @cc: (nullable):
*
* Clears are region of cells
*
......@@ -4793,7 +4793,7 @@ sheet_clear_region (Sheet *sheet,
GSList *merged, *ptr;
merged = gnm_sheet_merge_get_overlap (sheet, &r);
for (ptr = merged ; ptr != NULL ; ptr = ptr->next)
gnm_sheet_merge_remove (sheet, ptr->data, cc);
gnm_sheet_merge_remove (sheet, ptr->data);
g_slist_free (merged);
}
......
......@@ -37,10 +37,17 @@ As int:
1
List of cells in sheet:
A1
A2
A3
A4
A5
A6
A7
A1: 10 [bold]
C1: 10
A2: 101.25 [bold]
C2: 101.25
A3: =A1+A2
C3: =C1+C2
A4: '01
C4: '01
A5: zzz
C5: zzz
A6: abc
C6: abc
A7: TRUE
C7: TRUE
......@@ -25,6 +25,16 @@ sheet.cell_set_text(0,4,"zzz")
sheet.cell_set_value(0,5,Gnm.Value.new_string("abc"))
sheet.cell_set_value(0,6,Gnm.Value.new_bool(1))
# Copy A1:A7, paste to C1:C7
src = Gnm.Range()
src.init(0,0,0,6)
cr = Gnm.clipboard_copy_range(sheet,src)
dst = Gnm.Range()
dst.init(2,0,2,6)
pt = Gnm.PasteTarget.new (sheet,dst,Gnm.PasteFlags.DEFAULT)
Gnm.clipboard_paste_region(cr,pt,None)
# Make A1:A2 bold
st = Gnm.Style.new()
st.set_font_bold(1)
......@@ -47,4 +57,4 @@ print "\nList of cells in sheet:"
for c in sheet.cells(None):
st = sheet.style_get (c.pos.col,c.pos.row)
bold = st.get_font_bold()
print("{}: {}".format(c.name(), ("[bold]" if bold else "")))
print("{}: {} {}".format(c.name(), c.get_entered_text(), ("[bold]" if bold else "")))
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