-- TEditInput2Impl.mesa; Edited by Paxton on October 29, 1982 9:59 am
Last Edited by: Maxwell, January 6, 1983 11:24 am
Last Edited by: Plass, April 15, 1983 2:08 pm
DIRECTORY
InputFocus USING [SetInputFocus],
MessageWindow USING [Append, Blink],
Process USING [Detach],
TEditDisplay USING [EstablishLine],
TEditDocument USING [maxClip, Selection, SpinAndLock, TEditDocumentData, Unlock],
TEditImpl USING [ReloadTipTable, ReloadReadonlyTipTable, ReloadTypeScriptTipTable],
TEditInput,
TEditInputOps, -- USING Lots
TEditProfile USING [ReadProfile],
TEditSelection USING [CancelPrimary, CancelSecondary, CaretAfterSelection, CaretBeforeSelection, GrowSelection, GrowSelectionToBlanks, LockSel, MakePointSelection, MakePrimary, MakeSecondary, pSel, PendingDeleteSelection, NotPendingDeleteSelection, SelectEverything, UnlockSel],
TEditTouchup USING [LockAfterRefresh, UnlockAfterRefresh],
TextNode USING [ForwardClipped, Location, Level, Parent, Ref, RefTextNode, Root],
TreeCheck USING [Verify],
UserProfile USING [CallWhenProfileChanges, ProfileChangedProc],
ViewerOps USING [PaintViewer],
ViewerClasses USING [Viewer, ViewerRec],
WindowManager USING [UnWaitCursor, WaitCursor];
TEditInput2Impl: CEDAR PROGRAM
IMPORTS InputFocus, TEditImpl, TEditDisplay, MessageWindow, Process, TEditDocument, TEditInput, TEditInputOps, TEditProfile, TEditSelection, TEditTouchup, TextNode, TreeCheck, UserProfile, ViewerOps, WindowManager
EXPORTS TEditInput =
BEGIN OPEN TEditInput, TEditSelection;
Break: CommandProc = {
TEditInputOps.Break[] };
Join: CommandProc = {
TEditInputOps.Join[] };
Nest: CommandProc = {
TEditInputOps.Nest[] };
Paste: CommandProc = {
TEditInputOps.Paste[] };
SaveForPaste: CommandProc = {
TEditInputOps.SaveForPaste[] };
SetType: CommandProc = {
TEditInputOps.SetType[] };
GetType: CommandProc = {
TEditInputOps.GetType[] };
UnNest: CommandProc = {
TEditInputOps.UnNest[] };
AllCaps: CommandProc = {
TEditInputOps.Capitalise[allCaps] };
AllLower: CommandProc = {
TEditInputOps.Capitalise[allLower] };
FirstCap: CommandProc = {
TEditInputOps.Capitalise[firstCap] };
InitialCaps: CommandProc = {
TEditInputOps.Capitalise[initCaps] };
ForkPaint:
PROC [viewer: ViewerClasses.Viewer] =
TRUSTED {
Process.Detach[FORK ViewerOps.PaintViewer[viewer, client ! ABORTED => CONTINUE]] };
AllLevels:
PUBLIC CommandProc = {
tdd: TEditDocument.TEditDocumentData ← NARROW[viewer.data];
IF tdd = NIL THEN RETURN;
tdd.clipLevel ← TEditDocument.maxClip;
ForkPaint[viewer];
RETURN [FALSE] };
FirstLevelOnly:
PUBLIC CommandProc = {
tdd: TEditDocument.TEditDocumentData ← NARROW[viewer.data];
IF tdd = NIL THEN RETURN;
tdd.clipLevel ← 1;
CheckFirstLevel[tdd];
ForkPaint[viewer];
RETURN [FALSE] };
CheckFirstLevel:
PROC [tdd: TEditDocument.TEditDocumentData] = {
node: TextNode.Ref;
delta: INTEGER;
pos: TextNode.Location;
[] ← TEditDocument.SpinAndLock[tdd, "CheckFirstLevel", TRUE]; -- ok to interrupt repaint
pos ← tdd.lineTable.lines[0].pos; -- the start of the first line
delta ← TextNode.Level[pos.node]-tdd.clipLevel; -- how much too deep it is, if any
IF delta > 0
THEN
{
FOR i:
INTEGER
IN [0..delta)
DO
-- only do this if pos is too deep
pos ← [TextNode.Parent[pos.node],0];
ENDLOOP;
IF (node ← TextNode.ForwardClipped[pos.node,].nx) # NIL THEN pos ← [node,0];
TEditDisplay.EstablishLine[tdd, pos] };
TEditDocument.Unlock[tdd] };
MaxLevelShown:
PUBLIC
PROC [tdd: TEditDocument.TEditDocumentData]
RETURNS [level: INTEGER] = {
node, n: TextNode.Ref;
max: INTEGER ← 0;
IF tdd = NIL THEN RETURN [0];
FOR l:
INTEGER
IN [0..tdd.lineTable.lastLine]
DO
IF (n ← tdd.lineTable.lines[l].pos.node) # node
THEN {
node ← n;
max ← MAX[TextNode.Level[node],max] };
ENDLOOP;
level ← max };
MoreLevels:
PUBLIC CommandProc = {
tdd: TEditDocument.TEditDocumentData ← NARROW[viewer.data];
IF tdd = NIL THEN RETURN;
[] ← TEditDocument.SpinAndLock[tdd, "MoreLevels", TRUE]; -- ok to interrupt repaint
IF tdd.clipLevel < TEditDocument.maxClip THEN tdd.clipLevel ← MaxLevelShown[tdd]+1;
ForkPaint[viewer];
TEditDocument.Unlock[tdd];
RETURN [FALSE] };
FewerLevels:
PUBLIC CommandProc = {
tdd: TEditDocument.TEditDocumentData ← NARROW[viewer.data];
level: INTEGER;
IF tdd = NIL THEN RETURN;
IF ~TEditTouchup.LockAfterRefresh[tdd, "FewerLevels"] THEN RETURN [FALSE];
{ ENABLE UNWIND => TEditTouchup.UnlockAfterRefresh[tdd];
level ← tdd.clipLevel;
IF level = TEditDocument.maxClip THEN level ← MaxLevelShown[tdd];
IF level # 1
THEN {
tdd.clipLevel ← level-1;
CheckFirstLevel[tdd];
ForkPaint[viewer] };
TEditTouchup.UnlockAfterRefresh[tdd];
RETURN [FALSE] }};
CaretAfter: CommandProc = {
CaretAfterSelection[] };
CaretBefore: CommandProc = {
CaretBeforeSelection[] };
Everything: CommandProc = {
SelectEverything[] };
GrowSel: CommandProc = {
GrowSelection[] };
GrowSelToBlanks: CommandProc = {
GrowSelectionToBlanks[] };
InsertLineBreak: CommandProc = {
TEditInputOps.InsertLineBreak[] };
MakeNotPendingDelete: CommandProc = {
NotPendingDeleteSelection[] };
MakePendingDelete: CommandProc = {
PendingDeleteSelection[] };
MakePointSelection:
PUBLIC CommandProc = {
TEditSelection.LockSel[primary, "MakePointSelection"];
IF pSel.viewer#
NIL
THEN
TEditSelection.MakePointSelection[pSel,
IF pSel.insertion=before THEN pSel.start.pos
ELSE [pSel.end.pos.node,pSel.end.pos.where+1]];
TEditSelection.UnlockSel[primary] };
MakeControlCharacter: CommandProc = {
TEditInputOps.MakeControlCharacter[] };
MakeOctalCharacter: CommandProc = {
TEditInputOps.MakeOctalCharacter[] };
UnMakeControlCharacter: CommandProc = {
TEditInputOps.UnMakeControlCharacter[] };
UnMakeOctalCharacter: CommandProc = {
TEditInputOps.UnMakeOctalCharacter[] };
MakePrimaryOp: CommandProc = { MakePrimary[] };
MakeSecondaryOp: CommandProc = { MakeSecondary[] };
CancelPrimaryOp: CommandProc = { CancelPrimary[] };
CancelSecondaryOp: CommandProc = { CancelSecondary[] };
Paint: CommandProc = { ViewerOps.PaintViewer[viewer, client] };
PlaceholderBrackets: CommandProc = {
TEditInputOps.InsertBrackets[1C,2C] };
justRegistered: BOOL ← TRUE;
ProfileChanged: UserProfile.ProfileChangedProc = {
IF justRegistered THEN { justRegistered ← FALSE; RETURN };
TEditProfile.ReadProfile[] };
ReadTip: CommandProc = { ReadTipTables[] };
ReadTipTables:
PUBLIC
PROC = {
WindowManager.WaitCursor[];
TEditImpl.ReloadTipTable[];
TEditImpl.ReloadReadonlyTipTable[];
TEditImpl.ReloadTypeScriptTipTable[];
InputFocus.SetInputFocus[]; -- kill selection; force ChangeTIPContext
WindowManager.UnWaitCursor[] };
ReloadStyle: CommandProc = {
TEditInputOps.ReloadStyle[] };
SelectMatchingPlaceholderBrackets: CommandProc = {
TEditInputOps.SelectMatchingBrackets[1C,2C] };
SelectMatchingSingleQuotes: CommandProc = {
-- look for 140C as left single quote
TEditInputOps.SelectMatchingBrackets['\140,''] };
SelectMatchingDoubleQuotes: CommandProc = {
TEditInputOps.SelectMatchingBrackets['",'"] };
SelectMatchingDashBrackets: CommandProc = {
TEditInputOps.SelectMatchingBrackets['-,'-] };
PreviousPlaceholder: CommandProc = {
TEditInputOps.FindPlaceholders[FALSE] };
PreviousViewer: CommandProc = {
TEditInputOps.NextViewer[FALSE] };
NextPlaceholder: CommandProc = {
TEditInputOps.FindPlaceholders[TRUE] };
NextViewer: CommandProc = {
TEditInputOps.NextViewer[TRUE] };
ReadAbbreviations: CommandProc = {
TEditInputOps.LoadAbbreviations["Default"] };
VerifyTree: CommandProc = {
IF pSel.viewer=NIL THEN RETURN;
TreeCheck.Verify[TextNode.Root[pSel.start.pos.node]];
MessageWindow.Append["Verified", TRUE]; MessageWindow.Blink[] };
SelectMatchingParens: CommandProc = {
TEditInputOps.SelectMatchingBrackets['(,')] };
SelectMatchingAngleBrackets: CommandProc = {
TEditInputOps.SelectMatchingBrackets['<,'>] };
SelectMatchingCurlyBrackets: CommandProc = {
TEditInputOps.SelectMatchingBrackets['{,'}] };
SelectMatchingSquareBrackets: CommandProc = {
TEditInputOps.SelectMatchingBrackets['[,']] };
ParenBrackets: CommandProc = {
TEditInputOps.InsertBrackets['(,')] };
DashBrackets: CommandProc = {
TEditInputOps.InsertBrackets['-,'-] };
DoubleQuoteBrackets: CommandProc = {
TEditInputOps.InsertBrackets['",'"] };
AngleBrackets: CommandProc = {
TEditInputOps.InsertBrackets['<,'>] };
SingleQuoteBrackets: CommandProc = {
-- use 140C for left single quote
TEditInputOps.InsertBrackets['\140,''] };
CurlyBrackets: CommandProc = {
TEditInputOps.InsertBrackets['{,'}] };
SquareBrackets: CommandProc = {
TEditInputOps.InsertBrackets['[,']] };
ComArray: TYPE = ARRAY ComIndex OF LIST OF REF ANY;
coms: REF ComArray = NEW [ComArray];
SetCommand:
PUBLIC
PROC [num: ComIndex, params:
LIST
OF
REF
ANY] = {
coms[num] ← params };
GetCommand:
PUBLIC
PROC [num: ComIndex]
RETURNS [params:
LIST
OF
REF
ANY] = {
RETURN [coms[num]] };
DoCommand:
PROC [viewer: ViewerClasses.Viewer, num: ComIndex] = {
Interpret[viewer,coms[num]] };
Command0: CommandProc = {
DoCommand[viewer,0] };
Command1: CommandProc = {
DoCommand[viewer,1] };
Command2: CommandProc = {
DoCommand[viewer,2] };
Command3: CommandProc = {
DoCommand[viewer,3] };
Command4: CommandProc = {
DoCommand[viewer,4] };
Command5: CommandProc = {
DoCommand[viewer,5] };
Command6: CommandProc = {
DoCommand[viewer,6] };
Command7: CommandProc = {
DoCommand[viewer,7] };
Command8: CommandProc = {
DoCommand[viewer,8] };
Command9: CommandProc = {
DoCommand[viewer,9] };
SetComment: CommandProc = {
TEditInputOps.SetCommentProp[TRUE] };
SetNotComment: CommandProc = {
TEditInputOps.SetCommentProp[FALSE] };
RegisterCommandAtoms:
PROC = {
Register[$Break, Break];
Register[$Join, Join];
Register[$Nest, Nest];
Register[$Paste, Paste];
Register[$SaveForPaste, SaveForPaste];
Register[$SetType, SetType];
Register[$GetType, GetType];
Register[$UnNest, UnNest];
Register[$AllCaps, AllCaps];
Register[$AllLower, AllLower];
Register[$FirstCap, FirstCap];
Register[$InitialCaps, InitialCaps];
Register[$AllLevels, AllLevels];
Register[$FewerLevels, FewerLevels];
Register[$MoreLevels, MoreLevels];
Register[$FirstLevelOnly, FirstLevelOnly];
Register[$CaretAfter, CaretAfter];
Register[$CaretBefore, CaretBefore];
Register[$Everything, Everything];
Register[$GrowSelection, GrowSel];
Register[$GrowSelectionToBlanks, GrowSelToBlanks];
Register[$InsertLineBreak, InsertLineBreak];
Register[$MakeNotPendingDelete, MakeNotPendingDelete];
Register[$MakePendingDelete, MakePendingDelete];
Register[$MakePointSelection, MakePointSelection];
Register[$MakeControlCharacter, MakeControlCharacter];
Register[$MakeOctalCharacter, MakeOctalCharacter];
Register[$UnMakeControlCharacter, UnMakeControlCharacter];
Register[$UnMakeOctalCharacter, UnMakeOctalCharacter];
Register[$MakePrimary, MakePrimaryOp];
Register[$MakeSecondary, MakeSecondaryOp];
Register[$CancelPrimary, CancelPrimaryOp];
Register[$CancelSecondary, CancelSecondaryOp];
Register[$Paint, Paint];
Register[$PlaceholderBrackets, PlaceholderBrackets];
Register[$PreviousPlaceholder, PreviousPlaceholder];
Register[$PreviousViewer, PreviousViewer];
Register[$ReadProfile, ReadTip];
Register[$ReloadStyle, ReloadStyle];
Register[$SelectMatchingPlaceholderBrackets, SelectMatchingPlaceholderBrackets];
Register[$NextPlaceholder, NextPlaceholder];
Register[$NextViewer, NextViewer];
Register[$ReadAbbreviations, ReadAbbreviations];
Register[$VerifyTree, VerifyTree];
Register[$SelectMatchingParens, SelectMatchingParens];
Register[$SelectMatchingAngleBrackets, SelectMatchingAngleBrackets];
Register[$SelectMatchingCurlyBrackets, SelectMatchingCurlyBrackets];
Register[$SelectMatchingSquareBrackets, SelectMatchingSquareBrackets];
Register[$SelectMatchingSingleQuotes, SelectMatchingSingleQuotes];
Register[$SelectMatchingDoubleQuotes, SelectMatchingDoubleQuotes];
Register[$SelectMatchingDashBrackets, SelectMatchingDashBrackets];
Register[$ParenBrackets, ParenBrackets];
Register[$DashBrackets, DashBrackets];
Register[$AngleBrackets, AngleBrackets];
Register[$DoubleQuoteBrackets, DoubleQuoteBrackets];
Register[$SingleQuoteBrackets, SingleQuoteBrackets];
Register[$CurlyBrackets, CurlyBrackets];
Register[$SquareBrackets, SquareBrackets];
Register[$Command0, Command0];
Register[$Command1, Command1];
Register[$Command2, Command2];
Register[$Command3, Command3];
Register[$Command4, Command4];
Register[$Command5, Command5];
Register[$Command6, Command6];
Register[$Command7, Command7];
Register[$Command8, Command8];
Register[$Command9, Command9];
Register[$SetComment, SetComment];
Register[$SetNotComment, SetNotComment];
};
RegisterCommandAtoms;
UserProfile.CallWhenProfileChanges[ProfileChanged];
END.