Work on support for tabs

This commit is contained in:
anthony 2021-02-17 21:04:38 +00:00
parent 7513bf661c
commit 9194cde509
10 changed files with 161 additions and 16 deletions

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#import "NetsurfCallback.h"
#import "Website.h"
#import "BrowserWindowController.h"
#define TAG_MENU_REMOVE 206
#define TAG_MENU_CANCEL 204
@ -37,7 +38,8 @@ id historyWindowController;
id bookmarksWindowController;
id preferencesWindowController;
}
-(void)didTapNewWindow: (id)sender;
-(void)didTapNewTab: (id)sender;
-(void)showFindPanel: (id)sender;
-(void)showDownloadsWindow: (id)sender;
-(void)showHistoryWindow: (id)sender;
@ -46,4 +48,5 @@ id preferencesWindowController;
-(NSURL*)requestDownloadDestination;
-(void)openWebsite: (Website*)aWebsite;
-(NSString*)currentUrl;
-(BrowserWindowController*)activeBrowserWindow;
@end

View File

@ -132,6 +132,24 @@ static NSMenuItem *menuItemForItem(id item) {
}
}
-(void)didTapNewTab: (id)sender {
NSLog(@"Create new tab");
struct nsurl *url;
nserror error;
NSString *startupUrl = [[Preferences defaultPreferences] startupUrl];
error = nsurl_create([startupUrl cString], &url);
if (error == NSERROR_OK) {
error = browser_window_create(BW_CREATE_HISTORY | BW_CREATE_TAB, url,
NULL, NULL, NULL);
nsurl_unref(url);
}
if (error != NSERROR_OK) {
NSLog(@"Failed to create window");
}
}
-(void)showDownloadsWindow: (id)sender {
NSLog(@"Showing downloads ...");
if (!downloadsWindowController) {
@ -206,18 +224,24 @@ static NSMenuItem *menuItemForItem(id item) {
}
}
-(NSString*)currentUrl {
-(BrowserWindowController*)activeBrowserWindow {
NSArray *windows = [NSApp windows];
id controller;
for (NSUInteger i = 0; i < [windows count]; i++) {
controller = [[windows objectAtIndex: i] windowController];
if ([controller isKindOfClass: [BrowserWindowController class]]) {
return [controller visibleUrl];
return controller;
}
}
return nil;
}
-(NSString*)currentUrl {
return [[self activeBrowserWindow] visibleUrl];
}
@end
int main(int argc, char **argv) {
@ -250,4 +274,4 @@ int main(int argc, char **argv) {
[app run];
[pool release];
return 0;
}
}

View File

@ -10,14 +10,18 @@ struct browser_window;
id backButton;
id forwardButton;
id urlBar;
struct browser_window *browser;
id plotView;
id scrollView;
id tabView;
id refreshButton;
id caretView;
enum gui_pointer_shape lastRequestedPointer;
id searchBar;
id searchImage;
NSMutableArray *tabs;
// These three are set based on the currently focused tab.
id scrollView;
id plotView;
struct browser_window *browser;
}
-(id)initWithBrowser: (struct browser_window*)aBrowser;
@ -27,6 +31,7 @@ struct browser_window;
-(NSString*)visibleUrl;
-(void)enterSearch: (id)sender;
-(void)openWebsite: (Website*)aWebsite;
-(void)newTab: (struct browser_window*)aBrowser;
// Browser control
-(NSSize)getBrowserSize;

View File

@ -14,8 +14,38 @@
#import "Preferences.h"
#import "SearchProvider.h"
@interface TabContents: NSObject {
id scrollView;
id plotView;
struct browser_window *browser;
}
@end
@implementation TabContents
-(id)initWithScroll: (id)scroll plot: (id)plot browser: (struct browser_window *)brows {
if ((self = [super init])) {
scrollView = scroll;
plotView = plot;
browser = brows;
}
return self;
}
-(id)scrollView {
return scrollView;
}
-(id)plotView {
return plotView;
}
-(struct browser_window *)browser {
return browser;
}
@end
@interface BrowserWindowController (Private)
-(void)openUrlString: (NSString*)aUrlString;
-(void)addTab: (struct browser_window*)aBrowser;
-(void)removeTab: (struct browser_window*)aBrowser;
-(void)reconfigureTabLayout;
-(void)setActive: (TabContents*)tabContents;
@end
@implementation BrowserWindowController
@ -24,16 +54,26 @@
if ((self = [super initWithWindowNibName: @"Browser"])) {
browser = aBrowser;
lastRequestedPointer = 999;
tabs = [[NSMutableArray alloc] init];
}
return self;
}
-(void)dealloc {
[tabs release];
[super dealloc];
}
-(void)awakeFromNib {
[plotView setBrowser: browser];
[scrollView setLineScroll: 25];
[tabView removeTabViewItem: [tabView tabViewItemAtIndex: 0]];
[self addTab: browser];
NSLog(@"Browser window loaded");
}
-(void)newTab: (struct browser_window*)aBrowser {
[self addTab: aBrowser];
}
-(void)back: (id)sender {
NSLog(@"Browser backward");
[plotView back: sender];
@ -225,4 +265,60 @@
}
nsurl_unref(url);
}
// MARK: - TabViewDelegate
-(void)tabView: (NSTabView*)aTabView didSelectTabViewItem: (NSTabViewItem*)aTabViewItem {
NSLog(@"Selected tab");
NSInteger idx = [aTabView indexOfTabViewItem: aTabViewItem];
if (idx == NSNotFound || [tabs count] <= idx) {
NSLog(@"Tab not found...");
return;
}
TabContents *tc = [tabs objectAtIndex: idx];
[self setActive: tc];
}
-(void)addTab: (struct browser_window*)aBrowser {
NSString *identity = @"tab";
NSTabViewItem *tabItem = [[NSTabViewItem alloc] initWithIdentifier:
identity];
[tabItem setLabel: identity];
NSLog(@"TabView: %@", tabItem);
NSView *innerView = [tabItem view];
NSLog(@"Inner view: %@", innerView);
PlotView *newPlotView = [[PlotView alloc] initWithFrame: [innerView bounds]];
NSScrollView *newScrollView = [[NSScrollView alloc] initWithFrame: [innerView bounds]];
[newScrollView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[newScrollView setDocumentView: newPlotView];
[innerView addSubview: newScrollView];
[newPlotView setBrowser: aBrowser];
[newScrollView setLineScroll: 25];
NSInteger num = [tabView numberOfTabViewItems];
[tabView insertTabViewItem: tabItem atIndex: num];
[tabItem release];
TabContents *tc = [[TabContents alloc] initWithScroll: newScrollView plot:
newPlotView browser: aBrowser];
[self setActive: tc];
[tabs addObject: tc];
[tabView selectTabViewItem: tabItem];
[tc release];
[newPlotView release];
[newScrollView release];
}
-(void)removeTab: (struct browser_window*)aBrowser {
}
-(void)reconfigureTabLayout {
}
-(void)setActive: (TabContents*)tabContents {
plotView = [tabContents plotView];
scrollView = [tabContents scrollView];
browser = [tabContents browser];
}
@end

View File

@ -17,7 +17,8 @@
scrollView,
refreshButton,
searchImage,
searchBar
searchBar,
tabView
);
Super = NSWindowController;
};

View File

@ -7,7 +7,8 @@
"showFindPanel:",
"showHistoryWindow:",
"showBookmarksWindow:",
"showPreferencesWindow:"
"showPreferencesWindow:",
"didTapNewTab:"
);
Outlets = (
);
@ -19,7 +20,7 @@
"didTapNewWindow:",
"findNext:",
"findPrevious:",
"showPreferencesWindow:",
"didTapNewTab:",
"newFolder:",
"remove:",
"removeAll:",
@ -27,7 +28,8 @@
"showBookmarksWindow:",
"showDownloadsWindow:",
"showFindPanel:",
"showHistoryWindow:"
"showHistoryWindow:",
"showPreferencesWindow:"
);
Super = NSObject;
};

View File

@ -0,0 +1,6 @@
{
"fsn_info_type" = <*I0>;
iconposition = <*I5>;
iconsize = <*I48>;
labeltxtsize = <*I12>;
}

View File

@ -1,6 +1,8 @@
#import <Cocoa/Cocoa.h>
#import "AppDelegate.h"
#import "BrowserWindowController.h"
#import "netsurf/browser_window.h"
#import "netsurf/netsurf.h"
#import "netsurf/window.h"
#import "netsurf/types.h"
@ -16,10 +18,16 @@ static struct gui_window *gnustep_window_create(struct browser_window *bw,
struct gui_window *existing,
gui_window_create_flags flags) {
NSLog(@"gnustep_window_create");
BrowserWindowController *controller = [[BrowserWindowController alloc]
BrowserWindowController *controller = nil;
if (flags & BW_CREATE_TAB) {
controller = [[NSApp delegate] activeBrowserWindow];
[controller newTab: bw];
}
if (controller == nil) {
controller = [[BrowserWindowController alloc]
initWithBrowser: bw];
[controller loadWindow];
[controller loadWindow];
}
return (struct gui_window*)controller;
}