[mimics ViewerClasses.ClickProc, but with different return value]
curSel, escaped, spaced: ROPE;
viewer: ViewerClasses.Viewer ¬ NIL;
start: TiogaOps.Location;
viewerName: ROPE ¬ NIL;
fileName: ROPE ¬ NIL;
shortFileName: ROPE ¬ NIL;
baseFileName: ROPE ¬ NIL;
spaceFileName: ROPE ¬ NIL;
shortSpaceFileName: ROPE ¬ NIL;
quotedFileName: ROPE ¬ NIL;
shortQuotedFileName: ROPE ¬ NIL;
index: INT ¬ -1;
controlRope: ROPE ¬ IF control THEN "control" ELSE "noControl";
shiftRope: ROPE ¬ IF shift THEN "shift" ELSE "noShift";
buttonRope: ROPE;
SELECT mouseButton
FROM
red => buttonRope ¬ "left";
yellow => buttonRope ¬ "middle";
blue => buttonRope ¬ "right";
ENDCASE => ERROR;
IF cmdIn = NIL THEN RETURN;
def ¬ cmdIn;
[viewer: viewer, start: start] ¬ TiogaOps.GetSelection[primary];
curSel ¬ ViewerTools.GetSelectionContents[];
IF viewer #
NIL
AND
NOT viewer.destroyed
AND
NOT viewer.newFile
THEN {
root: TiogaOps.Ref ¬ TiogaOps.Root[start.node];
offset: INT ¬ TiogaOps.LocOffset[loc1: [root, 0], loc2: start, skipCommentNodes: TRUE];
index ¬ offset;
viewerName ¬ viewer.file;
IF viewerName = NIL THEN viewerName ¬ viewer.name;
fileName ¬ viewer.file;
fileName ¬ Rope.Substr[fileName, 0, Rope.SkipTo[fileName, 0, "!"]];
};
escaped ¬ Convert.RopeFromRope[from: curSel, quote: FALSE];
spaced ¬ RopeSubst[old: "\n", new: " ", base: curSel];
Get prefix of current selection before the first CR
curSel ¬ Rope.Substr[base: curSel, start: 0, len: curSel.Index[s2: "\n"]];
The curSel is the fileName if curSel is longer than one character and contains no whitespace.
fileName ¬ IF (Rope.SkipTo[s: curSel, pos: 0, skip: " \t"] = curSel.Length[]) AND (curSel.Length[] > 1) THEN curSel ELSE fileName;
shortFileName ¬ GetShortName[fileName];
baseFileName ¬ GetBaseName[shortFileName];
The curSel is the spaceFileName if curSel is longer than one character.
spaceFileName ¬ IF (curSel.Length[] > 1) THEN curSel ELSE fileName;
shortSpaceFileName ¬ GetShortName[spaceFileName];
Add quotes for the quoted version.
quotedFileName ¬ Rope.Cat["\"", spaceFileName, "\""];
shortQuotedFileName ¬ Rope.Cat["\"", shortSpaceFileName, "\""];
IF Rope.SkipTo[def, 0, "$"] < Rope.Length[def]
THEN {
It is likely that we have substitutions to do
def ¬ RopeSubst[old: "$CurrentSelection$", new: curSel, base: def, case: TRUE];
def ¬ RopeSubst[old: "$CurrentEscapedSelection$", new: escaped, base: def, case: TRUE];
def ¬ RopeSubst[old: "$CurrentSpacedSelection$", new: spaced, base: def, case: TRUE];
def ¬ RopeSubst[old: "$FileNameSelection$", new: fileName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$ShortFileNameSelection$", new: shortFileName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$BaseFileNameSelection$", new: baseFileName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$SpaceFileNameSelection$", new: spaceFileName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$ShortSpaceFileNameSelection$", new: shortSpaceFileName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$QuotedFileNameSelection$", new: quotedFileName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$ShortQuotedFileNameSelection$", new: shortQuotedFileName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$SelectedViewerName$", new: viewerName, base: def, case: TRUE];
def ¬ RopeSubst[old: "$ViewerPosition$", new: Convert.RopeFromInt[index, 10, FALSE], base: def, case: TRUE];
def ¬ RopeSubst[old: "$MouseButton$", new: buttonRope, base: def, case: TRUE];
def ¬ RopeSubst[old: "$ControlKey$", new: controlRope, base: def, case: TRUE];
def ¬ RopeSubst[old: "$ShiftKey$", new: shiftRope, base: def, case: TRUE];
};
RETURN [def];