📄 dws2syneditutils.pas
字号:
isCommentOrString := IsInCommentOrString(Editor, Point(TmpX, TmpY));
if ((LocLine[TmpX] = ')') or (NumBrackets > 0)) and (not isCommentOrString) then
begin
// search until start of line
Inc(NumBrackets);// := 1;
while (TmpX > 1) and (NumBrackets > 0) do begin
Dec(TmpX);
Test := LocLine[TmpX];
if (Test = ')') or (Test = '(') then
begin
isCommentOrString := IsInCommentOrString(Editor, Point(TmpX, TmpY));
if (Test = ')') and (not isCommentOrString) then
Inc(NumBrackets)
else if (Test = '(') and (not isCommentOrString) then
Dec(NumBrackets);
end;
end; {while}
end
else if (locLine[TmpX] = '(') and (not isCommentOrString) then
begin
//we have a valid open paren, lets see what the word before it is
StartX := TmpX;
StartY := TmpY;
{ Set the Popup window to start after the main word on the line after
the current line.
NOTE: The default behavior would be to move the popup window along with
the cursor as you type. This makes it more like Delphi. }
// use tmpPoint to get the screen coordinates for the popup
tmpPoint := ClientToScreen(RowColumnToPixels(Point(StartX+1, CaretY+1)));
x := tmpPoint.X;
y := tmpPoint.Y;
// re-use tmpPoint to get the position of the previous word
tmpPoint := PrevWordPosEx(Point(StartX, StartY));
FoundSymbol := Prg.SymbolDictionary.FindSymbolAtPosition(tmpPoint.X, tmpPoint.Y);
if FoundSymbol = nil then
dec(TmpX);
end
else if (LocLine[TmpX] = ',') and (not isCommentOrString) then
inc(TmpLocation);
// if reached the beginning of line, go up a line and begin searching from the end
if TmpX <= 1 then
begin
dec(TmpY);
locLine := Lines[TmpY-1] + ' '; //-1 because Lines is 0 based
TmpX := Length(locLine);
end;
dec(TmpX);
end;
end;
Result := False; // default to NOT execute
if FoundSymbol <> nil then
begin
ParamProposal.ItemList.Clear;
// needs to keep searching the previous word until reached a TFuncSymbol word, position CurrentIndex at that point
if FoundSymbol is TFuncSymbol then
begin
ParamDelim := ';'; // separate parameters in the list with ';'
// set current index to highlight. Total param count - commas encountered
ParamProposal.Form.CurrentIndex := TmpLocation;
for p := 0 to TFuncSymbol(FoundSymbol).Params.Count - 1 do
begin
thisParam := TFuncSymbol(FoundSymbol).Params[p].Description;
if Length(TParamSymbol(TFuncSymbol(FoundSymbol).Params[p]).DefaultValue) > 0 then
thisParam := '[' + thisParam + ']'; // has a default value, display appropriately
ParamText := ParamText + '"' + thisParam + ParamDelim+'"';
if p < TFuncSymbol(FoundSymbol).Params.Count - 1 then // if not the last param
ParamText := ParamText + ', ' // separate with a comma
else // if the last one
ParamDelim := ''; // clear the delimeter
end;
// if something to add, add to list
if ParamText <> '' then
ParamProposal.ItemList.Add(ParamText);
Result := True;
end;
end;
end;
{-----------------------------------------------------------------------------
Procedure: PerformHintProposal
Author: Mark Ericksen
Date: 21-Sep-2002
Arguments: Editor: TCustomSynEdit; Prg: TProgram; HintProposal: TSynCompletionProposal; var x, y: Integer
Result: Boolean
Purpose: Shows the pop-up hint information for the focused symbol.
-----------------------------------------------------------------------------}
function PerformHintProposal(Editor: TCustomSynEdit; Prg: TProgram;
HintProposal: TSynCompletionProposal;
var x, y: Integer; IncludeImages: Boolean): Boolean;
var
FoundSymbol: TSymbol;
SymText: string; // text to display to represent the symbol
DispOpts: TdSyn_DisplayOptions;
MousePos,
WordStart: TPoint;
SymPos: TSymbolPosition; // position in script where symbol is defined
begin
Result := False; // default to NOT show it.
if not Editor.GetPositionOfMouse(MousePos) then
EXIT;
HintProposal.ClBackground := clInfoBk;
HintProposal.Font.Color := clInfoText;
HintProposal.ItemList.Clear;
DispOpts := [doSynStyle];
if IncludeImages then
Include(DispOpts, doIncludeImage);
try
WordStart := Editor.WordStartEx(MousePos);
FoundSymbol := Prg.SymbolDictionary.FindSymbolAtPosition(WordStart.X, WordStart.Y);
if FoundSymbol <> nil then
begin
{ TODO -oMark -cDebug hint : If program is running, show run-time debug values for the expresion/variables }
{ If program is running, make the hint display the current value }
// if Prg.ProgramState in [{psRunning, }psRunningStopped] then
SymText := GetSymbolAsText(Prg.Table, FoundSymbol, DispOpts, [coIncludeContext, coIncludeUnit]);
if SymText <> '' then begin // if something to display, show it. ('Integer' is a symbol but is not represented with anything)
// find the line where symbol is declared, add to end if found
SymPos := Prg.SymbolDictionary.FindSymbolUsage(FoundSymbol, suDeclaration);
if Assigned(SymPos) then
SymText := SymText + Format(' (%d)', [SymPos.ScriptPos.Line]);
HintProposal.ItemList.Add(SymText);
Result := True; // OK to show it
end;
end;
// position the Hint window to be at the start of the word on the following line
y := Editor.ClientToScreen(Editor.RowColumnToPixels(Point(WordStart.X, WordStart.Y+1))).Y; // position under the current item
x := Editor.ClientToScreen(Editor.RowColumnToPixels(WordStart)).X;
finally
// if we can't show it, if it IS showing, turn it off (may be from previous time)
if (not Result) and HintProposal.Form.Visible then
HintProposal.CancelCompletion;
end;
end;
{-----------------------------------------------------------------------------
Procedure: PerformCodeCompletion
Author: Mark Ericksen
Date: 23-Sep-2002
Arguments: Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII; CodeProposal: TSynCompletionProposal; UnitItemsList, UnitInserts: TStrings; var x, y: Integer
Result: Boolean
Purpose: Simple wrapper for easier use.
-----------------------------------------------------------------------------}
function PerformCodeCompletion(Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII;
CodeProposal: TSynCompletionProposal;
UnitItemsList, UnitInserts: TStrings;
var x, y: Integer; IncludeImages, IncludePropertyAccessors: Boolean): Boolean;
var
Prg: TProgram;
begin
Prg := CompileWithSymbolsAndMap(DWScript, Editor.Lines.Text);
try
Result := PerformCodeCompletion(Editor, Prg, CodeProposal, UnitItemsList,
UnitInserts, x, y, IncludeImages,
IncludePropertyAccessors);
finally
Prg.Free;
end;
end;
{-----------------------------------------------------------------------------
Procedure: PerformCodeCompletion
Author: Mark Ericksen
Date: 23-Sep-2002
Arguments: Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII; CodeProposal: TSynCompletionProposal; var x, y: Integer
Result: Boolean
Purpose: Simple wrapper for easier use.
-----------------------------------------------------------------------------}
function PerformCodeCompletion(Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII;
CodeProposal: TSynCompletionProposal;
var x, y: Integer; IncludeImages, IncludePropertyAccessors: Boolean): Boolean;
begin
// Pass nil string lists. Force it to fill them internally.
Result := PerformCodeCompletion(Editor, DWScript, CodeProposal, nil, nil, x, y,
IncludeImages, IncludePropertyAccessors);
end;
{-----------------------------------------------------------------------------
Procedure: PerformParamProposal
Author: Mark Ericksen
Date: 23-Sep-2002
Arguments: Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII; ParamProposal: TSynCompletionProposal; var x, y: Integer
Result: Boolean
Purpose: Simple wrapper for easier use.
-----------------------------------------------------------------------------}
function PerformParamProposal(Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII;
ParamProposal: TSynCompletionProposal;
var x, y: Integer): Boolean;
var
Prg: TProgram;
begin
Prg := CompileWithSymbolsAndMap(DWScript, Editor.Lines.Text);
try
Result := PerformParamProposal(Editor, Prg, ParamProposal, x, y);
finally
Prg.Free;
end;
end;
{-----------------------------------------------------------------------------
Procedure: PerformHintProposal
Author: Mark Ericksen
Date: 23-Sep-2002
Arguments: Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII; HintProposal: TSynCompletionProposal; var x, y: Integer
Result: Boolean
Purpose: Simple wrapper for easier use.
-----------------------------------------------------------------------------}
function PerformHintProposal(Editor: TCustomSynEdit; DWScript: TDelphiWebScriptII;
HintProposal: TSynCompletionProposal;
var x, y: Integer; IncludeImages: Boolean): Boolean;
var
Prg: TProgram;
begin
Prg := CompileWithSymbolsAndMap(DWScript, Editor.Lines.Text);
try
Result := PerformHintProposal(Editor, Prg, HintProposal, x, y, IncludeImages);
finally
Prg.Free;
end;
end;
{-----------------------------------------------------------------------------
Procedure: ToggleFromDecl2Impl
Author: Mark Ericksen
Date: 18-Oct-2002
Arguments: Editor: TCustomSynEdit; AProgram: TProgram
Result: None
Purpose: Toggle position between Implementation and Declaration (procedures/methods)
-----------------------------------------------------------------------------}
procedure ToggleFromDecl2Impl(Editor: TCustomSynEdit; AProgram: TProgram);
var
NewPos: TScriptPos;
begin
NewPos := FindToggledFuncDeclImplPos(Editor.CaretX, Editor.CaretY, AProgram);
if NewPos.Pos > -1 then // -1 if NullPos was returned
begin
{ Place cursor on correct location }
Editor.CaretX := NewPos.Col;
Editor.CaretY := NewPos.Line;
{ Try to roughly center the new position in the window }
Editor.TopLine := Editor.CaretY - (Editor.LinesInWindow div 2);
end;
end;
{-----------------------------------------------------------------------------
Procedure: IsInCommentOrString
Author: Mark Ericksen
Date: 22-Mar-2003
Arguments: Editor: TCustomSynEdit; APoint: TPoint
Result: Boolean
Purpose: Return if the specified position (APoint) is in a comment or a
string as defined by the highlighter.
-----------------------------------------------------------------------------}
function IsInCommentOrString(Editor: TCustomSynEdit; APoint: TPoint): Boolean;
var
dumbstr: string;
attr: TSynHighlighterAttributes;
begin
Result := False;
if not Assigned(Editor) then
Exit;
if Editor.GetHighlighterAttriAtRowCol(APoint, dumbstr, attr) then
Result := (attr = Editor.Highlighter.StringAttribute) or
(attr = Editor.Highlighter.CommentAttribute)
else
Result := False;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -