CDBringoverCmds.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Pradeep Sindhu March 27, 1986 2:39:47 pm PST
Louis Monier February 7, 1986 7:45:03 pm PST
Bertrand Serlet June 16, 1986 4:42:09 pm PDT
DIRECTORY
CD, CDDirectory, CDGenerate, CDMenus, CDProperties, CDRemote, CDSequencer, FileNames, PW, Rope, TerminalIO;
CDBringoverCmds: CEDAR PROGRAM
IMPORTS CDDirectory, CDGenerate, CDMenus, CDProperties, CDRemote, FileNames, PW, Rope, TerminalIO
SHARES CDRemote
= BEGIN
ROPE: TYPE = Rope.ROPE;
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 part of the library file. Ie, if the file name is "Foo.dale", the property value is "Foo".
deleteProp: ATOM ← $CDBringoverDelete;
This property is used to mark objects to be deleted.
Public functions
Bringover: PROC [comm: CDSequencer.Command] = {
libFullFileName: ROPE ← TerminalIO.RequestRope["Library Name: "];
libFileName: ROPE ← GetNamePart[libFullFileName];
libDesign: CD.Design ← PW.OpenDesign[libFullFileName];
ForEachLibOb: CDDirectory.EachEntryAction = {
targetFound: BOOL;
targetOb: CD.Object;
libObProp: ROPENARROW[CDProperties.GetObjectProp[ob, libraryProp]];
[targetFound, targetOb] ← CDDirectory.Fetch[comm.design, name];
IF targetFound
THEN {
outRope: ROPE;
targetObProp: ROPE ← NARROW[CDProperties.GetObjectProp[targetOb, libraryProp]];
IF targetObProp=NIL
THEN outRope ← Rope.Cat["Object ", name, " from this design: "]
ELSE outRope ← Rope.Cat["Object ", name, " from library ", targetObProp, ": "];
IF Rope.Equal[libObProp, targetObProp, FALSE] OR Rope.Equal[libFileName, targetObProp, FALSE] OR TerminalIO.Confirm["Replace it?", outRope]
THEN {
copyOfLibOb: CD.Object ← CDRemote.Get[comm.design, libDesign.name, name];
IF libObProp=NIL THEN 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: "Bringover Library", p: Bringover, key: $Bringover, queue: doQueueAndMark];
END.