IDE: started focus hint

git-svn-id: trunk@31235 -
This commit is contained in:
mattias 2011-06-14 22:15:46 +00:00
parent f20eedc54a
commit 8bf43e981a
9 changed files with 57 additions and 21 deletions

View File

@ -22,6 +22,12 @@ div.title {
color: #005A9C; color: #005A9C;
} }
div.focushint {
text-align: right;
font-size: 10px;
color: #005A9C;
}
tt, span.keyword, pre { tt, span.keyword, pre {
font-family: Courier, monospace font-family: Courier, monospace
} }

View File

@ -40,6 +40,7 @@ interface
uses uses
Classes, SysUtils, LCLProc, Forms, Controls, FileUtil, Dialogs, AvgLvlTree, Classes, SysUtils, LCLProc, Forms, Controls, FileUtil, Dialogs, AvgLvlTree,
LCLType,
// codetools // codetools
CodeAtom, CodeTree, CodeToolManager, FindDeclarationTool, BasicCodeTools, CodeAtom, CodeTree, CodeToolManager, FindDeclarationTool, BasicCodeTools,
KeywordFuncLists, PascalParserTool, CodeCache, CacheCodeTools, FileProcs, KeywordFuncLists, PascalParserTool, CodeCache, CacheCodeTools, FileProcs,
@ -51,11 +52,11 @@ uses
// synedit // synedit
SynHighlighterPas, SynHighlighterPas,
// IDEIntf // IDEIntf
IDEMsgIntf, MacroIntf, PackageIntf, LazHelpIntf, ProjectIntf, IDEDialogs, IDECommands, IDEMsgIntf, MacroIntf, PackageIntf, LazHelpIntf, ProjectIntf,
IDEHelpIntf, LazIDEIntf, IDEDialogs, IDEHelpIntf, LazIDEIntf,
// IDE // IDE
LazarusIDEStrConsts, CompilerOptions, IDEProcs, PackageDefs, EnvironmentOpts, EditorOptions, LazarusIDEStrConsts, CompilerOptions, IDEProcs, PackageDefs,
TransferMacros, PackageSystem, DialogProcs; EnvironmentOpts, TransferMacros, PackageSystem, DialogProcs, KeyMapping;
const const
IDEProjectName = 'Lazarus'; IDEProjectName = 'Lazarus';
@ -215,7 +216,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.
chhoDeclarationHeader, // add a header with source position and type of identifier chhoDeclarationHeader, // add a header with source position and type of identifier
chhoNoComments // do not add the pasdoc comments chhoNoComments, // do not add the pasdoc comments
chhoShowFocusHint // show the shortcut ecFocusHint
); );
TCodeHelpHintOptions = set of TCodeHelpHintOption; TCodeHelpHintOptions = set of TCodeHelpHintOption;
@ -2240,6 +2242,7 @@ var
n: Integer; n: Integer;
LastOwner: TObject; LastOwner: TObject;
s: String; s: String;
Cmd: TKeyCommandRelation;
procedure AddLinkToOwner(CurOwner: TObject); procedure AddLinkToOwner(CurOwner: TObject);
var var
@ -2302,7 +2305,7 @@ begin
// add fpdoc entry // add fpdoc entry
FPDocFilename:=GetFPDocFilenameForSource(CTTool.MainFilename, FPDocFilename:=GetFPDocFilenameForSource(CTTool.MainFilename,
false,CacheWasUsed,AnOwner); false,CacheWasUsed,AnOwner);
//DebugLn(['TCodeHelpManager.GetHTMLHint2 FPDocFilename=',FPDocFilename,' ElementName="',ElementName,'"']); //DebugLn(['TCodeHelpManager.GetHTMLHint FPDocFilename=',FPDocFilename,' ElementName="',ElementName,'"']);
if (not CacheWasUsed) and (not Complete) then exit(chprParsing); if (not CacheWasUsed) and (not Complete) then exit(chprParsing);
if n=1 then if n=1 then
@ -2315,7 +2318,7 @@ begin
ElementNode:=FPDocFile.GetElementWithName(ElementName); ElementNode:=FPDocFile.GetElementWithName(ElementName);
if ElementNode<>nil then begin if ElementNode<>nil then begin
//debugln(['TCodeHelpManager.GetHTMLHint2 fpdoc element found "',ElementName,'"']); //debugln(['TCodeHelpManager.GetHTMLHint fpdoc element found "',ElementName,'"']);
AddLinkToOwner(AnOwner); AddLinkToOwner(AnOwner);
s:=AppendLineEnding(GetFPDocNodeAsHTML(FPDocFile,ElementNode.FindNode(FPDocItemNames[fpdiShort]))); s:=AppendLineEnding(GetFPDocNodeAsHTML(FPDocFile,ElementNode.FindNode(FPDocItemNames[fpdiShort])));
@ -2343,7 +2346,7 @@ begin
or ((CTNode.Desc in [ctnProcedure,ctnProcedureHead]) or ((CTNode.Desc in [ctnProcedure,ctnProcedureHead])
and (CTTool.ProcNodeHasSpecifier(CTNode,psOVERRIDE))) and (CTTool.ProcNodeHasSpecifier(CTNode,psOVERRIDE)))
then begin then begin
debugln(['TCodeHelpManager.GetHTMLHint2 searching for inherited of ',CTNode.DescAsString,' ',dbgs(XYPos)]); debugln(['TCodeHelpManager.GetHTMLHint searching for inherited of ',CTNode.DescAsString,' ',dbgs(XYPos)]);
OldXYPos:=XYPos; OldXYPos:=XYPos;
OldCTTool:=CTTool; OldCTTool:=CTTool;
OldCTNode:=CTNode; OldCTNode:=CTNode;
@ -2351,18 +2354,19 @@ begin
CTTool,CTNode,XYPos,aTopLine)) CTTool,CTNode,XYPos,aTopLine))
or (CTNode=OldCTNode) or (CTNode=OldCTNode)
then begin then begin
debugln(['TCodeHelpManager.GetHTMLHint2 inherited not found: ',dbgs(OldXYPos)]); debugln(['TCodeHelpManager.GetHTMLHint inherited not found: ',dbgs(OldXYPos)]);
break; break;
end; end;
end else begin end else begin
debugln(['TCodeHelpManager.GetHTMLHint2 not searching inherited for ',CTNode.DescAsString]); debugln(['TCodeHelpManager.GetHTMLHint not searching inherited for ',CTNode.DescAsString]);
break; break;
end; end;
end; end;
except except
on E: Exception do begin on E: Exception do begin
debugln(['TCodeHelpManager.GetHTMLHint2 Exception: ',E.Message]); debugln(['TCodeHelpManager.GetHTMLHint Exception: ',E.Message]);
//DumpExceptionBackTrace; //DumpExceptionBackTrace;
end; end;
end; end;
@ -2370,10 +2374,17 @@ begin
finally finally
ElementNames.Free; ElementNames.Free;
FreeListOfPCodeXYPosition(ListOfPCodeXYPosition); FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
if chhoShowFocusHint in Options then begin
Cmd:=EditorOpts.KeyMap.FindByCommand(ecFocusHint);
if (Cmd<>nil) and (not IDEShortCutEmpty(Cmd.ShortcutA)) then begin
HTMLHint:=HTMLHint+'<div class="focushint">Press '
+KeyAndShiftStateToEditorKeyString(Cmd.ShortcutA)+' for focus</div>'+LineEnding;
end;
end;
HTMLHint:='<html><head><link rel="stylesheet" href="lazdoc://lazarus/lazdoc.css" type="text/css"></head>'+LineEnding HTMLHint:='<html><head><link rel="stylesheet" href="lazdoc://lazarus/lazdoc.css" type="text/css"></head>'+LineEnding
+'<body>'+LineEnding+HTMLHint+'</body>'+LineEnding; +'<body>'+LineEnding+HTMLHint+'</body>'+LineEnding;
end; end;
debugln(['TCodeHelpManager.GetHTMLHint2 ',HTMLHint]); debugln(['TCodeHelpManager.GetHTMLHint ',HTMLHint]);
Result:=chprSuccess; Result:=chprSuccess;
end; end;

View File

@ -191,7 +191,8 @@ type
out HintWinRect: TRect): boolean; override; out HintWinRect: TRect): boolean; override;
function GetHintForSourcePosition(const ExpandedFilename: string; function GetHintForSourcePosition(const ExpandedFilename: string;
const CodePos: TPoint; const CodePos: TPoint;
out BaseURL, HTMLHint: string): TShowHelpResult; override; out BaseURL, HTMLHint: string;
Flags: TIDEHelpManagerCreateHintFlags = []): TShowHelpResult; override;
function ConvertSourcePosToPascalHelpContext(const CaretPos: TPoint; function ConvertSourcePosToPascalHelpContext(const CaretPos: TPoint;
const Filename: string): TPascalHelpContextList; override; const Filename: string): TPascalHelpContextList; override;
@ -1492,20 +1493,24 @@ begin
Result:=true; Result:=true;
end; end;
function TIDEHelpManager.GetHintForSourcePosition(const ExpandedFilename: string; function TIDEHelpManager.GetHintForSourcePosition(
const CodePos: TPoint; out BaseURL, HTMLHint: string): TShowHelpResult; const ExpandedFilename: string; const CodePos: TPoint; out BaseURL,
HTMLHint: string; Flags: TIDEHelpManagerCreateHintFlags): TShowHelpResult;
var var
Code: TCodeBuffer; Code: TCodeBuffer;
CacheWasUsed: boolean; CacheWasUsed: boolean;
HintFlags: TCodeHelpHintOptions;
begin begin
BaseURL:=''; BaseURL:='';
HTMLHint:=''; HTMLHint:='';
Code:=CodeToolBoss.LoadFile(ExpandedFilename,true,false); Code:=CodeToolBoss.LoadFile(ExpandedFilename,true,false);
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);
HintFlags:=[chhoDeclarationHeader];
if ihmchAddFocusHint in Flags then
Include(HintFlags,chhoShowFocusHint);
if CodeHelpBoss.GetHTMLHint(Code,CodePos.X,CodePos.Y, if CodeHelpBoss.GetHTMLHint(Code,CodePos.X,CodePos.Y,
[chhoDeclarationHeader], HintFlags,BaseURL,HTMLHint,CacheWasUsed)=chprSuccess
BaseURL,HTMLHint,CacheWasUsed)=chprSuccess
then then
exit(shrSuccess); exit(shrSuccess);
Result:=shrHelpNotFound; Result:=shrHelpNotFound;

View File

@ -607,6 +607,7 @@ begin
ecContextHelp: SetResult(VK_F1,[],VK_UNKNOWN,[]); ecContextHelp: SetResult(VK_F1,[],VK_UNKNOWN,[]);
ecEditContextHelp: SetResult(VK_F1,[ssShift,ssCtrl],VK_UNKNOWN,[]); ecEditContextHelp: SetResult(VK_F1,[ssShift,ssCtrl],VK_UNKNOWN,[]);
ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]); ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecFocusHint: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// designer // designer
ecDesignerCopy : SetResult(VK_C,[ssCtrl],VK_Insert,[ssCtrl]); ecDesignerCopy : SetResult(VK_C,[ssCtrl],VK_Insert,[ssCtrl]);
@ -1049,6 +1050,7 @@ begin
ecContextHelp: SetResult(VK_F1,[ssCtrl],VK_UNKNOWN,[]); ecContextHelp: SetResult(VK_F1,[ssCtrl],VK_UNKNOWN,[]);
ecEditContextHelp: SetResult(VK_F1,[ssCtrl,ssShift],VK_UNKNOWN,[]); ecEditContextHelp: SetResult(VK_F1,[ssCtrl,ssShift],VK_UNKNOWN,[]);
ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]); ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecFocusHint: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// designer // designer
ecDesignerCopy : SetResult(VK_C,[ssCtrl],VK_UNKNOWN,[],VK_Insert,[ssCtrl],VK_UNKNOWN,[]); ecDesignerCopy : SetResult(VK_C,[ssCtrl],VK_UNKNOWN,[],VK_Insert,[ssCtrl],VK_UNKNOWN,[]);
@ -1680,6 +1682,7 @@ begin
ecContextHelp: SetResult(VK_HELP,[],VK_UNKNOWN,[]); ecContextHelp: SetResult(VK_HELP,[],VK_UNKNOWN,[]);
ecEditContextHelp: SetResult(VK_HELP,[ssShift,ssCtrl],VK_HELP,[ssCtrl]); ecEditContextHelp: SetResult(VK_HELP,[ssShift,ssCtrl],VK_HELP,[ssCtrl]);
ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]); ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecFocusHint: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// designer // designer
ecDesignerCopy : SetResult(VK_C,[ssMeta],VK_UNKNOWN,[]); ecDesignerCopy : SetResult(VK_C,[ssMeta],VK_UNKNOWN,[]);
@ -2227,6 +2230,7 @@ begin
ecContextHelp : Result:= lisMenuContextHelp; ecContextHelp : Result:= lisMenuContextHelp;
ecEditContextHelp : Result:= lisMenuEditContextHelp; ecEditContextHelp : Result:= lisMenuEditContextHelp;
ecReportingBug : Result:= srkmecReportingBug; ecReportingBug : Result:= srkmecReportingBug;
ecFocusHint : Result:= lisFocusHint;
// desginer // desginer
ecDesignerCopy : Result:= lisDsgCopyComponents; ecDesignerCopy : Result:= lisDsgCopyComponents;
@ -2887,6 +2891,7 @@ begin
AddDefault(C, 'Context sensitive help', lisKMContextSensitiveHelp, ecContextHelp); AddDefault(C, 'Context sensitive help', lisKMContextSensitiveHelp, ecContextHelp);
AddDefault(C, 'Edit context sensitive help', lisKMEditContextSensitiveHelp, ecEditContextHelp); AddDefault(C, 'Edit context sensitive help', lisKMEditContextSensitiveHelp, ecEditContextHelp);
AddDefault(C, 'Reporting a bug', srkmecReportingBug, ecReportingBug); AddDefault(C, 'Reporting a bug', srkmecReportingBug, ecReportingBug);
AddDefault(C, 'Focus hint', lisFocusHint, ecFocusHint);
// designer - without menu items in the IDE bar (at least not directly) // designer - without menu items in the IDE bar (at least not directly)
C:=Categories[AddCategory('Designer',lisKeyCatDesigner,IDECmdScopeDesignerOnly)]; C:=Categories[AddCategory('Designer',lisKeyCatDesigner,IDECmdScopeDesignerOnly)];

View File

@ -2706,6 +2706,7 @@ resourcestring
// help menu // help menu
srkmecunknown = 'unknown editor command'; srkmecunknown = 'unknown editor command';
srkmecReportingBug = 'Reporting a bug'; srkmecReportingBug = 'Reporting a bug';
lisFocusHint = 'Focus hint';
// Category // Category
srkmCatCursorMoving = 'Cursor moving commands'; srkmCatCursorMoving = 'Cursor moving commands';

View File

@ -16139,7 +16139,8 @@ begin
if EditorOpts.AutoToolTipSymbTools then begin if EditorOpts.AutoToolTipSymbTools then begin
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource A');{$ENDIF} {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource A');{$ENDIF}
TIDEHelpManager(HelpBoss).GetHintForSourcePosition(ActiveUnitInfo.Filename, TIDEHelpManager(HelpBoss).GetHintForSourcePosition(ActiveUnitInfo.Filename,
CaretPos,BaseURL,SmartHintStr); CaretPos,BaseURL,SmartHintStr,
[{$IFDEF EnableFocusHint}ihmchAddFocusHint{$ENDIF}]);
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF} {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF}
end; end;
case ToolStatus of case ToolStatus of

View File

@ -310,6 +310,7 @@ const
ecContextHelp = ecFirstLazarus + 903; ecContextHelp = ecFirstLazarus + 903;
ecEditContextHelp = ecFirstLazarus + 904; ecEditContextHelp = ecFirstLazarus + 904;
ecReportingBug = ecFirstLazarus + 905; ecReportingBug = ecFirstLazarus + 905;
ecFocusHint = ecFirstLazarus + 906;
// designer // designer
ecDesignerCopy = ecFirstLazarus + 1000; ecDesignerCopy = ecFirstLazarus + 1000;

View File

@ -49,6 +49,11 @@ type
property ModifierStr: string read FModifierStr write FModifierStr; property ModifierStr: string read FModifierStr write FModifierStr;
end; end;
TIDEHelpManagerCreateHintFlag = (
ihmchAddFocusHint
);
TIDEHelpManagerCreateHintFlags = set of TIDEHelpManagerCreateHintFlag;
{ TBaseHelpManager } { TBaseHelpManager }
TBaseHelpManager = class(TComponent) TBaseHelpManager = class(TComponent)
@ -65,7 +70,8 @@ type
procedure ShowHelpForIDEControl(Sender: TControl); virtual; abstract; procedure ShowHelpForIDEControl(Sender: TControl); virtual; abstract;
function GetHintForSourcePosition(const ExpandedFilename: string; function GetHintForSourcePosition(const ExpandedFilename: string;
const CodePos: TPoint; const CodePos: TPoint;
out BaseURL, HTMLHint: string): TShowHelpResult; virtual; abstract; out BaseURL, HTMLHint: string;
Flags: TIDEHelpManagerCreateHintFlags = []): TShowHelpResult; virtual; abstract;
function CreateHint(aHintWindow: THintWindow; ScreenPos: TPoint; function CreateHint(aHintWindow: THintWindow; ScreenPos: TPoint;
const BaseURL: string; var TheHint: string; const BaseURL: string; var TheHint: string;
out HintWinRect: TRect): boolean; virtual; abstract; out HintWinRect: TRect): boolean; virtual; abstract;