DIRECTORY
Menus
USING [MouseButton, Menu, MenuEntry, MenuLine, MenuProc,
AppendMenuEntry, ChangeNumberOfLines, CreateMenu, CreateEntry, GetNumberOfLines, GetLine, SetLine],
Rope,
TiogaMenuOps
USING [AllLevels, FewerLevels, FirstLevelOnly, MoreLevels, Normalize,
Position, PrevPlace],
TiogaOps USING [SearchDir, FindDef, FindText, FindWord],
ViewerBLT USING [ChangeNumberOfLines],
ViewerClasses USING [Viewer],
ViewerOps USING [BlinkIcon, FetchProp],
WalnutDisplayerInternal USING [MsgGvId],
WalnutMsgSetDisplayerPrivate
USING [MsgSetInfo, MsgSetFieldHandle, MsgInfo,
AddProc, CategoriesProc, DeleteProc, DisplayProc, MoveToProc, NewMailProc,
PrintSelectedProc],
WalnutPrintOps USING [MsgSetPrintProc],
WalnutViewer USING [CreateMenuEntry],
WalnutWindowInternal USING [MsgSetButton, walnutQueue];
WalnutDisplayerMenusImpl: CEDAR PROGRAM
IMPORTS
Rope,
WalnutDisplayerInternal, WalnutMsgSetDisplayerPrivate,
WalnutPrintOps, WalnutViewer, WalnutWindowInternal,
Menus, TiogaMenuOps, TiogaOps,
ViewerBLT, ViewerOps
EXPORTS
WalnutMsgSetDisplayerPrivate
Menus used in message set displays
displayerMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
activeMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
deletedMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
buildingMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
readOnlyMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
placesMenuEntry: Menus.MenuEntry;
levelsMenuEntry: Menus.MenuEntry;
opsMenuEntry: Menus.MenuEntry;
Error message
FindProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
IF ~TiogaOps.FindText[
viewer: msI.tiogaViewer,
whichDir: GetDirection[mouseButton],
which: feedback,
case: ~shift]
THEN ViewerOps.BlinkIcon[msViewer];
};
WordProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
IF ~TiogaOps.FindWord[
viewer: msI.tiogaViewer,
whichDir: GetDirection[mouseButton],
which: feedback,
case: ~shift]
THEN ViewerOps.BlinkIcon[msViewer];
};
DefProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
IF ~TiogaOps.FindDef[
viewer: msI.tiogaViewer,
whichDir: GetDirection[mouseButton],
which: feedback,
case: ~shift]
THEN ViewerOps.BlinkIcon[msViewer];
};
PositionProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.Position[msI.tiogaViewer];
};
NormalizeProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.Normalize[msI.tiogaViewer];
};
PrevPlaceProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.PrevPlace[msI.tiogaViewer];
};
FirstOnlyProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.FirstLevelOnly[msI.tiogaViewer];
};
MoreLevelsProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.MoreLevels[msI.tiogaViewer];
};
FewerLevelsProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.FewerLevels[msI.tiogaViewer];
};
AllLevelsProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.AllLevels[msI.tiogaViewer];
};
GVIDProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
selected: MsgSetFieldHandle = msI.selected;
IF selected = NIL THEN RETURN;
WalnutDisplayerInternal.MsgGvId[selected.msgInfo.msg, mouseButton#red];
};
LevelsProc: Menus.MenuProc = { ChangeMenu[NARROW[parent], levelsMenuEntry] };
OpsProc: Menus.MenuProc = { ChangeMenu[NARROW[parent], opsMenuEntry] };
PlacesProc: Menus.MenuProc = { ChangeMenu[NARROW[parent], placesMenuEntry] };
GetDirection:
PROC[mb: Menus.MouseButton]
RETURNS[sd: TiogaOps.SearchDir] = {
SELECT mb
FROM
red => RETURN[forwards];
yellow => RETURN[anywhere];
blue => RETURN[backwards];
ENDCASE;
};
Getting the menu changed
ChangeMenu:
PROC [viewer: ViewerClasses.Viewer, subMenu: Menus.MenuEntry] = {
menu: Menus.Menu = viewer.menu;
found: BOOL ← FALSE;
numLines: Menus.MenuLine = Menus.GetNumberOfLines[menu];
newLines: Menus.MenuLine ← numLines;
FOR i: Menus.MenuLine
IN [1..numLines)
DO
-- see if already showing the submenu
IF Rope.Equal[Menus.GetLine[menu,i].name, subMenu.name]
THEN {
-- yes, so remove it
FOR j: Menus.MenuLine
IN (i..numLines)
DO
Menus.SetLine[menu, j-1, Menus.GetLine[menu, j]];
ENDLOOP;
Menus.ChangeNumberOfLines[menu, newLast-1];
newLines ← newLines-1;
found ← TRUE; EXIT
};
ENDLOOP;
IF ~found
THEN {
-- add it. do insertion sort to get it in the right place
GoesBefore:
PROC [m1, m2: Menus.MenuEntry]
RETURNS [
BOOL] = {
Priority:
PROC [m: Menus.MenuEntry]
RETURNS [
INTEGER] = {
higher priority means goes above in series of submenus
looks at rope for first item to identify the subMenu.
RETURN [
SELECT
TRUE
FROM
Rope.Equal[m.name, "Find"] => 2,
Rope.Equal[m.name, "FirstLevelOnly"] => 1,
Rope.Equal[m.name, "Categories"] => 0,
ENDCASE => -1 -- unknown menu goes at bottom -- ]
};
RETURN [Priority[m1] > Priority[m2]]
};
newLast: Menus.MenuLine = MIN[numLines, LAST[Menus.MenuLine]];
newLines ← newLines+1;
Menus.ChangeNumberOfLines[menu, newLast+1];
FOR i: Menus.MenuLine
IN [1..numLines)
DO
IF GoesBefore[subMenu, Menus.GetLine[menu, i]]
THEN {
-- put it here
FOR j: Menus.MenuLine
DECREASING
IN (i..newLast]
DO
Menus.SetLine[menu, j, Menus.GetLine[menu, j-1]]; ENDLOOP;
Menus.SetLine[menu, i, subMenu];
found ← TRUE; EXIT
};
ENDLOOP;
IF ~found THEN Menus.SetLine[menu, newLast, subMenu];
};
ViewerOps.EstablishViewerPosition[viewer, viewer.wx, viewer.wy, viewer.ww, viewer.wh];
ViewerOps.PaintViewer[viewer, all];
ViewerBLT.ChangeNumberOfLines[viewer, newLines];
};