diff options
author | mrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 18:32:57 +0000 |
---|---|---|
committer | mrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 18:32:57 +0000 |
commit | cdf8cf7bf3dc3834f6b18c95123c548a5d5fca08 (patch) | |
tree | 92fcdbbb9fa06057857b34cd35256bc097ff28b6 /chrome/browser/cocoa/bookmark_bar_controller.mm | |
parent | e29c77e0d8d63e3374a728bade376c01240820ba (diff) | |
download | chromium_src-cdf8cf7bf3dc3834f6b18c95123c548a5d5fca08.zip chromium_src-cdf8cf7bf3dc3834f6b18c95123c548a5d5fca08.tar.gz chromium_src-cdf8cf7bf3dc3834f6b18c95123c548a5d5fca08.tar.bz2 |
Implement cut and paste and rework copy and delete bookmark actions from context menus. Eliminate bifurcated 'parentController_' data member (leaving this common behavior to the BookmarkFolderTarget class). Provide context menus (one for button and another for folder) for the folder controller thus allowing far easier identification of the target of the action.
BookmarkBar.xib changes: Added Cut and Paste menu items to the button and folder contextual menus. Reconfigured the menus with separators and some rearranging to match Windows.
BookmarkBarFolderWindow.xib changes: Copied the button and folder contextual menus from the BookmarkBar.xib and wired them up to the folder controller instead.
BUG=23541
TEST=Present context menu for bookmark bar and verify the presence of Cut/Copy/Paste/Delete. Verify proper enabling (i.e. Paste should not be enabled until a bookmark or folder has been Cut or Copied). Perform each action Cut, Copy, Delete and Paste. Perform these tests for the contents of a folder coming off of the bookmark bar and for subfolders, too. Insure that pasting can be performed from the bar to a folder, a folder to the bar, bar to bar, folder to folder, at the beginning and at the end of each.
Review URL: http://codereview.chromium.org/1611027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index fe0c17b..bb6895a 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -13,7 +13,6 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #import "chrome/browser/browser_theme_provider.h" -#import "chrome/browser/browser_window.h" #import "chrome/browser/cocoa/background_gradient_view.h" #import "chrome/browser/cocoa/bookmark_bar_bridge.h" #import "chrome/browser/cocoa/bookmark_bar_constants.h" @@ -1037,7 +1036,9 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { } if ((action == @selector(editBookmark:)) || - (action == @selector(deleteBookmark:))) { + (action == @selector(deleteBookmark:)) || + (action == @selector(cutBookmark:)) || + (action == @selector(copyBookmark:))) { // Don't allow edit/delete of the bar node, or of "Other Bookmarks" if ((node == nil) || (node == bookmarkModel_->other_node()) || @@ -1046,6 +1047,10 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { } } + if (action == @selector(pasteBookmark:) && + !bookmark_utils::CanPasteFromClipboard(node)) + return NO; + // If this is an incognito window, don't allow "open in incognito". if ((action == @selector(openBookmarkInIncognitoWindow:)) || (action == @selector(openAllBookmarksIncognitoWindow:))) { @@ -1195,9 +1200,10 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { [self closeAllBookmarkFolders]; // Folder controller, like many window controllers, owns itself. - folderController_ = [[BookmarkBarFolderController alloc] - initWithParentButton:parentButton - parentController:self]; + folderController_ = + [[BookmarkBarFolderController alloc] initWithParentButton:parentButton + parentController:nil + barController:self]; [folderController_ showWindow:self]; // Only BookmarkBarController has this; the @@ -1257,12 +1263,41 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { nil); } +- (IBAction)cutBookmark:(id)sender { + const BookmarkNode* node = [self nodeFromMenuItem:sender]; + if (node) { + std::vector<const BookmarkNode*> nodes; + nodes.push_back(node); + bookmark_utils::CopyToClipboard(bookmarkModel_, nodes, true); + } +} + - (IBAction)copyBookmark:(id)sender { const BookmarkNode* node = [self nodeFromMenuItem:sender]; if (node) { - NSPasteboard* pboard = [NSPasteboard generalPasteboard]; - [[self folderTarget] copyBookmarkNode:node - toPasteboard:pboard]; + std::vector<const BookmarkNode*> nodes; + nodes.push_back(node); + bookmark_utils::CopyToClipboard(bookmarkModel_, nodes, false); + } +} + +// Paste the copied node immediately after the node for which the context +// menu has been presented. +- (IBAction)pasteBookmark:(id)sender { + const BookmarkNode* node = [self nodeFromMenuItem:sender]; + if (node) { + const BookmarkNode* parent = node->GetParent(); + // Pasting into the bar but not onto any element in the bar causes the + // pasted node to be placed at the right end of the bar. + int index = -1; + if (node == bookmarkModel_->GetBookmarkBarNode()) { + parent = node; + } else { + index = parent->IndexOfChild(node) + 1; + if (index > parent->GetChildCount()) + index = -1; + } + bookmark_utils::PasteFromClipboard(bookmarkModel_, parent, index); } } @@ -1271,9 +1306,6 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { if (node) { bookmarkModel_->Remove(node->GetParent(), node->GetParent()->IndexOfChild(node)); - // TODO(jrg): don't close; rebuild. - // http://crbug.com/36614 - [self closeAllBookmarkFolders]; } } @@ -1602,9 +1634,11 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { return; // If this is a rebuild request while we have a folder open, close it. - if (folderController_) { + // TODO(mrossetti): Eliminate the need for this because it causes the folder + // menu to disappear after a cut/copy/paste/delete change. + // See: http://crbug.com/36614 + if (folderController_) [self closeAllBookmarkFolders]; - } // Brute force nuke and build. savedFrameWidth_ = NSWidth([[self view] frame]); |