From e71ab596a64eaa34067c91e94fb362e375e8f742 Mon Sep 17 00:00:00 2001 From: dodi Date: Sun, 13 Dec 2009 14:16:54 +0000 Subject: [PATCH] dockmanager example: updated layout persistence: search first, handle invisible sites git-svn-id: trunk@23119 - --- .gitignore | 1 - examples/dockmanager/ide_demo/MiniIDE.lpi | 222 +++++++++---------- examples/dockmanager/ide_demo/fminiide.lfm | 1 + examples/dockmanager/ide_demo/fminiide.lrs | 11 +- examples/dockmanager/ide_demo/fminiide.pas | 80 +++++-- examples/dockmanager/package/easydockmgr.pas | 2 +- examples/dockmanager/package/umakesite.pas | 16 +- 7 files changed, 197 insertions(+), 136 deletions(-) diff --git a/.gitignore b/.gitignore index 2777f21514..758a021cbc 100644 --- a/.gitignore +++ b/.gitignore @@ -238,7 +238,6 @@ examples/designerbaseclass/example/units examples/designerbaseclass/lib/*.bak examples/designerbaseclass/lib/units examples/designerbaseclass/units -examples/dockmanager/ide_demo/MiniIDE.rc examples/dropfiles/units[!!-~]*.bak examples/easter/*.bak examples/easter/units diff --git a/examples/dockmanager/ide_demo/MiniIDE.lpi b/examples/dockmanager/ide_demo/MiniIDE.lpi index ab2432e225..3252d5a92c 100644 --- a/examples/dockmanager/ide_demo/MiniIDE.lpi +++ b/examples/dockmanager/ide_demo/MiniIDE.lpi @@ -9,7 +9,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -51,10 +51,13 @@ - - + + - + + + + @@ -65,7 +68,7 @@ - + @@ -74,10 +77,10 @@ - - - - + + + + @@ -85,8 +88,8 @@ - - + + @@ -97,11 +100,8 @@ - - - - - + + @@ -109,22 +109,22 @@ - + - + - - - - + + + + @@ -133,7 +133,7 @@ - + @@ -144,7 +144,7 @@ - + @@ -154,31 +154,29 @@ - - + + - - - + - + - + @@ -186,51 +184,51 @@ - - - - + + + + - + - + - + - - + + - + - - + + @@ -241,152 +239,152 @@ - - + + - + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + @@ -408,8 +406,8 @@ - - + + diff --git a/examples/dockmanager/ide_demo/fminiide.lfm b/examples/dockmanager/ide_demo/fminiide.lfm index 179bbb92e4..afa1951828 100644 --- a/examples/dockmanager/ide_demo/fminiide.lfm +++ b/examples/dockmanager/ide_demo/fminiide.lfm @@ -114,6 +114,7 @@ object MainBar: TMainBar Caption = '&Windows' object mnWindowDump: TMenuItem Caption = '&Dump' + OnClick = mnWindowDumpClick end object mnMinimize: TMenuItem Caption = 'Minimize all' diff --git a/examples/dockmanager/ide_demo/fminiide.lrs b/examples/dockmanager/ide_demo/fminiide.lrs index 9f877df742..087261a8bd 100644 --- a/examples/dockmanager/ide_demo/fminiide.lrs +++ b/examples/dockmanager/ide_demo/fminiide.lrs @@ -31,9 +31,10 @@ LazarusResources.Add('TMainBar','FORMDATA',[ +'2'#7'Caption'#6#9'Assembler'#7'OnClick'#7#13'ViewMenuClick'#0#0#9'TMenuItem' +#10'MenuItem13'#7'Caption'#6#12'Debug Output'#7'OnClick'#7#13'ViewMenuClick' +#0#0#0#0#9'TMenuItem'#10'MenuItem14'#7'Caption'#6#8'&Windows'#0#9'TMenuItem' - +#12'mnWindowDump'#7'Caption'#6#5'&Dump'#0#0#9'TMenuItem'#10'mnMinimize'#7'Ca' - +'ption'#6#12'Minimize all'#0#0#9'TMenuItem'#9'mnRestore'#7'Caption'#6#11'Res' - +'tore all'#0#0#0#0#11'TOpenDialog'#11'OpenDialog1'#6'Filter'#6#25'*.pas|*.pa' - +'s|All Files|*.*'#4'left'#3#184#0#0#0#11'TSaveDialog'#9'dlgLayout'#10'Defaul' - +'tExt'#6#4'.lyt'#6'Filter'#6#13'Layouts|*.lyt'#4'left'#3#144#0#0#0#0 + +#12'mnWindowDump'#7'Caption'#6#5'&Dump'#7'OnClick'#7#17'mnWindowDumpClick'#0 + +#0#9'TMenuItem'#10'mnMinimize'#7'Caption'#6#12'Minimize all'#0#0#9'TMenuItem' + +#9'mnRestore'#7'Caption'#6#11'Restore all'#0#0#0#0#11'TOpenDialog'#11'OpenDi' + +'alog1'#6'Filter'#6#25'*.pas|*.pas|All Files|*.*'#4'left'#3#184#0#0#0#11'TSa' + +'veDialog'#9'dlgLayout'#10'DefaultExt'#6#4'.lyt'#6'Filter'#6#13'Layouts|*.ly' + +'t'#4'left'#3#144#0#0#0#0 ]); diff --git a/examples/dockmanager/ide_demo/fminiide.pas b/examples/dockmanager/ide_demo/fminiide.pas index 749e2ed3c1..fd8ab95d81 100644 --- a/examples/dockmanager/ide_demo/fminiide.pas +++ b/examples/dockmanager/ide_demo/fminiide.pas @@ -49,6 +49,7 @@ type procedure FormCreate(Sender: TObject); procedure mnExitClick(Sender: TObject); procedure mnOpenClick(Sender: TObject); + procedure mnWindowDumpClick(Sender: TObject); procedure ViewMenuClick(Sender: TObject); private procedure GetLayouts; @@ -66,6 +67,8 @@ var implementation uses + LCLProc, + EasyDockSite, uMakeSite, fEditBook, fClientForm; { TMainBar } @@ -103,6 +106,49 @@ begin end; end; +procedure TMainBar.mnWindowDumpClick(Sender: TObject); + + procedure DumpOwner(fo: TComponent); + var + i: integer; + cmp: TComponent; + begin + for i := 0 to fo.ComponentCount - 1 do begin + cmp := fo.Components[i]; + //if cmp.Name <> '' then + begin + DebugLn(cmp.Name, ': ', cmp.ClassName); + end; + end; + end; + + procedure DumpForms; + var + i: integer; + cmp: TComponent; + begin + DebugLn('- Forms'); + for i := 0 to Screen.FormCount - 1 do begin + cmp := Screen.Forms[i]; + //if cmp.Name <> '' then + begin + DebugLn(cmp.Name, ': ', cmp.ClassName); + end; + end; + end; + +begin +//debug only + DebugLn('--- Screen'); + DumpOwner(Screen); + DumpForms; +{ + DebugLn('--- Owner'); + DumpOwner(DockMaster.Owner); +} + DebugLn('--- end dump'); +end; + procedure TMainBar.OpenFile(const AName: string); var frm: TEditBook; @@ -175,6 +221,7 @@ function TMainBar.CreateDockable(const cap: string; fWrap: boolean): TWinControl var //Site: TFloatingSite; Client: TViewWindow; + n: string; begin (* Translate into layout Reload format: %t=[%f=] @@ -183,19 +230,20 @@ begin We must force docking here, later the client will dock itself into a float host site, when it becomes floating. *) -//create the form - Client := TViewWindow.Create(Self); - Client.Label1.Caption := cap; - Client.Visible := True; -//name it - Client.Caption := cap; - try - Client.Name := StringReplace(cap, ' ', '', [rfReplaceAll]); - except - //here: simply ignore duplicate name +//lookup existing (assume single instance forms) + n := StringReplace(cap, ' ', '', [rfReplaceAll]); + Result := Screen.FindForm(n); + if Result = nil then begin + //create the form + Client := TViewWindow.Create(Self); + Client.Label1.Caption := cap; + Client.Visible := True; + //name it + Client.Caption := cap; + TryRename(Client, n); + DockMaster.MakeDockable(Client, fWrap); + Result := Client; end; - DockMaster.MakeDockable(Client, fWrap); - Result := Client; end; (* Special load/store cases: @@ -216,9 +264,11 @@ Since commas are used for notebook docking, we have to choose other delimiters. %t=[%f=] Default type is 'T', default instNo is 1? *) - if CtrlName[1] = '@' then - Result := CreateDockable(copy(CtrlName, 2, Length(CtrlName)), False) - else if CtrlName[1] = ',' then begin + if CtrlName[1] = '@' then begin + s := copy(CtrlName, 2, Length(CtrlName)); + Result := CreateDockable(s, False); + //if Result <> nil then Result.Visible := True; //edit forms without pages are hidden? + end else if CtrlName[1] = ',' then begin eb := TEditBook.Create(Application); lst := TStringList.Create; try diff --git a/examples/dockmanager/package/easydockmgr.pas b/examples/dockmanager/package/easydockmgr.pas index 4c6feec0fb..2db7947129 100644 --- a/examples/dockmanager/package/easydockmgr.pas +++ b/examples/dockmanager/package/easydockmgr.pas @@ -2,7 +2,7 @@ This source is only used to compile and install the package. } -unit EasyDockMgr; +unit easydockmgr; interface diff --git a/examples/dockmanager/package/umakesite.pas b/examples/dockmanager/package/umakesite.pas index a2bae8d3b7..bb57e0d634 100644 --- a/examples/dockmanager/package/umakesite.pas +++ b/examples/dockmanager/package/umakesite.pas @@ -585,12 +585,17 @@ begin //search existing forms if AName <> '' then begin Result := Screen.FindForm(AName); - if Result <> nil then + if Result <> nil then begin + Result.Visible := True; //empty edit book? exit; //found it - //also search in our Owner + end; +{ +//also search in our Owner cmp := Owner.FindComponent(AName); if (Result <> nil) and (Result is TWinControl) then exit; + { TODO -oDoDi : why are not all existing forms found? } +} end; //check if Factory can provide the form if assigned(Factory) then begin @@ -607,6 +612,7 @@ begin Result := TForm.Create(fo); //named Form1, Form2... - not now??? end else begin //create new instance + //DebugLn('!!! create new: ', AName); {$IFDEF old} if fMultiInst then SplitName @@ -997,6 +1003,7 @@ begin (* Special connect to DockManager, and restore NoteBooks. *) if False then Result:=inherited ReloadDockedControl(AName); //asking DockSite (very bad idea) +{$IFDEF old} if assigned(DockMaster) then begin Result := DockMaster.ReloadDockedControl(AName, FDockSite); end else begin //application default - search Application or Screen? @@ -1004,6 +1011,11 @@ begin //if Result = nil then Result := 'T' + AName { TODO -cdocking : load form by name, or create from typename } end; +{$ELSE} + Result := Screen.FindForm(AName); + if (Result = nil) and assigned(DockMaster) then + Result := DockMaster.ReloadDockedControl(AName, FDockSite); +{$ENDIF} if Result <> nil then DebugLn('Reloaded %s.%s', [Result.Owner.Name, Result.Name]) else