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
commit bfb356fd6c
Notes: sideshowbarker 2024-07-16 23:34:49 +09:00
3 changed files with 23 additions and 0 deletions

View file

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

View file

@ -35,6 +35,7 @@
} }
@property (nonatomic, strong) NSMutableArray<TabController*>* managed_tabs; @property (nonatomic, strong) NSMutableArray<TabController*>* managed_tabs;
@property (nonatomic, strong) Tab* active_tab;
@property (nonatomic, strong) TaskManagerController* task_manager_controller; @property (nonatomic, strong) TaskManagerController* task_manager_controller;
@ -119,6 +120,16 @@
return controller; return controller;
} }
- (void)setActiveTab:(Tab*)tab
{
self.active_tab = tab;
}
- (Tab*)activeTab
{
return self.active_tab;
}
- (void)removeTab:(TabController*)controller - (void)removeTab:(TabController*)controller
{ {
[self.managed_tabs removeObject: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.window makeKeyAndOrderFront:sender];
[self focusLocationToolbarItem]; [self focusLocationToolbarItem];
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
[delegate setActiveTab:[self tab]];
} }
#pragma mark - NSWindowDelegate #pragma mark - NSWindowDelegate
- (void)windowDidBecomeMain:(NSNotification*)notification
{
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
[delegate setActiveTab:[self tab]];
}
- (void)windowWillClose:(NSNotification*)notification - (void)windowWillClose:(NSNotification*)notification
{ {
[[self tab] tabWillClose]; [[self tab] tabWillClose];