mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-12 20:30:32 +02:00
134 lines
4.1 KiB
ObjectPascal
134 lines
4.1 KiB
ObjectPascal
{
|
|
***************************************************************************
|
|
* *
|
|
* This source is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This code is distributed in the hope that it will be useful, but *
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
* General Public License for more details. *
|
|
* *
|
|
* A copy of the GNU General Public License is available on the World *
|
|
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
|
* obtain it by writing to the Free Software Foundation, *
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
* *
|
|
***************************************************************************
|
|
|
|
Author: Mattias Gaertner
|
|
|
|
Abstract:
|
|
Hint using the lazdoc data.
|
|
}
|
|
unit LazDocHints;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, LCLProc, Forms, Controls, Graphics,
|
|
CodeToolManager, CodeCache, BasicCodeTools, IdentCompletionTool,
|
|
SrcEditorIntf,
|
|
CodeHelpForm, LazDoc;
|
|
|
|
type
|
|
|
|
{ TLazDocHintProvider }
|
|
|
|
TLazDocHintProvider = class(TCodeHintProvider)
|
|
private
|
|
FHintValid: boolean;
|
|
FWaitingForIdle: boolean;
|
|
procedure SetHintValid(const AValue: boolean);
|
|
procedure SetWaitingForIdle(const AValue: boolean);
|
|
procedure ApplicationIdle(Sender: TObject; var Done: Boolean);
|
|
procedure ReadLazDocData;
|
|
public
|
|
destructor Destroy; override;
|
|
procedure Paint(Canvas: TCanvas; const ARect: TRect); override;
|
|
procedure UpdateHint; override;
|
|
property WaitingForIdle: boolean read FWaitingForIdle write SetWaitingForIdle;
|
|
property HintValid: boolean read FHintValid write SetHintValid;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{ TLazDocHintProvider }
|
|
|
|
procedure TLazDocHintProvider.SetWaitingForIdle(const AValue: boolean);
|
|
begin
|
|
if FWaitingForIdle=AValue then exit;
|
|
FWaitingForIdle:=AValue;
|
|
if Application<>nil then begin
|
|
if FWaitingForIdle then
|
|
Application.AddOnIdleHandler(@ApplicationIdle)
|
|
else
|
|
Application.RemoveOnIdleHandler(@ApplicationIdle);
|
|
end;
|
|
end;
|
|
|
|
procedure TLazDocHintProvider.SetHintValid(const AValue: boolean);
|
|
begin
|
|
if FHintValid=AValue then exit;
|
|
FHintValid:=AValue;
|
|
end;
|
|
|
|
procedure TLazDocHintProvider.ApplicationIdle(Sender: TObject; var Done: Boolean
|
|
);
|
|
begin
|
|
WaitingForIdle:=false;
|
|
ReadLazDocData;
|
|
end;
|
|
|
|
procedure TLazDocHintProvider.ReadLazDocData;
|
|
var
|
|
Position: LongInt;
|
|
Item: TIdentifierListItem;
|
|
Code: TCodeBuffer;
|
|
DocFilename: String;
|
|
begin
|
|
if (SourceEditorWindow=nil) or (CodeToolBoss=nil)
|
|
or (CodeToolBoss.IdentifierList=nil) then
|
|
exit;
|
|
Position:=SourceEditorWindow.CompletionBoxPosition;
|
|
if (Position<0) or (Position>=CodeToolBoss.IdentifierList.GetFilteredCount) then
|
|
exit;
|
|
Item:=CodeToolBoss.IdentifierList.FilteredItems[Position];
|
|
DebugLn(['TLazDocHintProvider.ReadLazDocData Identifier=',GetIdentifier(Item.Identifier)]);
|
|
if (Item.Node<>nil) then begin
|
|
if (Item.Tool.Scanner=nil) then exit;
|
|
Code:=TCodeBuffer(Item.Tool.Scanner.MainCode);
|
|
if Code=nil then exit;
|
|
DocFilename:=LazDocBoss.GetFPDocFilenameForSource(Code.Filename,false);
|
|
if DocFilename='' then exit;
|
|
DebugLn(['TLazDocHintProvider.ReadLazDocData DocFilename=',DocFilename]);
|
|
end else begin
|
|
|
|
end;
|
|
end;
|
|
|
|
destructor TLazDocHintProvider.Destroy;
|
|
begin
|
|
WaitingForIdle:=false;
|
|
inherited Destroy;
|
|
end;
|
|
|
|
procedure TLazDocHintProvider.Paint(Canvas: TCanvas; const ARect: TRect);
|
|
begin
|
|
|
|
|
|
end;
|
|
|
|
procedure TLazDocHintProvider.UpdateHint;
|
|
begin
|
|
WaitingForIdle:=true;
|
|
inherited UpdateHint;
|
|
end;
|
|
|
|
end.
|
|
|