mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-31 20:00:26 +02:00
examples: idehelp: started load/save
git-svn-id: trunk@35121 -
This commit is contained in:
parent
c27b2e4e43
commit
24c54cb3c4
@ -45,13 +45,32 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LCLProc, FileUtil, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, LCLProc, FileUtil, Forms, Controls, Graphics, Dialogs,
|
||||||
LazHelpIntf, HelpIntfs, ComCtrls, StdCtrls, IDEHelpIntf, IDEDialogs,
|
LazHelpIntf, HelpIntfs, ComCtrls, StdCtrls, LazConfigStorage, IDEHelpIntf,
|
||||||
IDEOptionsIntf, BaseIDEIntf;
|
IDEDialogs, IDEOptionsIntf, BaseIDEIntf;
|
||||||
|
|
||||||
const
|
const
|
||||||
MyHelpOptionID: integer = 10000; // an arbitrary number, choose a big number
|
MyHelpOptionID: integer = 10000; // an arbitrary number, choose a big number
|
||||||
// to append your options frame as last / below the others
|
// to append your options frame as last / below the others
|
||||||
type
|
type
|
||||||
|
|
||||||
|
{ TMyHelpDatabase
|
||||||
|
This is base class for all the demonstrated IDE help databases.
|
||||||
|
In your help database you would probably combine all the features you
|
||||||
|
want into a single class. }
|
||||||
|
|
||||||
|
TMyHelpDatabase = class(THelpDatabase)
|
||||||
|
private
|
||||||
|
FEnabled: boolean;
|
||||||
|
FModified: boolean;
|
||||||
|
procedure SetEnabled(AValue: boolean);
|
||||||
|
public
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
procedure LoadFromConfig(Config: TConfigStorage); virtual; // called in Register
|
||||||
|
procedure SaveToConfig(Config: TConfigStorage); virtual; // called by TMyHelpSetupDialog.WriteSettings
|
||||||
|
property Enabled: boolean read FEnabled write SetEnabled; // switch to disable single example databases
|
||||||
|
property Modified: boolean read FModified write FModified;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TMyFPCKeywordHelpDatabase
|
{ TMyFPCKeywordHelpDatabase
|
||||||
Help for FPC keywords like 'procedure'.
|
Help for FPC keywords like 'procedure'.
|
||||||
Actually FPC keywords are a special case. Any LCL TControl can set its
|
Actually FPC keywords are a special case. Any LCL TControl can set its
|
||||||
@ -59,12 +78,11 @@ type
|
|||||||
Notes: Do not forget to register this using HelpDatabases.CreateHelpDatabase!
|
Notes: Do not forget to register this using HelpDatabases.CreateHelpDatabase!
|
||||||
You can combine all your databases into one. }
|
You can combine all your databases into one. }
|
||||||
|
|
||||||
TMyFPCKeywordHelpDatabase = class(THelpDatabase)
|
TMyFPCKeywordHelpDatabase = class(TMyHelpDatabase)
|
||||||
private
|
private
|
||||||
FAllKeywordNode: THelpNode;
|
FAllKeywordNode: THelpNode;
|
||||||
public
|
public
|
||||||
KeywordToText: TStrings; // every line has the format: Keyword=Text
|
KeywordToText: TStrings; // every line has the format: Keyword=Text
|
||||||
Enabled: boolean;
|
|
||||||
constructor Create(TheOwner: TComponent); override;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function GetNodesForKeyword(const HelpKeyword: string;
|
function GetNodesForKeyword(const HelpKeyword: string;
|
||||||
@ -73,6 +91,8 @@ type
|
|||||||
function ShowHelp(Query: THelpQuery; {%H-}BaseNode, {%H-}NewNode: THelpNode;
|
function ShowHelp(Query: THelpQuery; {%H-}BaseNode, {%H-}NewNode: THelpNode;
|
||||||
{%H-}QueryItem: THelpQueryItem;
|
{%H-}QueryItem: THelpQueryItem;
|
||||||
var {%H-}ErrMsg: string): TShowHelpResult; override;
|
var {%H-}ErrMsg: string): TShowHelpResult; override;
|
||||||
|
procedure LoadFromConfig(Config: TConfigStorage); override;
|
||||||
|
procedure SaveToConfig(Config: TConfigStorage); override;
|
||||||
end;
|
end;
|
||||||
var
|
var
|
||||||
MyFPCKeywordHelpDatabase: TMyFPCKeywordHelpDatabase;
|
MyFPCKeywordHelpDatabase: TMyFPCKeywordHelpDatabase;
|
||||||
@ -193,13 +213,31 @@ procedure Register;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure LoadMyIDEOptions(Filename: string);
|
procedure LoadMyIDEOptions(Filename: string);
|
||||||
|
var
|
||||||
|
Config: TConfigStorage;
|
||||||
begin
|
begin
|
||||||
|
Config:=GetIDEConfigStorage(Filename,true);
|
||||||
|
try
|
||||||
|
Config.AppendBasePath('FPCKeywords');
|
||||||
|
MyFPCKeywordHelpDatabase.LoadFromConfig(Config);
|
||||||
|
Config.UndoAppendBasePath;
|
||||||
|
finally
|
||||||
|
Config.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SaveMyIDEOptions(Filename: string);
|
procedure SaveMyIDEOptions(Filename: string);
|
||||||
|
var
|
||||||
|
Config: TConfigStorage;
|
||||||
begin
|
begin
|
||||||
|
Config:=GetIDEConfigStorage(Filename,false);
|
||||||
|
try
|
||||||
|
Config.AppendBasePath('FPCKeywords');
|
||||||
|
MyFPCKeywordHelpDatabase.SaveToConfig(Config);
|
||||||
|
Config.UndoAppendBasePath;
|
||||||
|
finally
|
||||||
|
Config.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
@ -218,6 +256,33 @@ begin
|
|||||||
|
|
||||||
// register frame in the IDE options to setup "My IDE help"
|
// register frame in the IDE options to setup "My IDE help"
|
||||||
MyHelpOptionID:=RegisterIDEOptionsEditor(GroupHelp,TMyHelpSetupDialog,MyHelpOptionID)^.Index;
|
MyHelpOptionID:=RegisterIDEOptionsEditor(GroupHelp,TMyHelpSetupDialog,MyHelpOptionID)^.Index;
|
||||||
|
|
||||||
|
LoadMyIDEOptions('demo_myidehelp.xml');
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TMyHelpDatabase }
|
||||||
|
|
||||||
|
procedure TMyHelpDatabase.SetEnabled(AValue: boolean);
|
||||||
|
begin
|
||||||
|
if FEnabled=AValue then Exit;
|
||||||
|
FEnabled:=AValue;
|
||||||
|
Modified:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TMyHelpDatabase.Create(TheOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(TheOwner);
|
||||||
|
Enabled:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMyHelpDatabase.LoadFromConfig(Config: TConfigStorage);
|
||||||
|
begin
|
||||||
|
Enabled:=Config.GetValue('Enabled',true);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMyHelpDatabase.SaveToConfig(Config: TConfigStorage);
|
||||||
|
begin
|
||||||
|
Config.SetDeleteValue('Enabled',Enabled,true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TMyHelpSetupDialog }
|
{ TMyHelpSetupDialog }
|
||||||
@ -506,7 +571,6 @@ end;
|
|||||||
constructor TMyFPCKeywordHelpDatabase.Create(TheOwner: TComponent);
|
constructor TMyFPCKeywordHelpDatabase.Create(TheOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(TheOwner);
|
inherited Create(TheOwner);
|
||||||
Enabled:=true;
|
|
||||||
KeywordToText:=TStringList.Create;
|
KeywordToText:=TStringList.Create;
|
||||||
KeywordToText.Add('procedure=Named code block');
|
KeywordToText.Add('procedure=Named code block');
|
||||||
end;
|
end;
|
||||||
@ -563,6 +627,18 @@ begin
|
|||||||
Result:=shrSuccess;
|
Result:=shrSuccess;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMyFPCKeywordHelpDatabase.LoadFromConfig(Config: TConfigStorage);
|
||||||
|
begin
|
||||||
|
inherited LoadFromConfig(Config);
|
||||||
|
Config.GetValue('KeywordToText',KeywordToText);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMyFPCKeywordHelpDatabase.SaveToConfig(Config: TConfigStorage);
|
||||||
|
begin
|
||||||
|
inherited SaveToConfig(Config);
|
||||||
|
Config.SetValue('KeywordToText',KeywordToText);
|
||||||
|
end;
|
||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user