CDViewerButtons.mesa
Copyright c 1985 by Xerox Corporation. All rights reserved.
Compile CDSaveButton; run CDSaveButton; AddSaveDesignButtonToCDViewers
Last Edited by Curry, April 17, 1985 7:40:43 pm PST
DIRECTORY
CDCommandOps,
CD,
CDDirectory,
CDIO,
CDMenus,
CDPanel,
CDProperties,
CDSequencer,
CDViewer,
IO,
Menus,
Rope,
TerminalIO,
ViewerClasses,
ViewerOps;
CDViewerButtons: CEDAR PROGRAM
IMPORTS CDCommandOps, CDDirectory, CDIO, CDMenus, CDPanel, CDProperties, CDSequencer, CDViewer, Menus, ViewerOps, TerminalIO =
BEGIN
CDViewerButtonData:  TYPE = REF CDViewerButtonDataRec;
CDViewerButtonDataRec: TYPE = RECORD[
name:  Rope.ROPE,
design: CD.Design,
atom:  ATOM];
AddCDViewerButton: PROC[atom: ATOM, name: Rope.ROPE] = {
design: CD.Design;
data:  CDViewerButtonData;
oldEntry:  Menus.MenuEntry;
newEntry: Menus.MenuEntry;
Checker: ViewerOps.EnumProc = { -- [v: Viewer] RETURNS [BOOL ← TRUE]
IF v.class.flavor#$Chipndale THEN RETURN[TRUE];
design ← CDViewer.DesignOf[v];
IF design=NIL THEN RETURN[TRUE];
data ← NEW[CDViewerButtonDataRec ← [name, design, atom]];
IF v.menu=NIL THEN ViewerOps.SetMenu[v, Menus.CreateMenu[] ];
oldEntry  ← Menus.FindEntry[v.menu, name];
newEntry ← Menus.CreateEntry[
name:   name,
proc:   CDViewerButtonProc,
clientData: data,
guarded:  TRUE];
IF oldEntry=NIL
THEN Menus.AppendMenuEntry [v.menu, newEntry]
ELSE Menus.ReplaceMenuEntry [v.menu, oldEntry, newEntry];
ViewerOps.PaintViewer[v, menu, ];
RETURN[TRUE]};
ViewerOps.EnumerateViewers[Checker] };
CDViewerButtonProc: Menus.ClickProc = {
[parent, clientData: REF, mouseButton: MouseButton, shift, control: BOOL]
ENABLE TerminalIO.UserAbort => GOTO userAbort;
viewer: ViewerClasses.Viewer ← NARROW[parent];
data:  CDViewerButtonData ← NARROW[clientData];
comm:  CDSequencer.Command ←
NEW[CDSequencer.CommandRec ← [design: data.design, a: data.atom]];
CDSequencer.ExecuteCommand[comm: comm];
EXITS
userAbort => {TerminalIO.WriteRope["discarded\n"]} };
SaveDesign: PROC [comm: CDSequencer.Command] = {
name: IO.ROPECDIO.MakeName
[comm.design.name, "dale", CDIO.GetWorkingDirectory[comm.design]];
[ ] ← CDIO.WriteDesign[comm.design, name]};
SetPWCondToName: PROC [comm: CDSequencer.Command] = {
aptr: CD.ApplicationPtr ← CDCommandOps.TheApplication
[comm, "Set Property $PWCond for "];
IF aptr#NIL AND aptr.ob#NIL THEN {
name: Rope.ROPE ← CDDirectory.Name[aptr.ob];
CDCommandOps.WriteInfo[aptr];
TerminalIO.WriteRope[" to be "];
TerminalIO.WriteRope[name];
TerminalIO.WriteRope[" . . . "];
CDProperties.PutPropOnApplication[onto: aptr, prop: $PWCond, val: name];
IF name#NIL
THEN TerminalIO.WriteRope[" done\n"]
ELSE TerminalIO.WriteRope[" removed\n"] } };
CDMenus.CreateEntry[
menu: CDMenus.GetMenu[$NameMenuFull],
entry: "SetPWCondToName",
key: $SetPWCondToName];
CDSequencer.ImplementCommand [$SetPWCondToName, SetPWCondToName];
AddCDViewerButton    [$SetPWCondToName, "SetPWCondToName"];
CDSequencer.ImplementCommand [$SaveDesign,   SaveDesign];
AddCDViewerButton    [$SaveDesign,   "SaveDesign"];
CDPanel.DefineButton
[name: "SaveDesign", proc: SaveDesign, command: $SaveDesign, border: TRUE]
END.