mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-26 13:08:39 +02:00
Cocoa/TabControl: exttabRemoveTabViewItem() refactored
This commit is contained in:
parent
cbb27a8f6d
commit
c34f708ae4
@ -868,50 +868,21 @@ begin
|
||||
removedIndex := exttabIndexOfTabViewItem( removedTabPage );
|
||||
isRemovingCurrentPage:= (removedIndex=currentIndex);
|
||||
|
||||
if fulltabs.count=1 then begin
|
||||
// there is only one Page, so must be removing current Page,
|
||||
// the selectedItem must be lost
|
||||
fulltabs.removeObjectAtIndex( removedIndex );
|
||||
removeTabViewItem( removedTabPage );
|
||||
end else if isRemovingCurrentPage then begin
|
||||
// removing current Page, and there is at least one other Page.
|
||||
// to keep the Page position stable and reduce selection changed events:
|
||||
// 1. if the current page is on the rightmost of the visible TabView,
|
||||
// try add the Next Page to the visible TabView first
|
||||
// 2. then look at the TabView again and if it still only has one page,
|
||||
// that means there is no Next Page, then there must be a prev Page,
|
||||
// insert it into the TabView
|
||||
// 3. if there is the next Page, select it, thne removedPage will be auto
|
||||
// removed in UpdateTabAndArrowVisibility(), otherwise remove the
|
||||
// removedPage directly, and the prev Page will be auto selected.
|
||||
// 4. finally remove the Page to be removed in fulltabs
|
||||
if currentIndex < fulltabs.count-1 then
|
||||
nextTabPage:= NSTabViewItem( fulltabs.objectAtIndex(currentIndex+1) )
|
||||
else
|
||||
nextTabPage:= nil;
|
||||
if (currentIndex=visibleRightIndex) and Assigned(nextTabPage) then begin // 1
|
||||
addTabViewItem( nextTabPage );
|
||||
inc( visibleRightIndex );
|
||||
end;
|
||||
if numberOfTabViewItems=1 then begin // 2
|
||||
prevTabPage:= NSTabViewItem( fulltabs.objectAtIndex(currentIndex-1) );
|
||||
insertTabViewItem_atIndex( prevTabPage, 0 );
|
||||
end;
|
||||
if Assigned(nextTabPage) then begin // 3
|
||||
selectTabViewItem( nextTabPage );
|
||||
end else begin
|
||||
removeTabViewItem( removedTabPage );
|
||||
end;
|
||||
fulltabs.removeObjectAtIndex( removedIndex ); // 4
|
||||
if removedIndex <= currentIndex then begin
|
||||
fulltabs.removeObjectAtIndex( removedIndex );
|
||||
|
||||
if isRemovingCurrentPage then begin
|
||||
// removing current page
|
||||
attachAllTabs;
|
||||
if currentIndex = fulltabs.count then begin
|
||||
dec( currentIndex );
|
||||
dec( leftKeepAmount );
|
||||
removeTabViewItem( removedTabPage );
|
||||
end else begin
|
||||
selectTabViewItemAtIndex( currentIndex );
|
||||
end;
|
||||
end else begin
|
||||
// not removing current page
|
||||
// only fulltabs need to be changed,
|
||||
// visible TabView auto updated in UpdateTabAndArrowVisibility()
|
||||
fulltabs.removeObjectAtIndex( removedIndex );
|
||||
if removedIndex < currentIndex then begin
|
||||
dec( currentIndex );
|
||||
if (removedIndex=visibleLeftIndex) and (removedIndex=currentIndex) then
|
||||
|
Loading…
Reference in New Issue
Block a user