CDBringoverCmds.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Pradeep Sindhu February 18, 1986 5:10:53 pm PST
Louis Monier February 7, 1986 7:45:03 pm PST
Bertrand Serlet March 25, 1986 11:12:57 pm PST
DIRECTORY
CD, CDDirectory, CDGenerate, CDMenus, CDOps, CDProperties, CDRemote, CDSequencer, FileNames, PW, Rope, TerminalIO;
CDBringoverCmds: CEDAR PROGRAM
IMPORTS CDDirectory, CDGenerate, CDMenus, CDOps, CDProperties, CDRemote, FileNames, PW, Rope, TerminalIO
SHARES CDRemote
= BEGIN
ROPE: TYPE = Rope.ROPE;
firstTimeHack: BOOLFALSE;
libraryProp: ATOMPW.RegisterProp[$CDBringoverLibraryName, TRUE];
This property indicates that the object it hangs on comes from a library. The property's value is the name of the library file.
deleteProp: ATOM ← $CDBringoverDelete;
This property is used to mark objects to be deleted.
Public functions
PutLibraryNameOnObjects: PROC [comm: CDSequencer.Command] = {
libFileName: ROPE ← GetNamePart[TerminalIO.RequestRope["Library Name: "]];
FOR w: LIST OF CD.Instance ← CDOps.InstList[comm.design], w.rest WHILE w#NIL DO
IF w.first.selected THEN PutLibraryName[w.first.ob, libFileName];
ENDLOOP;
};
Bringover: PROC [comm: CDSequencer.Command] = {
libFullFileName: ROPE ← TerminalIO.RequestRope["Library Name: "];
libFileName: ROPE ← GetNamePart[libFullFileName];
libDesign: CD.Design ← PW.OpenDesign[libFullFileName];
ForEachLibOb: CDDirectory.EachEntryAction = {
found: BOOL;
targetOb: CD.Object;
[found, targetOb] ← CDDirectory.Fetch[comm.design, name];
IF found
THEN {
prop: ROPENARROW [CDProperties.GetObjectProp[targetOb, libraryProp]];
outRope: ROPE;
IF prop=NIL AND ~firstTimeHack THEN RETURN;
IF prop=NIL
THEN outRope ← Rope.Cat["Object ", name, " from this design: "]
ELSE outRope ← Rope.Cat["Object ", name, " from library ", prop, ": "];
IF Rope.Equal[libFileName, prop, FALSE] OR TerminalIO.Confirm["Replace it?", outRope]
THEN {
copyOfLibOb: CD.Object ← CDRemote.Get[comm.design, libDesign.name, name];
PutLibraryName[copyOfLibOb, libFileName];
CDDirectory.ReplaceObject[comm.design, targetOb, copyOfLibOb];
MarkToBeDeleted[targetOb];
TerminalIO.WriteRopes["Replacing ", name, "\n"];
};
}
ELSE {
copyOfLibOb: CD.Object ← CDRemote.Get[comm.design, libDesign.name, name];
PutLibraryName[copyOfLibOb, libFileName];
TerminalIO.WriteRopes["Adding ", name, "\n"];
}
};
SaveChildrenOfUnMarked: CDDirectory.EachEntryAction = {
SaveChild: CDDirectory.EnumerateObjectsProc = {
CDProperties.PutObjectProp[me, deleteProp, NIL]
};
IF CDProperties.GetObjectProp[ob, deleteProp]=NIL
THEN CDDirectory.EnumerateChildObjects[ob, SaveChild];
};
DeleteIfMarked: CDDirectory.EachEntryAction = {
IF CDProperties.GetObjectProp[ob, deleteProp]#NIL
THEN [] ← CDDirectory.Remove[comm.design, name, ob]
};
FixNameIfLibraryObject: CDDirectory.EachEntryAction = {
newName: ROPE;
IF CDProperties.GetObjectProp[ob, libraryProp]=NIL THEN RETURN;
newName ← Rope.Substr[name, 0, Rope.Index[name, 0, "@"]];
IF ~Rope.Equal[newName, name] THEN
[] ← CDDirectory.Rename[comm.design, ob, newName, FALSE]
};
IF libDesign=NIL THEN {TerminalIO.WriteRope["** Error: File not found\n"]; RETURN};
CDGenerate.FlushAll[CDRemote.GetTable[libDesign.name], comm.design];
CDRemote.CacheDesign[comm.design, libDesign];
[] ← CDDirectory.Enumerate[libDesign, ForEachLibOb];
[] ← CDDirectory.Enumerate[comm.design, SaveChildrenOfUnMarked];
[] ← CDDirectory.Enumerate[comm.design, DeleteIfMarked];
[] ← CDDirectory.Enumerate[comm.design, FixNameIfLibraryObject];
TerminalIO.WriteRope["Bringover done\n"];
};
PutLibraryName: PROC [ob: CD.Object, name: ROPE] = {
ForEachChild: CDDirectory.EnumerateObjectsProc = {
CDProperties.PutObjectProp[me, libraryProp, name];
};
CDDirectory.EnumerateChildObjects[ob, ForEachChild];
CDProperties.PutObjectProp[ob, libraryProp, name];
};
MarkToBeDeleted: PROC [ob: CD.Object] = {
ForEachChild: CDDirectory.EnumerateObjectsProc = {
CDProperties.PutObjectProp[me, deleteProp, $foo];
};
CDDirectory.EnumerateChildObjects[ob, ForEachChild];
CDProperties.PutObjectProp[ob, deleteProp, $foo];
};
GetNamePart: PROC [fileName: ROPE] RETURNS [name: ROPE] = {
name ← FileNames.GetShortName[fileName];
name ← Rope.Substr[name, 0, Rope.Index[name, 0, "."]];
};
Initialization
CDMenus.ImplementEntryCommand[menu: $IOMenu, entry: "Put Library Name", p: PutLibraryNameOnObjects, key: $PutLibraryNameOnObjects, queue: doQueueAndMark];
CDMenus.ImplementEntryCommand[menu: $IOMenu, entry: "Bringover Library", p: Bringover, key: $Bringover, queue: doQueueAndMark];
END.