-- File: WalnutWindow.Mesa
-- Created by: Willie-Sue, March 23, 1982

-- Last Edited by:

-- Willie-Sue on June 8, 1983 11:02 am

DIRECTORY

 DB USING [Transaction],
 Buttons USING [ButtonProc],
 Commander USING [CommandProc],
 GVRetrieve USING [MBXState],
 Icons USING [IconFlavor],
 Menus USING [Menu],
 WalnutViewer USING [Queue],
 WalnutDB USING [Msg, MsgSet],
 Rope USING [ROPE],
 ViewerClasses USING [Viewer];

WalnutWindow: CEDAR DEFINITIONS =

BEGIN OPEN WalnutDB;

ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
Queue: TYPE = WalnutViewer.Queue;

initialActiveIconic: BOOL;
initialActiveOpen: BOOL;
initialActiveRight: BOOL;
msgSetBorders: BOOL;
enableTailRewrite: BOOL;

walnut: Viewer;
walnutQueue: Queue;
walnutSegmentFile: ROPE;
walnutLogName: ROPE;
walnutNullTrans: DB.Transaction;
logFileIsPilotFile: BOOL;
iconFilePathName: ROPE;

walnutIcon: Icons.IconFlavor;
newMailIcon: Icons.IconFlavor;
msgSetIcon: Icons.IconFlavor;
msgIcon: Icons.IconFlavor;

msgSetText: Viewer; -- the text argument for Create/Delete MsgSet
fileNameText: Viewer; -- fileName for Archiving
mailNotifyLabel: Viewer;

walnutMenu: Menus.Menu;
workingMenu: Menus.Menu;

-- ***********************************************************
-- types & variables shared with walnutmsgsetbuttonsimpl

MsgSetButton
: TYPE = REF MsgSetButtonObject;
MsgSetButtonObject: TYPE = RECORD[
  msgSet: MsgSet,
  selector, msViewer: Viewer← NIL,
  next: MsgSetButton← NIL,  -- list of all MsgSets
  selected: MsgSetButton← NIL]; -- list of Selected MsgSets
----------------------------

selectedMsgSetButtons: MsgSetButton;  -- List of selected MsgSets (may be empty)
lastMsgSetButton: MsgSetButton;    -- tail of List of MsgSets (never empty)
firstMsgSetButton: MsgSetButton;
walnutRulerBefore, walnutRulerAfter, walnutTS: Viewer;

-- ***********************************************************
-- Operation on Walnut Window [WalnutWindowImpl]

RestartWalnut: PROC;

QueueExecCall:PROC[proc: PROC[REF ANY], ra: REF ANY];
-- wait for rollback to finish (if necessary), then queues an action

SetWalnutUpdatesPending: PROC[isDirty: BOOL];
-- sets newversion bit on in walnut window

UncomittedUpdates: PROC RETURNS[updatesPending: BOOL];
-- returns TRUE if uncomitted updates to database exist

UserConfirmed
: PROC RETURNS[BOOL];
-- returns TRUE if user responds Confirm

WatchMailBox: PROC[newState: GVRetrieve.MBXState];

RetrieveNewMail: PROC;
-- checks if user has changes, then calls DoNewMail

Report: PROC[msg1, msg2, msg3, msg4: ROPENIL];
-- Prints non-omitted arguments in the Walnut window followed by CR.

ReportRope: PROC[msg1: ROPE];
-- Similar to above, but prints one rope and doesn't print CR at end.

SetUpTSLog: PROC[who: ROPE];
--for when walnut is not running

CloseTSLog: PROC;

ChangeWalnutMenu: PROC[newMenu: Menus.Menu];
-- private

TakeDownWalnutViewers: PROC;
--private

-- ***********************************************************
-- in WalnutExtrasImpl

-- for use by programs, goes thru walnutQueue

GetNewMail
: PUBLIC PROC;
ReadMailFile: PROC[fName, msgSet: ROPE];

-- *****************

DoNewMail
: PROC;
-- retrieves new mail from Grapevine & adds it to the database

SizeOfMsgSetButtonProc: Buttons.ButtonProc;

CreateMsgSetButtonProc: Buttons.ButtonProc;

DeleteMsgSetButtonProc: Buttons.ButtonProc;

ArchiveButtonProc: Buttons.ButtonProc;

WalnutReadMailFile: Commander.CommandProc;

WalnutExpunge: Commander.CommandProc;

WalnutScavenge: Commander.CommandProc;

WalnutNewMail: Commander.CommandProc;

WalnutDump: Commander.CommandProc;

DoScavenge: PROC[startPos: INT, internal: BOOL];
-- private proc

DoExpunge: PROC[doUpdates, tailRewrite: BOOL];
-- private proc

-- ***********************************************************
-- these are implemented in WalnutMsgSetButtonsImpl

DisplayMsgSet: PROC[msgSet: MsgSet] RETURNS[Viewer];
-- Walnut wants to check if a MsgSet msgSet is already being displayed

FindMSViewer: PROC[msgSet: MsgSet] RETURNS[Viewer];
-- returns NIL if msgSet is not being displayed

ShowMsgSetButtons: PROC;
-- constructs or re-constructs the msgSetButtons in the control window;
-- "knows"
where in the window the buttons belong

GetSelectedMsgSets: PROC RETURNS[msL: LIST OF MsgSet];
-- the list of MsgSets the user has selected (for Add/Remove Msg operations)

DeleteMsgSetButton: PROC[msgSet: MsgSet];

CreateMsgSetProc: PROC[msName: ROPE, select: BOOL] RETURNS[nameOK: BOOL];
-- creates button for MsgSet & selects it, if select is TRUE
-- RETURNS FALSE is if name is illegal for a MsgSet

AddMsgSetButton: PROC[msgSet: MsgSet, msName: ROPE, select: BOOL];
-- adds a button for msgSet

END.