You've already forked lazarus-ccr
manualdock: code cleanup
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1202 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -36,9 +36,9 @@ type
|
|||||||
|
|
||||||
TManualDocker = class(TObject)
|
TManualDocker = class(TObject)
|
||||||
private
|
private
|
||||||
FCurrentSrcWin: TWinControl;
|
FCurrentSrcWin : TWinControl;
|
||||||
protected
|
protected
|
||||||
procedure ChangeDocking(DockingEnabled: Boolean);
|
function DoChangeDocking(DockingEnabled: Boolean): Boolean;
|
||||||
procedure LoadState(cfg: TXMLConfig; var Astate: TDockState; const StateName: string);
|
procedure LoadState(cfg: TXMLConfig; var Astate: TDockState; const StateName: string);
|
||||||
procedure SaveState(cfg: TXMLConfig; const Astate: TDockState; const StateName: string);
|
procedure SaveState(cfg: TXMLConfig; const Astate: TDockState; const StateName: string);
|
||||||
procedure LoadStates;
|
procedure LoadStates;
|
||||||
@ -88,11 +88,12 @@ begin
|
|||||||
else Result := b;
|
else Result := b;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TManualDocker.ChangeDocking(DockingEnabled: Boolean);
|
function TManualDocker.DoChangeDocking(DockingEnabled:Boolean):Boolean;
|
||||||
var
|
var
|
||||||
i : Integer;
|
i : Integer;
|
||||||
begin
|
begin
|
||||||
if DockingEnabled then begin
|
if DockingEnabled then begin
|
||||||
|
Result:=False;
|
||||||
if not (Assigned(SourceEditorManagerIntf) and Assigned(SourceEditorManagerIntf.ActiveSourceWindow))
|
if not (Assigned(SourceEditorManagerIntf) and Assigned(SourceEditorManagerIntf.ActiveSourceWindow))
|
||||||
or not Assigned(IDEMessagesWindow)
|
or not Assigned(IDEMessagesWindow)
|
||||||
then Exit;
|
then Exit;
|
||||||
@ -100,8 +101,10 @@ begin
|
|||||||
if not Assigned(panel) then
|
if not Assigned(panel) then
|
||||||
AllocControls(SourceEditorManagerIntf.ActiveSourceWindow);
|
AllocControls(SourceEditorManagerIntf.ActiveSourceWindow);
|
||||||
|
|
||||||
if panel.Parent <> SourceEditorManagerIntf.ActiveSourceWindow then
|
if panel.Parent <> SourceEditorManagerIntf.ActiveSourceWindow then begin
|
||||||
|
split.Parent:=SourceEditorManagerIntf.ActiveSourceWindow;
|
||||||
panel.Parent:=SourceEditorManagerIntf.ActiveSourceWindow;
|
panel.Parent:=SourceEditorManagerIntf.ActiveSourceWindow;
|
||||||
|
end;
|
||||||
|
|
||||||
split.visible:=true;
|
split.visible:=true;
|
||||||
panel.visible:=true;
|
panel.visible:=true;
|
||||||
@ -113,17 +116,18 @@ begin
|
|||||||
IDEMessagesWindow.Parent := panel;
|
IDEMessagesWindow.Parent := panel;
|
||||||
IDEMessagesWindow.Align := alClient;
|
IDEMessagesWindow.Align := alClient;
|
||||||
IDEMessagesWindow.BorderStyle := bsNone;
|
IDEMessagesWindow.BorderStyle := bsNone;
|
||||||
IDEMessagesWindow.TabStop := false;
|
IDEMessagesWindow.TabStop := False;
|
||||||
for i := 0 to IDEMessagesWindow.ControlCount - 1 do
|
for i := 0 to IDEMessagesWindow.ControlCount - 1 do
|
||||||
if IDEMessagesWindow.Controls[i] is TWinControl then
|
if IDEMessagesWindow.Controls[i] is TWinControl then
|
||||||
TWinControl(IDEMessagesWindow.Controls[i]).TabStop := false;
|
TWinControl(IDEMessagesWindow.Controls[i]).TabStop := False;
|
||||||
panel.Height := MsgWnd.DockSize.cy;
|
panel.Height := MsgWnd.DockSize.cy;
|
||||||
|
Result:=True;
|
||||||
end else begin
|
end else begin
|
||||||
if Assigned(panel) then begin
|
if Assigned(panel) then begin
|
||||||
panel.visible := false;
|
panel.visible := False;
|
||||||
UpdateDockState(MsgWnd, panel);
|
UpdateDockState(MsgWnd, panel);
|
||||||
end;
|
end;
|
||||||
if Assigned(split) then split.visible := false;
|
if Assigned(split) then split.visible := False;
|
||||||
IDEMessagesWindow.Parent := nil;
|
IDEMessagesWindow.Parent := nil;
|
||||||
with MsgWnd do begin
|
with MsgWnd do begin
|
||||||
IDEMessagesWindow.BoundsRect := SafeRect(FloatRect,
|
IDEMessagesWindow.BoundsRect := SafeRect(FloatRect,
|
||||||
@ -132,9 +136,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
IDEMessagesWindow.TabStop := true;
|
IDEMessagesWindow.TabStop := true;
|
||||||
IDEMessagesWindow.Show;
|
IDEMessagesWindow.Show;
|
||||||
|
|
||||||
|
{undocking is always succesfull}
|
||||||
|
Result:=True;
|
||||||
end;
|
end;
|
||||||
MsgWnd.docked := DockingEnabled;
|
|
||||||
cmd.Checked := DockingEnabled;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TManualDocker.Create;
|
constructor TManualDocker.Create;
|
||||||
@ -169,13 +174,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TManualDocker.OnCmdClick(Sender: TObject);
|
procedure TManualDocker.OnCmdClick(Sender: TObject);
|
||||||
|
var
|
||||||
|
NeedDocking: Boolean;
|
||||||
begin
|
begin
|
||||||
ChangeDocking(not Cmd.Checked );
|
NeedDocking:=not Cmd.Checked;
|
||||||
|
DoChangeDocking(NeedDocking);
|
||||||
|
MsgWnd.docked:=NeedDocking;
|
||||||
|
cmd.Checked:=NeedDocking;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TManualDocker.OnProjectOpen(Sender: TObject; AProject: TLazProject): TModalResult;
|
function TManualDocker.OnProjectOpen(Sender: TObject; AProject: TLazProject): TModalResult;
|
||||||
begin
|
begin
|
||||||
if MsgWnd.Docked then ChangeDocking(true);
|
DoChangeDocking(MsgWnd.Docked);
|
||||||
Result := mrOK;
|
Result := mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -223,35 +233,27 @@ procedure TManualDocker.SourceWindowCreated(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
if Assigned(FCurrentSrcWin) or (SourceEditorManagerIntf.SourceWindowCount > 1) then
|
if Assigned(FCurrentSrcWin) or (SourceEditorManagerIntf.SourceWindowCount > 1) then
|
||||||
Exit;
|
Exit;
|
||||||
if MsgWnd.Docked then
|
if MsgWnd.Docked then DoChangeDocking(true);
|
||||||
ChangeDocking(true);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TManualDocker.SourceWindowDestroyed(Sender: TObject);
|
procedure TManualDocker.SourceWindowDestroyed(Sender: TObject);
|
||||||
var
|
var
|
||||||
IsDocked: Boolean;
|
|
||||||
i : Integer;
|
i : Integer;
|
||||||
begin
|
begin
|
||||||
IsDocked := MsgWnd.docked;
|
|
||||||
if FCurrentSrcWin <> Sender then Exit;
|
if FCurrentSrcWin <> Sender then Exit;
|
||||||
if IsDocked then ChangeDocking(False);
|
DoChangeDocking(False);
|
||||||
DeallocControls;
|
DeallocControls;
|
||||||
FCurrentSrcWin := nil;
|
FCurrentSrcWin := nil;
|
||||||
|
|
||||||
if IsDocked then begin
|
// avoid re-docking to the window being destroyed
|
||||||
for i:=0 to SourceEditorManagerIntf.SourceWindowCount-1 do
|
if MsgWnd.Docked and (SourceEditorManagerIntf.ActiveSourceWindow<>Sender) then
|
||||||
if SourceEditorManagerIntf.SourceWindows[i]<>Sender then begin
|
DoChangeDocking(True);
|
||||||
// any window is dockable!
|
|
||||||
ChangeDocking(True);
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TManualDocker.LoadState(cfg: TXMLConfig; var Astate: TDockState;
|
procedure TManualDocker.LoadState(cfg: TXMLConfig; var Astate: TDockState;
|
||||||
const StateName: string);
|
const StateName: string);
|
||||||
begin
|
begin
|
||||||
AState.docked := cfg.GetValue(StateName+'/docked', false);
|
AState.Docked := cfg.GetValue(StateName+'/docked', False);
|
||||||
AState.FloatRect.Left := cfg.GetValue(StateName+'/float/left', -1);
|
AState.FloatRect.Left := cfg.GetValue(StateName+'/float/left', -1);
|
||||||
AState.FloatRect.Top := cfg.GetValue(StateName+'/float/top', -1);
|
AState.FloatRect.Top := cfg.GetValue(StateName+'/float/top', -1);
|
||||||
AState.FloatRect.Right := cfg.GetValue(StateName+'/float/right', -1);
|
AState.FloatRect.Right := cfg.GetValue(StateName+'/float/right', -1);
|
||||||
@ -262,7 +264,7 @@ end;
|
|||||||
|
|
||||||
procedure TManualDocker.SaveState(cfg: TXMLConfig; const Astate: TDockState; const StateName: string);
|
procedure TManualDocker.SaveState(cfg: TXMLConfig; const Astate: TDockState; const StateName: string);
|
||||||
begin
|
begin
|
||||||
cfg.SetValue(StateName+'/docked', AState.docked);
|
cfg.SetValue(StateName+'/docked', AState.Docked);
|
||||||
cfg.SetValue(StateName+'/float/left', AState.FloatRect.Left);
|
cfg.SetValue(StateName+'/float/left', AState.FloatRect.Left);
|
||||||
cfg.SetValue(StateName+'/float/top', AState.FloatRect.Top);
|
cfg.SetValue(StateName+'/float/top', AState.FloatRect.Top);
|
||||||
cfg.SetValue(StateName+'/float/right', AState.FloatRect.Right);
|
cfg.SetValue(StateName+'/float/right', AState.FloatRect.Right);
|
||||||
@ -302,7 +304,7 @@ procedure Register;
|
|||||||
begin
|
begin
|
||||||
docker := TManualDocker.Create;
|
docker := TManualDocker.Create;
|
||||||
cmd := RegisterIDEMenuCommand(itmViewMainWindows, 'makeMessagesDocked', mnuDockMsgWindow, @docker.OnCmdClick, nil, nil, '');
|
cmd := RegisterIDEMenuCommand(itmViewMainWindows, 'makeMessagesDocked', mnuDockMsgWindow, @docker.OnCmdClick, nil, nil, '');
|
||||||
LazarusIDE.AddHandlerOnProjectOpened(@docker.OnProjectOpen, false);
|
LazarusIDE.AddHandlerOnProjectOpened(@docker.OnProjectOpen, False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
Reference in New Issue
Block a user