mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 04:49:29 +02:00
LCL: Figure out an unused name for a new Notebook page. Issue #36957.
This commit is contained in:
parent
a182389908
commit
7ce60d77d9
@ -69,16 +69,36 @@ end;
|
|||||||
function TUNBPages.AddObject(const S: string; AObject: TObject): Integer;
|
function TUNBPages.AddObject(const S: string; AObject: TObject): Integer;
|
||||||
var
|
var
|
||||||
NewPage: TPage;
|
NewPage: TPage;
|
||||||
|
NewName: string;
|
||||||
|
OK: Boolean;
|
||||||
|
i: integer;
|
||||||
begin
|
begin
|
||||||
Result := FPageList.Add(AObject);
|
Result := FPageList.Add(AObject);
|
||||||
NewPage := TPage(AObject);
|
NewPage := TPage(AObject);
|
||||||
if IsValidIdent(S) then NewPage.Name := S;
|
if IsValidIdent(S) then
|
||||||
|
begin
|
||||||
|
NewName := S;
|
||||||
|
i := 1;
|
||||||
|
repeat
|
||||||
|
OK := True;
|
||||||
|
try
|
||||||
|
NewPage.Name := NewName;
|
||||||
|
except // Name was reserved, try adding numbers to it.
|
||||||
|
on E: EComponentError do begin
|
||||||
|
OK := False;
|
||||||
|
NewName := S + IntToStr(i);
|
||||||
|
Inc(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
until OK;
|
||||||
|
end;
|
||||||
NewPage.Caption := S;
|
NewPage.Caption := S;
|
||||||
NewPage.Parent := FNotebook;
|
NewPage.Parent := FNotebook;
|
||||||
NewPage.Align := alClient;
|
NewPage.Align := alClient;
|
||||||
NewPage.Visible := False;
|
NewPage.Visible := False;
|
||||||
NewPage.ControlStyle := NewPage.ControlStyle + [csNoDesignVisible];
|
NewPage.ControlStyle := NewPage.ControlStyle + [csNoDesignVisible];
|
||||||
if FNotebook.PageIndex = -1 then FNotebook.SetPageIndex(Result);
|
if FNotebook.PageIndex = -1 then
|
||||||
|
FNotebook.SetPageIndex(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TUNBPages.Clear;
|
procedure TUNBPages.Clear;
|
||||||
@ -126,7 +146,8 @@ begin
|
|||||||
RaiseGDBException('TUNBPages.Insert Index out of bounds');
|
RaiseGDBException('TUNBPages.Insert Index out of bounds');
|
||||||
NewPage := TPage.Create(GetNotebookOwner);
|
NewPage := TPage.Create(GetNotebookOwner);
|
||||||
FPageList.Insert(Index, NewPage);
|
FPageList.Insert(Index, NewPage);
|
||||||
if IsValidIdent(S) then NewPage.Name := S;
|
if IsValidIdent(S) then
|
||||||
|
NewPage.Name := S;
|
||||||
NewPage.Caption := S;
|
NewPage.Caption := S;
|
||||||
NewPage.Parent := FNotebook;
|
NewPage.Parent := FNotebook;
|
||||||
NewPage.Align := alClient;
|
NewPage.Align := alClient;
|
||||||
@ -265,7 +286,8 @@ begin
|
|||||||
if Assigned(Items.Objects[Index]) then begin
|
if Assigned(Items.Objects[Index]) then begin
|
||||||
DummyDelete(Items[Index]);
|
DummyDelete(Items[Index]);
|
||||||
APage := TPage(Items.Objects[Index]);
|
APage := TPage(Items.Objects[Index]);
|
||||||
if IsValidIdent(Items[Index]) then APage.Name := Items[Index];
|
if IsValidIdent(Items[Index]) then
|
||||||
|
APage.Name := Items[Index];
|
||||||
APage.Caption := Items[Index];
|
APage.Caption := Items[Index];
|
||||||
APage.SetParent(Self);
|
APage.SetParent(Self);
|
||||||
DummyIndex := DummyPageList.IndexOf(APage);
|
DummyIndex := DummyPageList.IndexOf(APage);
|
||||||
|
Loading…
Reference in New Issue
Block a user