mirror of https://gitlab.com/basile.b/dexed.git
moved free functions used by the custom commands to the editor class
This commit is contained in:
parent
74e6984f68
commit
b12b6829aa
|
@ -13,7 +13,6 @@ type
|
||||||
|
|
||||||
TCEDubProject = class(TComponent, ICECommonProject)
|
TCEDubProject = class(TComponent, ICECommonProject)
|
||||||
private
|
private
|
||||||
fProjectName: string;
|
|
||||||
fInGroup: boolean;
|
fInGroup: boolean;
|
||||||
fDubProc: TCEProcess;
|
fDubProc: TCEProcess;
|
||||||
fPreCompilePath: string;
|
fPreCompilePath: string;
|
||||||
|
|
|
@ -145,6 +145,7 @@ type
|
||||||
fDisableFileDateCheck: boolean;
|
fDisableFileDateCheck: boolean;
|
||||||
fDetectIndentMode: boolean;
|
fDetectIndentMode: boolean;
|
||||||
fPhobosDocRoot: string;
|
fPhobosDocRoot: string;
|
||||||
|
procedure decCallTipsLvl;
|
||||||
procedure setMatchOpts(value: TIdentifierMatchOptions);
|
procedure setMatchOpts(value: TIdentifierMatchOptions);
|
||||||
function getMouseFileBytePos: Integer;
|
function getMouseFileBytePos: Integer;
|
||||||
procedure changeNotify(Sender: TObject);
|
procedure changeNotify(Sender: TObject);
|
||||||
|
@ -197,11 +198,13 @@ type
|
||||||
procedure save;
|
procedure save;
|
||||||
procedure saveTempFile;
|
procedure saveTempFile;
|
||||||
//
|
//
|
||||||
|
procedure curlyBraceCloseAndIndent;
|
||||||
|
procedure commentSelection;
|
||||||
|
procedure commentIdentifier;
|
||||||
procedure renameIdentifier;
|
procedure renameIdentifier;
|
||||||
procedure invertVersionAllNone;
|
procedure invertVersionAllNone;
|
||||||
procedure showCallTips(findOpenParen: boolean = true);
|
procedure showCallTips(findOpenParen: boolean = true);
|
||||||
procedure hideCallTips;
|
procedure hideCallTips;
|
||||||
procedure decCallTipsLvl;
|
|
||||||
procedure showDDocs;
|
procedure showDDocs;
|
||||||
procedure hideDDocs;
|
procedure hideDDocs;
|
||||||
procedure ShowPhobosDoc;
|
procedure ShowPhobosDoc;
|
||||||
|
@ -789,7 +792,7 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure curlyBraceCloseAndIndent(editor: TSynEdit);
|
procedure TCESynMemo.curlyBraceCloseAndIndent;
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
beg: string = '';
|
beg: string = '';
|
||||||
|
@ -797,12 +800,12 @@ var
|
||||||
numSpac: integer = 0;
|
numSpac: integer = 0;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
i := editor.CaretY - 1;
|
i := CaretY - 1;
|
||||||
while true do
|
while true do
|
||||||
begin
|
begin
|
||||||
if i < 0 then
|
if i < 0 then
|
||||||
break;
|
break;
|
||||||
beg := editor.Lines[i];
|
beg := Lines[i];
|
||||||
if (Pos('{', beg) = 0) then
|
if (Pos('{', beg) = 0) then
|
||||||
i -= 1
|
i -= 1
|
||||||
else
|
else
|
||||||
|
@ -817,76 +820,76 @@ begin
|
||||||
else break;
|
else break;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
numTabs += numSpac div editor.TabWidth;
|
numTabs += numSpac div TabWidth;
|
||||||
|
|
||||||
editor.BeginUndoBlock;
|
BeginUndoBlock;
|
||||||
|
|
||||||
editor.CommandProcessor(ecInsertLine, '', nil);
|
CommandProcessor(ecInsertLine, '', nil);
|
||||||
editor.CommandProcessor(ecDown, '', nil);
|
CommandProcessor(ecDown, '', nil);
|
||||||
|
|
||||||
editor.CommandProcessor(ecInsertLine, '', nil);
|
CommandProcessor(ecInsertLine, '', nil);
|
||||||
editor.CommandProcessor(ecDown, '', nil);
|
CommandProcessor(ecDown, '', nil);
|
||||||
while editor.CaretX <> 1 do editor.CommandProcessor(ecLeft, '' , nil);
|
while CaretX <> 1 do CommandProcessor(ecLeft, '' , nil);
|
||||||
for i:= 0 to numTabs-1 do editor.CommandProcessor(ecTab, '', nil);
|
for i:= 0 to numTabs-1 do CommandProcessor(ecTab, '', nil);
|
||||||
editor.CommandProcessor(ecChar, '}', nil);
|
CommandProcessor(ecChar, '}', nil);
|
||||||
|
|
||||||
editor.CommandProcessor(ecUp, '', nil);
|
CommandProcessor(ecUp, '', nil);
|
||||||
while editor.CaretX <> 1 do editor.CommandProcessor(ecLeft, '' , nil);
|
while CaretX <> 1 do CommandProcessor(ecLeft, '' , nil);
|
||||||
for i:= 0 to numTabs do editor.CommandProcessor(ecTab, '', nil);
|
for i:= 0 to numTabs do CommandProcessor(ecTab, '', nil);
|
||||||
|
|
||||||
editor.EndUndoBlock;
|
EndUndoBlock;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure commentSelection(editor: TSynEdit);
|
procedure TCESynMemo.commentSelection;
|
||||||
procedure commentHere;
|
procedure commentHere;
|
||||||
begin
|
begin
|
||||||
editor.ExecuteCommand(ecChar, '/', nil);
|
ExecuteCommand(ecChar, '/', nil);
|
||||||
editor.ExecuteCommand(ecChar, '/', nil);
|
ExecuteCommand(ecChar, '/', nil);
|
||||||
end;
|
end;
|
||||||
procedure unCommentHere;
|
procedure unCommentHere;
|
||||||
begin
|
begin
|
||||||
editor.ExecuteCommand(ecLineTextStart, '', nil);
|
ExecuteCommand(ecLineTextStart, '', nil);
|
||||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
ExecuteCommand(ecDeleteChar, '', nil);
|
||||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
ExecuteCommand(ecDeleteChar, '', nil);
|
||||||
end;
|
end;
|
||||||
var
|
var
|
||||||
i, j, dx, lx, numUndo: integer;
|
i, j, dx, lx, numUndo: integer;
|
||||||
line: string;
|
line: string;
|
||||||
undo: boolean = false;
|
mustUndo: boolean = false;
|
||||||
pt, cp: TPoint;
|
pt, cp: TPoint;
|
||||||
begin
|
begin
|
||||||
if not editor.SelAvail then
|
if not SelAvail then
|
||||||
begin
|
begin
|
||||||
i := editor.CaretX;
|
i := CaretX;
|
||||||
line := TrimLeft(editor.LineText);
|
line := TrimLeft(LineText);
|
||||||
undo := (line.length > 1) and (line[1..2] = '//');
|
mustUndo := (line.length > 1) and (line[1..2] = '//');
|
||||||
editor.BeginUndoBlock;
|
BeginUndoBlock;
|
||||||
editor.ExecuteCommand(ecLineTextStart, '', nil);
|
ExecuteCommand(ecLineTextStart, '', nil);
|
||||||
if not undo then
|
if not mustUndo then
|
||||||
begin
|
begin
|
||||||
commentHere;
|
commentHere;
|
||||||
editor.CaretX:= i+2;
|
CaretX:= i+2;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
unCommentHere;
|
unCommentHere;
|
||||||
editor.CaretX:= i-2;
|
CaretX:= i-2;
|
||||||
end;
|
end;
|
||||||
editor.EndUndoBlock;
|
EndUndoBlock;
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
undo := false;
|
mustUndo := false;
|
||||||
pt.X:= high(pt.X);
|
pt.X:= high(pt.X);
|
||||||
cp := editor.CaretXY;
|
cp := CaretXY;
|
||||||
numUndo := 0;
|
numUndo := 0;
|
||||||
for i := editor.BlockBegin.Y-1 to editor.BlockEnd.Y-1 do
|
for i := BlockBegin.Y-1 to BlockEnd.Y-1 do
|
||||||
begin
|
begin
|
||||||
line := TrimLeft(editor.Lines[i]);
|
line := TrimLeft(Lines[i]);
|
||||||
dx := editor.Lines[i].length - line.length;
|
dx := Lines[i].length - line.length;
|
||||||
lx := 0;
|
lx := 0;
|
||||||
for j := 1 to dx do
|
for j := 1 to dx do
|
||||||
if editor.Lines[i][j] = #9 then
|
if Lines[i][j] = #9 then
|
||||||
lx += editor.TabWidth
|
lx += TabWidth
|
||||||
else
|
else
|
||||||
lx += 1;
|
lx += 1;
|
||||||
if (lx + 1 < pt.X) and not line.isEmpty then
|
if (lx + 1 < pt.X) and not line.isEmpty then
|
||||||
|
@ -895,40 +898,40 @@ begin
|
||||||
numUndo += 1;
|
numUndo += 1;
|
||||||
end;
|
end;
|
||||||
if numUndo = 0 then
|
if numUndo = 0 then
|
||||||
undo := false
|
mustUndo := false
|
||||||
else if numUndo = editor.BlockEnd.Y + 1 - editor.BlockBegin.Y then
|
else if numUndo = BlockEnd.Y + 1 - BlockBegin.Y then
|
||||||
undo := true;
|
mustUndo := true;
|
||||||
editor.BeginUndoBlock;
|
BeginUndoBlock;
|
||||||
for i := editor.BlockBegin.Y to editor.BlockEnd.Y do
|
for i := BlockBegin.Y to BlockEnd.Y do
|
||||||
begin
|
begin
|
||||||
pt.Y:= i;
|
pt.Y:= i;
|
||||||
editor.ExecuteCommand(ecGotoXY, '', @pt);
|
ExecuteCommand(ecGotoXY, '', @pt);
|
||||||
while editor.CaretX < pt.X do
|
while CaretX < pt.X do
|
||||||
editor.ExecuteCommand(ecChar, ' ', nil);
|
ExecuteCommand(ecChar, ' ', nil);
|
||||||
if not undo then
|
if not mustUndo then
|
||||||
begin
|
begin
|
||||||
commentHere;
|
commentHere;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
unCommentHere;
|
unCommentHere;
|
||||||
end;
|
end;
|
||||||
if not undo then
|
if not mustUndo then
|
||||||
cp.X += 2
|
cp.X += 2
|
||||||
else
|
else
|
||||||
cp.X -= 2;
|
cp.X -= 2;
|
||||||
editor.CaretXY := cp;
|
CaretXY := cp;
|
||||||
editor.EndUndoBlock;
|
EndUndoBlock;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure commentIdentifier(editor: TSynEdit);
|
procedure TCESynMemo.commentIdentifier;
|
||||||
var
|
var
|
||||||
str: string;
|
str: string;
|
||||||
comment: boolean = true;
|
comment: boolean = true;
|
||||||
tkType, st: Integer;
|
tkType, st: Integer;
|
||||||
attrib: TSynHighlighterAttributes;
|
attrib: TSynHighlighterAttributes;
|
||||||
begin
|
begin
|
||||||
if not editor.GetHighlighterAttriAtRowColEx(editor.CaretXY, str, tkType, st, attrib) then
|
if not GetHighlighterAttriAtRowColEx(CaretXY, str, tkType, st, attrib) then
|
||||||
exit;
|
exit;
|
||||||
if str.isEmpty then
|
if str.isEmpty then
|
||||||
exit;
|
exit;
|
||||||
|
@ -939,33 +942,33 @@ begin
|
||||||
|
|
||||||
if comment then
|
if comment then
|
||||||
begin
|
begin
|
||||||
editor.BeginUndoBlock;
|
BeginUndoBlock;
|
||||||
editor.ExecuteCommand(ecWordLeft, '', nil);
|
ExecuteCommand(ecWordLeft, '', nil);
|
||||||
editor.ExecuteCommand(ecChar, '/', nil);
|
ExecuteCommand(ecChar, '/', nil);
|
||||||
editor.ExecuteCommand(ecChar, '*', nil);
|
ExecuteCommand(ecChar, '*', nil);
|
||||||
editor.ExecuteCommand(ecWordEndRight, '', nil);
|
ExecuteCommand(ecWordEndRight, '', nil);
|
||||||
editor.ExecuteCommand(ecChar, '*', nil);
|
ExecuteCommand(ecChar, '*', nil);
|
||||||
editor.ExecuteCommand(ecChar, '/', nil);
|
ExecuteCommand(ecChar, '/', nil);
|
||||||
editor.EndUndoBlock;
|
EndUndoBlock;
|
||||||
end else
|
end else
|
||||||
//TODO-ceditor: handle spaces between ident and comment beg end.
|
//TODO-ceditor: handle spaces between ident and comment beg end.
|
||||||
begin
|
begin
|
||||||
editor.BeginUndoBlock;
|
BeginUndoBlock;
|
||||||
if str[1..2] = '/*' then
|
if str[1..2] = '/*' then
|
||||||
begin
|
begin
|
||||||
editor.ExecuteCommand(ecWordLeft, '', nil);
|
ExecuteCommand(ecWordLeft, '', nil);
|
||||||
editor.ExecuteCommand(ecLeft, '', nil);
|
ExecuteCommand(ecLeft, '', nil);
|
||||||
editor.ExecuteCommand(ecLeft, '', nil);
|
ExecuteCommand(ecLeft, '', nil);
|
||||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
ExecuteCommand(ecDeleteChar, '', nil);
|
||||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
ExecuteCommand(ecDeleteChar, '', nil);
|
||||||
end;
|
end;
|
||||||
if str[str.length-1..str.length] = '*/' then
|
if str[str.length-1..str.length] = '*/' then
|
||||||
begin
|
begin
|
||||||
editor.ExecuteCommand(ecWordEndRight, '', nil);
|
ExecuteCommand(ecWordEndRight, '', nil);
|
||||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
ExecuteCommand(ecDeleteChar, '', nil);
|
||||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
ExecuteCommand(ecDeleteChar, '', nil);
|
||||||
end;
|
end;
|
||||||
editor.EndUndoBlock;
|
EndUndoBlock;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -997,15 +1000,15 @@ begin
|
||||||
showCallTips(true);
|
showCallTips(true);
|
||||||
end;
|
end;
|
||||||
ecCurlyBraceClose:
|
ecCurlyBraceClose:
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent;
|
||||||
ecCommentSelection:
|
ecCommentSelection:
|
||||||
commentSelection(self);
|
commentSelection;
|
||||||
ecSwapVersionAllNone:
|
ecSwapVersionAllNone:
|
||||||
invertVersionAllNone;
|
invertVersionAllNone;
|
||||||
ecRenameIdentifier:
|
ecRenameIdentifier:
|
||||||
renameIdentifier;
|
renameIdentifier;
|
||||||
ecCommentIdentifier:
|
ecCommentIdentifier:
|
||||||
commentIdentifier(self);
|
commentIdentifier;
|
||||||
ecShowPhobosDoc:
|
ecShowPhobosDoc:
|
||||||
ShowPhobosDoc;
|
ShowPhobosDoc;
|
||||||
end;
|
end;
|
||||||
|
@ -1656,13 +1659,13 @@ begin
|
||||||
autoCloseOnNewLineAlways: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
|
autoCloseOnNewLineAlways: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
|
||||||
begin
|
begin
|
||||||
Key := 0;
|
Key := 0;
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent;
|
||||||
end;
|
end;
|
||||||
autoCloseOnNewLineEof: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
|
autoCloseOnNewLineEof: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
|
||||||
if (CaretY = Lines.Count) and (CaretX = line.length+1) then
|
if (CaretY = Lines.Count) and (CaretX = line.length+1) then
|
||||||
begin
|
begin
|
||||||
Key := 0;
|
Key := 0;
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent;
|
||||||
end;
|
end;
|
||||||
autoCloseOnNewLineLexically: if (LogicalCaretXY.X - 1 >= line.length)
|
autoCloseOnNewLineLexically: if (LogicalCaretXY.X - 1 >= line.length)
|
||||||
or isBlank(line[LogicalCaretXY.X .. line.length]) then
|
or isBlank(line[LogicalCaretXY.X .. line.length]) then
|
||||||
|
@ -1672,7 +1675,7 @@ begin
|
||||||
if lexCanCloseBrace then
|
if lexCanCloseBrace then
|
||||||
begin
|
begin
|
||||||
Key := 0;
|
Key := 0;
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -1725,16 +1728,16 @@ begin
|
||||||
'{':
|
'{':
|
||||||
case fAutoCloseCurlyBrace of
|
case fAutoCloseCurlyBrace of
|
||||||
autoCloseAlways:
|
autoCloseAlways:
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent;
|
||||||
autoCloseAtEof:
|
autoCloseAtEof:
|
||||||
if (CaretY = Lines.Count) and (CaretX = LineText.length+1) then
|
if (CaretY = Lines.Count) and (CaretX = LineText.length+1) then
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent;
|
||||||
autoCloseLexically:
|
autoCloseLexically:
|
||||||
begin
|
begin
|
||||||
fLexToks.Clear;
|
fLexToks.Clear;
|
||||||
lex(lines.Text, fLexToks);
|
lex(lines.Text, fLexToks);
|
||||||
if lexCanCloseBrace then
|
if lexCanCloseBrace then
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
Loading…
Reference in New Issue