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;
}
div.focushint {
text-align: right;
font-size: 10px;
color: #005A9C;
}
tt, span.keyword, pre {
font-family: Courier, monospace
}

View File

@ -40,6 +40,7 @@ interface
uses
Classes, SysUtils, LCLProc, Forms, Controls, FileUtil, Dialogs, AvgLvlTree,
LCLType,
// codetools
CodeAtom, CodeTree, CodeToolManager, FindDeclarationTool, BasicCodeTools,
KeywordFuncLists, PascalParserTool, CodeCache, CacheCodeTools, FileProcs,
@ -51,11 +52,11 @@ uses
// synedit
SynHighlighterPas,
// IDEIntf
IDEMsgIntf, MacroIntf, PackageIntf, LazHelpIntf, ProjectIntf, IDEDialogs,
IDEHelpIntf, LazIDEIntf,
IDECommands, IDEMsgIntf, MacroIntf, PackageIntf, LazHelpIntf, ProjectIntf,
IDEDialogs, IDEHelpIntf, LazIDEIntf,
// IDE
LazarusIDEStrConsts, CompilerOptions, IDEProcs, PackageDefs, EnvironmentOpts,
TransferMacros, PackageSystem, DialogProcs;
EditorOptions, LazarusIDEStrConsts, CompilerOptions, IDEProcs, PackageDefs,
EnvironmentOpts, TransferMacros, PackageSystem, DialogProcs, KeyMapping;
const
IDEProjectName = 'Lazarus';
@ -215,7 +216,8 @@ type
TCodeHelpHintOption = (
chhoSmallStep, // do the next step. Use this to run on idle.
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;
@ -2240,6 +2242,7 @@ var
n: Integer;
LastOwner: TObject;
s: String;
Cmd: TKeyCommandRelation;
procedure AddLinkToOwner(CurOwner: TObject);
var
@ -2302,7 +2305,7 @@ begin
// add fpdoc entry
FPDocFilename:=GetFPDocFilenameForSource(CTTool.MainFilename,
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 n=1 then
@ -2315,7 +2318,7 @@ begin
ElementNode:=FPDocFile.GetElementWithName(ElementName);
if ElementNode<>nil then begin
//debugln(['TCodeHelpManager.GetHTMLHint2 fpdoc element found "',ElementName,'"']);
//debugln(['TCodeHelpManager.GetHTMLHint fpdoc element found "',ElementName,'"']);
AddLinkToOwner(AnOwner);
s:=AppendLineEnding(GetFPDocNodeAsHTML(FPDocFile,ElementNode.FindNode(FPDocItemNames[fpdiShort])));
@ -2343,7 +2346,7 @@ begin
or ((CTNode.Desc in [ctnProcedure,ctnProcedureHead])
and (CTTool.ProcNodeHasSpecifier(CTNode,psOVERRIDE)))
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;
OldCTTool:=CTTool;
OldCTNode:=CTNode;
@ -2351,18 +2354,19 @@ begin
CTTool,CTNode,XYPos,aTopLine))
or (CTNode=OldCTNode)
then begin
debugln(['TCodeHelpManager.GetHTMLHint2 inherited not found: ',dbgs(OldXYPos)]);
debugln(['TCodeHelpManager.GetHTMLHint inherited not found: ',dbgs(OldXYPos)]);
break;
end;
end else begin
debugln(['TCodeHelpManager.GetHTMLHint2 not searching inherited for ',CTNode.DescAsString]);
debugln(['TCodeHelpManager.GetHTMLHint not searching inherited for ',CTNode.DescAsString]);
break;
end;
end;
except
on E: Exception do begin
debugln(['TCodeHelpManager.GetHTMLHint2 Exception: ',E.Message]);
debugln(['TCodeHelpManager.GetHTMLHint Exception: ',E.Message]);
//DumpExceptionBackTrace;
end;
end;
@ -2370,10 +2374,17 @@ begin
finally
ElementNames.Free;
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
+'<body>'+LineEnding+HTMLHint+'</body>'+LineEnding;
end;
debugln(['TCodeHelpManager.GetHTMLHint2 ',HTMLHint]);
debugln(['TCodeHelpManager.GetHTMLHint ',HTMLHint]);
Result:=chprSuccess;
end;

View File

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

View File

@ -607,6 +607,7 @@ begin
ecContextHelp: SetResult(VK_F1,[],VK_UNKNOWN,[]);
ecEditContextHelp: SetResult(VK_F1,[ssShift,ssCtrl],VK_UNKNOWN,[]);
ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecFocusHint: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// designer
ecDesignerCopy : SetResult(VK_C,[ssCtrl],VK_Insert,[ssCtrl]);
@ -1049,6 +1050,7 @@ begin
ecContextHelp: SetResult(VK_F1,[ssCtrl],VK_UNKNOWN,[]);
ecEditContextHelp: SetResult(VK_F1,[ssCtrl,ssShift],VK_UNKNOWN,[]);
ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecFocusHint: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// designer
ecDesignerCopy : SetResult(VK_C,[ssCtrl],VK_UNKNOWN,[],VK_Insert,[ssCtrl],VK_UNKNOWN,[]);
@ -1680,6 +1682,7 @@ begin
ecContextHelp: SetResult(VK_HELP,[],VK_UNKNOWN,[]);
ecEditContextHelp: SetResult(VK_HELP,[ssShift,ssCtrl],VK_HELP,[ssCtrl]);
ecReportingBug: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecFocusHint: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// designer
ecDesignerCopy : SetResult(VK_C,[ssMeta],VK_UNKNOWN,[]);
@ -2227,6 +2230,7 @@ begin
ecContextHelp : Result:= lisMenuContextHelp;
ecEditContextHelp : Result:= lisMenuEditContextHelp;
ecReportingBug : Result:= srkmecReportingBug;
ecFocusHint : Result:= lisFocusHint;
// desginer
ecDesignerCopy : Result:= lisDsgCopyComponents;
@ -2887,6 +2891,7 @@ begin
AddDefault(C, 'Context sensitive help', lisKMContextSensitiveHelp, ecContextHelp);
AddDefault(C, 'Edit context sensitive help', lisKMEditContextSensitiveHelp, ecEditContextHelp);
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)
C:=Categories[AddCategory('Designer',lisKeyCatDesigner,IDECmdScopeDesignerOnly)];

View File

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

View File

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

View File

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

View File

@ -49,6 +49,11 @@ type
property ModifierStr: string read FModifierStr write FModifierStr;
end;
TIDEHelpManagerCreateHintFlag = (
ihmchAddFocusHint
);
TIDEHelpManagerCreateHintFlags = set of TIDEHelpManagerCreateHintFlag;
{ TBaseHelpManager }
TBaseHelpManager = class(TComponent)
@ -65,7 +70,8 @@ type
procedure ShowHelpForIDEControl(Sender: TControl); virtual; abstract;
function GetHintForSourcePosition(const ExpandedFilename: string;
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;
const BaseURL: string; var TheHint: string;
out HintWinRect: TRect): boolean; virtual; abstract;

View File

@ -306,7 +306,7 @@ type
function CheckInstallPackageList(PkgIDList: TObjectList;
Flags: TPkgInstallInIDEFlags = []): boolean; override;
function InstallPackages(PkgIdList: TObjectList;
Flags: TPkgInstallInIDEFlags = []): TModalResult; override;
Flags: TPkgInstallInIDEFlags = []): TModalResult; override;
procedure DoTranslatePackage(APackage: TLazPackage);
function DoOpenPackageSource(APackage: TLazPackage): TModalResult;
function DoCompileAutoInstallPackages(Flags: TPkgCompileFlags;