From fc7b95f95364efbd8209b89378e4a384281206f3 Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Mon, 1 Jul 2002 19:10:14 +0000 Subject: [PATCH] Hook up "Bookmark this link" context menu item (bug 154856). r=pinkerton. --- camino/BookmarksDataSource.h | 2 +- camino/BookmarksDataSource.mm | 23 ++++++++---- camino/BrowserWindowController.h | 2 +- camino/BrowserWindowController.mm | 16 ++++++-- camino/MainController.mm | 4 +- camino/StringUtils.h | 37 ------------------- camino/src/application/MainController.mm | 4 +- camino/src/bookmarks/BookmarksDataSource.h | 2 +- camino/src/bookmarks/BookmarksDataSource.mm | 23 ++++++++---- camino/src/browser/BrowserWindowController.h | 2 +- camino/src/browser/BrowserWindowController.mm | 16 ++++++-- chimera/BookmarksDataSource.h | 2 +- chimera/BookmarksDataSource.mm | 23 ++++++++---- chimera/BrowserWindowController.h | 2 +- chimera/BrowserWindowController.mm | 16 ++++++-- chimera/MainController.mm | 4 +- chimera/StringUtils.h | 37 ------------------- chimera/src/application/MainController.mm | 4 +- chimera/src/bookmarks/BookmarksDataSource.h | 2 +- chimera/src/bookmarks/BookmarksDataSource.mm | 23 ++++++++---- chimera/src/browser/BrowserWindowController.h | 2 +- .../src/browser/BrowserWindowController.mm | 16 ++++++-- 22 files changed, 124 insertions(+), 138 deletions(-) diff --git a/camino/BookmarksDataSource.h b/camino/BookmarksDataSource.h index bfaa0ce53e2..c38b70bb928 100644 --- a/camino/BookmarksDataSource.h +++ b/camino/BookmarksDataSource.h @@ -75,7 +75,7 @@ class BookmarksService; -(IBAction)addFolder:(id)aSender; --(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder; +-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; -(NSString*)resolveKeyword:(NSString*)aKeyword; diff --git a/camino/BookmarksDataSource.mm b/camino/BookmarksDataSource.mm index 9d985016cca..abf34c87210 100644 --- a/camino/BookmarksDataSource.mm +++ b/camino/BookmarksDataSource.mm @@ -53,6 +53,7 @@ #include "nsVoidArray.h" #import "BookmarksService.h" +#import "StringUtils.h" @implementation BookmarksDataSource @@ -95,15 +96,15 @@ -(IBAction)addBookmark:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: NO]; + [self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil]; } -(IBAction)addFolder:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: YES]; + [self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil]; } --(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder +-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { if (!mBookmarks) return; @@ -138,16 +139,22 @@ nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - // Fetch the title of the current page and the URL. nsAutoString title, href; if (!aIsFolder) { - BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], - title, href); + + // If no URL and title were specified, get them from the current page. + if (aURL && aTitle) { + NSStringTo_nsString(aURL, href); + NSStringTo_nsString(aTitle, title); + } else { + BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], + title, href); + } mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()]; [mCachedHref retain]; - } - else { + + } else { // Folder mCachedHref = nil; title = NS_LITERAL_STRING("New Folder"); } diff --git a/camino/BrowserWindowController.h b/camino/BrowserWindowController.h index a0c4eab6041..1abb4b80f30 100644 --- a/camino/BrowserWindowController.h +++ b/camino/BrowserWindowController.h @@ -190,7 +190,7 @@ class nsIDOMNode; - (BOOL)shouldShowBookmarkToolbar; -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; - (IBAction)manageBookmarks: (id)aSender; - (void)importBookmarks: (NSString*)aURLSpec; - (IBAction)toggleSidebar:(id)aSender; diff --git a/camino/BrowserWindowController.mm b/camino/BrowserWindowController.mm index 83e4f1b094a..41e91c66aec 100644 --- a/camino/BrowserWindowController.mm +++ b/camino/BrowserWindowController.mm @@ -735,7 +735,7 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; wrap:inWrap backwards:inBackwards]; } -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { [mSidebarBookmarksDataSource ensureBookmarks]; BOOL useSel = aIsFromMenu; @@ -748,19 +748,27 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; useSel = NO; } - [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder]; + [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle]; } - (IBAction)bookmarkPage: (id)aSender { - [self addBookmarkExtended:YES isFolder:NO]; + [self addBookmarkExtended:YES isFolder:NO URL:nil title:nil]; } - (IBAction)bookmarkLink: (id)aSender { - NSLog(@"Bookmark Link not yet implemented"); + nsCOMPtr linkContent; + nsAutoString href; + CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs\ + (linkContent), href); + nsAutoString linkText; + CHGeckoUtils::GatherTextUnder(linkContent, linkText); + NSString* urlStr = [NSString stringWithCharacters:href.get() length:href.Length()]; + NSString* titleStr = [NSString stringWithCharacters:linkText.get() length:linkText.Length()]; + [self addBookmarkExtended:YES isFolder:NO URL:urlStr title:titleStr]; } - (IBAction)back:(id)aSender diff --git a/camino/MainController.mm b/camino/MainController.mm index 1de823e02d6..6185e868670 100644 --- a/camino/MainController.mm +++ b/camino/MainController.mm @@ -376,12 +376,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) addBookmark:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO URL:nil title:nil]; } -(IBAction) addFolder:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES URL:nil title:nil]; } -(IBAction) addSeparator:(id)aSender diff --git a/camino/StringUtils.h b/camino/StringUtils.h index 482eec02b0f..e69de29bb2d 100644 --- a/camino/StringUtils.h +++ b/camino/StringUtils.h @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* The contents of this file are subject to the Mozilla Public -* License Version 1.1 (the "License"); you may not use this file -* except in compliance with the License. You may obtain a copy of -* the License at http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS -* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -* implied. See the License for the specific language governing -* rights and limitations under the License. -* -* The Original Code is the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -*/ - -// Utility to convert |NSString|s to unicode |nsString|s to save having -// to repeat this set of code each time someone wants to do this... -void -NSStringTo_nsString(NSString* aNSString, nsString& ansString) -{ - unsigned int len = [aNSString length]; - PRUnichar* buffer = new PRUnichar[len + 1]; - if (!buffer) - return; - - [aNSString getCharacters: buffer]; - buffer[len] = (PRUnichar)'\0'; - - ansString.Adopt(buffer); -} \ No newline at end of file diff --git a/camino/src/application/MainController.mm b/camino/src/application/MainController.mm index 1de823e02d6..6185e868670 100644 --- a/camino/src/application/MainController.mm +++ b/camino/src/application/MainController.mm @@ -376,12 +376,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) addBookmark:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO URL:nil title:nil]; } -(IBAction) addFolder:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES URL:nil title:nil]; } -(IBAction) addSeparator:(id)aSender diff --git a/camino/src/bookmarks/BookmarksDataSource.h b/camino/src/bookmarks/BookmarksDataSource.h index bfaa0ce53e2..c38b70bb928 100644 --- a/camino/src/bookmarks/BookmarksDataSource.h +++ b/camino/src/bookmarks/BookmarksDataSource.h @@ -75,7 +75,7 @@ class BookmarksService; -(IBAction)addFolder:(id)aSender; --(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder; +-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; -(NSString*)resolveKeyword:(NSString*)aKeyword; diff --git a/camino/src/bookmarks/BookmarksDataSource.mm b/camino/src/bookmarks/BookmarksDataSource.mm index 9d985016cca..abf34c87210 100644 --- a/camino/src/bookmarks/BookmarksDataSource.mm +++ b/camino/src/bookmarks/BookmarksDataSource.mm @@ -53,6 +53,7 @@ #include "nsVoidArray.h" #import "BookmarksService.h" +#import "StringUtils.h" @implementation BookmarksDataSource @@ -95,15 +96,15 @@ -(IBAction)addBookmark:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: NO]; + [self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil]; } -(IBAction)addFolder:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: YES]; + [self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil]; } --(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder +-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { if (!mBookmarks) return; @@ -138,16 +139,22 @@ nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - // Fetch the title of the current page and the URL. nsAutoString title, href; if (!aIsFolder) { - BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], - title, href); + + // If no URL and title were specified, get them from the current page. + if (aURL && aTitle) { + NSStringTo_nsString(aURL, href); + NSStringTo_nsString(aTitle, title); + } else { + BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], + title, href); + } mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()]; [mCachedHref retain]; - } - else { + + } else { // Folder mCachedHref = nil; title = NS_LITERAL_STRING("New Folder"); } diff --git a/camino/src/browser/BrowserWindowController.h b/camino/src/browser/BrowserWindowController.h index a0c4eab6041..1abb4b80f30 100644 --- a/camino/src/browser/BrowserWindowController.h +++ b/camino/src/browser/BrowserWindowController.h @@ -190,7 +190,7 @@ class nsIDOMNode; - (BOOL)shouldShowBookmarkToolbar; -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; - (IBAction)manageBookmarks: (id)aSender; - (void)importBookmarks: (NSString*)aURLSpec; - (IBAction)toggleSidebar:(id)aSender; diff --git a/camino/src/browser/BrowserWindowController.mm b/camino/src/browser/BrowserWindowController.mm index 83e4f1b094a..41e91c66aec 100644 --- a/camino/src/browser/BrowserWindowController.mm +++ b/camino/src/browser/BrowserWindowController.mm @@ -735,7 +735,7 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; wrap:inWrap backwards:inBackwards]; } -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { [mSidebarBookmarksDataSource ensureBookmarks]; BOOL useSel = aIsFromMenu; @@ -748,19 +748,27 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; useSel = NO; } - [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder]; + [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle]; } - (IBAction)bookmarkPage: (id)aSender { - [self addBookmarkExtended:YES isFolder:NO]; + [self addBookmarkExtended:YES isFolder:NO URL:nil title:nil]; } - (IBAction)bookmarkLink: (id)aSender { - NSLog(@"Bookmark Link not yet implemented"); + nsCOMPtr linkContent; + nsAutoString href; + CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs\ + (linkContent), href); + nsAutoString linkText; + CHGeckoUtils::GatherTextUnder(linkContent, linkText); + NSString* urlStr = [NSString stringWithCharacters:href.get() length:href.Length()]; + NSString* titleStr = [NSString stringWithCharacters:linkText.get() length:linkText.Length()]; + [self addBookmarkExtended:YES isFolder:NO URL:urlStr title:titleStr]; } - (IBAction)back:(id)aSender diff --git a/chimera/BookmarksDataSource.h b/chimera/BookmarksDataSource.h index bfaa0ce53e2..c38b70bb928 100644 --- a/chimera/BookmarksDataSource.h +++ b/chimera/BookmarksDataSource.h @@ -75,7 +75,7 @@ class BookmarksService; -(IBAction)addFolder:(id)aSender; --(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder; +-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; -(NSString*)resolveKeyword:(NSString*)aKeyword; diff --git a/chimera/BookmarksDataSource.mm b/chimera/BookmarksDataSource.mm index 9d985016cca..abf34c87210 100644 --- a/chimera/BookmarksDataSource.mm +++ b/chimera/BookmarksDataSource.mm @@ -53,6 +53,7 @@ #include "nsVoidArray.h" #import "BookmarksService.h" +#import "StringUtils.h" @implementation BookmarksDataSource @@ -95,15 +96,15 @@ -(IBAction)addBookmark:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: NO]; + [self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil]; } -(IBAction)addFolder:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: YES]; + [self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil]; } --(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder +-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { if (!mBookmarks) return; @@ -138,16 +139,22 @@ nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - // Fetch the title of the current page and the URL. nsAutoString title, href; if (!aIsFolder) { - BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], - title, href); + + // If no URL and title were specified, get them from the current page. + if (aURL && aTitle) { + NSStringTo_nsString(aURL, href); + NSStringTo_nsString(aTitle, title); + } else { + BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], + title, href); + } mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()]; [mCachedHref retain]; - } - else { + + } else { // Folder mCachedHref = nil; title = NS_LITERAL_STRING("New Folder"); } diff --git a/chimera/BrowserWindowController.h b/chimera/BrowserWindowController.h index a0c4eab6041..1abb4b80f30 100644 --- a/chimera/BrowserWindowController.h +++ b/chimera/BrowserWindowController.h @@ -190,7 +190,7 @@ class nsIDOMNode; - (BOOL)shouldShowBookmarkToolbar; -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; - (IBAction)manageBookmarks: (id)aSender; - (void)importBookmarks: (NSString*)aURLSpec; - (IBAction)toggleSidebar:(id)aSender; diff --git a/chimera/BrowserWindowController.mm b/chimera/BrowserWindowController.mm index 83e4f1b094a..41e91c66aec 100644 --- a/chimera/BrowserWindowController.mm +++ b/chimera/BrowserWindowController.mm @@ -735,7 +735,7 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; wrap:inWrap backwards:inBackwards]; } -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { [mSidebarBookmarksDataSource ensureBookmarks]; BOOL useSel = aIsFromMenu; @@ -748,19 +748,27 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; useSel = NO; } - [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder]; + [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle]; } - (IBAction)bookmarkPage: (id)aSender { - [self addBookmarkExtended:YES isFolder:NO]; + [self addBookmarkExtended:YES isFolder:NO URL:nil title:nil]; } - (IBAction)bookmarkLink: (id)aSender { - NSLog(@"Bookmark Link not yet implemented"); + nsCOMPtr linkContent; + nsAutoString href; + CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs\ + (linkContent), href); + nsAutoString linkText; + CHGeckoUtils::GatherTextUnder(linkContent, linkText); + NSString* urlStr = [NSString stringWithCharacters:href.get() length:href.Length()]; + NSString* titleStr = [NSString stringWithCharacters:linkText.get() length:linkText.Length()]; + [self addBookmarkExtended:YES isFolder:NO URL:urlStr title:titleStr]; } - (IBAction)back:(id)aSender diff --git a/chimera/MainController.mm b/chimera/MainController.mm index 1de823e02d6..6185e868670 100644 --- a/chimera/MainController.mm +++ b/chimera/MainController.mm @@ -376,12 +376,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) addBookmark:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO URL:nil title:nil]; } -(IBAction) addFolder:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES URL:nil title:nil]; } -(IBAction) addSeparator:(id)aSender diff --git a/chimera/StringUtils.h b/chimera/StringUtils.h index 482eec02b0f..e69de29bb2d 100644 --- a/chimera/StringUtils.h +++ b/chimera/StringUtils.h @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* The contents of this file are subject to the Mozilla Public -* License Version 1.1 (the "License"); you may not use this file -* except in compliance with the License. You may obtain a copy of -* the License at http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS -* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -* implied. See the License for the specific language governing -* rights and limitations under the License. -* -* The Original Code is the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -*/ - -// Utility to convert |NSString|s to unicode |nsString|s to save having -// to repeat this set of code each time someone wants to do this... -void -NSStringTo_nsString(NSString* aNSString, nsString& ansString) -{ - unsigned int len = [aNSString length]; - PRUnichar* buffer = new PRUnichar[len + 1]; - if (!buffer) - return; - - [aNSString getCharacters: buffer]; - buffer[len] = (PRUnichar)'\0'; - - ansString.Adopt(buffer); -} \ No newline at end of file diff --git a/chimera/src/application/MainController.mm b/chimera/src/application/MainController.mm index 1de823e02d6..6185e868670 100644 --- a/chimera/src/application/MainController.mm +++ b/chimera/src/application/MainController.mm @@ -376,12 +376,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) addBookmark:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO URL:nil title:nil]; } -(IBAction) addFolder:(id)aSender { - [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES]; + [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES URL:nil title:nil]; } -(IBAction) addSeparator:(id)aSender diff --git a/chimera/src/bookmarks/BookmarksDataSource.h b/chimera/src/bookmarks/BookmarksDataSource.h index bfaa0ce53e2..c38b70bb928 100644 --- a/chimera/src/bookmarks/BookmarksDataSource.h +++ b/chimera/src/bookmarks/BookmarksDataSource.h @@ -75,7 +75,7 @@ class BookmarksService; -(IBAction)addFolder:(id)aSender; --(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder; +-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; -(NSString*)resolveKeyword:(NSString*)aKeyword; diff --git a/chimera/src/bookmarks/BookmarksDataSource.mm b/chimera/src/bookmarks/BookmarksDataSource.mm index 9d985016cca..abf34c87210 100644 --- a/chimera/src/bookmarks/BookmarksDataSource.mm +++ b/chimera/src/bookmarks/BookmarksDataSource.mm @@ -53,6 +53,7 @@ #include "nsVoidArray.h" #import "BookmarksService.h" +#import "StringUtils.h" @implementation BookmarksDataSource @@ -95,15 +96,15 @@ -(IBAction)addBookmark:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: NO]; + [self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil]; } -(IBAction)addFolder:(id)aSender { - [self addBookmark: aSender useSelection: YES isFolder: YES]; + [self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil]; } --(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder +-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { if (!mBookmarks) return; @@ -138,16 +139,22 @@ nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - // Fetch the title of the current page and the URL. nsAutoString title, href; if (!aIsFolder) { - BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], - title, href); + + // If no URL and title were specified, get them from the current page. + if (aURL && aTitle) { + NSStringTo_nsString(aURL, href); + NSStringTo_nsString(aTitle, title); + } else { + BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], + title, href); + } mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()]; [mCachedHref retain]; - } - else { + + } else { // Folder mCachedHref = nil; title = NS_LITERAL_STRING("New Folder"); } diff --git a/chimera/src/browser/BrowserWindowController.h b/chimera/src/browser/BrowserWindowController.h index a0c4eab6041..1abb4b80f30 100644 --- a/chimera/src/browser/BrowserWindowController.h +++ b/chimera/src/browser/BrowserWindowController.h @@ -190,7 +190,7 @@ class nsIDOMNode; - (BOOL)shouldShowBookmarkToolbar; -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; - (IBAction)manageBookmarks: (id)aSender; - (void)importBookmarks: (NSString*)aURLSpec; - (IBAction)toggleSidebar:(id)aSender; diff --git a/chimera/src/browser/BrowserWindowController.mm b/chimera/src/browser/BrowserWindowController.mm index 83e4f1b094a..41e91c66aec 100644 --- a/chimera/src/browser/BrowserWindowController.mm +++ b/chimera/src/browser/BrowserWindowController.mm @@ -735,7 +735,7 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; wrap:inWrap backwards:inBackwards]; } -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder +- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle { [mSidebarBookmarksDataSource ensureBookmarks]; BOOL useSel = aIsFromMenu; @@ -748,19 +748,27 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; useSel = NO; } - [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder]; + [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle]; } - (IBAction)bookmarkPage: (id)aSender { - [self addBookmarkExtended:YES isFolder:NO]; + [self addBookmarkExtended:YES isFolder:NO URL:nil title:nil]; } - (IBAction)bookmarkLink: (id)aSender { - NSLog(@"Bookmark Link not yet implemented"); + nsCOMPtr linkContent; + nsAutoString href; + CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs\ + (linkContent), href); + nsAutoString linkText; + CHGeckoUtils::GatherTextUnder(linkContent, linkText); + NSString* urlStr = [NSString stringWithCharacters:href.get() length:href.Length()]; + NSString* titleStr = [NSString stringWithCharacters:linkText.get() length:linkText.Length()]; + [self addBookmarkExtended:YES isFolder:NO URL:urlStr title:titleStr]; } - (IBAction)back:(id)aSender