-- ReadonlyTioga.tip; Last Edited by Paxton, November 3, 1982 12:51 pm

-- general definitions

[DEF,ClickTime,(200)]

[DEF,DownClick,(~1 Down BEFORE [ClickTime])]

[DEF,UpClick,(~1 Up BEFORE [ClickTime])]

[DEF,Click,([UpClick,~1] AND [DownClick,~1])]

[DEF,BothUp,(~1 Up WHILE ~2 Up)]

[DEF,FourUp,(~1 Up WHILE ~2 Up WHILE ~3 Up WHILE ~4 Up)]
      
[DEF,WhileSixUp,
	(WHILE ~1 Up WHILE ~2 Up WHILE ~3 Up WHILE ~4 Up WHILE ~5 Up WHILE ~6 Up)]

[DEF,CTRL,(Ctrl Down | Spare3 Down)]

[DEF,SHIFT,(LeftShift Down | RightShift Down)]

[DEF,IfShift,(SELECT ENABLE FROM
	[SHIFT] => ~1;
	ENDCASE => ~2)]

[DEF,IfCtrl,(SELECT ENABLE FROM
	[CTRL] => ~1;
	ENDCASE => ~2)]

-- top level trigger select

SELECT TRIGGER FROM

  [DEF,Sel,(SELECT ENABLE FROM
      [SHIFT] => { ~2 Coords SelSecondary ToPrimary ForceSelNotPendDel ~1 };
      ENDCASE => { ~2 Coords ForceSelNotPendDel ~1 })]

  [DEF,MouseClick,(SELECT TRIGGER FROM
      [Click,~1] => [Sel,~3,~1Mouse];
      ENDCASE => [Sel,~2,~1Mouse])]
    
  Red Down => [MouseClick,Red,SelChar,SelNode];
    
  Yellow Down => SELECT ENABLE FROM
    Red Up => [MouseClick,Yellow,SelWord,SelBranch];
    ENDCASE;
  
  [DEF,Extend,([Sel,~1 SelStartExtend,BlueMouse])]
  
  Blue Down => SELECT ENABLE FROM
    [BothUp,Red,Yellow] => SELECT TRIGGER FROM
      [Click,Blue] => SELECT TRIGGER FROM
         [Click,Blue] => [Extend,SelExpand];
         ENDCASE => [Extend,SelReduce];
      ENDCASE => [Extend];
    ENDCASE;

  Mouse => SELECT ENABLE FROM
      Red Down => [Sel,SelUpdate];
      Yellow Down => [Sel,SelUpdate];
      Blue Down => { Coords SelExtend };
      ENDCASE;
  
  [DEF,ButtonUp,(SELECT ENABLE FROM
    [FourUp,LeftShift,RightShift,Ctrl,Spare3] WHILE [BothUp,~1,~2] => DoEdit;
     ENDCASE)]
	  
  Red Up => SELECT ENABLE FROM
	Blue Down => [Extend];
	ENDCASE => [ButtonUp,Blue,Yellow];

  Yellow Up =>  SELECT ENABLE FROM
	Blue Down WHILE Red Up => [Extend];
	ENDCASE => [ButtonUp,Red,Blue];

  Blue Up => [ButtonUp,Red,Yellow];

-- Shift key Commands
  
  LeftShift Up [WhileSixUp,Red,Yellow,Blue,Ctrl,Spare3,RightShift] => DoEdit;
  
  RightShift Up [WhileSixUp,Red,Yellow,Blue,Ctrl,Spare3,LeftShift] => DoEdit;
  
  Ctrl Up [WhileSixUp,LeftShift,Red,Yellow,Blue,Spare3,RightShift] => DoEdit;

  Spare3 Up [WhileSixUp,LeftShift,Red,Yellow,Blue,Ctrl,RightShift] => DoEdit;


-- Function key Commands

  Spare2 Down => [IfCtrl,
  	[IfShift,{ IntermediateUser CtrlPrevPlaceholder },{ IntermediateUser CtrlNextPlaceholder }],
  	[IfShift,{ IntermediateUser PreviousPlaceholder },{ IntermediateUser NextPlaceholder }]];

  DEL Down => SELECT ENABLE FROM
      [SHIFT] => EditAbort;
      [CTRL] => EditAbort;
      Red Down => EditAbort;
      Yellow Down => EditAbort;
      Blue Down => EditAbort;
      ENDCASE;

-- Punctuation Commands
      
  Zero Down WHILE [SHIFT] WHILE [CTRL] =>
  	{ IntermediateUser SelectMatchingParens };
  
  Period Down WHILE [SHIFT] WHILE [CTRL] =>
  	{ IntermediateUser SelectMatchingAngleBrackets };
  
  RightBracket Down WHILE [CTRL] =>
  	[IfShift,{ IntermediateUser SelectMatchingCurlyBrackets },
  		{ IntermediateUser SelectMatchingSquareBrackets }];
  
-- Letter Commands
  
  D Down WHILE [CTRL] =>
  	{ IntermediateUser Everything };
  	
  S Down WHILE [CTRL] => 	-- copy primary
  	{ IntermediateUser MakeNotPendingDelete ToSecondary SelSecondary SelNotPendDel };
  	
  V Down WHILE [CTRL] =>
  	{ IntermediateUser GrowSelectionToBlanks };

  ENDCASE.