File: WhiteboardDump.mesa
Copyright (C) 1984 by Xerox Corporation. All rights reserved.
For dumping of whiteboard databases. (Companion to WhiteboardLoadImpl.mesa.)
Last edited by: Jennifer Widom, August 24, 1984 10:36:43 pm PDT
Last edited by: Donahue, March 14, 1986 1:31:53 pm PST
(Changed to catch WBError)
Last Edited by: Winkler, December 18, 1984 11:05:46 am PST
DIRECTORY
Atom,
Commander USING [CommandProc, Register],
Convert USING [RopeFromRope],
DB,
FS USING [StreamOpen],
IO,
Rope,
ViewerTools,
WhiteboardDB USING[Dump, WBError],
WhiteboardDBPrivate;
WhiteboardDump: CEDAR PROGRAM
IMPORTS
Atom, Commander, Convert, DB, FS, IO, WhiteboardDBPrivate, WhiteboardDB =
BEGIN OPEN IO, Rope, WhiteboardDBPrivate;
DoDump: Commander.CommandProc =
BEGIN
ENABLE WhiteboardDB.WBError => {
SELECT reason FROM
$ServerDown => {msg ← "Dump Failed -- server unavailable; retry later"; CONTINUE};
$TransactionAbort => {msg ← "Dump Failed -- transaction aborted; retry later"; CONTINUE};
ENDCASE => REJECT };
h: IO.STREAM = IO.RIS[cmd.commandLine];
[] ← h.SkipWhitespace[];
IF h.EndOf THEN [] ← WhiteboardDB.Dump["Whiteboard.dump"]
ELSE [] ← WhiteboardDB.Dump[h.GetLineRope[]]; -- make sure to go through the monitor
END;
DumpToFile: PUBLIC PROC[fileName: ROPE] =
BEGIN
file: STREAM;
IF fileName = NIL THEN fileName ← "Whiteboard.dump";
file ← OpenFile[fileName];
DumpWBs[file];
file.Close[];
END;
DumpWBs: PROC[file: STREAM] =
BEGIN
FOR el: LIST OF Whiteboard ← Enumerate[NIL], el.rest UNTIL el = NIL DO
file.Put[rope["\nWHITEBOARD "]];
file.Put[rope[DB.EntityInfo[el.first].name]];
DumpWBItems[file, el.first];
file.Put[rope["\nEND\n"]];
ENDLOOP;
END;
DumpWBItems: PROC[file: STREAM, wb: WhiteboardDBPrivate.Whiteboard] =
BEGIN
children: ChildSet = Children[wb];
FOR child: WBItem ← NextChild[children], NextChild[children] UNTIL child = NIL DO
IF TypeOf[child] = note THEN
{ file.Put[rope[" "]]; DumpNote[file, child] }
ELSE { file.Put[rope[" "]]; DumpIcon[file, child] };
ENDLOOP;
END;
DumpNote: PROC[file: STREAM, note: WBNote] =
BEGIN
x, y, w, h: INT;
text: ViewerTools.TiogaContents = GetContents[note];
file.Put[rope["\n NOTE "]];
[x, y] ← Position[note];
[w, h] ← Size[note];
WriteCoords[file, x, y, w, h];
WriteRope[file, text.contents];
file.Put[rope[" "]];
WriteRope[file, text.formatting];
END;
DumpIcon: PROC[file: STREAM, icon: WBIcon] =
BEGIN
x, y: INTEGER ← 0;
name, label, iconName, argument: ROPE;
type: ATOM;
file.Put[rope["\n ICON "]];
[x, y] ← Position[icon];
file.Put[int[x]];
file.Put[rope[" "]];
file.Put[int[y]];
file.Put[rope[" "]];
[label, iconName] ← GetDisplayProps[icon];
argument ← GetToolArgument[icon];
[name, type] ← GetIconProps[icon];
WriteRope[file, name];
file.Put[rope[" "]];
WriteRope[file, label];
file.Put[rope[" "]];
WriteRope[file, IF type = NIL THEN "" ELSE Atom.GetPName[type]];
file.Put[rope[" "]];
WriteRope[file, iconName];
file.Put[rope[" "]];
WriteRope[file, argument];
END;
WriteRope: PROC[file: STREAM, r: ROPE] =
BEGIN
file.Put[rope[" "]];
file.Put[rope[Convert.RopeFromRope[r]]];
END;
WriteCoords: PROC[file: STREAM, x, y, w, h: INTEGER] =
BEGIN
file.Put[int[x]];
file.Put[rope[" "]];
file.Put[int[y]];
file.Put[rope[" "]];
file.Put[int[w]];
file.Put[rope[" "]];
file.Put[int[h]];
END;
OpenFile: PROC[fileName: ROPE] RETURNS [file: STREAM] =
BEGIN
IF fileName = NIL THEN RETURN;
file ← FS.StreamOpen[fileName: fileName, accessOptions: $create]
END;
Commander.Register[key: "WBDump", proc: DoDump,
doc: "\nDumps current whiteboard segment to named file\n (File defaults to Whiteboard.dump)"]
END...