Changeset 248 for Docking


Ignore:
Timestamp:
May 26, 2011, 3:06:47 PM (14 years ago)
Author:
george
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/Managers/UCDManagerTabs.pas

    r244 r248  
    1616  TCDManagerTabsItem = class(TCDManagerItem)
    1717    IconImage: TImage;
     18    TabSheet: TTabSheet;
    1819    constructor Create; override;
    1920    destructor Destroy; override;
     
    3839    function FindControlInPanels(Control: TControl): TCDManagerItem; override;
    3940    function GetHeaderPos: THeaderPos; override;
     41    function FindTabSheet(TabSheet: TTabSheet): TCDManagerTabsItem;
    4042  public
    4143    MouseDownSkip: Boolean;
     
    263265  end; //else raise Exception.Create(Format('Control %s not found in DockItems', [Control.Name]));
    264266
     267  ManagerItem.Control.Visible := False;
     268  ManagerItem.Control.Parent := nil;
    265269  DockItems.Remove(ManagerItem);
    266270  ClientCount := DockItems.Count;
     
    291295end;
    292296
     297function TCDManagerTabs.FindTabSheet(TabSheet: TTabSheet): TCDManagerTabsItem;
     298var
     299  I: Integer;
     300begin
     301  I := 0;
     302  while (I < FDockItems.Count) and
     303    (TCDManagerTabsItem(FDockItems[I]).TabSheet <> TabSheet) do Inc(I);
     304  if I < FDockItems.Count then Result := TCDManagerTabsItem(FDockItems[I])
     305    else Result := nil;
     306end;
     307
    293308procedure TCDManagerTabs.SetHeaderPos(const AValue: THeaderPos);
    294309begin
     
    343358  end;
    344359
    345   while PageControl.PageList.Count > DockItems.Count do begin
     360  // Remove old existed tabs which doesn't have item associated
     361  for I := PageControl.PageList.Count - 1 downto 0 do begin
    346362//    TCDManagerTabsItem(DockItems[DockItems.Count - 1]).Control.Visible := False;
    347363//    TCDManagerTabsItem(DockItems[DockItems.Count - 1]).Control.Parent := nil;
    348364
    349     PageControl.OnChange := nil;
    350     DeletedPage := PageControl.Pages[PageControl.PageCount - 1];
    351     DeletedPage.Parent := nil;
    352     PageControl.OnChange := TabControlChange;
    353     DeletedPage.Free;
    354     TabImageList.Delete(TabImageList.Count - 1);
    355   end;
    356   while PageControl.PageList.Count < DockItems.Count do begin
    357     NewTabSheet := TTabSheet.Create(PageControl);
    358     NewTabSheet.PageControl := PageControl;
    359     TabImageList.Add(TCDManagerTabsItem(DockItems[PageControl.PageList.Count - 1]).IconImage.Picture.Bitmap, nil);
     365    if FindTabSheet(TTabSheet(PageControl.PageList[I])) = nil then begin
     366      PageControl.OnChange := nil;
     367      DeletedPage := PageControl.Pages[I];
     368      DeletedPage.Parent := nil;
     369      PageControl.OnChange := TabControlChange;
     370      DeletedPage.Free;
     371      TabImageList.Delete(I);
     372    end;
     373  end;
     374
     375  // Create tabs for new items
     376  for I := 0 to DockItems.Count - 1 do
     377  with TCDManagerTabsItem(DockItems[I]) do begin
     378    if not Assigned(TabSheet) then begin
     379      NewTabSheet := TTabSheet.Create(PageControl);
     380      NewTabSheet.PageControl := PageControl;
     381      TabSheet := NewTabSheet;
     382      TabImageList.Add(IconImage.Picture.Bitmap, nil);
     383    end;
    360384  end;
    361385
Note: See TracChangeset for help on using the changeset viewer.