Page 1 of 1

UN-DO action ignores LoadRVFFromStream into table cells

Posted: Thu Nov 22, 2007 5:47 am
by lwinter
Hi Sergey,

The task:
Multi-cell-paste from a source to a target table.
Fill the contents of multiple cells from a source-table (in a separate dummy RVEditor-control) into multiple cells in a target-table (overriding any previous cell contents).
This multi-cell-paste should be un-do-able as ONE un-do-action. See code below.

The problem(s):
The un-do action is not including the direct insertions into table-cells.
LoadRVFFromStream can not be undone.
InsertRowsBelow un-do works ok though.

When using anInplaceEditor.InsertRVFFromStreamEd(tempStream), then the insertion for each individual table can be undone.
In this case multiple un-do actions are created, but now there is one for each table-cell. Also the anInplaceEditor.Clear can not be undone.

The question:
How can I group multiple direct cell insertions into one un-do group?

Code: Select all

    // Begin Un-do sequence
    itemIdx := aRVEditor.GetItemNo(aTargetTable);
    BeginUndoGroup(rvutInsert);
    SetUndoGroupMode(true);
    aRVEditor.BeginItemModify(itemIdx, modifyData);

    // Add rows to target table if necessary
    iDiff := aSourceTable.RowCount - ( aTargetTable.RowCount - topRow );
    if iDiff > 0 then
    begin

{UN-DO WORKS OK WITH INSERTROWSBELOW}
        aTargetTable.InsertRowsBelow(iDiff);

    end;

    // Do the insert
    for r := 0 to (aSourceTable.Rows.Count-1) do
        for c := 0 to (insertCols-1) do
        begin
            tempStream.Clear;
            aSourceCell := aSourceTable.Cells[r,c];
            aTargetCell := aTargetTable.Cells[(topRow + r),(leftCol + c)];
            aSourceCell.SaveRVFToStream(tempStream, false, aColor, aBackground, aLayout);
            tempStream.Position := 0;
 
{UN-DO DOES NOT WORK WITH LOADRVFFROMSTREAM}
            aTargetCell.LoadRVFFromStream(tempStream, aColor, aBackground, aLayout);
            
{UN-DO NEITHER WORKS WITH INPLACEEDITOR}
{				
            aTargetTable.EditCell((topRow + r),(leftCol + c));
            anInplaceEditor := aTargetTable.GetEditedCell(row, col);
            anInplaceEditor.Clear;
            anInplaceEditor.LoadRVFFromStreamEd(tempStream);
            anInplaceEditor.Deselect;
}
        end;

    // End Undo sequence
    aRVEditor.EndItemModify(itemIdx, modifyData);
    SetUndoGroupMode(false);
Thanks!
-- Lutz

Posted: Thu Nov 22, 2007 8:22 am
by Sergey Tkachenko
Yes, LoadRVFFromStream and Clear cannot be undone.
So, there are only 2 solutions possible in the current version of TRichView:
1) create a copy of aTargetTable (using table.SaveToStream/LoadFromStream), modify this copy and insert it in place of aTargetTable (by selecting aTargetTable using SetSelectionBounds before calling InsertItem)
Obviously, this is a bad solution if aTargetTable is large.
But this is the only way to implement undo as one operation.

2) Use inplace editor with InsertRVFFromStreamEd. Instead of calling Clear, call SelectAll, the selection will be replaced. To prevent flickering, call aRVEditor.BeginModify and EndModify.
But, unfortunately, undo in different inplace editors cannot be grouped.