PopUpCommandImpl.mesa
Copyright Ó 1986, 1992 by Xerox Corporation. All rights reserved.
Eric Nickell, May 22, 1986 2:51:21 pm PDT
Last edited by: Christian Jacobi, August 7, 1990 2:25 pm PDT
DIRECTORY
Commander, CommanderOps, IO, PopUpSelection, Rope;
PopUpCommandImpl: CEDAR PROGRAM
IMPORTS Commander, CommanderOps, IO, PopUpSelection, Rope
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
usageMessage: ROPE ~ "\n Usage: PopUpCommand [-title] \"cmd1\" \"cmd2\" ...";
PopUp: Commander.CommandProc = {
options: LIST OF ROPE ¬ CommanderOps.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];
};
};
--(Ch. J) Used to FORK. But had problem of finding streams and property lists. I did forget why the fork was useful and therefore removed it. I think it was only useful to allow button ahead.
BEGIN
selection: INT;
docs, doctail: LIST OF ROPE ¬ NIL;
FOR list: LIST OF ROPE ¬ options, list.rest WHILE list#NIL DO
doc: ROPE ¬ Doc[list.first];
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: 0]; --default was 1 but 0 prevents silly bug
IF selection>0 THEN {
THROUGH [1..selection) DO
options ¬ options.rest;
ENDLOOP;
--(Ch. J) Used to use viewer.class.notify....
IO.PutRope[cmd.out, Rope.Cat[" ", options.first, "\n"]];
[result, msg] ¬ CommanderOps.ExecuteCommand[cmd, Rope.Concat[options.first, "\n"]];
};
END;
}
ELSE RETURN [msg: usageMessage, result: $Failure];
};
FirstNonBlank: PROC [r: ROPE] RETURNS [ROPE] = {
n: INT ~ Rope.SkipTo[s: r, skip: " "];
RETURN [Rope.Substr[base: r, len: n]]
};
LimitHelp: PROC [r: ROPE] RETURNS [ROPE] = {
n: INT ~ Rope.SkipTo[s: r, skip: "\r\l\n"];
Translator: Rope.TranslatorType = {
SELECT TRUE FROM
old>=32C AND old<=177C => RETURN [old];
ENDCASE => RETURN [' ]
};
RETURN [Rope.Translate[base: r, len: n, translator: Translator]]
};
Doc: PROC [for: ROPE] RETURNS [ROPE¬NIL] = {
--(Ch. J) Used to use CommandToolLookup which gave more info. This is simpler...
procData: Commander.CommandProcHandle ¬ Commander.Lookup[FirstNonBlank[for]];
IF procData#NIL THEN RETURN [LimitHelp[procData.doc]];
};
Commander.Register[key: "PopUpCommand", proc: PopUp, doc: Rope.Concat["Pops up menu for selection of next command.", usageMessage], interpreted: FALSE];
END.