2
(* EditorSite by DoDi <DrDiettrich1@aol.com>
3
Mimics an Delphi editor window, that allows to dock other windows to it,
4
with several extensions:
5
- optionally enlarging the window
6
- detach a page into a new editor window
7
- move a page into a different editor window
10
Some quirks should be handled properly in a true IDE implementation:
12
For simplicity an IDE main menu has been added to the main window,
13
that allows to create several project (View) window dummies,
14
which can be docked to each other, or to the editor window.
16
Mixed docking of editor pages and View windows (currently) is not blocked,
17
so that you can have multiple edit views within the editor window.
19
Secondary editor windows should have the same docking capabilities.
23
- The IDE suspects dangling references - KEEP these references!
24
Please report if you know how to fix this issue.
26
+ Problems with non-form project windows.
27
Since the IDE windows are all forms, we only handle this case now.
32
{$DEFINE minimize} //test application minimize/restore
37
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
38
ExtCtrls, ComCtrls, Menus,
44
//TEditorSite = class(TDockingSite)
45
TEditorSite = class(TForm)
46
MenuItem10: TMenuItem;
47
MenuItem11: TMenuItem;
48
MenuItem12: TMenuItem;
49
MenuItem13: TMenuItem;
50
MenuItem14: TMenuItem;
52
mnMinimize: TMenuItem;
53
mnWindowDump: TMenuItem;
63
OpenDialog1: TOpenDialog;
69
procedure FormActivate(Sender: TObject);
70
procedure FormCreate(Sender: TObject);
71
procedure FormDeactivate(Sender: TObject);
72
procedure FormHide(Sender: TObject);
73
procedure FormResize(Sender: TObject);
74
procedure FormWindowStateChange(Sender: TObject);
75
procedure mnMinimizeClick(Sender: TObject);
76
procedure mnRestoreClick(Sender: TObject);
77
procedure mnWindowDumpClick(Sender: TObject);
78
procedure ViewMenuClick(Sender: TObject);
79
procedure mnExitClick(Sender: TObject);
80
procedure mnOpenClick(Sender: TObject);
82
FEdit: TEditBook; //to become a frame!
85
function CreateDockable(const cap: string): TWinControl;
86
function OpenFile(const FileName: string): TObject;
90
EditorSite: TEditorSite;
102
procedure TEditorSite.FormCreate(Sender: TObject);
104
(* EditBook should be a frame!
106
FEdit := TEditBook.Create(self);
107
FEdit.Align := alClient;
108
FEdit.BorderStyle := bsNone;
109
FEdit.Parent := self;
110
FEdit.Visible := True;
111
FEdit.DragMode := dmManual; //disallow undocking
112
FEdit.StayDocked := True;
115
function TEditorSite.CreateDockable(const cap: string): TWinControl;
120
(* Create a client form, and dock it into a floating dock host site.
121
We must force docking here, later the client will dock itself into
122
a float host site, when it becomes floating.
125
Client := TViewWindow.Create(Application);
126
Client.Label1.Caption := cap;
127
Client.Visible := True;
129
Client.Caption := cap;
131
Client.Name := StringReplace(cap, ' ', '', [rfReplaceAll]);
133
//here: simply ignore duplicate name
135
//Client.FloatingDockSiteClass := TFloatingSite;
136
Site := TFloatingSite.Create(Application);
137
Client.ManualDock(Site, nil, alClient);
142
procedure TEditorSite.ViewMenuClick(Sender: TObject);
144
item: TMenuItem absolute Sender;
146
(* Create a dummy window from the menu item name.
148
CreateDockable(item.Caption);
151
function TEditorSite.OpenFile(const FileName: string): TObject;
153
//todo: load the file
154
CurEdit := TEditPage.Create(self);
155
CurEdit.LoadFile(FileName);
156
CurEdit.ManualDock(FEdit);
158
Result := CurEdit; //or what?
161
procedure TEditorSite.mnOpenClick(Sender: TObject);
163
if OpenDialog1.Execute then begin
164
OpenFile(OpenDialog1.FileName);
168
procedure TEditorSite.mnExitClick(Sender: TObject);
174
// ----------- application window handling -------------
176
procedure TEditorSite.FormActivate(Sender: TObject);
178
//DebugLn('--- Activate');
181
procedure TEditorSite.FormDeactivate(Sender: TObject);
183
//DebugLn('--- Deactivate');
186
procedure TEditorSite.FormHide(Sender: TObject);
188
//DebugLn('--- FormHide'); //not when minimized manually (win32)
189
//mnMinimizeClick(Sender);
192
procedure TEditorSite.FormResize(Sender: TObject);
194
//DebugLn('--- Resize');
197
procedure TEditorSite.FormWindowStateChange(Sender: TObject);
200
//test manual Hide/Show
206
procedure TEditorSite.mnMinimizeClick(Sender: TObject);
212
for i := 0 to Screen.FormCount - 1 do begin
213
f := Screen.Forms[i];
214
//if f = self then f.WindowState := wsMinimized else
215
if (f <> self) and f.Visible and (f.WindowState = wsNormal) then begin
216
//both changes together crash on Linux/gtk2 :-(
218
//f.WindowState := wsMinimized;
225
procedure TEditorSite.mnRestoreClick(Sender: TObject);
231
for i := 0 to Screen.FormCount - 1 do begin
232
f := Screen.Forms[i];
233
//if f = self then f.WindowState := wsMinimized else
234
if not f.Visible and (f.WindowState = wsNormal) then begin
235
//both changes together crash on Linux/gtk2 :-(
237
//f.WindowState := wsNormal;
244
procedure TEditorSite.mnWindowDumpClick(Sender: TObject);
250
DebugLn('--- CustomForms ---');
251
for i := 0 to Screen.CustomFormCount - 1 do begin
252
f := Screen.CustomForms[i];
254
while f.HostDockSite <> nil do begin
256
s := s + ' in ' + f.Name;
260
{ Seems to be the same list
262
DebugLn('--- Forms ---');
263
for i := 0 to Screen.FormCount - 1 do begin
264
f := Screen.Forms[i];
266
while f.Parent <> nil do begin
268
s := s + ' in ' + f.Name;