Make newTab a responder action, and implement closing tabs
This commit is contained in:
parent
9194cde509
commit
5013c2e8a6
|
@ -39,7 +39,6 @@ id bookmarksWindowController;
|
|||
id preferencesWindowController;
|
||||
}
|
||||
-(void)didTapNewWindow: (id)sender;
|
||||
-(void)didTapNewTab: (id)sender;
|
||||
-(void)showFindPanel: (id)sender;
|
||||
-(void)showDownloadsWindow: (id)sender;
|
||||
-(void)showHistoryWindow: (id)sender;
|
||||
|
|
|
@ -132,24 +132,6 @@ 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) {
|
||||
|
|
|
@ -31,7 +31,10 @@ struct browser_window;
|
|||
-(NSString*)visibleUrl;
|
||||
-(void)enterSearch: (id)sender;
|
||||
-(void)openWebsite: (Website*)aWebsite;
|
||||
-(void)newTab: (struct browser_window*)aBrowser;
|
||||
-(void)newTab: (id)sender;
|
||||
-(void)newTabWithBrowser: (struct browser_window*)aBrowser;
|
||||
-(void)close: (id)sender;
|
||||
-(void)netsurfWindowDestroy;
|
||||
|
||||
// Browser control
|
||||
-(NSSize)getBrowserSize;
|
||||
|
@ -53,4 +56,6 @@ struct browser_window;
|
|||
-(void)showAll: (NSString*)needle matchCase: (BOOL)matchCase sender: (id)sender;
|
||||
-(void)bookmarkPage: (id)sender;
|
||||
|
||||
|
||||
+(id)newTabTarget;
|
||||
@end
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#import "Preferences.h"
|
||||
#import "SearchProvider.h"
|
||||
|
||||
static id newTabTarget;
|
||||
|
||||
@interface TabContents: NSObject {
|
||||
id scrollView;
|
||||
id plotView;
|
||||
|
@ -70,10 +72,55 @@
|
|||
NSLog(@"Browser window loaded");
|
||||
}
|
||||
|
||||
-(void)newTab: (struct browser_window*)aBrowser {
|
||||
-(void)newTabWithBrowser: (struct browser_window*)aBrowser {
|
||||
[self addTab: aBrowser];
|
||||
}
|
||||
|
||||
-(void)newTab: (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) {
|
||||
newTabTarget = self;
|
||||
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)close: (id)sender {
|
||||
NSLog(@"Close");
|
||||
NSTabViewItem *selectedTab = [tabView selectedTabViewItem];
|
||||
NSInteger idx = [tabView indexOfTabViewItem: selectedTab];
|
||||
if (idx == NSNotFound) {
|
||||
NSLog(@"Tab not found.");
|
||||
return;
|
||||
}
|
||||
TabContents *tc = [tabs objectAtIndex: idx];
|
||||
// This will call into netsurfWindowDestroy in the window.m callback...
|
||||
browser_window_destroy([tc browser]);
|
||||
|
||||
}
|
||||
-(void)netsurfWindowDestroy {
|
||||
NSLog(@"ns destroy");
|
||||
NSTabViewItem *selectedTab = [tabView selectedTabViewItem];
|
||||
NSInteger idx = [tabView indexOfTabViewItem: selectedTab];
|
||||
if (idx == NSNotFound) {
|
||||
NSLog(@"Tab not found.");
|
||||
return;
|
||||
}
|
||||
[tabView removeTabViewItem: selectedTab];
|
||||
TabContents *tc = [tabs objectAtIndex: idx];
|
||||
[tabs removeObjectAtIndex: idx];
|
||||
}
|
||||
|
||||
-(void)back: (id)sender {
|
||||
NSLog(@"Browser backward");
|
||||
[plotView back: sender];
|
||||
|
@ -270,7 +317,7 @@
|
|||
-(void)tabView: (NSTabView*)aTabView didSelectTabViewItem: (NSTabViewItem*)aTabViewItem {
|
||||
NSLog(@"Selected tab");
|
||||
NSInteger idx = [aTabView indexOfTabViewItem: aTabViewItem];
|
||||
if (idx == NSNotFound || [tabs count] <= idx) {
|
||||
if (idx == NSNotFound || (NSInteger)[tabs count] <= idx) {
|
||||
NSLog(@"Tab not found...");
|
||||
return;
|
||||
}
|
||||
|
@ -288,6 +335,8 @@
|
|||
NSLog(@"Inner view: %@", innerView);
|
||||
PlotView *newPlotView = [[PlotView alloc] initWithFrame: [innerView bounds]];
|
||||
NSScrollView *newScrollView = [[NSScrollView alloc] initWithFrame: [innerView bounds]];
|
||||
[newScrollView setHasVerticalScroller: YES];
|
||||
[newScrollView setHasHorizontalScroller: YES];
|
||||
[newScrollView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
|
||||
[newScrollView setDocumentView: newPlotView];
|
||||
[innerView addSubview: newScrollView];
|
||||
|
@ -296,13 +345,14 @@
|
|||
[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];
|
||||
|
||||
[tabItem release];
|
||||
[tc release];
|
||||
[newPlotView release];
|
||||
[newScrollView release];
|
||||
|
@ -321,4 +371,8 @@
|
|||
scrollView = [tabContents scrollView];
|
||||
browser = [tabContents browser];
|
||||
}
|
||||
|
||||
+(id)newTabTarget {
|
||||
return newTabTarget;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
"showFindPanel:",
|
||||
"showHistoryWindow:",
|
||||
"showBookmarksWindow:",
|
||||
"showPreferencesWindow:",
|
||||
"didTapNewTab:"
|
||||
"showPreferencesWindow:"
|
||||
);
|
||||
Outlets = (
|
||||
);
|
||||
|
@ -20,7 +19,7 @@
|
|||
"didTapNewWindow:",
|
||||
"findNext:",
|
||||
"findPrevious:",
|
||||
"didTapNewTab:",
|
||||
"newTab:",
|
||||
"newFolder:",
|
||||
"remove:",
|
||||
"removeAll:",
|
||||
|
|
Binary file not shown.
|
@ -20,8 +20,8 @@ static struct gui_window *gnustep_window_create(struct browser_window *bw,
|
|||
NSLog(@"gnustep_window_create");
|
||||
BrowserWindowController *controller = nil;
|
||||
if (flags & BW_CREATE_TAB) {
|
||||
controller = [[NSApp delegate] activeBrowserWindow];
|
||||
[controller newTab: bw];
|
||||
controller = [BrowserWindowController newTabTarget];
|
||||
[controller newTabWithBrowser: bw];
|
||||
}
|
||||
if (controller == nil) {
|
||||
controller = [[BrowserWindowController alloc]
|
||||
|
@ -34,7 +34,7 @@ static struct gui_window *gnustep_window_create(struct browser_window *bw,
|
|||
// Destroy the specified window
|
||||
static void gnustep_window_destroy(struct gui_window *gw) {
|
||||
NSLog(@"gnustep_window_destroy");
|
||||
[(id)gw release];
|
||||
[(id)gw netsurfWindowDestroy];
|
||||
}
|
||||
|
||||
// Trigger a redraw of the specified area, or the entire window if null
|
||||
|
|
Loading…
Reference in New Issue