ide: minor refactoring:

- add GetOperandFromCaret, GetOperandAtCurrentCaret to the TSourceEditor class
  - use that methods for the debugger tooltip evaluation and for the debugger evaluate dialog

git-svn-id: trunk@21969 -
This commit is contained in:
paul 2009-10-02 02:26:41 +00:00
parent b11fa376c6
commit 71d8ecf4de
3 changed files with 24 additions and 16 deletions

View File

@ -1690,7 +1690,7 @@ begin
if SourceNotebook.GetActiveSE.SelectionAvailable then
TEvaluateDlg(CurDialog).FindText := SourceNotebook.GetActiveSE.Selection
else
TEvaluateDlg(CurDialog).FindText := SourceNotebook.GetActiveSE.GetWordAtCurrentCaret;
TEvaluateDlg(CurDialog).FindText := SourceNotebook.GetActiveSE.GetOperandAtCurrentCaret;
end;
FDialogs[ADialogType].Show;
end;

View File

@ -13513,9 +13513,7 @@ procedure TMainIDE.OnSrcNotebookShowHintForSource(SrcEdit: TSourceEditor;
var
ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo;
Identifier, SmartHintStr: string;
Expression, DebugEval: string;
BaseURL: String;
BaseURL, SmartHintStr, Expression, DebugEval: String;
begin
//DebugLn(['TMainIDE.OnSrcNotebookShowHintForSource START']);
if (SrcEdit=nil) then exit;
@ -13538,16 +13536,10 @@ begin
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF}
end;
itDebugger: begin
Identifier := SrcEdit.GetWordFromCaret(CaretPos);
//DebugLn(['TMainIDE.OnSrcNotebookShowHintForSource ',Identifier]);
if Identifier = '' then Exit;
if SrcEdit.SelectionAvailable and SrcEdit.CaretInSelection(CaretPos) then
if SrcEdit.SelectionAvailable and SrcEdit.CaretInSelection(CaretPos) then
Expression := SrcEdit.GetText(True)
else
if not CodeToolBoss.ExtractOperand(SrcEdit.CodeBuffer,
CaretPos.X,CaretPos.Y,Expression,false) then
Expression := Identifier;
//DebugLn(['TMainIDE.OnSrcNotebookShowHintForSource Expr="',Expression,'"']);
Expression := SrcEdit.GetOperandFromCaret(CaretPos);
if not DebugBoss.Evaluate(Expression, DebugEval) or (DebugEval = '') then
DebugEval := '???';
SmartHintStr := Expression + ' = ' + DebugEval;
@ -13556,8 +13548,8 @@ begin
Exit;
end;
if SmartHintStr<>'' then
SrcEdit.ActivateHint(ClientPos,BaseURL,SmartHintStr);
if SmartHintStr <> '' then
SrcEdit.ActivateHint(ClientPos, BaseURL, SmartHintStr);
end;
procedure TMainIDE.OnSrcNoteBookActivated(Sender: TObject);

View File

@ -312,6 +312,8 @@ type
function GetWordAtPosition(Position: TPoint): String;
function GetWordFromCaret(const ACaretPos: TPoint): String;
function GetWordAtCurrentCaret: String;
function GetOperandFromCaret(const ACaretPos: TPoint): String;
function GetOperandAtCurrentCaret: String;
function CaretInSelection(const ACaretPos: TPoint): Boolean;
function PositionInSelection(const APosition: TPoint): Boolean;
@ -3274,16 +3276,30 @@ begin
FillExecutionMarks;
end;
Function TSourceEditor.GetWordAtCurrentCaret: String;
function TSourceEditor.GetWordAtCurrentCaret: String;
var
CaretPos: TPoint;
begin
Result := '';
CaretPos.Y := CurrentCursorYLine;
CaretPos.X := CurrentCursorXLine;
Result := GetWordFromCaret(ScreenToTextPosition(CaretPos));
end;
function TSourceEditor.GetOperandFromCaret(const ACaretPos: TPoint): String;
begin
if not CodeToolBoss.ExtractOperand(CodeBuffer, ACaretPos.X, ACaretPos.Y, Result, False) then
Result := GetWordFromCaret(ACaretPos);
end;
function TSourceEditor.GetOperandAtCurrentCaret: String;
var
CaretPos: TPoint;
begin
CaretPos.Y := CurrentCursorYLine;
CaretPos.X := CurrentCursorXLine;
Result := GetOperandFromCaret(ScreenToTextPosition(CaretPos));
end;
function TSourceEditor.GetWordFromCaret(const ACaretPos: TPoint): String;
begin
Result := FEditor.GetWordAtRowCol(ACaretPos);