TEditInput2Impl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Plass, March 18, 1985 5:42:29 pm PST
Russ Atkinson (RRA) June 25, 1985 2:34:52 am PDT
Michael Plass, March 20, 1986 9:52:52 am PST
Doug Wyatt, September 2, 1986 4:16:12 pm PDT
DIRECTORY
InputFocus USING [SetInputFocus],
MessageWindow USING [Append, Blink],
TEditDisplay USING [EstablishLine],
TEditDocument USING [maxClip, Selection, SpinAndLock, TEditDocumentData, Unlock],
TEditPrivate 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, Node, Parent, Root],
TreeCheck USING [Verify],
UserProfile USING [CallWhenProfileChanges, ProfileChangedProc],
ViewerClasses USING [Viewer, ViewerRec],
ViewerForkers USING [ForkPaint],
WindowManager USING [UnWaitCursor, WaitCursor];
TEditInput2Impl:
CEDAR
PROGRAM
IMPORTS InputFocus, TEditPrivate, TEditDisplay, MessageWindow, TEditDocument, TEditInput, TEditInputOps, TEditProfile, TEditSelection, TEditTouchup, TextNode, TreeCheck, UserProfile, ViewerForkers, 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[] };
SetFormat: CommandProc = { TEditInputOps.SetFormat[] };
GetFormat: CommandProc = { TEditInputOps.GetFormat[] };
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 {
ViewerForkers.ForkPaint[viewer: viewer, hint: client, tryShortCuts: TRUE];
};
AllLevels:
PUBLIC CommandProc = {
WITH viewer.data
SELECT
FROM
tdd: TEditDocument.TEditDocumentData => {
IF tdd.clipLevel # TEditDocument.maxClip
THEN {
[] ← TEditDocument.SpinAndLock[tdd, "AllLevels", TRUE];
tdd.clipLevel ← TEditDocument.maxClip;
ForkPaint[viewer];
TEditDocument.Unlock[tdd];
};
};
ENDCASE;
RETURN [FALSE];
};
FirstLevelOnly:
PUBLIC CommandProc = {
WITH viewer.data
SELECT
FROM
tdd: TEditDocument.TEditDocumentData => {
IF tdd.clipLevel # 1
THEN {
[] ← TEditDocument.SpinAndLock[tdd, "FirstLevelOnly", TRUE];
tdd.clipLevel ← 1;
CheckFirstLevel[tdd];
ForkPaint[viewer];
TEditDocument.Unlock[tdd];
};
};
ENDCASE;
RETURN [FALSE];
};
CheckFirstLevel:
PROC [tdd: TEditDocument.TEditDocumentData] = {
node: TextNode.Node;
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.Node;
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 = {
WITH viewer.data
SELECT
FROM
tdd: TEditDocument.TEditDocumentData => {
IF tdd.clipLevel < TEditDocument.maxClip
THEN {
ENABLE UNWIND => TEditTouchup.UnlockAfterRefresh[tdd];
[] ← TEditDocument.SpinAndLock[tdd, "MoreLevels", TRUE];
tdd.clipLevel ← MaxLevelShown[tdd]+1;
ForkPaint[viewer];
TEditDocument.Unlock[tdd];
};
};
ENDCASE;
};
FewerLevels:
PUBLIC CommandProc = {
WITH viewer.data
SELECT
FROM
tdd: TEditDocument.TEditDocumentData =>
IF tdd.clipLevel # 1
THEN {
IF TEditTouchup.LockAfterRefresh[tdd, "FewerLevels"]
THEN {
ENABLE UNWIND => TEditTouchup.UnlockAfterRefresh[tdd];
level: INTEGER ← 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];
};
};
ENDCASE;
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 = { ForkPaint[viewer] };
PlaceholderBrackets: CommandProc = { TEditInputOps.InsertBrackets[1C,2C] };
justRegistered: BOOL ← TRUE;
ProfileChanged: UserProfile.ProfileChangedProc = {
IF NOT justRegistered THEN TEditProfile.ReadProfile[];
justRegistered ← FALSE;
};
ReadTip: CommandProc = { ReadTipTables[] };
ReadTipTables:
PUBLIC
PROC = {
WindowManager.WaitCursor[];
TEditPrivate.ReloadTipTable[];
TEditPrivate.ReloadReadonlyTipTable[];
TEditPrivate.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['[,']] };
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[$SetFormat, SetFormat];
Register[$SetType, SetFormat]; -- For compatability
Register[$GetFormat, GetFormat];
Register[$GetType, GetFormat]; -- For compatability
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];
};
ComArray: TYPE = ARRAY ComIndex OF LIST OF REF ANY;
coms: REF ComArray = NEW [ComArray];
RegisterCommandAtoms[];
UserProfile.CallWhenProfileChanges[ProfileChanged];
END.