LoginCommands.Mesa
Spreitzer, November 9, 1984 1:48:44 pm PST
Russ Atkinson, May 24, 1984 1:11:56 pm PDT
DIRECTORY Commander, CommandExtras, CommandTool, CommandToolExtras, EditedStream, IO, MessageWindow, Process, Rope, UserCredentials, UserProfile, ViewerClasses, ViewerOps;
LoginCommands: CEDAR MONITOR
IMPORTS Commander, CommandExtras, CommandTool, CommandToolExtras, EditedStream, MessageWindow, --Process,-- Rope, UserCredentials, UserProfile, ViewerOps =
BEGIN
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
currentUser: ROPENIL;
perLogin, perCommandTool: ROPENIL;
preferred: Viewer ← NIL;
enabled: BOOLEANFALSE;
asterisky: BOOLEANFALSE;
Login: Commander.CommandProc --PROC [cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]-- = {
oldEcho: IO.STREAM;
StartInteraction: PROC RETURNS [in, out: IO.STREAM] = {
IF asterisky THEN {
EditedStream.SetMode[
stream: cmd.in,
echoAsterisks: TRUE]}
ELSE {
oldEcho ← EditedStream.GetEcho[cmd.in];
EditedStream.SetEcho[cmd.in, NIL]};
in ← cmd.in;
out ← cmd.out;
};
EndInteraction: PROC [in, out: IO.STREAM] = {
IF asterisky THEN {
EditedStream.SetMode[
stream: cmd.in,
echoAsterisks: FALSE]}
ELSE {
EditedStream.SetEcho[cmd.in, oldEcho]};
};
UserCredentials.Login[
startInteraction: StartInteraction,
endInteraction: EndInteraction,
options: [alwaysInteract: TRUE]];
};
NoteHere: Commander.CommandProc --PROC [cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]-- = {
preferred ← CommandToolExtras.GetViewer[cmd];
};
DoPerCommandTool: Commander.CommandProc --PROC [cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]-- = {
IF enabled THEN [] ← CommandTool.DoCommand[commandLine: perCommandTool, parent: cmd];
};
Enable: Commander.CommandProc --PROC [cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]-- = {
enabled ← TRUE;
NoteLogin[firstTime];
};
News: ENTRY PROC [reason: UserProfile.ProfileChangeReason] RETURNS [new: BOOL] =
BEGIN ENABLE UNWIND => {};
user, pl, pc: ROPE;
new ← FALSE;
user ← UserCredentials.Get[].name;
pl ← UserProfile.Token[key: "LoginCommands.PerLogin", default: NIL];
pc ← UserProfile.Token[key: "LoginCommands.PerCommandTool", default: NIL];
IF NOT user.Equal[s2: currentUser, case: FALSE] THEN {
currentUser ← user;
new ← TRUE};
IF NOT pl.Equal[s2: perLogin, case: FALSE] THEN {
perLogin ← pl;
IF reason # edit THEN new ← TRUE ELSE primed ← TRUE};
IF NOT pc.Equal[s2: perCommandTool, case: FALSE] THEN {
perCommandTool ← pc;
IF reason # edit THEN new ← TRUE ELSE primed ← TRUE};
IF primed AND (reason # edit) THEN new ← TRUE;
IF new THEN primed ← FALSE;
END;
primed: BOOLFALSE;
LoginWork: PROC =
BEGIN
looking: BOOL ← preferred = NIL OR preferred.destroyed;
FindOne: ViewerOps.EnumProc --PROC [v: Viewer] RETURNS [BOOL ← TRUE]-- =
BEGIN
IF v.name.Find["CommandTool: "] = 0 AND v.class.flavor = $Typescript
THEN {preferred ← v; looking ← FALSE};
RETURN [looking];
END;
NoteViewer: ViewerOps.EnumProc --PROC [v: Viewer] RETURNS [BOOL ← TRUE]-- =
BEGIN
IF v.name.Find["CommandTool: "] = 0 AND v.class.flavor = $Typescript THEN {
IF v # preferred THEN v.class.notify[v, LIST[perCommandTool]];
};
END;
Process.Pause[Process.SecondsToTicks[45]];
IF perLogin.Length[] # 0 THEN {
IF looking THEN ViewerOps.EnumerateViewers[FindOne];
IF looking THEN MessageWindow.Append[" LoginCommands couldn't find a CommandTool"]
ELSE preferred.class.notify[preferred, LIST[perLogin]];
};
IF perCommandTool.Length[] # 0
THEN ViewerOps.EnumerateViewers[NoteViewer];
END;
NoteLogin: PROC [reason: UserProfile.ProfileChangeReason] =
BEGIN
IF enabled AND News[reason] THEN LoginWork[];
END;
pcReason: UserProfile.ProfileChangeReason;
NoteProfileChanges: UserProfile.ProfileChangedProc --PROC [reason: ProfileChangeReason]-- =
BEGIN
pcReason ← reason;
IF reason = rollBack THEN enabled ← TRUE;
NoteLogin[reason];
END;
EnsureButton: Commander.CommandProc --PROC [cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]-- = {
[] ← CommandTool.DoCommand[
commandLine: Rope.Cat["RemoveButton ", cmd.commandLine],
parent: cmd];
[] ← CommandTool.DoCommand[
commandLine: Rope.Cat["CreateButton ", cmd.commandLine],
parent: cmd];
};
Commander.Register[key: "///Commands/EnsureButton", proc: EnsureButton, doc: "Remove and Create Button"];
CommandExtras.MakeUninterpreted[Commander.Lookup["///Commands/EnsureButton"]];
Commander.Register[key: "LoginCommandsHere", proc: NoteHere, doc: "Use this CommandTool for per login commands"];
Commander.Register[key: "EnableLoginCommands", proc: Enable, doc: "Enable login commands"];
Commander.Register[key: "DoPerCommandTool", proc: DoPerCommandTool, doc: "Execute the PerCommandTool login commands, if enabled"];
UserProfile.CallWhenProfileChanges[NoteProfileChanges];
END.