externhelp: implemented load/save items in packages

git-svn-id: trunk@24882 -
This commit is contained in:
mattias 2010-04-24 15:53:57 +00:00
parent d1fe7c62e5
commit 3c931c022f
4 changed files with 137 additions and 58 deletions

View File

@ -17,7 +17,7 @@
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Description Value="Help for pscal bindings"/>
<Description Value="Help for pascal bindings"/>
<License Value="modified LGPL"/>
<Version Major="1" Minor="1"/>
<Files Count="2">
@ -51,5 +51,22 @@
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
</PublishOptions>
<CustomOptions Childs="ExternHelp">
<_ExternHelp Childs="Count/Item1">
<_Count Value="1"/>
<_Item1 Childs="Filename/Name/URL/WithSubDirectories">
<_Filename Childs="Value">
<_Value Value="$(FPCSrcDir)/packages/gtk2/"/>
</_Filename>
<_Name Value="Gtk2"/>
<_URL Childs="Value">
<_Value Value="http://www.google.com/custom?domains=library.gnome.org&amp;sitesearch=library.gnome.org&amp;q=$(Identifier)"/>
</_URL>
<_WithSubDirectories Childs="Value">
<_Value Value="True"/>
</_WithSubDirectories>
</_Item1>
</_ExternHelp>
</CustomOptions>
</Package>
</CONFIG>

View File

@ -153,12 +153,13 @@ type
destructor Destroy; override;
procedure Clear;
procedure ClearItemsStoredInUserSettings;
procedure ClearItemsStoredInPackages(const Name: string = '*');
procedure ClearItemsStoredInPackages(Parent: TExternHelpItem;
const Name: string = '*');
class function GetGroupCaption: string; override;
class function GetInstance: TAbstractIDEOptions; override;
function Load(Config: TConfigStorage; KeepPackageOpts: boolean): TModalResult; virtual;
function Save(Config: TConfigStorage): TModalResult; virtual;
procedure LoadOptionsFromPackage(Pkg: TIDEPackage);
procedure LoadOptionsFromPackage(Pkg: TIDEPackage; Parent: TExternHelpItem);
procedure LoadOptionsFromPackages;
procedure SaveOptionsToPackage(Pkg: TIDEPackage);
procedure SaveOptionsToPackages;
@ -283,7 +284,7 @@ end;
procedure TExternHelpOptions.PkgFileLoaded(Sender: TObject);
begin
if Sender is TIDEPackage then
LoadOptionsFromPackage(TIDEPackage(Sender));
LoadOptionsFromPackage(TIDEPackage(Sender),RootItem);
end;
procedure TExternHelpOptions.LoadNode(Config: TConfigStorage; Path: string;
@ -361,14 +362,15 @@ begin
end;
end;
procedure TExternHelpOptions.ClearItemsStoredInPackages(const Name: string);
procedure TExternHelpOptions.ClearItemsStoredInPackages(Parent: TExternHelpItem;
const Name: string);
var
i: Integer;
Item: TExternHelpItem;
begin
if RootItem<>nil then begin
for i:=RootItem.ChildCount-1 downto 0 do begin
Item:=RootItem.Childs[i];
if Parent<>nil then begin
for i:=Parent.ChildCount-1 downto 0 do begin
Item:=Parent.Childs[i];
if (Item.StoreIn<>'')
and (Name='*') or (SysUtils.CompareText(Item.StoreIn,Name)=0) then
Item.Free;
@ -376,7 +378,8 @@ begin
end;
end;
procedure TExternHelpOptions.LoadOptionsFromPackage(Pkg: TIDEPackage);
procedure TExternHelpOptions.LoadOptionsFromPackage(Pkg: TIDEPackage;
Parent: TExternHelpItem);
var
Cnt: integer;
i: Integer;
@ -384,12 +387,13 @@ var
NewItem: TExternHelpItem;
begin
if Pkg.Name='' then exit;
ClearItemsStoredInPackages(Pkg.Name);
ClearItemsStoredInPackages(Parent,Pkg.Name);
Path:='ExternHelp/';
Cnt:=Pkg.CustomOptions.GetValue(Path+'Count',0);
//DebugLn(['TExternHelpOptions.LoadOptionsFromPackage ',Pkg.Name,' Cnt=',Cnt]);
for i:=1 to Cnt do begin
NewItem:=TExternHelpItem.Create;
RootItem.AddChild(NewItem);
Parent.AddChild(NewItem);
NewItem.StoreIn:=Pkg.Name;
LoadNode(Pkg.CustomOptions,Path+'Item'+IntToStr(i)+'/',NewItem);
end;
@ -400,9 +404,9 @@ var
i: Integer;
begin
if PackageEditingInterface=nil then exit;
ClearItemsStoredInPackages('*');
ClearItemsStoredInPackages(RootItem,'*');
for i:=0 to PackageEditingInterface.GetPackageCount-1 do
LoadOptionsFromPackage(PackageEditingInterface.GetPackages(i));
LoadOptionsFromPackage(PackageEditingInterface.GetPackages(i),RootItem);
end;
procedure TExternHelpOptions.SaveOptionsToPackage(Pkg: TIDEPackage);
@ -411,40 +415,62 @@ var
Path: String;
Item: TExternHelpItem;
i: Integer;
TmpRoot: TExternHelpItem;
Changed: Boolean;
begin
if Pkg.Name='' then exit;
Path:='ExternHelp/';
//DebugLn(['TExternHelpOptions.SaveOptionsToPackage START ',Pkg.Name]);
// check if something changed
TmpRoot:=TExternHelpItem.Create;
try
LoadOptionsFromPackage(Pkg,TmpRoot);
Changed:=false;
Cnt:=0;
for i:=0 to RootItem.ChildCount-1 do begin
Item:=RootItem.Childs[i];
if SysUtils.CompareText(Item.StoreIn,Pkg.Name)<>0 then continue;
if (Cnt=TmpRoot.ChildCount)
or (not TmpRoot.Childs[Cnt].IsEqual(Item,true)) then begin
Changed:=true;
break;
end;
inc(Cnt);
end;
if TmpRoot.ChildCount>Cnt then Changed:=true;
if not Changed then exit;
finally
TmpRoot.Free;
end;
DebugLn(['TExternHelpOptions.SaveOptionsToPackage CHANGED: ',Pkg.Name]);
// save to package and mark it modified
Path:='ExternHelp';
Pkg.CustomOptions.DeletePath(Path);
Path:=Path+'/';
Cnt:=0;
for i:=0 to RootItem.ChildCount-1 do begin
Item:=RootItem.Childs[i];
//DebugLn(['TExternHelpOptions.SaveOptionsToPackage ',Item.Name,' StoreIN=',Item.StoreIn,' ',SysUtils.CompareText(Item.StoreIn,Pkg.Name)=0]);
if SysUtils.CompareText(Item.StoreIn,Pkg.Name)<>0 then continue;
inc(Cnt);
SaveNode(Pkg.CustomOptions,Path+'Item'+IntToStr(i)+'/',Item);
SaveNode(Pkg.CustomOptions,Path+'Item'+IntToStr(Cnt)+'/',Item);
end;
Pkg.CustomOptions.SetDeleteValue(Path+'Count',Cnt,0);
Pkg.Modified:=True;
DebugLn(['TExternHelpOptions.SaveOptionsToPackage MODIFIED: ',Pkg.Name]);
end;
procedure TExternHelpOptions.SaveOptionsToPackages;
var
i: Integer;
Item: TExternHelpItem;
SavedPackages: TFPList;
Pkg: TIDEPackage;
begin
if PackageEditingInterface=nil then exit;
SavedPackages:=TFPList.Create;
try
for i:=0 to RootItem.ChildCount-1 do begin
Item:=RootItem.Childs[i];
if Item.StoreIn='' then continue;
Pkg:=PackageEditingInterface.FindPackageWithName(Item.StoreIn);
if (Pkg=nil) or (SavedPackages.IndexOf(Pkg)>=0) then continue;
SavedPackages.Add(Pkg);
SaveOptionsToPackage(Pkg);
end;
finally
SavedPackages.Free;
for i:=0 to PackageEditingInterface.GetPackageCount-1 do begin
Pkg:=PackageEditingInterface.GetPackages(i);
if Pkg.ReadOnly then continue;
SaveOptionsToPackage(Pkg);
end;
end;
@ -1078,12 +1104,12 @@ begin
ExternHelpOptions.Assign(Options);
try
ExternHelpOptions.Save;
ExternHelpOptions.SaveOptionsToPackages;
except
on E: Exception do begin
DebugLn(['TExternHelpGeneralOptsFrame.WriteSettings unable to write file ',ExternHelpOptions.Filename,': ',E.Message]);
end;
end;
ExternHelpOptions.SaveOptionsToPackages;
ExternHelpOptions.UpdateHelpDB;
end;

View File

@ -22,7 +22,7 @@ unit LazConfigStorage;
interface
uses
Classes, SysUtils, AvgLvlTree;
Classes, SysUtils, AvgLvlTree, LCLProc;
type
{ TConfigStorage }
@ -126,7 +126,8 @@ type
destructor Destroy; override;
procedure Clear; override;
procedure SaveToConfig(Config: TConfigStorage; const APath: string);
procedure LoadFromToConfig(Config: TConfigStorage; const APath: string);
procedure LoadFromConfig(Config: TConfigStorage; const APath: string);
procedure WriteDebugReport;
end;
function CompareConfigMemStorageNames(p1, p2: PChar): integer;
@ -382,6 +383,7 @@ var
Child: TConfigMemStorageNode;
NewName: string;
begin
//DebugLn(['TConfigMemStorage.Modify APath="',APath,'" Mode=',ord(Mode),' AValue="',AValue,'"']);
p:=PChar(APath);
if p=nil then begin
if Root<>nil then begin
@ -399,25 +401,28 @@ begin
repeat
StartPos:=p;
while (not (p^ in ['/',#0])) do inc(p);
//DebugLn(['TConfigMemStorage.Modify Node="',Node.Name,'" StartPos="',StartPos,'"']);
// child node
if Node.Childs=nil then begin
if Mode in [cmsmDelete,cmsmDeleteValue] then exit;
CreateChilds(Node);
end;
ChildNode:=Node.Childs.FindKey(StartPos,@ComparePCharWithConfigMemStorageNode);
if ChildNode=nil then begin
if Mode in [cmsmDelete,cmsmDeleteValue] then exit;
NewName:='';
SetLength(NewName,p-StartPos);
if NewName<>'' then
System.Move(StartPos^,NewName[1],p-StartPos);
//DebugLn(['TConfigMemStorage.Modify Adding "',NewName,'"']);
Child:=TConfigMemStorageNode.Create(Node,NewName);
Node.Childs.Add(Child);
end else
Child:=TConfigMemStorageNode(ChildNode.Data);
Node:=Child;
if p^='/' then begin
// child node
if Node.Childs=nil then begin
if Mode in [cmsmDelete,cmsmDeleteValue] then exit;
CreateChilds(Node);
end;
ChildNode:=Node.Childs.FindKey(StartPos,@ComparePCharWithConfigMemStorageNode);
if ChildNode=nil then begin
if Mode in [cmsmDelete,cmsmDeleteValue] then exit;
SetLength(NewName,p-StartPos);
if NewName<>'' then
System.Move(StartPos^,NewName[1],p-StartPos);
Child:=TConfigMemStorageNode.Create(Node,NewName);
Node.Childs.Add(Child);
end else
Child:=TConfigMemStorageNode(ChildNode.Data);
// next level
Node:=Child;
inc(p);
while (p^='/') do inc(p);
end else begin
// end of path
case Mode of
@ -426,9 +431,13 @@ begin
cmsmDelete,cmsmDeleteValue:
begin
Node.Value:='';
while (Node.Childs=nil) or (Node.Childs.Count=0) do begin
if Mode=cmsmDelete then
Node.ClearChilds;
while (Node<>nil) and ((Node.Childs=nil) or (Node.Childs.Count=0))
do begin
Child:=Node;
Node:=Node.Parent;
if Root=Child then Root:=nil;
Child.Free;
end;
end;
@ -569,7 +578,8 @@ procedure TConfigMemStorage.SaveToConfig(Config: TConfigStorage;
Names: String;
begin
if Node=nil then exit;
SubPath:=SubPath+'_'+Node.Name+'/';
if (Node<>Root) then
SubPath:=SubPath+'_'+Node.Name+'/';
Config.SetDeleteValue(SubPath+'Value',Node.Value,'');
Names:='';
if Node.Childs<>nil then begin
@ -589,7 +599,7 @@ begin
Save(Root,APath);
end;
procedure TConfigMemStorage.LoadFromToConfig(Config: TConfigStorage;
procedure TConfigMemStorage.LoadFromConfig(Config: TConfigStorage;
const APath: string);
procedure Load(Node: TConfigMemStorageNode; SubPath: string);
@ -601,14 +611,17 @@ procedure TConfigMemStorage.LoadFromToConfig(Config: TConfigStorage;
Child: TConfigMemStorageNode;
begin
if Node=nil then exit;
SubPath:=SubPath+'_'+Node.Name+'/';
if (Node<>Root) then
SubPath:=SubPath+'_'+Node.Name+'/';
Node.Value:=Config.GetValue(SubPath+'Value','');
ChildNames:=Config.GetValue(SubPath+'Childs','');
//DebugLn(['Load SubPath="',SubPath,'" Value="',Node.Value,'" ChildNames="',ChildNames,'"']);
if ChildNames<>'' then begin
p:=PChar(ChildNames);
repeat
StartPos:=p;
while not (p^ in ['/',#0]) do inc(p);
ChildName:='';
SetLength(ChildName,p-StartPos);
if ChildName<>'' then
System.Move(StartPos^,ChildName[1],p-StartPos);
@ -617,19 +630,42 @@ procedure TConfigMemStorage.LoadFromToConfig(Config: TConfigStorage;
CreateChilds(Node);
Node.Childs.Add(Child);
Load(Child,SubPath);
if p=#0 then break;
if p^=#0 then break;
inc(p);
until false;
end;
end;
begin
//DebugLn(['TConfigMemStorage.LoadFromConfig ']);
Clear;
if Root=nil then
CreateRoot;
Load(Root,APath);
end;
procedure TConfigMemStorage.WriteDebugReport;
procedure w(Node: TConfigMemStorageNode; Prefix: string);
var
AVLNode: TAvgLvlTreeNode;
begin
if Node=nil then exit;
DebugLn(['TConfigMemStorage.WriteDebugReport ',Prefix,'Name="',Node.Name,'" Value="',Node.Value,'"']);
if Node.Childs<>nil then begin
AVLNode:=Node.Childs.FindLowest;
while AVLNode<>nil do begin
w(TConfigMemStorageNode(AVLNode.Data),Prefix+' ');
AVLNode:=Node.Childs.FindSuccessor(AVLNode);
end;
end;
end;
begin
DebugLn(['TConfigMemStorage.WriteDebugReport ']);
w(Root,'');
end;
{ TConfigMemStorageNode }
procedure TConfigMemStorageNode.ClearChilds;
@ -640,7 +676,7 @@ begin
OldChilds:=Childs;
Childs:=nil;
OldChilds.FreeAndClear;
FreeAndNil(OldChilds);
OldChilds.Free;
end;
end;

View File

@ -2503,7 +2503,7 @@ var
else
Exclude(FFlags,lpfAutoIncrementVersionOnBuild);
end;
begin
Flags:=Flags+[lpfLoading];
FileVersion:=XMLConfig.GetValue(Path+'Version',0);
@ -2557,7 +2557,7 @@ begin
LoadStringList(XMLConfig,FProvides,Path+'Provides/');
Config:=TXMLOptionsStorage.Create(XMLConfig);
try
TConfigMemStorage(CustomOptions).LoadFromToConfig(Config,Path+'CustomOptions/');
TConfigMemStorage(CustomOptions).LoadFromConfig(Config,Path+'CustomOptions/');
finally
Config.Free;
end;
@ -2630,7 +2630,7 @@ begin
SaveStringList(XMLConfig,FProvides,Path+'Provides/');
Config:=TXMLOptionsStorage.Create(XMLConfig);
try
TConfigMemStorage(CustomOptions).SaveToConfig(Config,Path+'CustomOptions');
TConfigMemStorage(CustomOptions).SaveToConfig(Config,Path+'CustomOptions/');
finally
Config.Free;
end;