PopUpCommandImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Eric Nickell, May 22, 1986 2:51:21 pm PDT
DIRECTORY
Commander, CommandTool, PopUpMenu, Process, ProcessProps, Rope, ViewerClasses;
PopUpCommandImpl: CEDAR PROGRAM
IMPORTS Commander, CommandTool, PopUpMenu, Process, ProcessProps, Rope
EXPORTS ExportsList
~ BEGIN
OPEN Interface;
ROPE: TYPE ~ Rope.ROPE;
usageMessage: ROPE ~ "\n Usage: PopUpCommand [-title] \"cmd1\" \"cmd2\" ...";
PopUp: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
options: LIST OF ROPE ← CommandTool.ParseToList[cmd: cmd].list;
IF options#NIL THEN {
label: ROPENIL;
IF Rope.Fetch[base: options.first]='- THEN {
label ← Rope.Substr[base: options.first, start: 1];
options ← options.rest;
IF options=NIL THEN RETURN [msg: usageMessage, result: $Failure];
IF Rope.Length[label]=0 THEN {
label ← options.first;
options ← options.rest;
IF options=NIL THEN RETURN [msg: usageMessage, result: $Failure];
};
};
TRUSTED {Process.Detach[FORK SelectAndExecute[label: label, options: options, processProps: ProcessProps.GetPropList[], viewer: CommandTool.GetViewer[cmd: cmd]]]};
}
ELSE RETURN [msg: usageMessage, result: $Failure];
};
SelectAndExecute: PROC [label: ROPE, options: LIST OF ROPE, processProps: ProcessProps.AList, viewer: ViewerClasses.Viewer] ~ {
Inner: PROC ~ {
selection: INT ← PopUpMenu.RequestSelection[label: label, choice: options, default: 1];
IF selection>0 THEN {
THROUGH [1..selection) DO
options ← options.rest;
ENDLOOP;
viewer.class.notify[viewer, LIST[Rope.Concat[options.first, "\n"]]];
};
};
ProcessProps.AddPropList[propList: processProps, inner: Inner];
};
Commander.Register[key: "///Commands/PopUpCommand", proc: PopUp, doc: "Pops up menu for selection of next command."];
END.