PopUpCommandImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Eric Nickell, May 22, 1986 2:51:21 pm PDT
Last edited by: Christian Jacobi, August 26, 1986 4:35:49 pm PDT
DIRECTORY
Atom, Commander, CommandTool, CommandToolLookup, PopUpSelection, Process, ProcessProps, Rope, ViewerClasses;
PopUpCommandImpl:
CEDAR
PROGRAM
IMPORTS Atom, Commander, CommandTool, CommandToolLookup, PopUpSelection, Process, ProcessProps, Rope
ROPE: TYPE ~ Rope.ROPE;
usageMessage: ROPE ~ "\n Usage: PopUpCommand [-title] \"cmd1\" \"cmd2\" ...";
PopUp: Commander.CommandProc = {
options: LIST OF ROPE ← CommandTool.ParseToList[cmd: cmd].list;
IF options#
NIL
THEN {
header: ROPE ← NIL;
IF Rope.Fetch[options.first]='-
THEN {
header ← Rope.Substr[base: options.first, start: 1];
options ← options.rest;
IF options=NIL THEN RETURN [msg: usageMessage, result: $Failure];
IF Rope.Length[header]=0
THEN {
header ← options.first;
options ← options.rest;
IF options=NIL THEN RETURN [msg: usageMessage, result: $Failure];
};
};
TRUSTED {Process.Detach[FORK SelectAndExecute[header: header, options: options, processProps: ProcessProps.GetPropList[], viewer: CommandTool.GetViewer[cmd: cmd]]]};
}
ELSE RETURN [msg: usageMessage, result: $Failure];
};
FirstNonBlank:
PROC [r:
ROPE]
RETURNS [
ROPE] =
INLINE {
n: INT ~ Rope.SkipTo[s: r, skip: " "];
RETURN [Rope.Substr[base: r, len: n]]
};
Doc:
PROC [for:
ROPE, rules:
REF←
NIL]
RETURNS [
ROPE←
NIL] = {
procData: Commander.CommandProcHandle ← CommandToolLookup.FindMatchingCommands[FirstNonBlank[for], TRUE, rules].data;
IF procData#NIL THEN RETURN [procData.doc];
};
SelectAndExecute:
PROC [header:
ROPE, options:
LIST
OF
ROPE, processProps: ProcessProps.AList, viewer: ViewerClasses.Viewer] ~ {
Inner:
PROC ~ {
selection: INT; rules: REF ← NIL;
docs, doctail: LIST OF ROPE ← NIL;
WITH Atom.GetPropFromList[processProps, $CommanderHandle]
SELECT
FROM
h: Commander.Handle => rules ← Atom.GetPropFromList[h.propertyList, $SearchRules];
ENDCASE => NULL;
FOR list:
LIST
OF
ROPE ← options, list.rest
WHILE list#
NIL
DO
doc: ROPE ← Doc[list.first, rules];
IF doctail#
NIL
THEN {
doctail.rest ← LIST[doc];
doctail ← doctail.rest;
}
ELSE doctail ← docs ← LIST[doc];
ENDLOOP;
selection ← PopUpSelection.Request[header: header, choice: options, choiceDoc: docs, 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.", interpreted: FALSE];
END.