IDE: fpdoc link editor: cursor up/down

git-svn-id: trunk@21054 -
This commit is contained in:
mattias 2009-08-01 11:49:10 +00:00
parent cde1f77fe0
commit fde82e5b5f
2 changed files with 60 additions and 11 deletions

View File

@ -31,7 +31,7 @@ interface
uses uses
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls, ButtonPanel, FileUtil, ExtCtrls, StdCtrls, ButtonPanel, FileUtil, LCLType,
PackageIntf, ProjectIntf, PackageIntf, ProjectIntf,
CodeHelp, LazarusIDEStrConsts, PackageSystem, PackageDefs, Laz_DOM; CodeHelp, LazarusIDEStrConsts, PackageSystem, PackageDefs, Laz_DOM;
@ -50,10 +50,16 @@ type
TFPDocLinkCompletionList = class TFPDocLinkCompletionList = class
private private
FBGColor: TColor;
FItemHeight: integer;
FItems: TFPList; // list of TFPDocLinkCompletionItem FItems: TFPList; // list of TFPDocLinkCompletionItem
FPrefix: string; FPrefix: string;
FSelected: integer; FSelected: integer;
FSelectedBGColor: TColor;
FSelectedTextColor: TColor;
FTextColor: TColor;
FTop: integer; FTop: integer;
FVisibleItems: integer;
function GetCount: integer; function GetCount: integer;
function GetItems(Index: integer): TFPDocLinkCompletionItem; function GetItems(Index: integer): TFPDocLinkCompletionItem;
procedure SetSelected(const AValue: integer); procedure SetSelected(const AValue: integer);
@ -69,9 +75,15 @@ type
procedure Draw(Canvas: TCanvas; Width, Height: integer); procedure Draw(Canvas: TCanvas; Width, Height: integer);
property Count: integer read GetCount; property Count: integer read GetCount;
property Items[Index: integer]: TFPDocLinkCompletionItem read GetItems; property Items[Index: integer]: TFPDocLinkCompletionItem read GetItems;
property ItemHeight: integer read FItemHeight write FItemHeight;// pixel per item
property VisibleItems: integer read FVisibleItems write FVisibleItems;// visible lines
property Top: integer read FTop write SetTop; property Top: integer read FTop write SetTop;
property Selected: integer read FSelected write SetSelected; property Selected: integer read FSelected write SetSelected;
property Prefix: string read FPrefix write FPrefix; property Prefix: string read FPrefix write FPrefix;
property BGColor: TColor read FBGColor write FBGColor;
property TextColor: TColor read FTextColor write FTextColor;
property SelectedBGColor: TColor read FSelectedBGColor write FSelectedBGColor;
property SelectedTextColor: TColor read FSelectedTextColor write FSelectedTextColor;
end; end;
{ TFPDocLinkEditorDlg } { TFPDocLinkEditorDlg }
@ -167,8 +179,12 @@ end;
procedure TFPDocLinkEditorDlg.CompletionBoxPaint(Sender: TObject); procedure TFPDocLinkEditorDlg.CompletionBoxPaint(Sender: TObject);
begin begin
CompletionBox.Canvas.Brush.Color:=clInfoBk; fItems.BGColor:=clWindow;
CompletionBox.Canvas.Font.Color:=clInfoText; fItems.TextColor:=clWindowText;
fItems.SelectedBGColor:=clHighlight;
fItems.SelectedTextColor:=clHighlightText;
fItems.ItemHeight:=Canvas.TextHeight('ABCTWSMgqp')+4;
fItems.VisibleItems:=CompletionBox.ClientHeight div fItems.ItemHeight;
fItems.Draw(CompletionBox.Canvas, fItems.Draw(CompletionBox.Canvas,
CompletionBox.ClientWidth,CompletionBox.ClientHeight); CompletionBox.ClientWidth,CompletionBox.ClientHeight);
end; end;
@ -181,8 +197,34 @@ end;
procedure TFPDocLinkEditorDlg.LinkEditKeyDown(Sender: TObject; var Key: Word; procedure TFPDocLinkEditorDlg.LinkEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); Shift: TShiftState);
var
Handled: Boolean;
begin begin
if Shift=[] then begin
Handled:=true;
case Key of
VK_UP:
if FItems.Selected>0 then begin
FItems.Selected:=FItems.Selected-1;
if FItems.Top>fItems.Selected then
FItems.Top:=fItems.Selected;
CompletionBox.Invalidate;
end;
VK_DOWN:
if FItems.Selected<fItems.Count-1 then begin
FItems.Selected:=FItems.Selected+1;
if FItems.Selected>=fItems.Top+fItems.VisibleItems then
FItems.Top:=FItems.Top+1;
CompletionBox.Invalidate;
end;
VK_RETURN:
if (FItems.Selected>=0) and (FItems.Selected<fItems.Count) then
Link:=FItems.Items[fItems.Selected].Text;
else
Handled:=false;
end;
if Handled then Key:=VK_UNKNOWN;
end;
end; end;
procedure TFPDocLinkEditorDlg.SetSourceFilename(const AValue: string); procedure TFPDocLinkEditorDlg.SetSourceFilename(const AValue: string);
@ -484,6 +526,8 @@ var
begin begin
for i:=0 to FItems.Count-1 do TObject(FItems[i]).Free; for i:=0 to FItems.Count-1 do TObject(FItems[i]).Free;
FItems.Clear; FItems.Clear;
FSelected:=0;
FTop:=0;
end; end;
procedure TFPDocLinkCompletionList.AddPackage(Pkg: TLazPackage); procedure TFPDocLinkCompletionList.AddPackage(Pkg: TLazPackage);
@ -519,9 +563,18 @@ begin
DebugLn(['TFPDocLinkCompletionList.Draw ',Width,' ',Height,' Count=',Count]); DebugLn(['TFPDocLinkCompletionList.Draw ',Width,' ',Height,' Count=',Count]);
i:=Top; i:=Top;
y:=0; y:=0;
dy:=Canvas.TextHeight('ABCTWSMgqp')+4; dy:=ItemHeight;
while (y<Height) and (i<Count) do begin while (y<Height) and (i<Count) do begin
Item:=Items[i]; Item:=Items[i];
Canvas.Brush.Style:=bsSolid;
Canvas.Font.Style:=[];
if i=Selected then begin
Canvas.Brush.Color:=SelectedBGColor;
Canvas.Font.Color:=SelectedTextColor;
end else begin
Canvas.Brush.Color:=BGColor;
Canvas.Font.Color:=TextColor;
end;
Canvas.FillRect(0,y,Width,y+dy); Canvas.FillRect(0,y,Width,y+dy);
s:=Item.Text; s:=Item.Text;
Canvas.TextOut(2,y+2,s); Canvas.TextOut(2,y+2,s);
@ -531,6 +584,7 @@ begin
inc(i); inc(i);
end; end;
if y<Height then begin if y<Height then begin
Canvas.Brush.Color:=BGColor;
Canvas.FillRect(0,y,Width,Height); Canvas.FillRect(0,y,Width,Height);
end; end;
end; end;

View File

@ -10,10 +10,10 @@
<MainUnitHasTitleStatement Value="False"/> <MainUnitHasTitleStatement Value="False"/>
<LRSInOutputDirectory Value="False"/> <LRSInOutputDirectory Value="False"/>
</Flags> </Flags>
<SessionStorage Value="InIDEConfig"/>
<MainUnit Value="0"/> <MainUnit Value="0"/>
<TargetFileExt Value=""/> <TargetFileExt Value=""/>
<Title Value="lazres"/> <Title Value="lazres"/>
<ActiveEditorIndexAtStart Value="0"/>
</General> </General>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>
@ -36,11 +36,6 @@
<Filename Value="lazres.pp"/> <Filename Value="lazres.pp"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="LazRes"/> <UnitName Value="LazRes"/>
<CursorPos X="23" Y="101"/>
<TopLine Value="82"/>
<EditorIndex Value="0"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit0> </Unit0>
</Units> </Units>
</ProjectOptions> </ProjectOptions>