Ensure that correct Bookmarks context menu items are enabled when certain types of element are selected. Hook up 'Open in New Window' for Bookmark Groups

This commit is contained in:
ben%netscape.com 2002-06-02 10:51:02 +00:00
parent 181ca4c488
commit 875ed4db44
16 changed files with 236 additions and 4 deletions

View File

@ -84,6 +84,8 @@ class nsIAtom;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -675,10 +675,46 @@
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
else
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
@end
@implementation BookmarkItem

View File

@ -161,6 +161,7 @@ class nsIDOMNode;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;

View File

@ -750,6 +750,25 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
}
}
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
// Tell the Tab Browser in the newly created window to load the group
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
id tabBrowser = [browser getTabBrowser];
[mSidebarBookmarksDataSource openBookmarkGroup: tabBrowser groupElement: aFolderElement];
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];

View File

@ -84,6 +84,8 @@ class nsIAtom;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -675,10 +675,46 @@
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
else
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
@end
@implementation BookmarkItem

View File

@ -161,6 +161,7 @@ class nsIDOMNode;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;

View File

@ -750,6 +750,25 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
}
}
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
// Tell the Tab Browser in the newly created window to load the group
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
id tabBrowser = [browser getTabBrowser];
[mSidebarBookmarksDataSource openBookmarkGroup: tabBrowser groupElement: aFolderElement];
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];

View File

@ -84,6 +84,8 @@ class nsIAtom;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -675,10 +675,46 @@
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
else
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
@end
@implementation BookmarkItem

View File

@ -161,6 +161,7 @@ class nsIDOMNode;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;

View File

@ -750,6 +750,25 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
}
}
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
// Tell the Tab Browser in the newly created window to load the group
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
id tabBrowser = [browser getTabBrowser];
[mSidebarBookmarksDataSource openBookmarkGroup: tabBrowser groupElement: aFolderElement];
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];

View File

@ -84,6 +84,8 @@ class nsIAtom;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -675,10 +675,46 @@
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
else
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
elt->GetAttribute(NS_LITERAL_STRING("group"), group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
@end
@implementation BookmarkItem

View File

@ -161,6 +161,7 @@ class nsIDOMNode;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;

View File

@ -750,6 +750,25 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
}
}
-(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
// Tell the Tab Browser in the newly created window to load the group
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
id tabBrowser = [browser getTabBrowser];
[mSidebarBookmarksDataSource openBookmarkGroup: tabBrowser groupElement: aFolderElement];
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];