mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 23:59:24 +02:00
anchordocking: started default layouts
git-svn-id: trunk@26133 -
This commit is contained in:
parent
b85fe6bd88
commit
e792ed60eb
@ -453,6 +453,8 @@ type
|
|||||||
|
|
||||||
// save/restore layouts
|
// save/restore layouts
|
||||||
procedure SaveMainLayoutToTree(LayoutTree: TAnchorDockLayoutTree);
|
procedure SaveMainLayoutToTree(LayoutTree: TAnchorDockLayoutTree);
|
||||||
|
procedure SaveSiteLayoutToTree(AForm: TCustomForm;
|
||||||
|
LayoutTree: TAnchorDockLayoutTree);
|
||||||
procedure SaveLayoutToConfig(Config: TConfigStorage);
|
procedure SaveLayoutToConfig(Config: TConfigStorage);
|
||||||
function ConfigIsEmpty(Config: TConfigStorage): boolean;
|
function ConfigIsEmpty(Config: TConfigStorage): boolean;
|
||||||
function LoadLayoutFromConfig(Config: TConfigStorage): boolean;
|
function LoadLayoutFromConfig(Config: TConfigStorage): boolean;
|
||||||
@ -1833,13 +1835,35 @@ begin
|
|||||||
Site.SaveLayout(LayoutTree,LayoutNode);
|
Site.SaveLayout(LayoutTree,LayoutNode);
|
||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
raise EAnchorDockLayoutError.Create('invalid root control class '+DbgSName(AControl));
|
raise EAnchorDockLayoutError.Create('invalid root control for save: '+DbgSName(AControl));
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
SavedSites.Free;
|
SavedSites.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockMaster.SaveSiteLayoutToTree(AForm: TCustomForm;
|
||||||
|
LayoutTree: TAnchorDockLayoutTree);
|
||||||
|
var
|
||||||
|
LayoutNode: TAnchorDockLayoutTreeNode;
|
||||||
|
Site: TAnchorDockHostSite;
|
||||||
|
begin
|
||||||
|
if (AForm is TAnchorDockHostSite) then begin
|
||||||
|
Site:=TAnchorDockHostSite(AForm);
|
||||||
|
Site.SaveLayout(LayoutTree,LayoutTree.Root);
|
||||||
|
end else if IsCustomSite(AForm) then begin
|
||||||
|
LayoutTree.Root.NodeType:=adltnCustomSite;
|
||||||
|
LayoutTree.Root.Assign(AForm);
|
||||||
|
// can have one normal dock site
|
||||||
|
Site:=TAnchorDockManager(AForm.DockManager).GetChildSite;
|
||||||
|
if Site<>nil then begin
|
||||||
|
LayoutNode:=LayoutTree.NewNode(LayoutTree.Root);
|
||||||
|
Site.SaveLayout(LayoutTree,LayoutNode);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
raise EAnchorDockLayoutError.Create('invalid root control for save: '+DbgSName(AForm));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TAnchorDockMaster.SaveLayoutToConfig(Config: TConfigStorage);
|
procedure TAnchorDockMaster.SaveLayoutToConfig(Config: TConfigStorage);
|
||||||
var
|
var
|
||||||
Tree: TAnchorDockLayoutTree;
|
Tree: TAnchorDockLayoutTree;
|
||||||
@ -3982,7 +4006,7 @@ procedure TAnchorDockHeader.Paint;
|
|||||||
|
|
||||||
procedure DrawGrabber(r: TRect);
|
procedure DrawGrabber(r: TRect);
|
||||||
begin
|
begin
|
||||||
Canvas.Frame3d(r,4,bvLowered);
|
Canvas.Frame3d(r,2,bvLowered);
|
||||||
Canvas.Frame3d(r,4,bvRaised);
|
Canvas.Frame3d(r,4,bvRaised);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -191,12 +191,41 @@ type
|
|||||||
FLayout: TAnchorDockLayoutTree;
|
FLayout: TAnchorDockLayoutTree;
|
||||||
procedure SetControlNames(const AValue: TStrings);
|
procedure SetControlNames(const AValue: TStrings);
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create; overload;
|
||||||
|
constructor Create(aLayout: TAnchorDockLayoutTree); overload;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
function IndexOfControlName(AName: string): integer;
|
||||||
|
function HasControlName(AName: string): boolean;
|
||||||
|
procedure RemoveControlName(AName: string);
|
||||||
|
procedure UpdateControlNames;
|
||||||
|
procedure LoadFromConfig(Config: TConfigStorage);
|
||||||
|
procedure SaveToConfig(Config: TConfigStorage);
|
||||||
property ControlNames: TStrings read FControlNames write SetControlNames;
|
property ControlNames: TStrings read FControlNames write SetControlNames;
|
||||||
property Layout: TAnchorDockLayoutTree read FLayout;
|
property Layout: TAnchorDockLayoutTree read FLayout;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TAnchorDockDefaultLayouts }
|
||||||
|
|
||||||
|
TAnchorDockDefaultLayouts = class
|
||||||
|
private
|
||||||
|
fItems: TFPList;
|
||||||
|
function GetItems(Index: integer): TAnchorDockDefaultLayout;
|
||||||
|
public
|
||||||
|
constructor Create;
|
||||||
|
destructor Destroy; override;
|
||||||
|
procedure Clear;
|
||||||
|
procedure Delete(Index: integer);
|
||||||
|
function IndexOfName(AControlName: string): integer;
|
||||||
|
function FindByName(AControlName: string): TAnchorDockDefaultLayout;
|
||||||
|
procedure Add(Layout: TAnchorDockDefaultLayout; RemoveOther: boolean);
|
||||||
|
procedure RemoveByName(AControlName: string);
|
||||||
|
procedure LoadFromConfig(Config: TConfigStorage);
|
||||||
|
procedure SaveToConfig(Config: TConfigStorage);
|
||||||
|
function ConfigIsEmpty(Config: TConfigStorage): boolean;
|
||||||
|
function Count: integer;
|
||||||
|
property Items[Index: integer]: TAnchorDockDefaultLayout read GetItems;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TADNameToControl }
|
{ TADNameToControl }
|
||||||
|
|
||||||
TADNameToControl = class
|
TADNameToControl = class
|
||||||
@ -1719,6 +1748,13 @@ begin
|
|||||||
FLayout:=TAnchorDockLayoutTree.Create;
|
FLayout:=TAnchorDockLayoutTree.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TAnchorDockDefaultLayout.Create(aLayout: TAnchorDockLayoutTree);
|
||||||
|
begin
|
||||||
|
FControlNames:=TStringList.Create;
|
||||||
|
FLayout:=aLayout;
|
||||||
|
UpdateControlNames;
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TAnchorDockDefaultLayout.Destroy;
|
destructor TAnchorDockDefaultLayout.Destroy;
|
||||||
begin
|
begin
|
||||||
FreeAndNil(FLayout);
|
FreeAndNil(FLayout);
|
||||||
@ -1726,5 +1762,202 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockDefaultLayout.IndexOfControlName(AName: string): integer;
|
||||||
|
begin
|
||||||
|
Result:=fControlNames.Count;
|
||||||
|
while (Result>=0) and (CompareText(AName,FControlNames[Result])<>0) do
|
||||||
|
dec(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockDefaultLayout.HasControlName(AName: string): boolean;
|
||||||
|
begin
|
||||||
|
Result:=IndexOfControlName(AName)>=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayout.RemoveControlName(AName: string);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i:=FControlNames.Count-1 downto 0 do
|
||||||
|
if CompareText(AName,FControlNames[i])=0 then
|
||||||
|
FControlNames.Delete(i);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayout.UpdateControlNames;
|
||||||
|
|
||||||
|
procedure Check(Node: TAnchorDockLayoutTreeNode);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if (Node.Name<>'') and (Node.NodeType in [adltnControl,adltnCustomSite])
|
||||||
|
and (not HasControlName(Node.Name)) then
|
||||||
|
FControlNames.Add(Node.Name);
|
||||||
|
for i:=0 to Node.Count-1 do
|
||||||
|
Check(Node[i]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
FControlNames.Clear;
|
||||||
|
Check(Layout.Root);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayout.LoadFromConfig(Config: TConfigStorage);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
AName: string;
|
||||||
|
Node: TAnchorDockLayoutTreeNode;
|
||||||
|
begin
|
||||||
|
FControlNames.Delimiter:=',';
|
||||||
|
FControlNames.StrictDelimiter:=true;
|
||||||
|
FControlNames.DelimitedText:=Config.GetValue('Names','');
|
||||||
|
Layout.LoadFromConfig(Config);
|
||||||
|
for i:=FControlNames.Count-1 downto 0 do begin
|
||||||
|
AName:=FControlNames[i];
|
||||||
|
if (AName<>'') and IsValidIdent(AName)
|
||||||
|
and (Layout.Root<>nil) then begin
|
||||||
|
Node:=Layout.Root.FindChildNode(AName,true);
|
||||||
|
if (Node<>nil) and (Node.NodeType in [adltnControl,adltnCustomSite]) then
|
||||||
|
continue;
|
||||||
|
end;
|
||||||
|
FControlNames.Delete(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayout.SaveToConfig(Config: TConfigStorage);
|
||||||
|
begin
|
||||||
|
FControlNames.Delimiter:=',';
|
||||||
|
FControlNames.StrictDelimiter:=true;
|
||||||
|
Config.SetDeleteValue('Names',FControlNames.DelimitedText,'');
|
||||||
|
Layout.SaveToConfig(Config);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TAnchorDockDefaultLayouts }
|
||||||
|
|
||||||
|
function TAnchorDockDefaultLayouts.GetItems(Index: integer
|
||||||
|
): TAnchorDockDefaultLayout;
|
||||||
|
begin
|
||||||
|
Result:=TAnchorDockDefaultLayout(fItems[Index]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TAnchorDockDefaultLayouts.Create;
|
||||||
|
begin
|
||||||
|
fItems:=TFPList.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TAnchorDockDefaultLayouts.Destroy;
|
||||||
|
begin
|
||||||
|
Clear;
|
||||||
|
FreeAndNil(fItems);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayouts.Clear;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i:=0 to fItems.Count-1 do
|
||||||
|
TObject(fItems[i]).Free;
|
||||||
|
fItems.Clear;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayouts.Delete(Index: integer);
|
||||||
|
begin
|
||||||
|
TObject(fItems[Index]).Free;
|
||||||
|
fItems.Delete(Index);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockDefaultLayouts.IndexOfName(AControlName: string): integer;
|
||||||
|
begin
|
||||||
|
Result:=Count-1;
|
||||||
|
while (Result>=0) and not Items[Result].HasControlName(AControlName) do
|
||||||
|
dec(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockDefaultLayouts.FindByName(AControlName: string
|
||||||
|
): TAnchorDockDefaultLayout;
|
||||||
|
var
|
||||||
|
i: LongInt;
|
||||||
|
begin
|
||||||
|
i:=IndexOfName(AControlName);
|
||||||
|
if i>=0 then
|
||||||
|
Result:=Items[i]
|
||||||
|
else
|
||||||
|
Result:=nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayouts.Add(Layout: TAnchorDockDefaultLayout;
|
||||||
|
RemoveOther: boolean);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if RemoveOther then begin
|
||||||
|
for i:=0 to Layout.ControlNames.Count-1 do
|
||||||
|
RemoveByName(Layout.ControlNames[i]);
|
||||||
|
end;
|
||||||
|
fItems.Add(Layout);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayouts.RemoveByName(AControlName: string);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
Layout: TAnchorDockDefaultLayout;
|
||||||
|
begin
|
||||||
|
for i:=Count-1 downto 0 do begin
|
||||||
|
Layout:=Items[i];
|
||||||
|
Layout.RemoveControlName(AControlName);
|
||||||
|
if Layout.ControlNames.Count=0 then
|
||||||
|
Delete(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayouts.LoadFromConfig(Config: TConfigStorage);
|
||||||
|
var
|
||||||
|
NewCount: longint;
|
||||||
|
NewItem: TAnchorDockDefaultLayout;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Clear;
|
||||||
|
NewCount:=Config.GetValue('Count',0);
|
||||||
|
for i:=1 to NewCount do begin
|
||||||
|
NewItem:=TAnchorDockDefaultLayout.Create;
|
||||||
|
Config.AppendBasePath('Item'+IntToStr(i+1)+'/');
|
||||||
|
try
|
||||||
|
NewItem.LoadFromConfig(Config);
|
||||||
|
finally
|
||||||
|
Config.UndoAppendBasePath;
|
||||||
|
end;
|
||||||
|
if NewItem.ControlNames.Count>0 then
|
||||||
|
fItems.Add(NewItem)
|
||||||
|
else
|
||||||
|
NewItem.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TAnchorDockDefaultLayouts.SaveToConfig(Config: TConfigStorage);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Config.SetDeleteValue('Count',Count,0);
|
||||||
|
for i:=0 to Count-1 do begin
|
||||||
|
Config.AppendBasePath('Item'+IntToStr(i+1)+'/');
|
||||||
|
try
|
||||||
|
Items[i].SaveToConfig(Config);
|
||||||
|
finally
|
||||||
|
Config.UndoAppendBasePath;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockDefaultLayouts.ConfigIsEmpty(Config: TConfigStorage
|
||||||
|
): boolean;
|
||||||
|
begin
|
||||||
|
Result:=Config.GetValue('Count',0)<=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockDefaultLayouts.Count: integer;
|
||||||
|
begin
|
||||||
|
Result:=fItems.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -2087,7 +2087,7 @@ begin
|
|||||||
if WindowState = wsMinimized then
|
if WindowState = wsMinimized then
|
||||||
WindowState := wsNormal;
|
WindowState := wsNormal;
|
||||||
BringToFront;
|
BringToFront;
|
||||||
//DebugLn('TCustomForm.ShowOnTop ',Name,':',ClassName,' ',Visible,' ',HandleAllocated,' ',csDesigning in ComponentState);
|
//DebugLn(['TCustomForm.ShowOnTop ',Name,':',ClassName,' ',Visible,' ',HandleAllocated,' ',csDesigning in ComponentState]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomForm.AutoSizeCheckParent: Boolean;
|
function TCustomForm.AutoSizeCheckParent: Boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user