IDE: source hint: improved default label control

git-svn-id: trunk@30441 -
This commit is contained in:
mattias 2011-04-23 19:33:23 +00:00
parent 69f7e02f62
commit f529fa5679
4 changed files with 91 additions and 37 deletions

View File

@ -38,3 +38,4 @@ msgstr "Scegli stampante..."
#: iphtmlpv.rsiphtmlpreviewzoom #: iphtmlpv.rsiphtmlpreviewzoom
msgid "Zoom:" msgid "Zoom:"
msgstr "Ingrandimento:" msgstr "Ingrandimento:"

View File

@ -214,8 +214,8 @@ type
TCodeHelpHintOption = ( TCodeHelpHintOption = (
chhoSmallStep, // do the next step. Use this to run on idle. chhoSmallStep, // do the next step. Use this to run on idle.
chhoSmartHint, // add smart hint chhoDeclarationHeader, // add a header with source position and type of identifier
chhoComments // return info from comments in the code chhoNoComments // do not add the pasdoc comments
); );
TCodeHelpHintOptions = set of TCodeHelpHintOption; TCodeHelpHintOptions = set of TCodeHelpHintOption;
@ -2275,6 +2275,7 @@ var
begin begin
{$IFDEF EnableNewCodeHints} {$IFDEF EnableNewCodeHints}
Result:=GetHTMLHint2(Code,X,Y,Options,BaseURL,HTMLHint,CacheWasUsed); Result:=GetHTMLHint2(Code,X,Y,Options,BaseURL,HTMLHint,CacheWasUsed);
exit;
{$ENDIF} {$ENDIF}
{$ifdef VerboseHints} {$ifdef VerboseHints}
DebugLn(['TCodeHelpManager.GetHint ',Code.Filename,' ',X,',',Y]); DebugLn(['TCodeHelpManager.GetHint ',Code.Filename,' ',X,',',Y]);
@ -2283,7 +2284,7 @@ begin
IsHTML:=false; IsHTML:=false;
CodeToolBoss.ActivateWriteLock; CodeToolBoss.ActivateWriteLock;
try try
if chhoSmartHint in Options then if chhoDeclarationHeader in Options then
HTMLHint := CodeToolBoss.FindSmartHint(Code,X,Y) HTMLHint := CodeToolBoss.FindSmartHint(Code,X,Y)
else else
HTMLHint := ''; HTMLHint := '';
@ -2322,7 +2323,7 @@ begin
end; end;
// Add comments // Add comments
if chhoComments in Options then if not (chhoNoComments in Options) then
begin begin
FreeListOfPCodeXYPosition(ListOfPCodeXYPosition); FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
if CodeToolBoss.GetPasDocComments(Item.CodeXYPos.Code, if CodeToolBoss.GetPasDocComments(Item.CodeXYPos.Code,
@ -2394,12 +2395,14 @@ var
i: Integer; i: Integer;
OldXYPos: TCodeXYPosition; OldXYPos: TCodeXYPosition;
OldCTTool: TFindDeclarationTool; OldCTTool: TFindDeclarationTool;
OldCTNode: TCodeTreeNode;
n: Integer;
begin begin
Result:=chprFailed; Result:=chprFailed;
BaseURL:='lazdoc://'; BaseURL:='lazdoc://';
HTMLHint:=''; HTMLHint:='';
CacheWasUsed:=true; CacheWasUsed:=true;
if not CodeToolBoss.InitCurCodeTool(Code) then exit;
CursorPos.X:=X; CursorPos.X:=X;
CursorPos.Y:=Y; CursorPos.Y:=Y;
CursorPos.Code:=Code; CursorPos.Code:=Code;
@ -2407,6 +2410,7 @@ begin
Complete:=not (chhoSmallStep in Options); Complete:=not (chhoSmallStep in Options);
ElementNames:=TStringList.Create; ElementNames:=TStringList.Create;
try try
if not CodeToolBoss.InitCurCodeTool(Code) then exit;
try try
// find declaration // find declaration
if not CodeToolBoss.CurCodeTool.FindDeclaration(CursorPos,DefaultFindSmartHintFlags, if not CodeToolBoss.CurCodeTool.FindDeclaration(CursorPos,DefaultFindSmartHintFlags,
@ -2414,17 +2418,21 @@ begin
then then
exit; exit;
// add declaration if chhoDeclarationHeader in Options then begin
CTHint:=CTTool.GetSmartHint(CTNode,XYPos,false); HTMLHint:=HTMLHint+'<div class="header">';
HTMLHint:=SourceToFPDocHint(CTHint); // add declaration
CTHint:=CTTool.GetSmartHint(CTNode,XYPos,false);
HTMLHint:=HTMLHint+' '+SourceToFPDocHint(CTHint);
// add link // add link
HTMLHint:=HTMLHint+'<br>'+LineEnding; HTMLHint:=HTMLHint+'<br>'+LineEnding;
if XYPos.Code=nil then if XYPos.Code=nil then
CTTool.CleanPosToCaret(CTNode.StartPos,XYPos); CTTool.CleanPosToCaret(CTNode.StartPos,XYPos);
HTMLHint:=HTMLHint+SourcePosToFPDocHint(XYPos); HTMLHint:=HTMLHint+' '+SourcePosToFPDocHint(XYPos)+LineEnding;
HTMLHint:=HTMLHint+'</div>'+LineEnding;
end;
repeat for n:=1 to 30 do begin
ElementName:=CodeNodeToElementName(CTTool,CTNode); ElementName:=CodeNodeToElementName(CTTool,CTNode);
i:=ElementNames.Count-1; i:=ElementNames.Count-1;
while (i>=0) and (ElementNames.Objects[i]<>CTTool) while (i>=0) and (ElementNames.Objects[i]<>CTTool)
@ -2432,12 +2440,10 @@ begin
dec(i); dec(i);
if i>=0 then begin if i>=0 then begin
// a loop or a forward definition // a loop or a forward definition
if ElementNames.Count>16 then break;
end else begin end else begin
ElementNames.AddObject(ElementName,CTTool); ElementNames.AddObject(ElementName,CTTool);
// add fpdoc entry // add fpdoc entry
// ToDo: check if ElementName already added (can happen on forward definitions)
FPDocFilename:=GetFPDocFilenameForSource(CTTool.MainFilename, FPDocFilename:=GetFPDocFilenameForSource(CTTool.MainFilename,
false,CacheWasUsed,AnOwner); false,CacheWasUsed,AnOwner);
DebugLn(['TCodeHelpManager.GetHTMLHint2 FPDocFilename=',FPDocFilename,' ElementName="',ElementName,'"']); DebugLn(['TCodeHelpManager.GetHTMLHint2 FPDocFilename=',FPDocFilename,' ElementName="',ElementName,'"']);
@ -2456,8 +2462,11 @@ begin
end; end;
end; end;
// add pasdoc if not (chhoNoComments in Options) then
HTMLHint:=HTMLHint+GetPasDocCommentsAsHTML(CTTool,CTNode); begin
// add pasdoc
HTMLHint:=HTMLHint+GetPasDocCommentsAsHTML(CTTool,CTNode);
end;
end; end;
// find inherited node // find inherited node
@ -2468,8 +2477,10 @@ begin
debugln(['TCodeHelpManager.GetHTMLHint2 searching for inherited of ',CTNode.DescAsString,' ',dbgs(XYPos)]); debugln(['TCodeHelpManager.GetHTMLHint2 searching for inherited of ',CTNode.DescAsString,' ',dbgs(XYPos)]);
OldXYPos:=XYPos; OldXYPos:=XYPos;
OldCTTool:=CTTool; OldCTTool:=CTTool;
if not OldCTTool.FindDeclaration(OldXYPos,DefaultFindSmartHintFlags, OldCTNode:=CTNode;
CTTool,CTNode,XYPos,aTopLine) if (not OldCTTool.FindDeclaration(OldXYPos,[fsfSearchSourceName],
CTTool,CTNode,XYPos,aTopLine))
or (CTNode=OldCTNode)
then begin then begin
debugln(['TCodeHelpManager.GetHTMLHint2 inherited not found: ',dbgs(OldXYPos)]); debugln(['TCodeHelpManager.GetHTMLHint2 inherited not found: ',dbgs(OldXYPos)]);
break; break;
@ -2479,16 +2490,17 @@ begin
break; break;
end; end;
until false; end;
except except
on E: Exception do begin on E: Exception do begin
debugln(['TCodeHelpManager.GetHTMLHint2 ',E.Message]); debugln(['TCodeHelpManager.GetHTMLHint2 Exception: ',E.Message]);
end; end;
end; end;
finally finally
ElementNames.Free; ElementNames.Free;
FreeListOfPCodeXYPosition(ListOfPCodeXYPosition); FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
HTMLHint:='<HTML><HEADER></HEADER><BODY>'+LineEnding+HTMLHint+LineEnding+'</BODY>'+LineEnding;
end; end;
debugln(['TCodeHelpManager.GetHTMLHint2 ',HTMLHint]); debugln(['TCodeHelpManager.GetHTMLHint2 ',HTMLHint]);
Result:=chprSuccess; Result:=chprSuccess;
@ -2523,7 +2535,9 @@ begin
CommentStr:=ExtractCommentContent(CommentCode.Source,CommentStart, CommentStr:=ExtractCommentContent(CommentCode.Source,CommentStart,
NestedComments,true,true,true); NestedComments,true,true,true);
if CommentStr <> '' then if CommentStr <> '' then
Result:=Result+'<span class="comment">'+TextToHTML(CommentStr)+'</span><br>'+LineEnding; Result:=Result+'<span class="comment">'+TextToHTML(CommentStr)
+'('+SourcePosToFPDocHint(CodeXYPos^,'Source')+')'
+'</span><br>'+LineEnding;
end; end;
finally finally
@ -2553,14 +2567,18 @@ function TCodeHelpManager.GetFPDocNodeAsHTML(DOMNode: TDOMNode): string;
begin begin
Result:=''; Result:='';
if Node=nil then exit; if Node=nil then exit;
debugln(['NodeToHTML ',DbgSName(Node)]); //debugln(['TCodeHelpManager.GetFPDocNodeAsHTML.NodeToHTML ',DbgSName(Node)]);
if (Node.NodeName='short') if (Node.NodeName='short')
or (Node.NodeName='descr') then begin or (Node.NodeName='descr') then begin
s:=AddChilds(Node); s:=AddChilds(Node);
if s<>'' then if s<>'' then
Result:=Result+'<div class="'+Node.NodeName+'">'+s+'</div>'; Result:=Result+'<div class="'+Node.NodeName+'">'+s+'</div>'+LineEnding;
end else if (Node.NodeName='p') then begin
Result:=Result+'<'+Node.NodeName+'>'+AddChilds(Node)+'</'+Node.NodeName+'>';
end else if (Node.NodeName='#text') then begin
Result:=Result+Node.NodeValue;
end else begin end else begin
debugln(['Traverse ',Node.NodeName]); debugln(['TCodeHelpManager.GetFPDocNodeAsHTML.NodeToHTML skipping ',Node.NodeName]);
end; end;
end; end;

View File

@ -21,7 +21,7 @@
Author: Mattias Gaertner Author: Mattias Gaertner
Abstract: Abstract:
Hint using the fpdoc data. A hint using the fpdoc data.
} }
unit FPDocHints; unit FPDocHints;
@ -141,7 +141,7 @@ begin
end; end;
//DebugLn(['TFPDocHintProvider.ReadLazDocData ',Item.Identifier,' ',Item.Tool.MainFilename,' ',Caret.Code.Filename,' ',Caret.X,',',Caret.Y]); //DebugLn(['TFPDocHintProvider.ReadLazDocData ',Item.Identifier,' ',Item.Tool.MainFilename,' ',Caret.Code.Filename,' ',Caret.X,',',Caret.Y]);
HelpResult:=CodeHelpBoss.GetHTMLHint(Caret.Code,Caret.X,Caret.Y, HelpResult:=CodeHelpBoss.GetHTMLHint(Caret.Code,Caret.X,Caret.Y,
[chhoSmartHint, chhoComments], [chhoDeclarationHeader],
FBaseURL,FHTMLHint,CacheWasUsed); FBaseURL,FHTMLHint,CacheWasUsed);
if HelpResult<>chprSuccess then begin if HelpResult<>chprSuccess then begin
DebugLn(['TFPDocHintProvider.ReadLazDocData FAILED Identifier=',Item.Identifier]); DebugLn(['TFPDocHintProvider.ReadLazDocData FAILED Identifier=',Item.Identifier]);

View File

@ -97,10 +97,11 @@ type
TSimpleHTMLControl = class(TLabel,TIDEHTMLControlIntf) TSimpleHTMLControl = class(TLabel,TIDEHTMLControlIntf)
private private
FMaxLineCount: integer;
FProvider: TAbstractIDEHTMLProvider; FProvider: TAbstractIDEHTMLProvider;
FURL: string; FURL: string;
procedure SetProvider(const AValue: TAbstractIDEHTMLProvider); procedure SetProvider(const AValue: TAbstractIDEHTMLProvider);
function HTMLToCaption(const s: string): string; function HTMLToCaption(const s: string; MaxLines: integer): string;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
function GetURL: string; function GetURL: string;
@ -108,6 +109,7 @@ type
property Provider: TAbstractIDEHTMLProvider read FProvider write SetProvider; property Provider: TAbstractIDEHTMLProvider read FProvider write SetProvider;
procedure SetHTMLContent(Stream: TStream); procedure SetHTMLContent(Stream: TStream);
procedure GetPreferredControlSize(out AWidth, AHeight: integer); procedure GetPreferredControlSize(out AWidth, AHeight: integer);
property MaxLineCount: integer read FMaxLineCount write FMaxLineCount;
end; end;
{ TIDEHelpDatabases } { TIDEHelpDatabases }
@ -258,18 +260,23 @@ begin
FProvider:=AValue; FProvider:=AValue;
end; end;
function TSimpleHTMLControl.HTMLToCaption(const s: string): string; function TSimpleHTMLControl.HTMLToCaption(const s: string; MaxLines: integer
): string;
var var
p: Integer; p: Integer;
EndPos: Integer; EndPos: Integer;
CurTag: String; CurTag: String;
NewTag: String; NewTag: String;
Line: Integer;
sp: LongInt;
begin begin
Result:=s; Result:=s;
//debugln(['TSimpleHTMLControl.HTMLToCaption HTML="',Result,'"']);
Line:=1;
p:=1; p:=1;
while p<=length(Result) do begin while p<=length(Result) do begin
if Result[p]='<' then begin if Result[p]='<' then begin
// skip html tag // removes html tags
EndPos:=p+1; EndPos:=p+1;
while (EndPos<=length(Result)) do begin while (EndPos<=length(Result)) do begin
if Result[EndPos]='"' then begin if Result[EndPos]='"' then begin
@ -285,8 +292,30 @@ begin
inc(EndPos); inc(EndPos);
end; end;
CurTag:=copy(Result,p,EndPos-p); CurTag:=copy(Result,p,EndPos-p);
if SysUtils.CompareText(CurTag,'<BR>')=0 then
NewTag:=LineEnding if ((SysUtils.CompareText(CurTag,'<P>')=0)
or (SysUtils.CompareText(CurTag,'</P>')=0))
then begin
// add a line break if there is not already one
sp:=p;
while (sp>1) and (Result[sp-1] in [' ',#9]) do dec(sp);
if (sp>1) and (not (Result[sp-1] in [#10,#13])) then
CurTag:='<BR>';
end;
if (p>1)
and ((SysUtils.CompareText(CurTag,'<BR>')=0)
or (SysUtils.CompareText(CurTag,'<DIV>')=0)
or (SysUtils.CompareText(copy(CurTag,1,5),'<DIV ')=0)
or (SysUtils.CompareText(CurTag,'</DIV>')=0))
then begin
NewTag:=LineEnding;
inc(Line);
if Line>MaxLines then begin
Result:=copy(Result,1,p)+LineEnding+'...';
break;
end;
end
else else
NewTag:=''; NewTag:='';
if NewTag='' then if NewTag='' then
@ -310,12 +339,18 @@ begin
end else end else
inc(p); inc(p);
end; end;
//DebugLn(['TSimpleHTMLControl.HTMLToCaption "',dbgstr(Result),'"']); // trim space at end
p:=length(Result);
while (p>0) and (Result[p] in [' ',#9,#10,#13]) do dec(p);
SetLength(Result,p);
//DebugLn(['TSimpleHTMLControl.HTMLToCaption Caption="',dbgstr(Result),'"']);
end; end;
constructor TSimpleHTMLControl.Create(AOwner: TComponent); constructor TSimpleHTMLControl.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
MaxLineCount:=30;
WordWrap := True; WordWrap := True;
Layout := tlCenter; Layout := tlCenter;
Alignment := taLeftJustify; Alignment := taLeftJustify;
@ -344,7 +379,7 @@ begin
SetLength(s,Stream.Size); SetLength(s,Stream.Size);
if s<>'' then if s<>'' then
Stream.Read(s[1],length(s)); Stream.Read(s[1],length(s));
Caption:=HTMLToCaption(s); Caption:=HTMLToCaption(s,MaxLineCount);
Provider.ReleaseStream(FURL); Provider.ReleaseStream(FURL);
except except
on E: Exception do begin on E: Exception do begin
@ -360,7 +395,7 @@ begin
SetLength(s,Stream.Size); SetLength(s,Stream.Size);
if s<>'' then if s<>'' then
Stream.Read(s[1],length(s)); Stream.Read(s[1],length(s));
Caption:=HTMLToCaption(s); Caption:=HTMLToCaption(s,MaxLineCount);
end; end;
procedure TSimpleHTMLControl.GetPreferredControlSize(out AWidth, AHeight: integer); procedure TSimpleHTMLControl.GetPreferredControlSize(out AWidth, AHeight: integer);
@ -1294,7 +1329,7 @@ begin
if (Code=nil) or Code.LineColIsSpace(CodePos.Y,CodePos.X) then if (Code=nil) or Code.LineColIsSpace(CodePos.Y,CodePos.X) then
exit(shrHelpNotFound); exit(shrHelpNotFound);
if CodeHelpBoss.GetHTMLHint(Code,CodePos.X,CodePos.Y, if CodeHelpBoss.GetHTMLHint(Code,CodePos.X,CodePos.Y,
[chhoSmartHint, chhoComments], [chhoDeclarationHeader],
BaseURL,HTMLHint,CacheWasUsed)=chprSuccess BaseURL,HTMLHint,CacheWasUsed)=chprSuccess
then then
exit(shrSuccess); exit(shrSuccess);