Added code for editor hints.

Shane

git-svn-id: trunk@463 -
This commit is contained in:
lazarus 2001-11-27 21:09:46 +00:00
parent 527ebfb5ce
commit 3cbe0ff3ae
2 changed files with 149 additions and 2 deletions

View File

@ -348,6 +348,8 @@ Begin
if ControlSelection.ActiveGrabber=nil then begin if ControlSelection.ActiveGrabber=nil then begin
NonVisualComp:=NonVisualComponentAtPos( NonVisualComp:=NonVisualComponentAtPos(
MouseDownPos.X,MouseDownPos.Y); MouseDownPos.X,MouseDownPos.Y);
Writeln('ActiveGrabber = nil');
if NonVisualComp<>nil then Writeln('1') else Writeln('2');
if NonVisualComp<>nil then MouseDownComponent:=NonVisualComp; if NonVisualComp<>nil then MouseDownComponent:=NonVisualComp;
CompIndex:=ControlSelection.IndexOf(MouseDownComponent); CompIndex:=ControlSelection.IndexOf(MouseDownComponent);
if (Message.Keys and MK_SHIFT)>0 then begin if (Message.Keys and MK_SHIFT)>0 then begin

View File

@ -38,7 +38,7 @@ uses
FindReplaceDialog, EditorOptions, CustomFormEditor, KeyMapping, StdCtrls, FindReplaceDialog, EditorOptions, CustomFormEditor, KeyMapping, StdCtrls,
Compiler, MsgView, WordCompletion, CodeToolManager, CodeCache, SourceLog, Compiler, MsgView, WordCompletion, CodeToolManager, CodeCache, SourceLog,
SynEdit, SynEditHighlighter, SynHighlighterPas, SynEditAutoComplete, SynEdit, SynEditHighlighter, SynHighlighterPas, SynEditAutoComplete,
SynEditKeyCmds,SynCompletion, Graphics, Extctrls, Menus, Splash, FindInFilesDlg; SynEditKeyCmds,SynCompletion, Graphics, Extctrls, Menus, Splash, FindInFilesDlg,LMessages;
type type
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -92,7 +92,9 @@ type
FOnCreateBreakPoint: TOnCreateDeleteBreakPoint; FOnCreateBreakPoint: TOnCreateDeleteBreakPoint;
FOnDeleteBreakPoint: TOnCreateDeleteBreakPoint; FOnDeleteBreakPoint: TOnCreateDeleteBreakPoint;
FVisible : Boolean; FVisible : Boolean;
FOnMouseMove: TMouseMoveEvent;
Procedure EditorMouseMoved(Sender : TObject;Shift : TShiftState; X,Y : Integer);
Function FindFile(const Value : String) : String; Function FindFile(const Value : String) : String;
procedure SetCodeBuffer(NewCodeBuffer: TCodeBuffer); procedure SetCodeBuffer(NewCodeBuffer: TCodeBuffer);
@ -163,6 +165,7 @@ type
procedure FindNext; procedure FindNext;
procedure FindPrevious; procedure FindPrevious;
procedure GetDialogPosition(Width, Height:integer; var Left,Top:integer); procedure GetDialogPosition(Width, Height:integer; var Left,Top:integer);
Function GetWordAtPosition(Position : TPoint) : String;
property CodeBuffer: TCodeBuffer read FCodeBuffer write SetCodeBuffer; property CodeBuffer: TCodeBuffer read FCodeBuffer write SetCodeBuffer;
// property Control : TComponent read FControl write FControl; //commented out on 11-14-2001 // property Control : TComponent read FControl write FControl; //commented out on 11-14-2001
@ -197,6 +200,8 @@ type
read FOnCreateBreakPoint write FOnCreateBreakPoint; read FOnCreateBreakPoint write FOnCreateBreakPoint;
property OnDeleteBreakPoint: TOnCreateDeleteBreakPoint property OnDeleteBreakPoint: TOnCreateDeleteBreakPoint
read FOnDeleteBreakPoint write FOnDeleteBreakPoint; read FOnDeleteBreakPoint write FOnDeleteBreakPoint;
property OnMouseMove : TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
end; end;
@ -251,6 +256,12 @@ type
X, Y: integer): boolean; X, Y: integer): boolean;
procedure OnSynCompletionSearchPosition(var APosition:integer); procedure OnSynCompletionSearchPosition(var APosition:integer);
//hintwindow stuff
FHintWIndow : THintWindow;
FHintTimer : TTimer;
Procedure HintTimer(sender : TObject);
Procedure OnMouseMove(Sender : TObject; Shift: TShiftstate; X,Y : Integer);
Procedure NextEditor; Procedure NextEditor;
Procedure PrevEditor; Procedure PrevEditor;
MarksImgList : TImageList; MarksImgList : TImageList;
@ -1081,6 +1092,7 @@ writeln('TSourceEditor.CreateEditor A ');
OnReplaceText := @OnReplace; OnReplaceText := @OnReplace;
OnGutterClick := @Self.OnGutterClick; OnGutterClick := @Self.OnGutterClick;
OnSpecialLineColors:=@OnEditorSpecialLineColor; OnSpecialLineColors:=@OnEditorSpecialLineColor;
OnMouseMove := @EditorMouseMoved;
Show; Show;
end; end;
if FCodeTemplates<>nil then if FCodeTemplates<>nil then
@ -1358,6 +1370,66 @@ begin
Result:=''; Result:='';
end; end;
Procedure TSourceEditor.EditorMouseMoved(Sender : TObject; Shift : TShiftState; X,Y : Integer);
begin
// Writeln('MOuseMove in Editor',X,',',Y);
if Assigned(OnMouseMove) then
OnMouseMove(self,Shift,X,Y);
end;
Function TSourceEditor.GetWordAtPosition(Position : TPoint) : String;
var
TopLine : Integer;
LineHeight : Integer;
LineNum : Integer;
XLine : Integer;
EditorLine,Texts : String;
begin
Result := '';
//Figure out the line number
TopLine := FEditor.TopLine;
LineHeight := FEditor.LineHeight;
// Writeln('GetWord...,',position.X,',',Position.Y);
if Position.Y > 1 then
LineNum := Position.Y div LineHeight
else
LineNum := 1;
XLine := Position.X div FEditor.CharWidth;
if XLine = 0 then inc(XLine);
EditorLine := FEditor.Lines[LineNum];
// Writeln('XLine and LineNum = ',XLine,',',LineNum);
if Length(trim(EditorLine)) = 0 then Exit;
if XLine > Length(EditorLine) then Exit;
//walk backwards to a space or non-standard character.
while (((ord(upcase(EditorLine[XLine])) >= 65)
and (ord(upcase(EditorLine[xLine])) <= 90)) or
((ord(EditorLine[XLine]) >= ord('1'))
and (ord(EditorLine[XLine]) <= ord('0')))) and (XLine>1) do
dec(xLine);
if ( (XLine > 1) and (XLine < Length(EditorLine))) then Inc(xLine);
Texts := Copy(EditorLine,XLine,length(EditorLine)); //chop off the beginning
XLine := 1;
while (((ord(upcase(Texts[xLine])) >= 65) and (ord(upcase(Texts[xLine])) <= 90))
or ((ord(EditorLine[XLine]) >= ord('1'))
and (ord(EditorLine[XLine]) <= ord('0'))))
and (XLine< length(Texts)) do
inc(xLine);
if (XLine < Length(Texts) ) and (XLine >1) then dec(xLine);
if not((((ord(upcase(Texts[xLine])) >= 65) and (ord(upcase(Texts[xLine])) <= 90)))
or ((ord(EditorLine[XLine]) >= ord('1'))
and (ord(EditorLine[XLine]) <= ord('0')))) then
dec(xLine);
Texts := Copy(Texts,1,XLine);
Result := Texts;
end;
{------------------------------------------------------------------------} {------------------------------------------------------------------------}
{ TSourceNotebook } { TSourceNotebook }
@ -1507,6 +1579,19 @@ begin
Visible:=false; Visible:=false;
//hinttimer
FHintTimer := TTimer.Create(nil);
FHintTimer.Interval := 500;
FHintTimer.Enabled := False;
FHintTimer.OnTimer := @HintTimer;
FHintWindow := THintWindow.Create(nil);
FHIntWindow.Visible := False;
FHintWindow.Caption := 'This is a hint window'#13#10'NEat huh?';
FHintWindow.HideInterval := 4000;
FHintWindow.AutoHide := True;
end; end;
destructor TSourceNotebook.Destroy; destructor TSourceNotebook.Destroy;
@ -1526,6 +1611,10 @@ begin
FCodeTemplateModul.Free; FCodeTemplateModul.Free;
FSourceEditorList.Free; FSourceEditorList.Free;
Gotodialog.free; Gotodialog.free;
FHintTimer.free;
FHintWindow.Free;
inherited Destroy; inherited Destroy;
end; end;
@ -2074,6 +2163,13 @@ writeln('TSourceNotebook.NewSE C ');
Result.EditorComponent.BookMarkOptions.BookmarkImages := MarksImgList; Result.EditorComponent.BookMarkOptions.BookmarkImages := MarksImgList;
Result.PopupMenu:=SrcPopupMenu; Result.PopupMenu:=SrcPopupMenu;
Result.OnEditorChange := @EditorChanged; Result.OnEditorChange := @EditorChanged;
writeln('ASSIGNING ONMOUSEMOVE');
Result.OnMouseMove := @OnMouseMove;
Writeln('-------------------------------------------');
Writeln('-------------------------------------------');
Writeln('-------------------------------------------');
Writeln('-------------------------------------------');
Writeln('-------------------------------------------');
{$IFDEF IDE_DEBUG} {$IFDEF IDE_DEBUG}
writeln('TSourceNotebook.NewSE end '); writeln('TSourceNotebook.NewSE end ');
{$ENDIF} {$ENDIF}
@ -2758,6 +2854,55 @@ Begin
end; end;
end; end;
Procedure TSourceNotebook.OnMouseMove(Sender : TObject; Shift: TShiftstate; X,Y : Integer);
begin
//writeln('MOUSEMOVE');
if FHintWIndow.Visible then
FHintWindow.Visible := False;
FHintTimer.Enabled := False;
FHintTimer.Enabled := not ((ssLeft in Shift) or (ssRight in Shift) or (ssMiddle in Shift));
end;
Procedure TSourceNotebook.HintTimer(sender : TObject);
var
Rect : TRect;
AHint : String;
cPosition : TPoint;
TextPosition : TPoint;
SE : TSourceEditor;
begin
FHintTimer.Enabled := False;
cPosition := Mouse.CursorPos;
cPosition := ScreenToClient(cPosition);
if ((cPosition.X <=EditorOpts.GutterWidth) or (cPosition.X >= Width) or (cPosition.Y <= 25)
or (cPosition.Y >= Height)) then
Exit;
Se := GetActiveSE;
if Not Assigned(se) then Exit;
TextPosition.x := cPosition.X-EditorOPts.GutterWidth;
TextPosition.Y := cPosition.Y - 28;
AHint := SE.GetWordAtPosition(TextPosition);
if AHint = '' then Exit;
Writeln('cPosition ius ',cPosition.x,',',cPosition.y);
Rect := FHintWindow.CalcHintRect(0,AHint,nil); //no maxwidth
// Position := ClientToScreen(FLastMouseMovePos);
Rect.Left := cPosition.X+Left+10;
Rect.Top := cPosition.Y+Top+10;
//adding tab height
Rect.Top := Rect.Top + 25;
Rect.Right := Rect.Left + Rect.Right+3;
Rect.Bottom := Rect.Top + Rect.Bottom+3;
FHintWindow.ActivateHint(Rect,AHint);
end;
{ GOTO DIALOG} { GOTO DIALOG}