IDE: Fix regression caused by r49802 #bf21367723 related to old window positions. Issues #28732,#28754.

git-svn-id: trunk@49938 -
This commit is contained in:
juha 2015-10-05 13:55:15 +00:00
parent 4c2b9176c0
commit d9ace5ff7b
2 changed files with 36 additions and 25 deletions

View File

@ -213,12 +213,15 @@ type
FDefaultWidth: integer; FDefaultWidth: integer;
FDefaultHeight: integer; FDefaultHeight: integer;
FWindowState: TIDEWindowState; FWindowState: TIDEWindowState;
FForm: TCustomForm;
FFormID: string; FFormID: string;
FDefaultWindowPlacement: TIDEWindowPlacement; FDefaultWindowPlacement: TIDEWindowPlacement;
FDividers: TSimpleWindowLayoutDividerPosList; FDividers: TSimpleWindowLayoutDividerPosList;
function GetForm: TCustomForm; procedure SetForm(const AForm: TCustomForm);
function GetFormCaption: string; function GetFormCaption: string;
procedure OnFormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction); procedure OnFormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public public
constructor Create(AFormID: string); reintroduce; constructor Create(AFormID: string); reintroduce;
destructor Destroy; override; destructor Destroy; override;
@ -235,7 +238,6 @@ type
function CustomCoordinatesAreValid: boolean; function CustomCoordinatesAreValid: boolean;
function DefaultCoordinatesAreValid: boolean; function DefaultCoordinatesAreValid: boolean;
procedure CloseForm; procedure CloseForm;
procedure SetForm(const AForm: TCustomForm);
function ValidateAndSetCoordinates(const aForce: Boolean = False): Boolean; function ValidateAndSetCoordinates(const aForce: Boolean = False): Boolean;
procedure SetDefaultPosition(const AForm: TCustomForm); procedure SetDefaultPosition(const AForm: TCustomForm);
public public
@ -254,7 +256,7 @@ type
property DefaultWidth: integer read FDefaultWidth write FDefaultWidth; property DefaultWidth: integer read FDefaultWidth write FDefaultWidth;
property DefaultHeight: integer read FDefaultHeight write FDefaultHeight; property DefaultHeight: integer read FDefaultHeight write FDefaultHeight;
property WindowState: TIDEWindowState read FWindowState write FWindowState; property WindowState: TIDEWindowState read FWindowState write FWindowState;
property Form: TCustomForm read GetForm; property Form: TCustomForm read FForm write SetForm;
property Visible: boolean read FVisible write FVisible; property Visible: boolean read FVisible write FVisible;
property Applied: boolean read FApplied write FApplied; property Applied: boolean read FApplied write FApplied;
property Dividers: TSimpleWindowLayoutDividerPosList read FDividers; property Dividers: TSimpleWindowLayoutDividerPosList read FDividers;
@ -1182,6 +1184,7 @@ end;
destructor TSimpleWindowLayout.Destroy; destructor TSimpleWindowLayout.Destroy;
begin begin
Form:=nil;
inherited Destroy; inherited Destroy;
FDividers.Free; FDividers.Free;
end; end;
@ -1220,6 +1223,18 @@ begin
FDividers.LoadFromConfig(Config, P + 'Divider/'); FDividers.LoadFromConfig(Config, P + 'Divider/');
end; end;
procedure TSimpleWindowLayout.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation=opRemove then begin
if fForm=AComponent then begin
fForm:=nil;
Applied:=false;
end;
end;
end;
procedure TSimpleWindowLayout.SaveToConfig(Config: TConfigStorage; procedure TSimpleWindowLayout.SaveToConfig(Config: TConfigStorage;
const Path: string); const Path: string);
var var
@ -1352,11 +1367,20 @@ end;
procedure TSimpleWindowLayout.SetForm(const AForm: TCustomForm); procedure TSimpleWindowLayout.SetForm(const AForm: TCustomForm);
begin begin
if Assigned(AForm) then if fForm=AForm then exit;
if Assigned(Form) then
begin begin
fFormID := AForm.Name; RemoveFreeNotification(Form);
FFormCaption := AForm.Caption; Form.RemoveHandlerClose(@OnFormClose);
AForm.AddHandlerClose(@OnFormClose); end;
fForm:=AForm;
if Assigned(Form) then
begin
Assert(Form.Name <> '');
fFormID := Form.Name;
FFormCaption := Form.Caption;
FreeNotification(Form);
Form.AddHandlerClose(@OnFormClose);
Applied:=false; Applied:=false;
end; end;
end; end;
@ -1483,19 +1507,6 @@ begin
//debugln('TSimpleWindowLayout.GetCurrentPosition ',DbgSName(Self),' ',FormID,' Width=',dbgs(Width)); //debugln('TSimpleWindowLayout.GetCurrentPosition ',DbgSName(Self),' ',FormID,' Width=',dbgs(Width));
end; end;
function TSimpleWindowLayout.GetForm: TCustomForm;
var
I: Integer;
begin
for I := 0 to Screen.CustomFormCount-1 do
if Screen.CustomForms[I].Name = FFormID then
begin
Result := Screen.CustomForms[I];
Exit;
end;
Result := nil;
end;
function TSimpleWindowLayout.Apply(const aForce: Boolean): Boolean; function TSimpleWindowLayout.Apply(const aForce: Boolean): Boolean;
var var
xForm: TCustomForm; xForm: TCustomForm;
@ -1745,7 +1756,7 @@ begin
ALayout:=ItemByFormID(AForm.Name); ALayout:=ItemByFormID(AForm.Name);
if ALayout<>nil then if ALayout<>nil then
begin begin
ALayout.SetForm(AForm); ALayout.Form:=AForm;
if ALayout.Applied then exit; if ALayout.Applied then exit;
if ALayout.Apply then exit; if ALayout.Apply then exit;
end; end;
@ -1898,7 +1909,7 @@ begin
SelfI := IndexOf(SrcList[SrcI].FormID); SelfI := IndexOf(SrcList[SrcI].FormID);
if SelfI < 0 then if SelfI < 0 then
SelfI := Self.Add(TSimpleWindowLayout.Create(SrcList[SrcI].FormID));//not found, create SelfI := Self.Add(TSimpleWindowLayout.Create(SrcList[SrcI].FormID));//not found, create
Self.fItems.Move(SelfI, SrcI);//move it to right position Self.fItems.Move(SelfI, Min(SrcI, Self.Count-1));//move it to right position
SelfI := SrcI; SelfI := SrcI;
Self.Items[SelfI].Assign(SrcList[SrcI]) Self.Items[SelfI].Assign(SrcList[SrcI])
end; end;
@ -1926,7 +1937,7 @@ function TSimpleWindowLayoutList.CreateWindowLayout(const TheForm: TCustomForm
): TSimpleWindowLayout; ): TSimpleWindowLayout;
begin begin
Result:=CreateWindowLayout(TheForm.Name); Result:=CreateWindowLayout(TheForm.Name);
Result.SetForm(TheForm); Result.Form:=TheForm;
end; end;
{ TIDEWindowCreator } { TIDEWindowCreator }
@ -2275,7 +2286,7 @@ begin
SimpleLayoutStorage.CreateWindowLayout(AForm); SimpleLayoutStorage.CreateWindowLayout(AForm);
end end
else else
Layout.SetForm(AForm); Layout.Form:=AForm;
if (IDEDockMaster<>nil) and (not (csDesigning in AForm.ComponentState)) if (IDEDockMaster<>nil) and (not (csDesigning in AForm.ComponentState))
and (FindWithName(AForm.Name)<>nil) then and (FindWithName(AForm.Name)<>nil) then

View File

@ -6941,7 +6941,7 @@ begin
// => disconnect first // => disconnect first
Layout:=IDEWindowCreators.SimpleLayoutStorage.ItemByForm(Self); Layout:=IDEWindowCreators.SimpleLayoutStorage.ItemByForm(Self);
if Layout<>nil then if Layout<>nil then
Layout.SetForm(nil); Layout.Form:=nil;
Name := Name + '___' + IntToStr({%H-}PtrUInt(Pointer(Self))); Name := Name + '___' + IntToStr({%H-}PtrUInt(Pointer(Self)));
CloseAction := caFree; CloseAction := caFree;
end end