-- TapeToolUtilitiesImpl.mesa
Copyright © 1984, 1985 Xerox Corporation. All rights reserved.
Last Edited by: McCreight, February 26, 1985 3:40:46 pm PST
Tim Diebert May 13, 1985 4:37:49 pm PDT
DIRECTORY
Idle USING [IdleHandler, RegisterIdleHandler, UnregisterIdleHandler],
IO USING [Close, EndOfStream, GetTokenRope, IDProc, RIS, STREAM],
Rope USING [Cat, Index, ROPE, Substr],
TapeToolInternal USING [ExecuteOp, Parameters, TapeTool, ToolParameters],
UserCredentials USING [Get],
UserProfile USING [Boolean, ListOfTokens, Number, ProfileChangedProc, Token],
VFonts USING [EstablishFont, Font, FontHeight],
ViewerClasses USING [Viewer],
ViewerTools USING [GetContents, SetContents];
TapeToolUtilitiesImpl: CEDAR MONITOR
IMPORTS Idle, IO, Rope, TapeToolInternal, UserCredentials, UserProfile, VFonts, ViewerTools
EXPORTS TapeToolInternal =
BEGIN
OPEN Tool: TapeToolInternal;
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
---- ---- ---- ---- ---- ---- ---- ----
Global Variables (protected by monitor)
---- ---- ---- ---- ---- ---- ---- ----
parameters: Tool.Parameters ← NIL;
atIdle: BOOLFALSE;
profileTool: Tool.TapeTool ← NIL;
curUser: ROPENIL;
---- ---- ---- ---- ---- ---- ---- ----
Utilities (exports to TapeToolInternal for individual ops)
---- ---- ---- ---- ---- ---- ---- ----
ViewerToRopeList: PUBLIC PROC [viewer: ViewerClasses.Viewer]
RETURNS [list: LIST OF ROPENIL] = BEGIN
tail: LIST OF ROPENIL;
s: IO.STREAM = IO.RIS[ViewerTools.GetContents[viewer]];
DO
r: ROPE ← s.GetTokenRope[IO.IDProc ! IO.EndOfStream => EXIT].token;
rL: LIST OF ROPE;
rL ← CONS[r, NIL];
IF list = NIL THEN list ← rL ELSE tail.rest ← rL;
tail ← rL;
ENDLOOP;
s.Close[];
END;
GetToolParameters: PUBLIC PROC RETURNS [Tool.Parameters] = {RETURN[parameters]};
ResetNewParameters: PUBLIC ENTRY PROC = BEGIN
parameters.new ← FALSE;
END;
ReactToProfile: PUBLIC ENTRY UserProfile.ProfileChangedProc = BEGIN
ENABLE UNWIND => NULL;
params: Tool.Parameters ← NEW[Tool.ToolParameters];
fontFamily: ROPE = UserProfile.Token["TapeTool.FontFamily", "Tioga"];
fontSize: NAT = UserProfile.Number["TapeTool.FontSize", 10];
userName: ROPE ← UserCredentials.Get[].name;
host: ROPE ← UserProfile.Token["TapeTool.Host", "Ivy"];
userName ← userName.Substr[len: userName.Index[s2: "."]];
params.fileNamePrefixes ← UserProfile.ListOfTokens[
key: "TapeTool.FileNamePrefixes",
default: LIST[Rope.Cat["[", host, "]<", userName, ">"], NIL]
];
params.font ← VFonts.EstablishFont[fontFamily, fontSize];
params.fixedFont ← VFonts.EstablishFont[family: "Gacha", size: fontSize - 2];
params.entryHeight ← VFonts.FontHeight[params.font] + 2;
params.entryVSpace ← VFonts.FontHeight[params.font]*1/6;
params.entryHSpace ← 10;
params.localDisk ← UserProfile.Boolean["TapeTool.Local", FALSE];
params.defaultServer ← UserProfile.Token["TapeTool.Server", "Maggie"];
params.new ← TRUE;
parameters ← params;
IF profileTool # NIL THEN BEGIN
ViewerTools.SetContents[profileTool.fileNameViewer,
(IF params.fileNamePrefixes = NIL
THEN NIL ELSE params.fileNamePrefixes.first)];
END;
END;
RegisterProfile: PUBLIC ENTRY PROC [tool: Tool.TapeTool] = BEGIN
profileTool ← tool;
END;
UnregisterProfile: PUBLIC ENTRY PROC [tool: Tool.TapeTool] = BEGIN
profileTool ← NIL;
END;
RegisterIdle: PUBLIC ENTRY PROC [tool: Tool.TapeTool] = BEGIN
tool.idleEvent ← Idle.RegisterIdleHandler[RegisterProc, tool];
END;
UnRegisterIdle: PUBLIC ENTRY PROC [tool: Tool.TapeTool] = BEGIN
IF tool.idleEvent = NIL THEN RETURN [];
Idle.UnregisterIdleHandler[tool.idleEvent];
END;
IdleCheck: PUBLIC ENTRY PROC [tool: Tool.TapeTool] RETURNS [idle: BOOL] = BEGIN
RETURN [atIdle];
END;
RegisterProc: Idle.IdleHandler = BEGIN
IdleHandler: TYPE = PROC [data: REF, reason: IdleReason];
tool: Tool.TapeTool ← NARROW[data];
atIdle ← IF reason = becomingIdle THEN TRUE ELSE FALSE;
IF atIdle AND tool.open AND NOT tool.active THEN Tool.ExecuteOp[tool: tool, op: [op: Close]];
END;
ReactToProfile[edit];
END.