EditToolTopImpl.mesa
Copyright Ó 1985, 1986, 1990, 1991, 1992 by Xerox Corporation. All rights reserved.
Michael Plass, October 8, 1991 12:22 pm PDT
Russ Atkinson (RRA) June 18, 1985 5:08:56 pm PDT
Alison Lee September 10, 1986 2:58:07 pm PDT
Swinehart, November 14, 1986 10:11:06 am PST
Bier, July 26, 1991 11:18 am PDT
Doug Wyatt, March 25, 1992 4:59 pm PST
DIRECTORY
Commander USING [CommandProc, Register],
CommanderOps USING [Failed, NextArgument],
Containers USING [ScrollOffset],
Convert USING [AtomFromRope ],
EditToolBuilder USING [HRule, LayoutRec, ToMiddle, ToNext, VGap],
EditToolPrivate USING [BuildExtraButtons, BuildFileListEntries, BuildFormatButtons, BuildGetAndSetOpsEntries, BuildInitCapEntry, BuildLooksButtons, BuildMiniPatternDocEntry, BuildOperationEntry, BuildOperationField, BuildPropertyButtons, BuildRealExtraButtons, BuildRealFileListEntries, BuildRealFormatButtons, BuildRealGetAndSetOpsEntries, BuildRealLooksButtons, BuildRealPropertyButtons, BuildRealSortButtons, BuildRealStyleButtons, BuildRegisterButtons, BuildSearchButtons, BuildSortButtons, BuildSourceEntry, BuildStyleButtons, BuildSubstituteEntry, BuildTargetEntry, ButtonCommandRec, DoCountMenuButton, DoItMenuButton, DoNoMenuButton, DoSearchMenuButton, DoSubstituteMenuButton, DoYesMenuButton, HeightScheme, Info, InfoRec, LastHRule, maxNumHeights, numScrollRegions, otherField],
EditToolOps,
Menus USING [AppendMenuEntry, CopyEntry, FindEntry, SetClientData, CreateEntry, CreateMenu, GetLine, SetLine, MenuLine, MenuEntry, ChangeNumberOfLines, GetNumberOfLines, Menu, MenuProc],
Rope USING [ROPE, Equal, Match],
TiogaOps USING [CommandProc, RegisterCommand],
TEditInput USING [CommandProc, Interpret, interrupt, Register, UnRegister],
ViewerClasses USING [Column, Viewer, ViewerClass],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerLocks USING [CallUnderWriteLocks],
ViewerBLT USING [ChangeNumberOfLines],
ViewerOps USING [AddProp, ChangeColumn, ComputeColumn, CreateViewer, DestroyViewer, EnumerateViewers, EnumProc, GrowViewer, MoveBelowViewer, OpenIcon, PaintViewer, TopViewer, SetOpenHeight ];
EditToolTopImpl: CEDAR PROGRAM
IMPORTS Commander, CommanderOps, Containers, Convert, EditToolBuilder, EditToolPrivate, TiogaOps, Menus, Rope, TEditInput, ViewerBLT, ViewerEvents, ViewerLocks, ViewerOps
EXPORTS EditToolPrivate, EditToolOps
= { OPEN EditToolBuilder, EditToolPrivate, EditToolOps;
ROPE: TYPE ~ Rope.ROPE;
registered: LIST OF RegCom ¬ NIL;
additionalRegistered: LIST OF ButtonCommandRec ¬ NIL;
RegCom: TYPE = RECORD [atom: ATOM, op: TEditInput.CommandProc];
editTool: PUBLIC ViewerClasses.Viewer;
mainToolInfo: PUBLIC Info;
BuildContainer: PROC [info: Info, name: ROPE, useRealNames: BOOL, useAuxMenu: BOOL] RETURNS [viewer: ViewerClasses.Viewer] =
{ OPEN info;
editToolMenu: Menus.Menu ¬ Menus.CreateMenu[2];
scrollSectionInfo[0].name ¬ "Subs";
scrollSectionInfo[0].entryNum ¬ 0;
scrollSectionInfo[1].name ¬ "Looks";
scrollSectionInfo[1].entryNum ¬ 1;
scrollSectionInfo[2].name ¬ "Format";
scrollSectionInfo[2].entryNum ¬ 2;
scrollSectionInfo[3].name ¬ "Style";
scrollSectionInfo[3].entryNum ¬ 3;
scrollSectionInfo[4].name ¬ "Property";
scrollSectionInfo[4].entryNum ¬ 4;
scrollSectionInfo[5].name ¬ "Sort";
scrollSectionInfo[5].entryNum ¬ 5;
scrollSectionInfo[6].name ¬ "Operations";
scrollSectionInfo[6].entryNum ¬ 6;
scrollSectionInfo[7].name ¬ "Others";
scrollSectionInfo[7].entryNum ¬ 7;
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["Stop", Stop]];
Menus.AppendMenuEntry[editToolMenu,
Menus.CreateEntry[name: "Search", proc: DoSearchMenuButton, fork: TRUE]];
Menus.AppendMenuEntry[editToolMenu,
Menus.CreateEntry[name: "Substitute", proc: DoSubstituteMenuButton, fork: TRUE]];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["Yes", DoYesMenuButton]];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["No", DoNoMenuButton]];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["Replace", DoItMenuButton]];
Menus.AppendMenuEntry[editToolMenu,
Menus.CreateEntry[name: "Count", proc: DoCountMenuButton, fork: TRUE]];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["Sections", DoScrollToOpsMenuButton, NEW[ BOOL ¬ useAuxMenu ]]]; -- clientData says whether subMenu available.
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["RealOps", DoRealNamesMenuButton, NEW[ BOOL ¬ useRealNames]]]; -- clientData says whether realNames used.
FOR i: NAT IN [0..EditToolPrivate.numScrollRegions) DO
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry[scrollSectionInfo[i].name, DoScrollToMenuButton, NEW[INTEGER ¬ info.scrollSectionInfo[i].entryNum]], 1];
ENDLOOP;
goToSectionMenu ¬ Menus.GetLine[editToolMenu, 1];
Don't want the aux menu to show, so show only the top level to start.
IF ~useAuxMenu THEN Menus.ChangeNumberOfLines[editToolMenu, 1];
layout.container ¬ viewer ¬ ViewerOps.CreateViewer[flavor: $Container,
info: [name: name, iconic: TRUE, column: right, menu: editToolMenu, icon: VAL[5]],
paint: TRUE];
editTool ¬ viewer; -- save in global variable
};
ChangeEditToolPanel: PROC [viewer: ViewerClasses.Viewer, realNamePanel: BOOL] = {
class: ViewerClasses.ViewerClass ¬ viewer.class;
menu: Menus.Menu ¬ viewer.menu;
opened: BOOL ¬ ~viewer.iconic;
clientData: REF ANY¬ Menus.SetClientData[ Menus.FindEntry[ menu, "Sections"], NIL ];
data: REF BOOL ¬ NARROW[clientData];
auxMenuAvail: BOOL ¬ data­;
whichHeightScheme: EditToolPrivate.HeightScheme ¬ mainToolInfo.whichHeightScheme;
currentHeightIndex: [0..EditToolPrivate.maxNumHeights) ¬ mainToolInfo.currentHeightIndex;
oldScrollOffset: INTEGER ¬ ABS[ Containers.ScrollOffset[ viewer ] ];
scrollOffset, offset: INTEGER;
height: INTEGER;
onlyViewerInColumn: BOOL ¬ TRUE;
column: ViewerClasses.Column ¬ viewer.column;
viewerAbove: ViewerClasses.Viewer ¬ viewer.sibling; -- sibling chains the viewers of a column bottom up.
FindViewerLocation: ViewerOps.EnumProc ~ {
IF v.column = viewer.column AND NOT v.iconic AND NOT Rope.Equal[viewer.name, v.name] THEN onlyViewerInColumn ¬ FALSE;
};
What portion was visible in a viewer.
FOR heightIndex: INTEGER IN [0..numScrollRegions) DO
IF oldScrollOffset = mainToolInfo.scrollSectionInfo[heightIndex].startLocation
THEN {
Set things back to the right section if we were previously over the beginning of a section.
offset ¬ 0;
EXIT;
};
ENDLOOP;
If not over the beginning of a section, determine its offset from the section it was last known to be so that we can be back in the same proximity.
IF offset # 0 THEN offset ¬ oldScrollOffset - mainToolInfo.scrollSectionInfo[currentHeightIndex].startLocation;
ViewerOps.EnumerateViewers[ FindViewerLocation ];
ViewerOps.DestroyViewer[ viewer, TRUE ]; -- viewer information is no longer useful, editTool has new viewer value and mainToolInfo has new info.
Draw new alternate panel, leaving realNames, auxMenuAvail same as before.
ReRegister[];
ReRegisterAdditional[];
[mainToolInfo, editTool] ¬ DrawPanelViewer[realNamePanel, auxMenuAvail];
viewer ¬ editTool;
Restore previous state information to the best of our ability, e.g. height, opened, proper column, slide it back to same place within a column.
mainToolInfo.currentHeightIndex ¬ currentHeightIndex;
mainToolInfo.whichHeightScheme ¬ whichHeightScheme;
scrollOffset ¬ mainToolInfo.scrollSectionInfo[currentHeightIndex].startLocation + offset;
IF scrollOffset < 0 THEN scrollOffset ¬ 0;
IF whichHeightScheme = fixed THEN height ¬ mainToolInfo.heights[0]
ELSE height ¬ mainToolInfo.scrollSectionInfo[currentHeightIndex].height;
[] ¬ class.scroll[ self: viewer, op: up, amount: scrollOffset ];
ViewerOps.SetOpenHeight[viewer, height];
IF viewer.column # column THEN ViewerOps.ChangeColumn[ viewer, column ];
Must open the tool at the same column it was before.
IF opened THEN ViewerOps.OpenIcon[ icon: viewer, paint: FALSE ];
Restore the viewer to its right location.
IF onlyViewerInColumn THEN ViewerOps.GrowViewer[ viewer ]
ELSE IF viewerAbove = NIL THEN ViewerOps.TopViewer[ viewer ]
ELSE ViewerOps.MoveBelowViewer[ altered: viewer, static: viewerAbove ];
};
DoRealNamesMenuButton: PUBLIC Menus.MenuProc = {
viewer: ViewerClasses.Viewer ¬ NARROW[parent];
menu: Menus.Menu ¬ viewer.menu;
data: REF BOOL ¬ NARROW[ clientData ];
useRealNames: BOOL ¬ ~data­; -- Toggled, reflects the new intended value.
ChangeEditToolPanel[ viewer, useRealNames ];
};
DoScrollToOpsMenuButton: PUBLIC Menus.MenuProc = {
viewer: ViewerClasses.Viewer ¬ NARROW[parent];
menu: Menus.Menu ¬ viewer.menu;
data: REF BOOL ¬ NARROW[ clientData ];
menuNowAvail: BOOL ¬ ~data­; -- Toggled, reflects the new intended value.
newLines: Menus.MenuLine ¬ Menus.GetNumberOfLines[menu];
Toggle the clientData value.
[] ¬ Menus.SetClientData[ Menus.FindEntry[ menu, "Sections"], NEW[BOOL ¬ menuNowAvail ]];
IF menuNowAvail
THEN {
add it.
Menus.SetLine[menu, 2, mainToolInfo.goToSectionMenu];
newLines ¬ newLines+1;
}
ELSE -- yes, so remove it
newLines ¬ newLines-1;
ViewerBLT.ChangeNumberOfLines[viewer, newLines];
};
DoScrollToMenuButton: PUBLIC Menus.MenuProc = {
viewer: ViewerClasses.Viewer ¬ NARROW[parent];
scrollRegion: INTEGER ¬ NARROW[ clientData, REF INTEGER ]­;
amount: INTEGER;
scrollOffset: INTEGER ¬ ABS[ Containers.ScrollOffset[ viewer ] ];
class: ViewerClasses.ViewerClass ¬ viewer.class;
IF mouseButton = blue
THEN {
Want variable height Scheme, do it if it is not the same.
IF mainToolInfo.currentHeightIndex # scrollRegion OR mainToolInfo.whichHeightScheme = fixed
THEN {
mainToolInfo.currentHeightIndex ¬ scrollRegion;
ViewerOps.SetOpenHeight[ viewer, mainToolInfo.scrollSectionInfo[scrollRegion].height ];
ViewerOps.ComputeColumn[ viewer.column, TRUE ];
};
IF mainToolInfo.whichHeightScheme = fixed THEN mainToolInfo.whichHeightScheme ¬ variable;
}
ELSE IF mouseButton = red
THEN {
Want to Revert to a fixed height Scheme, use heights[0] value.
IF mainToolInfo.currentHeightIndex # scrollRegion
THEN mainToolInfo.currentHeightIndex ¬ scrollRegion;
IF mainToolInfo.whichHeightScheme = variable
THEN {
mainToolInfo.whichHeightScheme ¬ fixed;
ViewerOps.SetOpenHeight[ viewer, mainToolInfo.heights[0] ];
ViewerOps.ComputeColumn[ viewer.column, TRUE ];
};
};
IF scrollOffset > mainToolInfo.scrollSectionInfo[scrollRegion].startLocation
THEN {
must scroll down to get to whereToScrollTo
amount ¬ scrollOffset - mainToolInfo.scrollSectionInfo[scrollRegion].startLocation;
[] ¬ class.scroll[ self: viewer, op: down, amount: amount ]
}
ELSE IF scrollOffset < mainToolInfo.scrollSectionInfo[scrollRegion].startLocation
THEN {
must scroll up to get to whereToScrollTo
amount ¬ mainToolInfo.scrollSectionInfo[scrollRegion].startLocation - scrollOffset;
[] ¬ class.scroll[ self: viewer, op: up, amount: amount ]
};
};
MyDestroy: ViewerEvents.EventProc = {
IF viewer#editTool THEN RETURN; -- filter
mainToolInfo ¬ NIL;
editTool ¬ NIL;
UnRegister[];
UnRegisterAdditional[];
};
Stop: Menus.MenuProc = {
mainToolInfo.interrupt­ ¬ TRUE;
};
--------------------------
ChangeState: PUBLIC PROC [flag: BOOL, trueList, falseList: LIST OF REF] = {
DoButton[IF ~flag THEN trueList ELSE falseList] };
--------------------------
CycleTriple: PUBLIC PROC [state: [0..2], list0, list1, list2: LIST OF REF] = {
next: ARRAY [0..3) OF LIST OF REF ~ [list1, list2, list0];
DoButton[next[state]] };
--------------------------
DoButton: PUBLIC PROC [
redList, blueList: LIST OF REF ¬ NIL,
redButton: BOOL ¬ FALSE,
viewer: ViewerClasses.Viewer ¬ NIL] = {
IF viewer=NIL THEN viewer ¬ mainToolInfo.targetArg; -- must be a text viewer
IF ~redButton AND blueList#NIL THEN TEditInput.Interpret[viewer,blueList]
ELSE TEditInput.Interpret[viewer,redList] };
--------------------------
Register: PUBLIC PROC [atom: ATOM, op: TEditInput.CommandProc] RETURNS [LIST OF REF] = {
TEditInput.Register[atom, op];
registered ¬ CONS[[atom, op], registered];
RETURN [LIST[atom]] };
ReRegister: PROC = {
FOR r: LIST OF RegCom ¬ registered, r.rest UNTIL r=NIL DO
TEditInput.Register[r.first.atom, r.first.op];
ENDLOOP};
UnRegister: PROC = {
FOR r: LIST OF RegCom ¬ registered, r.rest UNTIL r=NIL DO
TEditInput.UnRegister[r.first.atom, r.first.op];
ENDLOOP };
--------------------------
RegisterAdditional: PROC [name: ROPE, proc: TiogaOps.CommandProc, before: BOOL ¬ TRUE, startNextLine: BOOL ¬ TRUE] = {
viewer: ViewerClasses.Viewer ¬ editTool;
noMainEditTool: BOOL ¬ viewer = NIL;
registerButtonCommand: LIST OF ButtonCommandRec ¬ NIL;
menu: Menus.Menu;
menuEntry: Menus.MenuEntry;
clientData: REF ANY;
data: REF BOOL;
menuNowAvail: BOOL;
atom: ATOM ¬ Convert.AtomFromRope[ name ];
exists: BOOL ¬ FALSE;
DrawUpdates: PROC = {
scrollOffset: INTEGER ¬ Containers.ScrollOffset[viewer];
ViewerOps.DestroyViewer[ viewer: mainToolInfo.lastRule, paint: FALSE ]; -- destroy rule
mainToolInfo.layout ¬ NEW[ EditToolBuilder.LayoutRec ¬ mainToolInfo.lastLayout];
mainToolInfo.layout.heightSoFar ¬ mainToolInfo.lastLayout.heightSoFar + scrollOffset;
EditToolPrivate.BuildRegisterButtons[mainToolInfo, registerButtonCommand];
mainToolInfo.lastLayout ¬ mainToolInfo.layout­;
mainToolInfo.lastLayout.heightSoFar ¬ mainToolInfo.layout.heightSoFar - scrollOffset;
ToNext[mainToolInfo.layout, TRUE];
mainToolInfo.lastRule ¬ LastHRule[info: mainToolInfo.layout];
mainToolInfo.layout.heightSoFar ¬ mainToolInfo.layout.heightSoFar - scrollOffset;
mainToolInfo.scrollSectionInfo[EditToolPrivate.otherField].height ¬ mainToolInfo.layout.heightSoFar - mainToolInfo.scrollSectionInfo[EditToolPrivate.otherField].startLocation;
ViewerOps.PaintViewer[ viewer: viewer, hint: client ];
};
TiogaOps.RegisterCommand[ atom, proc, TRUE];
Check to see if it exists.
FOR r: LIST OF ButtonCommandRec ¬ additionalRegistered, r.rest UNTIL r=NIL DO
IF Rope.Equal[r.first.name, name] THEN {
just change the reference to the proc.
exists ¬ TRUE;
r.first.commandOp ¬ proc;
EXIT;
};
ENDLOOP;
IF ~exists THEN {
Record it for the future.
Never start a New Line since it already happened for the first additional button
IF additionalRegistered = NIL THEN
registerButtonCommand ¬ CONS[ [name, atom, LIST[atom], proc, before, FALSE, NIL], registerButtonCommand]
ELSE
registerButtonCommand ¬ CONS[ [name, atom, LIST[atom], proc, before, startNextLine, NIL], registerButtonCommand];
additionalRegistered ¬ CONS[registerButtonCommand.first, additionalRegistered];
};
Don't bother to update if the EditTool viewer doesn't exist or the command already appears.
IF noMainEditTool OR exists THEN RETURN;
an EditTool already exists, so update by first removing the LastHRule and last ToNext
menu ¬ viewer.menu;
menuEntry ¬ Menus.CopyEntry[ Menus.FindEntry[ menu, "Sections"] ];
clientData ¬ Menus.SetClientData[ menuEntry, NIL]; -- only way to query the clientData without affecting it.
data ¬ NARROW[ clientData ];
menuNowAvail ¬ data­;
ViewerLocks.CallUnderWriteLocks[DrawUpdates, viewer];
Adjust height if viewer is on, user is using scrollToOps menu, using variable height, and portion visible is in the other buttons area.
IF ~viewer.iconic AND menuNowAvail AND mainToolInfo.whichHeightScheme = variable AND mainToolInfo.currentHeightIndex = EditToolPrivate.otherField
THEN {
ViewerOps.SetOpenHeight[ viewer, mainToolInfo.scrollSectionInfo[EditToolPrivate.otherField].height ];
ViewerOps.ComputeColumn[ viewer.column, TRUE ];
};
};
ReRegisterAdditional: PROC = {
FOR r: LIST OF ButtonCommandRec ¬ additionalRegistered, r.rest UNTIL r=NIL DO
TiogaOps.RegisterCommand[ r.first.atom, r.first.commandOp, r.first.before ];
ENDLOOP};
UnRegisterAdditional: PROC = {
FOR r: LIST OF ButtonCommandRec ¬ additionalRegistered, r.rest UNTIL r=NIL DO
TEditInput.UnRegister[r.first.atom, r.first.commandOp];
ENDLOOP};
--------------------------
ClearAllNewCommandButtons: PUBLIC PROC = {
toolViewer: ViewerClasses.Viewer ¬ editTool;
noMainEditTool: BOOL ¬ toolViewer = NIL;
menu: Menus.Menu;
menuEntry: Menus.MenuEntry;
clientData: REF ANY;
data: REF BOOL;
menuNowAvail: BOOL;
destroyNewCommandButton: PROC= {
scrollOffset: INTEGER ¬ Containers.ScrollOffset[toolViewer];
FOR r: LIST OF ButtonCommandRec ¬ additionalRegistered, r.rest UNTIL r=NIL DO
ViewerOps.DestroyViewer[ viewer: r.first.viewer, paint: FALSE ]; -- destroy buttons
ENDLOOP;
ViewerOps.DestroyViewer[ viewer: mainToolInfo.lastRule, paint: FALSE ]; -- destroy rule
Back up mainTool.layout to the end of Standard Registered Command
mainToolInfo.layout ¬ NEW[ EditToolBuilder.LayoutRec ¬ mainToolInfo.layoutBeforeExtraCommandButtons ];
mainToolInfo.lastLayout ¬ mainToolInfo.layoutBeforeExtraCommandButtons;
mainToolInfo.layout.heightSoFar ¬ mainToolInfo.lastLayout.heightSoFar + scrollOffset;
mainToolInfo.lastRule ¬ LastHRule[info: mainToolInfo.layout]; -- draw new rule
mainToolInfo.lastLayout.heightSoFar ¬ mainToolInfo.layout.heightSoFar ¬ mainToolInfo.lastLayout.heightSoFar - scrollOffset;
mainToolInfo.scrollSectionInfo[EditToolPrivate.otherField].height ¬ mainToolInfo.layout.heightSoFar - mainToolInfo.scrollSectionInfo[EditToolPrivate.otherField].startLocation;
ViewerOps.PaintViewer[ viewer: toolViewer, hint: client ];
};
Return if the EditTool viewer does not exists, otherwise destroy the viewers
IF noMainEditTool THEN RETURN;
menu ¬ toolViewer.menu;
menuEntry ¬ Menus.CopyEntry[ Menus.FindEntry[ menu, "Sections"] ];
clientData ¬ Menus.SetClientData[ menuEntry, NIL]; -- only way to query the clientData without affecting it.
data ¬ NARROW[ clientData ];
menuNowAvail ¬ data­;
ViewerLocks.CallUnderWriteLocks[destroyNewCommandButton, toolViewer];
IF ~toolViewer.iconic AND menuNowAvail AND mainToolInfo.whichHeightScheme = variable AND mainToolInfo.currentHeightIndex = EditToolPrivate.otherField
THEN {
Adjust height, user is using scrollToOps menu, using variable height, and portion visible is in the operations area.
ViewerOps.SetOpenHeight[ toolViewer, mainToolInfo.scrollSectionInfo[EditToolPrivate.otherField].height ];
ViewerOps.ComputeColumn[ toolViewer.column, TRUE ];
};
Unregister the Commands and set additionalRegistered to NIL
UnRegisterAdditional[];
additionalRegistered ¬ NIL;
};
RegisterCommandButton: PUBLIC PROC [buttonName: ROPE, proc: TiogaOps.CommandProc, before: BOOL ¬ TRUE, startNextLine: BOOL ¬ TRUE] = {
RegisterAdditional[ buttonName, proc, before, startNextLine ]};
EditToolCommand: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: ROPE ← NIL]
viewer: ViewerClasses.Viewer ¬ editTool;
aMainEditTool: BOOL ¬ viewer # NIL;
menu: Menus.Menu;
menuEntry: Menus.MenuEntry;
clientData: REF ANY;
data: REF BOOL;
useRealNames: BOOL ¬ FALSE;
wantsRealNames: BOOL ¬ FALSE;
wantsIconic: BOOL ¬ FALSE;
FOR arg: ROPE ← CommanderOps.NextArgument[cmd], CommanderOps.NextArgument[cmd] UNTIL arg = NIL DO
SELECT TRUE FROM
Rope.Match[arg, "-realnames", FALSE] => wantsRealNames ← TRUE;
Rope.Match[arg, "-iconic", FALSE] => wantsIconic ← TRUE;
ENDCASE => CommanderOps.Failed[cmd.procData.doc];
ENDLOOP;
IF aMainEditTool
THEN {
An EditTool already exists.
menu ¬ viewer.menu;
menuEntry ¬ Menus.CopyEntry[ Menus.FindEntry[ menu, "RealOps"] ];
clientData ¬ Menus.SetClientData[ menuEntry, NIL]; -- only way to query the clientData without affecting it.
data ¬ NARROW[ clientData ];
useRealNames ¬ data­;
IF wantsRealNames = useRealNames
THEN {
The desired editTool panel already exist, just flush the command.
IF viewer.iconic AND NOT wantsIconic THEN ViewerOps.OpenIcon[viewer];
RETURN[NIL, "An Edit Tool already exists."];
}
ELSE {
Same as selecting the RealNames button in the menu but from command line, switch panes.
ChangeEditToolPanel[ viewer, wantsRealNames ]; -- mainToolInfo and editTool will be reinitialized.
[] ¬ Menus.SetClientData[Menus.FindEntry[ menu, "RealOps"], NEW[BOOL ¬ wantsRealNames]]; -- Record new value in the clientData associated with RealNames.
RETURN [NIL, "Changed the Edit Tool pane."];
}
}
ELSE {
No EditTool exists as yet, create a whole new one.
ReRegister[];
ReRegisterAdditional[];
[mainToolInfo, editTool] ¬ DrawPanelViewer[wantsRealNames, TRUE];
[] ← NoteNewEditToolCommand[cmd];
RETURN [NIL, "Created new Edit Tool."];
};
};
NoteNewEditToolCommand: Commander.CommandProc = {
line: ROPE ← UserProfile.Line["EditTool.NewTool", NIL];
IF line # NIL THEN [] ← CommandTool.DoCommand[line, cmd];
};
DrawPanelViewer: PROC [useRealNames: BOOL, useAuxMenu: BOOL] RETURNS [info:Info, viewer: ViewerClasses.Viewer] = {
lastHeightSoFar: INTEGER;
info ¬ NEW[InfoRec];
info.layout ¬ NEW[LayoutRec];
{OPEN info;
BuildRealContents: PROC[] = {
scrollSectionInfo[1].startLocation ¬ layout.heightSoFar;
EditToolPrivate.BuildRealLooksButtons[info]; -- caret/selection looks, Looks:, Get, Set, etc.
ToNext[layout];
scrollSectionInfo[1].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[2].startLocation ¬ layout.heightSoFar;
EditToolPrivate.BuildRealFormatButtons[info];
ToNext[layout];
scrollSectionInfo[2].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[3].startLocation ¬ layout.heightSoFar;
EditToolPrivate.BuildRealStyleButtons[info];
ToNext[layout];
heights[2] ¬ layout.heightSoFar+layout.entryVSpace+1;
scrollSectionInfo[3].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[4].startLocation ¬ layout.heightSoFar;
EditToolPrivate.BuildRealPropertyButtons[info]; -- property values
scrollSectionInfo[4].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[5].startLocation ¬ layout.heightSoFar;
EditToolPrivate.BuildRealSortButtons[info]; -- Sort increasing/decreasing; sort text/lines/branches; Sort
ToNext[layout];
scrollSectionInfo[5].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[6].startLocation ¬ layout.heightSoFar;
BuildOperationField[info]; -- the "Operations:" field
VGap[layout];
BuildRealGetAndSetOpsEntries[info]; -- "GetLast" "SetCom" "GetCom" etc.
VGap[layout];
BuildRealFileListEntries[info]; -- the "Files:" field and the DoForEachFile command
VGap[layout];
heights[3] ¬ layout.heightSoFar+layout.entryVSpace+1;
scrollSectionInfo[6].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[7].startLocation ¬ layout.heightSoFar;
EditToolPrivate.BuildRealExtraButtons[info]; -- the low level edit
--------------------------
};
BuildContents: PROC[] = {
scrollSectionInfo[1].startLocation ¬ layout.heightSoFar;
BuildLooksButtons[info]; -- caret/selection looks, Looks:, Get, Set, etc.
ToNext[layout];
scrollSectionInfo[1].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[2].startLocation ¬ layout.heightSoFar;
BuildFormatButtons[info]; -- format names
ToNext[layout];
scrollSectionInfo[2].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[3].startLocation ¬ layout.heightSoFar;
BuildStyleButtons[info]; -- style names
ToNext[layout];
heights[2] ¬ layout.heightSoFar+layout.entryVSpace+1;
scrollSectionInfo[3].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[4].startLocation ¬ layout.heightSoFar;
BuildPropertyButtons[info]; -- property values
scrollSectionInfo[4].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[5].startLocation ¬ layout.heightSoFar;
BuildSortButtons[info]; -- Sort increasing/decreasing; sort text/lines/branches; Sort
ToNext[layout];
scrollSectionInfo[5].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[6].startLocation ¬ layout.heightSoFar;
BuildOperationField[info]; -- the "Operations:" field
VGap[layout];
BuildGetAndSetOpsEntries[info]; -- "GetLast" "SetCom" "GetCom" etc.
VGap[layout];
BuildFileListEntries[info]; -- the "Files:" field and the DoForEachFile command
VGap[layout];
heights[3] ¬ layout.heightSoFar+layout.entryVSpace+1;
scrollSectionInfo[6].height ¬ layout.heightSoFar - lastHeightSoFar;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
scrollSectionInfo[7].startLocation ¬ layout.heightSoFar;
BuildExtraButtons[info]; -- the low level edit
--------------------------
};
interrupt ¬ TEditInput.interrupt;
layout.entryLeft ¬ layout.initLeft ¬ 0;
layout.entryVSpace ¬ 3;
scrollSectionInfo[0].startLocation ¬ lastHeightSoFar ¬ layout.heightSoFar ¬ layout.initHeight ¬ 1;
--------------------------
viewer ¬ BuildContainer[info, "EditTool", useRealNames, useAuxMenu]; -- build enclosing viewer
--------------------------
BuildTargetEntry[info]; -- the "target:" field
BuildSourceEntry[info]; -- the "replacement:" field
heights[0] ¬ layout.heightSoFar+layout.entryVSpace;
layout.heightSoFar ¬ layout.heightSoFar+2;
--------------------------
BuildSearchButtons[info, useRealNames]; -- the various choices for seaching
ToNext[layout];
BuildInitCapEntry[info, useRealNames]; -- Capitalize like first replaced char or not
ToMiddle[layout];
BuildOperationEntry[info, useRealNames]; -- Do Replace / Do Operations Specified Below
ToNext[layout];
BuildSubstituteEntry[info, useRealNames]; -- the within/after/entire choice
ToNext[layout];
BuildMiniPatternDocEntry[info];
scrollSectionInfo[0].height ¬ heights[1] ¬ layout.heightSoFar+layout.entryVSpace+1;
HRule[layout];
lastHeightSoFar ¬ layout.heightSoFar;
--------------------------
IF useRealNames
THEN BuildRealContents[]
ELSE BuildContents[];
--------------------------
ToNext[layout, TRUE];
lastLayout ¬ layout­;
layoutBeforeExtraCommandButtons ¬ layout­;
IF additionalRegistered # NIL THEN {
EditToolPrivate.BuildRegisterButtons[info, additionalRegistered];
Save the information in info.layout, in case additional buttons get added later
lastLayout ¬ layout­;
ToNext[layout, TRUE];
};
lastRule ¬ LastHRule[layout];
scrollSectionInfo[7].height ¬ layout.heightSoFar - lastHeightSoFar;
--------------------------
--BuildPatternDocEntry[info];-- -- explaining special chars for patterns
--------------------------
whichHeightScheme ¬ fixed;
currentHeightIndex ¬ 0;
ViewerOps.SetOpenHeight[layout.container, heights[currentHeightIndex]];
}; -- of open info.
ViewerOps.AddProp[ viewer, $EditTool, info ]; -- save the info structure away in the viewer so other tools can get at them.
};
-- Initialization
Commander.Register["EditTool", EditToolCommand, "Create a Tioga Edit Tool\nswitches:\n -realnames - use alternate panel\n -iconic - create as icon"];
Commander.Register["NoteNewEditTool", NoteNewEditToolCommand, "Executes the EditTool.NewTool user profile item."];
[] ¬ ViewerEvents.RegisterEventProc[MyDestroy, destroy];
}.