IDE: code browser: added TCodeBrowserView.GetCodeHelp

git-svn-id: trunk@26857 -
This commit is contained in:
mattias 2010-07-27 16:06:13 +00:00
parent d66103ac53
commit c6dba477e5
3 changed files with 85 additions and 4 deletions

View File

@ -45,14 +45,14 @@ interface
uses
Classes, SysUtils, types, LCLProc, LResources, Forms, Controls, Graphics,
Dialogs, Clipbrd, LCLIntf, AVL_Tree, StdCtrls, ExtCtrls, ComCtrls, Buttons,
Menus,
Menus, HelpIntfs,
// codetools
CodeAtom, BasicCodeTools, DefineTemplates, CodeTree, CodeCache,
CodeToolsStructs, CodeToolManager, PascalParserTool, LinkScanner, FileProcs,
CodeIndex, StdCodeTools, SourceLog,
CodeIndex, StdCodeTools, SourceLog, CustomCodeTool,
// IDEIntf
IDEWindowIntf, SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage,
PackageIntf, TextTools, IDECommands, LazIDEIntf,
IDEHelpIntf, PackageIntf, TextTools, IDECommands, LazIDEIntf,
// IDE
Project, DialogProcs, PackageSystem, PackageDefs, LazarusIDEStrConsts,
IDEOptionDefs, MsgQuickFixes, BasePkgManager, AddToProjectDlg,
@ -322,6 +322,7 @@ type
procedure InitImageList;
function GetNodeImage(CodeNode: TObject): integer;
function GetTVNodeHint(TVNode: TTreeNode): string;
function GetCodeHelp(TVNode: TTreeNode; out BaseURL, HTMLHint: string): boolean;
procedure ExpandCollapseAllNodesInTreeView(NodeType: TExpandableNodeType;
Expand: boolean);
procedure CopyNode(TVNode: TTreeNode; NodeType: TCopyNodeType);
@ -2455,6 +2456,83 @@ begin
end;
end;
function TCodeBrowserView.GetCodeHelp(TVNode: TTreeNode; out BaseURL,
HTMLHint: string): boolean;
var
NodeData: TObject;
Node: TCodeBrowserNode;
Tool: TCodeTool;
CleanPos: integer;
CTNode: TCodeTreeNode;
NewCodePos: TCodeXYPosition;
begin
Result:=false;
BaseURL:='';
HTMLHint:='';
if (TVNode=nil) or (TVNode.Data=nil) then exit;
NodeData:=TObject(TVNode.Data);
if NodeData is TCodeBrowserNode then begin
Node:=TCodeBrowserNode(NodeData);
if Node.CodePos.Code=nil then exit;
if not LazarusIDE.BeginCodeTools then // commit source editor changes to codetools
exit;
// parse unit
CodeToolBoss.Explore(Node.CodePos.Code,Tool,false,false);
if Tool=nil then exit;
// find source position in parsed code
CleanPos:=Node.CodePos.P;
// find node
CTNode:=Tool.FindDeepestNodeAtPos(CleanPos,false);
if (CTNode=nil) or (CTNode.Desc<>Node.Desc) then
exit; // source has changed
// find cleanpos of identifier
case CTNode.Desc of
ctnProcedure:
begin
if SysUtils.CompareText(Tool.ExtractProcName(CTNode,[]),Node.Identifier)<>0
then
exit; // source has changed
Tool.MoveCursorToProcName(CTNode,true);
CleanPos:=Tool.CurPos.StartPos;
end;
ctnProperty:
begin
if SysUtils.CompareText(Tool.ExtractPropName(CTNode,false),Node.Identifier)<>0
then
exit; // source has changed
Tool.MoveCursorToPropName(CTNode);
CleanPos:=Tool.CurPos.StartPos;
end;
ctnGenericType:
begin
Tool.ExtractDefinitionName(CTNode);
if CTNode.FirstChild<>nil then
CleanPos:=CTNode.FirstChild.StartPos;
if SysUtils.CompareText(Tool.ExtractIdentifier(CleanPos),Node.Identifier)<>0
then
exit; // source has changed
end;
ctnVarDefinition,ctnTypeDefinition,ctnConstDefinition,
ctnEnumIdentifier:
if SysUtils.CompareText(Tool.ExtractIdentifier(CleanPos),Node.Identifier)<>0
then
exit; // source has changed
else
exit;
end;
// get source position
if not Tool.CleanPosToCaret(CleanPos,NewCodePos) then exit;
// ask the help system about the identifier
if LazarusHelp.GetHintForSourcePosition(NewCodePos.Code.Filename,
Point(NewCodePos.X,NewCodePos.Y),BaseURL,HTMLHint)<>shrSuccess then exit;
Result:=true;
end;
end;
procedure TCodeBrowserView.ExpandCollapseAllNodesInTreeView(
NodeType: TExpandableNodeType; Expand: boolean);
var

View File

@ -168,7 +168,7 @@ type
out HintWinRect: TRect): boolean; override;
function GetHintForSourcePosition(const ExpandedFilename: string;
const CodePos: TPoint;
out BaseURL, HTMLHint: string): TShowHelpResult;
out BaseURL, HTMLHint: string): TShowHelpResult; override;
function ConvertSourcePosToPascalHelpContext(const CaretPos: TPoint;
const Filename: string): TPascalHelpContextList; override;

View File

@ -62,6 +62,9 @@ type
var ErrMsg: string): TShowHelpResult; virtual; abstract;
procedure ShowHelpForMessage(Line: integer); virtual; abstract;
procedure ShowHelpForObjectInspector(Sender: TObject); virtual; abstract;
function GetHintForSourcePosition(const ExpandedFilename: string;
const CodePos: TPoint;
out BaseURL, HTMLHint: string): TShowHelpResult; virtual; abstract;
function CreateHint(aHintWindow: THintWindow; ScreenPos: TPoint;
const BaseURL: string; var TheHint: string;
out HintWinRect: TRect): boolean; virtual; abstract;