diff --git a/components/turbopower_ipro/languages/iphtmlpv.it.po b/components/turbopower_ipro/languages/iphtmlpv.it.po index f89145077c..585872aac7 100644 --- a/components/turbopower_ipro/languages/iphtmlpv.it.po +++ b/components/turbopower_ipro/languages/iphtmlpv.it.po @@ -38,3 +38,4 @@ msgstr "Scegli stampante..." #: iphtmlpv.rsiphtmlpreviewzoom msgid "Zoom:" msgstr "Ingrandimento:" + diff --git a/ide/codehelp.pas b/ide/codehelp.pas index 93eed861bb..d0e3cff79c 100644 --- a/ide/codehelp.pas +++ b/ide/codehelp.pas @@ -214,8 +214,8 @@ type TCodeHelpHintOption = ( chhoSmallStep, // do the next step. Use this to run on idle. - chhoSmartHint, // add smart hint - chhoComments // return info from comments in the code + chhoDeclarationHeader, // add a header with source position and type of identifier + chhoNoComments // do not add the pasdoc comments ); TCodeHelpHintOptions = set of TCodeHelpHintOption; @@ -2275,6 +2275,7 @@ var begin {$IFDEF EnableNewCodeHints} Result:=GetHTMLHint2(Code,X,Y,Options,BaseURL,HTMLHint,CacheWasUsed); + exit; {$ENDIF} {$ifdef VerboseHints} DebugLn(['TCodeHelpManager.GetHint ',Code.Filename,' ',X,',',Y]); @@ -2283,7 +2284,7 @@ begin IsHTML:=false; CodeToolBoss.ActivateWriteLock; try - if chhoSmartHint in Options then + if chhoDeclarationHeader in Options then HTMLHint := CodeToolBoss.FindSmartHint(Code,X,Y) else HTMLHint := ''; @@ -2322,7 +2323,7 @@ begin end; // Add comments - if chhoComments in Options then + if not (chhoNoComments in Options) then begin FreeListOfPCodeXYPosition(ListOfPCodeXYPosition); if CodeToolBoss.GetPasDocComments(Item.CodeXYPos.Code, @@ -2394,12 +2395,14 @@ var i: Integer; OldXYPos: TCodeXYPosition; OldCTTool: TFindDeclarationTool; + OldCTNode: TCodeTreeNode; + n: Integer; begin Result:=chprFailed; BaseURL:='lazdoc://'; HTMLHint:=''; CacheWasUsed:=true; - if not CodeToolBoss.InitCurCodeTool(Code) then exit; + CursorPos.X:=X; CursorPos.Y:=Y; CursorPos.Code:=Code; @@ -2407,6 +2410,7 @@ begin Complete:=not (chhoSmallStep in Options); ElementNames:=TStringList.Create; try + if not CodeToolBoss.InitCurCodeTool(Code) then exit; try // find declaration if not CodeToolBoss.CurCodeTool.FindDeclaration(CursorPos,DefaultFindSmartHintFlags, @@ -2414,17 +2418,21 @@ begin then exit; - // add declaration - CTHint:=CTTool.GetSmartHint(CTNode,XYPos,false); - HTMLHint:=SourceToFPDocHint(CTHint); + if chhoDeclarationHeader in Options then begin + HTMLHint:=HTMLHint+'
'; + // add declaration + CTHint:=CTTool.GetSmartHint(CTNode,XYPos,false); + HTMLHint:=HTMLHint+' '+SourceToFPDocHint(CTHint); - // add link - HTMLHint:=HTMLHint+'
'+LineEnding; - if XYPos.Code=nil then - CTTool.CleanPosToCaret(CTNode.StartPos,XYPos); - HTMLHint:=HTMLHint+SourcePosToFPDocHint(XYPos); + // add link + HTMLHint:=HTMLHint+'
'+LineEnding; + if XYPos.Code=nil then + CTTool.CleanPosToCaret(CTNode.StartPos,XYPos); + HTMLHint:=HTMLHint+' '+SourcePosToFPDocHint(XYPos)+LineEnding; + HTMLHint:=HTMLHint+'
'+LineEnding; + end; - repeat + for n:=1 to 30 do begin ElementName:=CodeNodeToElementName(CTTool,CTNode); i:=ElementNames.Count-1; while (i>=0) and (ElementNames.Objects[i]<>CTTool) @@ -2432,12 +2440,10 @@ begin dec(i); if i>=0 then begin // a loop or a forward definition - if ElementNames.Count>16 then break; end else begin ElementNames.AddObject(ElementName,CTTool); // add fpdoc entry - // ToDo: check if ElementName already added (can happen on forward definitions) FPDocFilename:=GetFPDocFilenameForSource(CTTool.MainFilename, false,CacheWasUsed,AnOwner); DebugLn(['TCodeHelpManager.GetHTMLHint2 FPDocFilename=',FPDocFilename,' ElementName="',ElementName,'"']); @@ -2456,8 +2462,11 @@ begin end; end; - // add pasdoc - HTMLHint:=HTMLHint+GetPasDocCommentsAsHTML(CTTool,CTNode); + if not (chhoNoComments in Options) then + begin + // add pasdoc + HTMLHint:=HTMLHint+GetPasDocCommentsAsHTML(CTTool,CTNode); + end; end; // find inherited node @@ -2468,8 +2477,10 @@ begin debugln(['TCodeHelpManager.GetHTMLHint2 searching for inherited of ',CTNode.DescAsString,' ',dbgs(XYPos)]); OldXYPos:=XYPos; OldCTTool:=CTTool; - if not OldCTTool.FindDeclaration(OldXYPos,DefaultFindSmartHintFlags, - CTTool,CTNode,XYPos,aTopLine) + OldCTNode:=CTNode; + if (not OldCTTool.FindDeclaration(OldXYPos,[fsfSearchSourceName], + CTTool,CTNode,XYPos,aTopLine)) + or (CTNode=OldCTNode) then begin debugln(['TCodeHelpManager.GetHTMLHint2 inherited not found: ',dbgs(OldXYPos)]); break; @@ -2479,16 +2490,17 @@ begin break; end; - until false; + end; except on E: Exception do begin - debugln(['TCodeHelpManager.GetHTMLHint2 ',E.Message]); + debugln(['TCodeHelpManager.GetHTMLHint2 Exception: ',E.Message]); end; end; finally ElementNames.Free; FreeListOfPCodeXYPosition(ListOfPCodeXYPosition); + HTMLHint:='
'+LineEnding+HTMLHint+LineEnding+''+LineEnding; end; debugln(['TCodeHelpManager.GetHTMLHint2 ',HTMLHint]); Result:=chprSuccess; @@ -2523,7 +2535,9 @@ begin CommentStr:=ExtractCommentContent(CommentCode.Source,CommentStart, NestedComments,true,true,true); if CommentStr <> '' then - Result:=Result+''+TextToHTML(CommentStr)+'
'+LineEnding; + Result:=Result+''+TextToHTML(CommentStr) + +'('+SourcePosToFPDocHint(CodeXYPos^,'Source')+')' + +'
'+LineEnding; end; finally @@ -2553,14 +2567,18 @@ function TCodeHelpManager.GetFPDocNodeAsHTML(DOMNode: TDOMNode): string; begin Result:=''; if Node=nil then exit; - debugln(['NodeToHTML ',DbgSName(Node)]); + //debugln(['TCodeHelpManager.GetFPDocNodeAsHTML.NodeToHTML ',DbgSName(Node)]); if (Node.NodeName='short') or (Node.NodeName='descr') then begin s:=AddChilds(Node); if s<>'' then - Result:=Result+'
'+s+'
'; + Result:=Result+'
'+s+'
'+LineEnding; + end else if (Node.NodeName='p') then begin + Result:=Result+'<'+Node.NodeName+'>'+AddChilds(Node)+''; + end else if (Node.NodeName='#text') then begin + Result:=Result+Node.NodeValue; end else begin - debugln(['Traverse ',Node.NodeName]); + debugln(['TCodeHelpManager.GetFPDocNodeAsHTML.NodeToHTML skipping ',Node.NodeName]); end; end; diff --git a/ide/fpdochints.pas b/ide/fpdochints.pas index 6ad28def5b..13fa761028 100644 --- a/ide/fpdochints.pas +++ b/ide/fpdochints.pas @@ -21,7 +21,7 @@ Author: Mattias Gaertner Abstract: - Hint using the fpdoc data. + A hint using the fpdoc data. } unit FPDocHints; @@ -141,7 +141,7 @@ begin end; //DebugLn(['TFPDocHintProvider.ReadLazDocData ',Item.Identifier,' ',Item.Tool.MainFilename,' ',Caret.Code.Filename,' ',Caret.X,',',Caret.Y]); HelpResult:=CodeHelpBoss.GetHTMLHint(Caret.Code,Caret.X,Caret.Y, - [chhoSmartHint, chhoComments], + [chhoDeclarationHeader], FBaseURL,FHTMLHint,CacheWasUsed); if HelpResult<>chprSuccess then begin DebugLn(['TFPDocHintProvider.ReadLazDocData FAILED Identifier=',Item.Identifier]); diff --git a/ide/helpmanager.pas b/ide/helpmanager.pas index e6135dfdd3..3cc278682d 100644 --- a/ide/helpmanager.pas +++ b/ide/helpmanager.pas @@ -97,10 +97,11 @@ type TSimpleHTMLControl = class(TLabel,TIDEHTMLControlIntf) private + FMaxLineCount: integer; FProvider: TAbstractIDEHTMLProvider; FURL: string; procedure SetProvider(const AValue: TAbstractIDEHTMLProvider); - function HTMLToCaption(const s: string): string; + function HTMLToCaption(const s: string; MaxLines: integer): string; public constructor Create(AOwner: TComponent); override; function GetURL: string; @@ -108,6 +109,7 @@ type property Provider: TAbstractIDEHTMLProvider read FProvider write SetProvider; procedure SetHTMLContent(Stream: TStream); procedure GetPreferredControlSize(out AWidth, AHeight: integer); + property MaxLineCount: integer read FMaxLineCount write FMaxLineCount; end; { TIDEHelpDatabases } @@ -258,18 +260,23 @@ begin FProvider:=AValue; end; -function TSimpleHTMLControl.HTMLToCaption(const s: string): string; +function TSimpleHTMLControl.HTMLToCaption(const s: string; MaxLines: integer + ): string; var p: Integer; EndPos: Integer; CurTag: String; NewTag: String; + Line: Integer; + sp: LongInt; begin Result:=s; + //debugln(['TSimpleHTMLControl.HTMLToCaption HTML="',Result,'"']); + Line:=1; p:=1; while p<=length(Result) do begin if Result[p]='<' then begin - // skip html tag + // removes html tags EndPos:=p+1; while (EndPos<=length(Result)) do begin if Result[EndPos]='"' then begin @@ -285,8 +292,30 @@ begin inc(EndPos); end; CurTag:=copy(Result,p,EndPos-p); - if SysUtils.CompareText(CurTag,'
')=0 then - NewTag:=LineEnding + + if ((SysUtils.CompareText(CurTag,'

')=0) + or (SysUtils.CompareText(CurTag,'

')=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:='
'; + end; + + if (p>1) + and ((SysUtils.CompareText(CurTag,'
')=0) + or (SysUtils.CompareText(CurTag,'
')=0) + or (SysUtils.CompareText(copy(CurTag,1,5),'
')=0)) + then begin + NewTag:=LineEnding; + inc(Line); + if Line>MaxLines then begin + Result:=copy(Result,1,p)+LineEnding+'...'; + break; + end; + end else NewTag:=''; if NewTag='' then @@ -310,12 +339,18 @@ begin end else inc(p); 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; constructor TSimpleHTMLControl.Create(AOwner: TComponent); begin inherited Create(AOwner); + MaxLineCount:=30; WordWrap := True; Layout := tlCenter; Alignment := taLeftJustify; @@ -344,7 +379,7 @@ begin SetLength(s,Stream.Size); if s<>'' then Stream.Read(s[1],length(s)); - Caption:=HTMLToCaption(s); + Caption:=HTMLToCaption(s,MaxLineCount); Provider.ReleaseStream(FURL); except on E: Exception do begin @@ -360,7 +395,7 @@ begin SetLength(s,Stream.Size); if s<>'' then Stream.Read(s[1],length(s)); - Caption:=HTMLToCaption(s); + Caption:=HTMLToCaption(s,MaxLineCount); end; procedure TSimpleHTMLControl.GetPreferredControlSize(out AWidth, AHeight: integer); @@ -1294,7 +1329,7 @@ begin if (Code=nil) or Code.LineColIsSpace(CodePos.Y,CodePos.X) then exit(shrHelpNotFound); if CodeHelpBoss.GetHTMLHint(Code,CodePos.X,CodePos.Y, - [chhoSmartHint, chhoComments], + [chhoDeclarationHeader], BaseURL,HTMLHint,CacheWasUsed)=chprSuccess then exit(shrSuccess);