CopyMessages:
PUBLIC
PROC [to:
ROPE, delete:
BOOL] = {
sourceViewer, destViewer: Viewer;
destDoc, sourceDoc, destLast, sourceLast, afterSource: Node;
start, end: TiogaOps.Location;
level: TiogaOps.SelectionGrain;
caretBefore, pendingDelete: BOOL;
lockedPrimary, lockedSecondary, lockedDest, lockedSource: BOOL ¬ FALSE;
TopParent:
PROC [node, root: Node]
RETURNS [parent: Node] = {
DO
parent ¬ TiogaOps.Parent[node];
IF parent=root THEN RETURN [node];
node ¬ parent;
ENDLOOP;
};
Cleanup:
PROC = {
IF lockedPrimary THEN TiogaOps.UnlockSel[primary];
IF lockedSecondary THEN TiogaOps.UnlockSel[secondary];
IF lockedDest THEN TiogaOps.Unlock[destDoc];
IF lockedSource THEN TiogaOps.Unlock[sourceDoc];
};
destViewer ¬ GetMailViewer[to];
TiogaOps.LockSel[primary]; lockedPrimary ¬ TRUE;
[sourceViewer, start, end, level, caretBefore, pendingDelete] ¬ TiogaOps.GetSelection[];
IF sourceViewer=
NIL
OR sourceViewer.class.flavor#$Text
THEN {
TiogaOps.UnlockSel[primary]; OutputRope["\nSelect message(s)."]; RETURN };
TiogaOps.LockSel[secondary]; lockedSecondary ¬ TRUE;
destDoc ¬ TiogaOps.ViewerDoc[destViewer];
TiogaOps.Lock[destDoc]; lockedDest ¬ TRUE;
sourceDoc ¬ TiogaOps.ViewerDoc[sourceViewer];
IF sourceDoc#destDoc THEN { TiogaOps.Lock[sourceDoc]; lockedSource ¬ TRUE };
destLast ¬ TiogaOps.LastChild[destDoc];
sourceLast ¬ TopParent[end.node, sourceDoc];
afterSource ¬ TiogaOps.Next[sourceLast];
TiogaOps.SelectBranches[
-- source
viewer: sourceViewer, level: branch, caretBefore: FALSE,
pendingDelete: delete, which: primary,
start: TopParent[start.node, sourceDoc], end: sourceLast];
TiogaOps.SelectBranches[
-- destination
viewer: destViewer, start: destLast, end: destLast,
level: branch, caretBefore: FALSE, pendingDelete: FALSE, which: secondary];
TiogaOps.ToSecondary[];
IF
NOT delete
THEN
-- restore original selection
TiogaOps.SetSelection[sourceViewer, start, end, level, caretBefore, pendingDelete, primary]
ELSE IF afterSource # NIL THEN TiogaOps.SelectPoint[sourceViewer, [afterSource,0], primary]
ELSE TiogaOps.CancelSelection[primary];
Cleanup[];
OutputRope[IF delete THEN "\nMoved to " ELSE "\nCopied to "];
OutputRope[to];
};