WPFinchDirectoryImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Terry, June 17, 1987 11:33:12 am PDT
Whitepage directory facilities taken from FinchDirectoryImpl.mesa (on June 17, 1987 10:28:49 am PDT). Eventually this should be better integrated with Finch (the only change was exporting DirectoryButtonNotifier and removing stuff not needed by it).
DIRECTORY
FinchSmarts USING [ ConvDesc, PlaceCall ],
FinchTool USING [ CheckActive, FeepValue, finchQueue, finchToolHandle, GetSelectedDesc, Report, Status ],
IO,
MBQueue USING [QueueClientAction],
NodeProps USING [ GetProp ],
Rope,
Thrush USING [ ConversationID, nullConvID ],
TiogaButtons USING [ GetRope, TextNodeRef, TiogaButton, TiogaButtonProc ],
TiogaOps USING [ Ref, Root, SetSelection ],
ViewerClasses USING [ Column, Viewer, ViewerRec ],
ViewerTools USING [ SetContents ],
VoiceUtils USING [ Registrize ],
WPDirectory;
WPFinchDirectoryImpl: CEDAR PROGRAM
IMPORTS Rope, FinchSmarts, FinchTool, IO, MBQueue, NodeProps, TiogaButtons, TiogaOps, ViewerTools, VoiceUtils
EXPORTS WPDirectory = {
OPEN IO;
Types and Typeoids
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
DirectoryInstance: TYPE = REF DirectoryInstanceBody;
DirectoryInstanceBody: TYPE = RECORD [
rName: Rope.ROPE←NIL,
name: Rope.ROPE←NIL,
number: Rope.ROPE←NIL,
homeNumber: Rope.ROPE←NIL,
remarks: Rope.ROPENIL,
where: Where ← office, -- Oh, for closures!
filled: BOOLFALSE
];
Where: TYPE = { office, home };
Selecting, Placing calls
DirectoryButtonNotifier: PUBLIC TiogaButtons.TiogaButtonProc = {
[parent: REF ANY, clientData: REF ANY ← NIL,
mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
directoryInstance: DirectoryInstance;
SelectEntryInDirectory[button];
directoryInstance ← IF button.clientData = NIL THEN
(button.clientData ← NEW[DirectoryInstanceBody ← []]) ELSE NARROW[button.clientData];
IF control OR mouseButton = red THEN RETURN;
directoryInstance.where ← SELECT mouseButton FROM blue=>home, ENDCASE=>office;
MBQueue.QueueClientAction[FinchTool.finchQueue, DirectoryButton, button];
};
SelectEntryInDirectory: PROC[button: TiogaButtons.TiogaButton] = {
root: TiogaOps.Ref = TiogaOps.Root[button.startLoc.node];
v: ViewerClasses.Viewer =
NARROW[NodeProps.GetProp[TiogaButtons.TextNodeRef[root], $Viewer]];
IF v=NIL THEN ERROR;
TiogaOps.SetSelection[
viewer: v, start: [button.startLoc.node, 0],
end: [button.endLoc.node, TiogaButtons.GetRope[button].Length[]],
level: node, which: feedback ];
};
DirectoryButton: PROC[r: REF ANY] = {
Check these for new Cedar interp.
button: TiogaButtons.TiogaButton = NARROW[r];
directoryInstance: DirectoryInstance ← FillDirectoryInstance[button];
convDesc: FinchSmarts.ConvDesc = FinchTool.GetSelectedDesc[];
IF convDesc#NIL AND convDesc.situation.self.state > $parsing THEN
FinchTool.Report["Call already in progress"]
ELSE CallNumber[directoryInstance, directoryInstance.where, convDesc];
};
CallNumber: PROC[
instance: DirectoryInstance, where: Where, convDesc: FinchSmarts.ConvDesc] = {
name, number: Rope.ROPE;
convID: Thrush.ConversationID
= IF convDesc=NIL THEN Thrush.nullConvID ELSE convDesc.situation.self.convID;
IF instance=NIL OR ~FinchTool.CheckActive[FinchTool.finchToolHandle] THEN RETURN;
name ← IF instance.rName#NIL THEN instance.rName ELSE instance.name;
number ← IF where=home THEN instance.homeNumber ELSE instance.number;
IF where=home AND Rope.Equal[number,""] THEN {
FinchTool.Status[IO.PutFR["No home number for %s", rope[name]]];
}
ELSE {
contents: ROPE ← name;
FinchTool.Status[IO.PutFR["Placing call to %s (%s)", rope[name], rope[number]]];
IF where=home THEN contents ← contents.Concat[" at home"];
ViewerTools.SetContents[FinchTool.finchToolHandle.calledPartyText, contents];
FinchSmarts.PlaceCall[convID: convID, rName: name, number: FinchTool.FeepValue[number], useNumber: where=home OR instance.rName=NIL];
This should launch the call
};
};
Creating, Maintaining Directories
FillDirectoryInstance: PROC [button: TiogaButtons.TiogaButton]
RETURNS[instance: DirectoryInstance] = {
entry: Rope.ROPE = TiogaButtons.GetRope[button];
entryStream: IO.STREAM = IO.RIS[entry];
rnameStart, rnameEnd: INT;
instance ← NARROW[button.clientData];
IF instance=NIL THEN {
instance ← NEW[DirectoryInstanceBody←[]]; button.clientData ← instance; };
IF instance.filled THEN RETURN;
instance.filled ← TRUE;
IF entry=NIL THEN RETURN;
instance.name ← ToTab[entryStream];
instance.number ← ToTab[entryStream];
instance.homeNumber ← ToTab[entryStream];
instance.remarks ← ToTab[entryStream];
rnameStart ← instance.name.Find["<"];
IF rnameStart<0 THEN RETURN;
rnameEnd instance.name.Find[">", rnameStart];
instance.rName ←
VoiceUtils.Registrize[instance.name.Substr[rnameStart+1, rnameEnd-rnameStart-1]];
};
ToTab: PROC[s: IO.STREAM] RETURNS [field: Rope.ROPENIL] = {
ToTabProc: IO.BreakProc = {
RETURN[IF char=IO.TAB OR char=IO.CR THEN sepr ELSE other]; };
field ← s.GetTokenRope[ToTabProc ! IO.EndOfStream=> CONTINUE;].token;
IF field.Equal["*"] THEN field←NIL;
};
}.