Ladybird/AppKit: Track the currently active tab

Will be needed to open new tabs from other Ladybird processes from the
active tab.
This commit is contained in:
Timothy Flynn 2024-04-28 12:29:31 -04:00 committed by Andrew Kaster
parent 7ad7ec3c0c
commit bfb356fd6c
3 changed files with 23 additions and 0 deletions

View file

@ -37,6 +37,9 @@
fromTab:(nullable Tab*)tab
activateTab:(Web::HTML::ActivateTab)activate_tab;
- (void)setActiveTab:(nonnull Tab*)tab;
- (nullable Tab*)activeTab;
- (void)removeTab:(nonnull TabController*)controller;
- (WebView::CookieJar&)cookieJar;

View file

@ -35,6 +35,7 @@
}
@property (nonatomic, strong) NSMutableArray<TabController*>* managed_tabs;
@property (nonatomic, strong) Tab* active_tab;
@property (nonatomic, strong) TaskManagerController* task_manager_controller;
@ -119,6 +120,16 @@
return controller;
}
- (void)setActiveTab:(Tab*)tab
{
self.active_tab = tab;
}
- (Tab*)activeTab
{
return self.active_tab;
}
- (void)removeTab:(TabController*)controller
{
[self.managed_tabs removeObject:controller];

View file

@ -520,10 +520,19 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
[self.window makeKeyAndOrderFront:sender];
[self focusLocationToolbarItem];
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
[delegate setActiveTab:[self tab]];
}
#pragma mark - NSWindowDelegate
- (void)windowDidBecomeMain:(NSNotification*)notification
{
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
[delegate setActiveTab:[self tab]];
}
- (void)windowWillClose:(NSNotification*)notification
{
[[self tab] tabWillClose];