DockedFormEditor: Hide tab "Code" when just code without form is edited

git-svn-id: trunk@64547 -
This commit is contained in:
michl 2021-02-12 00:28:02 +00:00
parent 018f2c310e
commit 7e625598d0
3 changed files with 74 additions and 59 deletions

View File

@ -197,7 +197,7 @@ var
begin
if ASourceEditor = nil then Exit;
LPageCtrl := SourceEditorWindows.FindModulePageControl(ASourceEditor);
LPageCtrl.PageIndex := 0;
LPageCtrl.ShowCode;
end;
procedure TDockedTabMaster.ShowDesigner(ASourceEditor: TSourceEditorInterface; AIndex: Integer);
@ -206,11 +206,7 @@ var
begin
if ASourceEditor = nil then Exit;
LPageCtrl := SourceEditorWindows.FindModulePageControl(ASourceEditor);
if (AIndex = 0) or not (LPageCtrl.Pages[AIndex].TabVisible) then
AIndex := 1;
if not LPageCtrl.Pages[AIndex].TabVisible then Exit;
LPageCtrl.PageIndex := AIndex;
LPageCtrl.OnChange(LPageCtrl);
LPageCtrl.ShowDesigner(AIndex);
end;
procedure TDockedTabMaster.ShowForm(AForm: TCustomForm);
@ -233,7 +229,7 @@ begin
LPageCtrl := SourceEditorWindows.FindModulePageControl(LastActiveSourceEditor);
LRefreshDesigner := Assigned(LPageCtrl) and (LPageCtrl.PageIndex in [1, 2]);
LPageIndex := LPageCtrl.PageIndex;
LPageCtrl.ShowAnchorPage;
LPageCtrl.CreateTabSheetAnchors;
DesignForms.RemoveAllAnchorDesigner;
@ -292,9 +288,9 @@ begin
if LPageCtrl <> nil then
begin
LPageCtrl.DesignForm := LDesignForm;
LPageCtrl.ShowDesignPage;
LPageCtrl.CreateTabSheetDesigner;
if LDesignForm.IsAnchorDesign then
LPageCtrl.ShowAnchorPage;
LPageCtrl.CreateTabSheetAnchors;
end;
end;
SetTimer(AForm.Handle, WM_SETNOFRAME, 10, nil);
@ -445,9 +441,9 @@ begin
else begin
if not Assigned(LPageCtrl.Resizer) then
LPageCtrl.CreateResizer;
LPageCtrl.ShowDesignPage;
LPageCtrl.CreateTabSheetDesigner;
if LDesignForm.IsAnchorDesign then
LPageCtrl.ShowAnchorPage;
LPageCtrl.CreateTabSheetAnchors;
end;
LSourceEditorWindowInterface := TSourceEditorWindowInterface(LPageCtrl.Owner);
@ -473,6 +469,7 @@ begin
SourceEditorWindows.SourceEditorWindow[LSourceEditorWindowInterface].ActiveDesignForm := nil;
end;
LPageCtrl.InitPage;
if (LPageCtrl.PageIndex in [1, 2]) then
begin
if not LDesignForm.Hiding then
@ -579,6 +576,7 @@ begin
LSourceEditorWindow := SourceEditorWindows.SourceEditorWindow[LActiveSourceWindowInterface];
if LSourceEditorWindow = nil then Exit;
LPageCtrl.InitPage;
if not (LPageCtrl.PageIndex in [1, 2]) then
LSourceEditorWindow.ActiveDesignForm := nil
else begin
@ -595,7 +593,6 @@ begin
LSourceEditorWindow.ActiveDesignForm := LDesignForm;
// enable autosizing after creating a new form
DockedTabMaster.EnableAutoSizing(LDesignForm.Form);
LPageCtrl.InitPage;
LPageCtrl.DesignerSetFocus;
end;
end;

View File

@ -35,6 +35,9 @@ type
TModulePageControl = class(TPageControl)
private
FTabSheetAnchors: TTabSheet;
FTabSheetCode: TTabSheet;
FTabSheetDesigner: TTabSheet;
FResizer: TResizer;
FDesignForm: TDesignForm;
procedure OnAdjustPage(Sender: TObject);
@ -45,12 +48,14 @@ type
destructor Destroy; override;
procedure AdjustPage;
procedure CreateResizer;
procedure CreateTabSheetAnchors;
procedure CreateTabSheetDesigner;
procedure DesignerSetFocus;
procedure HideDesignPages;
procedure InitPage;
procedure RefreshResizer;
procedure ShowAnchorPage;
procedure ShowDesignPage;
procedure ShowCode;
procedure ShowDesigner(AIndex: Integer = 0);
public
property DesignForm: TDesignForm read FDesignForm write SetDesignForm;
property Resizer: TResizer read FResizer;
@ -90,28 +95,17 @@ begin
end;
constructor TModulePageControl.Create(TheOwner: TComponent);
var
LNewTabSheet: TTabSheet;
begin
inherited Create(TheOwner);
FResizer := nil;
TabPosition := DockedOptions.TabPosition;
Align := alClient;
ShowTabs := False;
LNewTabSheet := TTabSheet.Create(Self);
LNewTabSheet.PageControl := Self;
LNewTabSheet.Caption := SCode;
LNewTabSheet := TTabSheet.Create(Self);
LNewTabSheet.PageControl := Self;
LNewTabSheet.Caption := SDesigner;
Pages[1].TabVisible := False;
LNewTabSheet := TTabSheet.Create(Self);
LNewTabSheet.PageControl := Self;
LNewTabSheet.Caption := SAnchors;
Pages[2].TabVisible := False;
FTabSheetCode := TTabSheet.Create(Self);
FTabSheetCode.PageControl := Self;
FTabSheetCode.Caption := SCode;
end;
destructor TModulePageControl.Destroy;
@ -132,7 +126,26 @@ begin
if Assigned(FResizer) then
raise Exception.Create('TModulePageControl.CreateResizer: Resizer already created');
FResizer := TResizer.Create(Self);
FResizer.Parent := Pages[1];
if not Assigned(FTabSheetDesigner) then
CreateTabSheetDesigner;
FResizer.Parent := FTabSheetDesigner;
end;
procedure TModulePageControl.CreateTabSheetAnchors;
begin
if not DockedOptions.AnchorTabVisible then Exit;
if Assigned(FTabSheetAnchors) then Exit;
FTabSheetAnchors := TTabSheet.Create(Self);
FTabSheetAnchors.PageControl := Self;
FTabSheetAnchors.Caption := SAnchors;
end;
procedure TModulePageControl.CreateTabSheetDesigner;
begin
if Assigned(FTabSheetDesigner) then Exit;
FTabSheetDesigner := TTabSheet.Create(Self);
FTabSheetDesigner.PageControl := Self;
FTabSheetDesigner.Caption := SDesigner;
end;
procedure TModulePageControl.DesignerSetFocus;
@ -142,33 +155,31 @@ end;
procedure TModulePageControl.HideDesignPages;
begin
Pages[1].TabVisible := False;
Pages[2].TabVisible := False;
FreeAndNil(FTabSheetAnchors);
FreeAndNil(FTabSheetDesigner);
end;
procedure TModulePageControl.InitPage;
begin
case PageIndex of
1:
begin
Resizer.Parent := Pages[1];
Resizer.ResizeFrame.PanelFormClient.Visible := True;
Resizer.ResizeFrame.PanelAnchorContainer.Visible := False;
end;
2:
begin
Resizer.Parent := Pages[2];
Resizer.ResizeFrame.PanelFormClient.Visible := False;
Resizer.ResizeFrame.PanelAnchorContainer.Visible := True;
if not Assigned(DesignForm.AnchorDesigner) then
begin
DesignForm.AnchorDesigner := TAnchorDesigner.Create(DesignForm, Resizer.ResizeFrame.PanelAnchorContainer);
DesignForm.AnchorDesigner.IsFocusedFunc := @Resizer.ResizeFrame.IsFocused;
DesignForm.AnchorDesigner.OnDesignerSetFocus := @DesignerSetFocus;
end;
DesignForm.AnchorDesigner.Refresh;
end;
else;
ShowTabs := PageCount > 1;
if ActivePage = FTabSheetDesigner then
begin
Resizer.Parent := FTabSheetDesigner;
Resizer.ResizeFrame.PanelFormClient.Visible := True;
Resizer.ResizeFrame.PanelAnchorContainer.Visible := False;
end
else if ActivePage = FTabSheetAnchors then
begin
Resizer.Parent := FTabSheetAnchors;
Resizer.ResizeFrame.PanelFormClient.Visible := False;
Resizer.ResizeFrame.PanelAnchorContainer.Visible := True;
if not Assigned(DesignForm.AnchorDesigner) then
begin
DesignForm.AnchorDesigner := TAnchorDesigner.Create(DesignForm, Resizer.ResizeFrame.PanelAnchorContainer);
DesignForm.AnchorDesigner.IsFocusedFunc := @Resizer.ResizeFrame.IsFocused;
DesignForm.AnchorDesigner.OnDesignerSetFocus := @DesignerSetFocus;
end;
DesignForm.AnchorDesigner.Refresh;
end;
end;
@ -179,14 +190,21 @@ begin
CreateResizer;
end;
procedure TModulePageControl.ShowAnchorPage;
procedure TModulePageControl.ShowCode;
begin
Pages[2].TabVisible := DockedOptions.AnchorTabVisible;
PageIndex := 0;
InitPage;
end;
procedure TModulePageControl.ShowDesignPage;
procedure TModulePageControl.ShowDesigner(AIndex: Integer);
begin
Pages[1].TabVisible := True;
if (AIndex = 0) or not (Pages[AIndex].TabVisible) then
AIndex := 1;
if PageCount <= AIndex then Exit;
if not Pages[AIndex].TabVisible then Exit;
PageIndex := AIndex;
InitPage;
OnChange(Self);
end;
end.

View File

@ -275,9 +275,9 @@ begin
then
LPageCtrl.HideDesignPages
else begin
LPageCtrl.ShowDesignPage;
LPageCtrl.CreateTabSheetDesigner;
if not (LPageCtrl.DesignForm.Form is TNonControlProxyDesignerForm) then
LPageCtrl.ShowAnchorPage;
LPageCtrl.CreateTabSheetAnchors;
end;
end;
end;