DIRECTORY
Atom USING [GetPName, MakeAtom],
ChoiceButtons USING [EnumTypeRef, BuildEnumTypeSelection, BuildTextPrompt, GetSelectedButton],
Commander USING [CommandProc, Handle, Register],
CommandTool USING [NextArgument],
Containers USING [ ChildXBound, ChildYBound, Container, Create ],
FS USING [ComponentPositions, ExpandName, Position],
Icons USING [ IconFlavor, NewIconFromFile ],
LoganBerry USING [AttributeType, AttributeValue, BuildIndices, Close, CompactLogs, Describe, Entry, EntryProc, Error, ErrorCode, Open, OpenDB, SchemaInfo],
LoganBerryRpcControl USING [ImportInterface, UnimportInterface],
LoganQuery USING [ComplexCursor, EndGenerate, FilterEntries, FilterProc, GenerateEntries, MergeEntries, NextEntry, Equal, Prefix, Wildcard, RE, Soundex],
LupineRuntime USING [BindingError],
Menus USING [AppendMenuEntry, ChangeNumberOfLines, ClickProc, CreateEntry, CreateMenu, GetNumberOfLines, Menu, MenuLine],
MessageWindow USING [Append, Blink],
RefTab USING [Ref, EachPairAction, Fetch, Pairs, Create, Store],
Rope USING [Cat, Concat, Equal, Fetch, FromChar, Index, Length, ROPE, SkipTo, Substr],
RPC USING [CallFailed, CallFailure, ImportFailed],
Rules USING [ Create, Rule ],
TiogaButtons USING [ CreateButton, CreateButtonFromNode, CreateViewer, FindTiogaButton, GetRope, LoadViewer, TextNodeRef, TiogaButton, TiogaButtonProc, TiogaOpsRef ],
TiogaButtonsExtra USING [CreateButtonForEachNode],
TypeScript USING [ Create, ChangeLooks, Reset, PutChar, PutRope ],
ViewerBLT USING [ChangeNumberOfLines],
ViewerClasses USING [ Viewer, ViewerClassRec, ViewerRec ],
ViewerEvents USING [ EventProc, RegisterEventProc ],
ViewerOps USING [AddProp, FetchProp, MoveViewer, PaintViewer],
ViewerTools USING [GetContents]
;
Types
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
BrowserTool: TYPE = REF BrowserToolRec;
BrowserToolRec:
TYPE =
RECORD[
outer: Containers.Container, -- main container
menu: Menus.Menu, -- command menu
dbFileName: ROPE, -- name of database
instance: ROPE, -- RPC interface instance
imported: BOOL←FALSE, -- is interface imported?
db: LoganBerry.OpenDB, -- open database handle
entryform: RefTab.Ref, -- set of "FormField"s
sortButton: ChoiceButtons.EnumTypeRef, -- order of retrieval
details: Containers.Container, -- container for choice buttons
historyData: REF ANY, -- log of executed queries
history: Viewer, -- viewer for history data
inner: Viewer, -- viewer for retrieved database entries
stop: BOOLEAN, -- stop database retrievals if TRUE
height: CARDINAL ← 0 -- current height of tool (excluding typescript viewer)
];
FormField: TYPE = REF FormFieldRec;
FormFieldRec:
TYPE =
RECORD [
textViewer: Viewer,
patternButton: ChoiceButtons.EnumTypeRef
];
Command menu
StopProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
tool.stop ← TRUE;
};
BrowseProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
IF mouseButton # blue
THEN
TypeScript.Reset[tool.inner];
DoQuery[tool.db, tool.entryform, Atom.MakeAtom[ChoiceButtons.GetSelectedButton[tool.sortButton]], tool.inner, tool];
ViewerOps.PaintViewer[viewer: tool.inner, hint: all];
};
DetailsProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
IF tool.details.wx = 0
THEN
HideViewer[tool.details]
ELSE
UnHideViewer[tool.details];
};
HistoryProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
IF tool.history.wx = 0
THEN {
HideViewer[tool.history];
ViewerOps.MoveViewer[viewer: tool.inner, x: tool.inner.wx, y: tool.inner.wy - historyHeight, w: tool.inner.ww, h: tool.inner.wh];
tool.height ← tool.height - historyHeight;
}
ELSE {
ViewerOps.MoveViewer[viewer: tool.inner, x: tool.inner.wx, y: tool.inner.wy + historyHeight, w: tool.inner.ww, h: tool.inner.wh];
UnHideViewer[tool.history];
tool.height ← tool.height + historyHeight;
};
MessageWindow.Append["Not fully implemented.", TRUE];
MessageWindow.Blink[];
};
AdminOpsProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
newCount: CARDINAL ← IF Menus.GetNumberOfLines[tool.menu] = 1 THEN 2 ELSE 1;
Menus.ChangeNumberOfLines[tool.menu, newCount];
ViewerBLT.ChangeNumberOfLines[tool.outer, newCount];
};
OpenProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
msg: ROPE ← NIL;
tool: BrowserTool ← NARROW[clientData];
IF ~tool.imported THEN {
msg ← ImportLoganBerry[tool.instance];
IF msg # NIL THEN ReportLBError[NIL, "Can't import LoganBerry RPC interface", tool.inner]
ELSE tool.imported ← TRUE;
};
tool.db ← LoganBerry.Open[dbName: tool.dbFileName ! LoganBerry.Error => {ReportLBError[ec, explanation, tool.inner]; CONTINUE}];
};
CloseProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
LoganBerry.Close[db: tool.db ! LoganBerry.Error => {ReportLBError[ec, explanation, tool.inner]; CONTINUE}];
};
BuildIndiciesProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
LoganBerry.BuildIndices[db: tool.db ! LoganBerry.Error => {ReportLBError[ec, explanation, tool.inner]; CONTINUE}];
};
CompactLogsProc: Menus.ClickProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
LoganBerry.CompactLogs[db: tool.db ! LoganBerry.Error => {ReportLBError[ec, explanation, tool.inner]; CONTINUE}];
};
DestroyProc: ViewerEvents.EventProc = {
[viewer: ViewerClasses.Viewer, event: ViewerEvents.ViewerEvent, before: BOOL] RETURNS [abort: BOOL ← FALSE]
-- Does nothing at the moment
tool: BrowserTool ← NARROW[ViewerOps.FetchProp[viewer: viewer, prop: $BrowserTool]];
LoganBerry.Close[db: tool.db ! LoganBerry.Error => {ReportLBError[ec, explanation, tool.inner]; CONTINUE}];
};
MakeMainMenu:
PROC [tool: BrowserTool]
RETURNS [] ~ {
AppendMenu:
PROC[menu: Menus.Menu, name:
ROPE, proc: Menus.ClickProc, line: Menus.MenuLine ← 0, guarded:
BOOL ←
FALSE] = {
Menus.AppendMenuEntry[
menu: menu,
entry: Menus.CreateEntry[name: name, proc: proc, clientData: tool, guarded: guarded],
line: line
];
};
tool.menu ← Menus.CreateMenu[lines: 2];
first line
AppendMenu[tool.menu, "STOP!", StopProc];
AppendMenu[tool.menu, "Browse", BrowseProc];
AppendMenu[tool.menu, "Details", DetailsProc];
AppendMenu[tool.menu, "History", HistoryProc];
AppendMenu[tool.menu, "AdminOps", AdminOpsProc];
second line
AppendMenu[tool.menu, "Open", OpenProc, 1];
AppendMenu[tool.menu, "Close", CloseProc, 1, TRUE];
AppendMenu[tool.menu, "BuildIndicies", BuildIndiciesProc, 1, TRUE];
AppendMenu[tool.menu, "CompactLogs", CompactLogsProc, 1, TRUE];
};
Commander commands
MakeBrowserTool: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
tool: BrowserTool ← NEW[BrowserToolRec];
position: FS.Position;
shortname: ROPE;
cp: FS.ComponentPositions;
errormsg: ROPE ← NIL;
The server component of the input file name is taken as an RPC instance; the DB file name is then given an empty server component since the file is assumed to be local to the server exporting the interface.
tool.dbFileName ← CommandTool.NextArgument[cmd];
IF tool.dbFileName =
NIL
THEN
RETURN[msg: "No database name given.\n"];
[tool.dbFileName, cp] ← FS.ExpandName[tool.dbFileName];
tool.instance ← Rope.Substr[tool.dbFileName, cp.server.start, cp.server.length];
tool.dbFileName ← Rope.Concat["[]", Rope.Substr[tool.dbFileName, cp.dir.start-1]];
errormsg ← ImportLoganBerry[tool.instance];
IF errormsg # NIL THEN
RETURN[msg: errormsg];
tool.imported ← TRUE;
open database
tool.db ← LoganBerry.Open[dbName: tool.dbFileName
! LoganBerry.Error => errormsg ← Rope.Cat["Error: ", Atom.GetPName[ec], " — ", explanation]];
IF errormsg #
NIL
THEN
RETURN[msg: errormsg];
find short database name
position ← FS.ExpandName[tool.dbFileName].cp.base;
shortname ← Rope.Substr[base: tool.dbFileName, start: position.start, len: position.length];
create command section
MakeMainMenu[tool];
tool.outer ← Containers.Create[info: [
name: Rope.Concat["LoganBerry Browser: ", tool.dbFileName],
icon: browserIcon,
label: shortname,
iconic: FALSE,
column: left,
menu: tool.menu,
scrollable: FALSE]];
Menus.ChangeNumberOfLines[tool.menu, 1];
ViewerBLT.ChangeNumberOfLines[tool.outer, 1];
ViewerOps.AddProp[viewer: tool.outer, prop: $BrowserTool, val: tool];
[] ← ViewerEvents.RegisterEventProc[proc: DestroyProc, event: destroy, filter: tool.outer];
create input form
tool.details ← Containers.Create[info: [
parent: tool.outer,
ww: 9999,
wh: 9999,
scrollable: FALSE,
border: FALSE]];
Containers.ChildXBound[container: tool.outer, child: tool.details];
Containers.ChildYBound[container: tool.outer, child: tool.details];
tool.height ← interItemHeight;
MakeEntryForm[tool];
MakeSortButton[tool];
DividingLine[tool];
create history viewer
tool.history ← TiogaButtons.CreateViewer[info: [
parent: tool.outer,
wy: tool.height,
ww: 9999,
wh: historyHeight,
border: TRUE]];
Containers.ChildXBound[tool.outer, tool.history]; -- constrain rule to be width of parent
HideViewer[tool.history];
create output browser
tool.inner ← TypeScript.Create[info: [
name: "LoganBerry Browser output",
parent: tool.outer,
wx: 0,
wy: tool.height,
ww: 9999,
wh: 9999,
border: FALSE]];
Containers.ChildXBound[tool.outer, tool.inner]; -- constrain rule to be width of parent
Containers.ChildYBound[tool.outer, tool.inner]; -- constrain rule to be height of parent
};
Doug Terry, November 27, 1985 3:22:06 pm PST
taken from WPBrowserToolImpl.mesa
changes to: DIRECTORY, LoganBerryBrowserTool, browserIcon, db, dbFileName, NamedFilter, Commander, END, BrowseProc, DetailsProc, HistoryProc, MakeMainMenu, BrowserToolRec, MakeBrowserTool, itemHeight, interItemHeight, ruleHeight, patternButtonWidth, patternHSpace, historyHeight, AppendMenu (local of MakeMainMenu), MakeEntryForm, AppendEntry (local of MakeEntryForm), MakeSortButton, DividingLine, FormFieldRec, AddToSortList (local of MakeSortButton), StopProc, BrowseProc, DoQuery, PutEntry (local of DoQuery), NewFilter (local of DoQuery), ROPE, STREAM