X11EvalWidget.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Christian Jacobi, April 24, 1991 7:16 pm PDT
Christian Jacobi, March 27, 1992 11:17 am PST
DIRECTORY
Commander, CommanderOps, IO, Rope, X11Eval, Xl, XTk, XTkWidgets;
X11EvalWidget: CEDAR PROGRAM
IMPORTS Commander, CommanderOps, IO, Rope, X11Eval, Xl, XTk, XTkWidgets ~
BEGIN
Instance: TYPE = REF InstanceRec;
InstanceRec: TYPE = RECORD [
text, dest, server: XTk.Widget ¬ NIL,
log: IO.STREAM
];
LegalDestination: PROC [destination: Rope.ROPE] RETURNS [BOOL¬TRUE] = {
IF Rope.IsEmpty[destination] THEN RETURN [FALSE];
};
DoStuff: XTkWidgets.ButtonHitProcType = {
state: X11Eval.Result;
answer: Rope.ROPE;
i: Instance ~ NARROW[registerData];
text: Rope.ROPE ~ XTkWidgets.GetText[i.text];
destination: Rope.ROPE ~ XTkWidgets.GetText[i.dest];
server: Rope.ROPE ~ XTkWidgets.GetText[i.server];
connection: REF ANY ¬ server;
IF ~LegalDestination[destination] THEN {
IO.PutRope[i.log, "Illegal selection\n"];
RETURN
};
IF Rope.Equal[server, "LocalHost", FALSE] OR Rope.IsEmpty[server] THEN {
connection ¬ i.text.connection
};
[state, answer] ¬ X11Eval.Query[server: connection, selection: destination, text: text, timeout: 5];
SELECT state FROM
noServer => IO.PutRope[i.log, "No server;"];
noSelection => IO.PutRope[i.log, "No selection;"];
timeout => IO.PutRope[i.log, "Timeout;"];
badProtocol => IO.PutRope[i.log, "Protocol error;"];
crashed => IO.PutRope[i.log, "Crashed;"];
failed => IO.PutRope[i.log, "Failed;"];
success => IO.PutRope[i.log, "Done:"];
ENDCASE => {};
IO.PutF1[i.log, " %g\n", IO.rope[answer]];
};
CreateInstanceCommand: Commander.CommandProc ~ {
ENABLE {
Xl.XError => CommanderOps.Failed[err.explanation];
Xl.connectionNotCreated => CommanderOps.Failed[why.reason];
};
i: Instance ~ NEW[InstanceRec];
shell: XTk.Widget ~ XTkWidgets.CreateShell[windowHeader: "X11 Eval widget", className: $X11EvalWidget, standardMigration: TRUE];
doit: XTk.Widget ~ XTkWidgets.CreateButton[text: "Apply", hitProc: DoStuff, registerData: i, tq: shell.rootTQ];
logWidget: XTk.Widget ~ XTkWidgets.CreateStreamWidget[[geometry: XTk.G[300, 100, 1]]];
i.log ¬ XTkWidgets.CreateStream[logWidget];
i.text ¬ XTkWidgets.CreateLabeledField[[], "command:", "date"];
i.dest ¬ XTkWidgets.CreateLabeledField[[], "selection:", "CedarCommander"];
i.server ¬ XTkWidgets.CreateLabeledField[[], "server:", "LocalHost"];
XTkWidgets.SetShellChild[shell: shell, child: XTkWidgets.CreateYStack[stack: LIST[doit, i.server, i.dest, i.text, logWidget]]];
XTkWidgets.RealizeShell[shell];
};
Commander.Register["X11EvalWidget", CreateInstanceCommand, "Creates a X11Eval widget"];
END.