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, December 21, 1984 9:50:08 am 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, Rope, 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[], el.rest UNTIL el = NIL DO
file.Put[rope["(WHITEBOARD "]];
file.Put[rope[DB.NameOf[el.first]]];
DumpWBItems[file, el.first];
file.Put[rope[")\n\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;
file.Put[rope[")"]];
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];
file.Put[rope[" )"]];
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];
IF Rope.Equal[name, ""] THEN file.Put[rope["-"]] ELSE file.Put[rope[name]];
file.Put[rope["|"]];
IF Rope.Equal[label, ""] THEN file.Put[rope["-"]] ELSE file.Put[rope[label]];
file.Put[rope["|"]];
IF type = NIL THEN file.Put[rope["-"]] ELSE file.Put[rope[Atom.GetPName[type]]];
file.Put[rope["|"]];
IF Rope.Equal[iconName, ""] THEN file.Put[rope["-"]] ELSE file.Put[rope[iconName]];
file.Put[rope["|"]];
IF Rope.Equal[argument, ""] THEN file.Put[rope["-"]] ELSE file.Put[rope[argument]];
file.Put[rope[")"]];
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...