diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-22 18:18:56 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-22 18:18:56 +0000 |
commit | 1d379a14439d1ba1753a3fbe91d3fd4bcd6e21ba (patch) | |
tree | c765a5a2b54b9d408056cb151aebe421300e8199 | |
parent | 51cb4f57e5143cdf7c0a46ce86c6b3091f66e7f3 (diff) | |
download | chromium_src-1d379a14439d1ba1753a3fbe91d3fd4bcd6e21ba.zip chromium_src-1d379a14439d1ba1753a3fbe91d3fd4bcd6e21ba.tar.gz chromium_src-1d379a14439d1ba1753a3fbe91d3fd4bcd6e21ba.tar.bz2 |
Bookmark Bar Add Folder / Rename Folder dialog and controller.
TEST=Right click on bar --> Add Folder...
Type a name and it shows up as a folder in the bookmark bar.
(You can't do anything with it yet; sorry).
Right click on folder name --> Edit...
Make sure you can rename the folder.
Review URL: http://codereview.chromium.org/159183
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21293 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/nibs/BookmarkBar.xib | 43 | ||||
-rw-r--r-- | chrome/app/nibs/BookmarkNameFolder.xib | 425 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.h | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 30 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_editor_controller_unittest.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_name_folder_controller.h | 38 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_name_folder_controller.mm | 85 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_name_folder_controller_unittest.mm | 63 | ||||
-rw-r--r-- | chrome/chrome.gyp | 4 |
9 files changed, 671 insertions, 20 deletions
diff --git a/chrome/app/nibs/BookmarkBar.xib b/chrome/app/nibs/BookmarkBar.xib index 4abb7d0..e719a99 100644 --- a/chrome/app/nibs/BookmarkBar.xib +++ b/chrome/app/nibs/BookmarkBar.xib @@ -333,14 +333,6 @@ <object class="IBActionConnection" key="connection"> <string key="label">commandDispatch:</string> <reference key="source" ref="1003"/> - <reference key="destination" ref="90793013"/> - </object> - <int key="connectionID">38</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> <reference key="destination" ref="61770624"/> </object> <int key="connectionID">39</int> @@ -357,14 +349,6 @@ <object class="IBActionConnection" key="connection"> <string key="label">commandDispatch:</string> <reference key="source" ref="1003"/> - <reference key="destination" ref="595609715"/> - </object> - <int key="connectionID">47</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> <reference key="destination" ref="807677456"/> </object> <int key="connectionID">48</int> @@ -441,6 +425,22 @@ </object> <int key="connectionID">59</int> </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">addOrRenameFolder:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="595609715"/> + </object> + <int key="connectionID">60</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">addOrRenameFolder:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="90793013"/> + </object> + <int key="connectionID">61</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -735,7 +735,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">59</int> + <int key="maxID">61</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -755,6 +755,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>addOrRenameFolder:</string> <string>addPage:</string> <string>deleteBookmark:</string> <string>editBookmark:</string> @@ -774,6 +775,7 @@ <string>id</string> <string>id</string> <string>id</string> + <string>id</string> </object> </object> <object class="NSMutableDictionary" key="outlets"> @@ -810,6 +812,13 @@ <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/status_bubble_mac.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> <string key="minorKey">browser/cocoa/tab_strip_model_observer_bridge.h</string> </object> </object> diff --git a/chrome/app/nibs/BookmarkNameFolder.xib b/chrome/app/nibs/BookmarkNameFolder.xib new file mode 100644 index 0000000..420253c --- /dev/null +++ b/chrome/app/nibs/BookmarkNameFolder.xib @@ -0,0 +1,425 @@ +<?xml version="1.0" encoding="UTF-8"?> +<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> + <data> + <int key="IBDocument.SystemTarget">1050</int> + <string key="IBDocument.SystemVersion">9J61</string> + <string key="IBDocument.InterfaceBuilderVersion">677</string> + <string key="IBDocument.AppKitVersion">949.46</string> + <string key="IBDocument.HIToolboxVersion">353.00</string> + <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> + <bool key="EncodedWithXMLCoder">YES</bool> + <integer value="2"/> + </object> + <object class="NSArray" key="IBDocument.PluginDependencies"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + </object> + <object class="NSMutableDictionary" key="IBDocument.Metadata"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + </object> + <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSCustomObject" id="1001"> + <string key="NSClassName">BookmarkNameFolderController</string> + </object> + <object class="NSCustomObject" id="1003"> + <string key="NSClassName">FirstResponder</string> + </object> + <object class="NSCustomObject" id="1004"> + <string key="NSClassName">NSApplication</string> + </object> + <object class="NSWindowTemplate" id="1005"> + <int key="NSWindowStyleMask">7</int> + <int key="NSWindowBacking">2</int> + <string key="NSWindowRect">{{196, 408}, {480, 102}}</string> + <int key="NSWTFlags">536870912</int> + <string key="NSWindowTitle">New Folder</string> + <string key="NSWindowClass">NSWindow</string> + <nil key="NSViewClass"/> + <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> + <object class="NSView" key="NSWindowView" id="1006"> + <reference key="NSNextResponder"/> + <int key="NSvFlags">256</int> + <object class="NSMutableArray" key="NSSubviews"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSTextField" id="1000877900"> + <reference key="NSNextResponder" ref="1006"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{17, 62}, {45, 17}}</string> + <reference key="NSSuperview" ref="1006"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="383706794"> + <int key="NSCellFlags">68288064</int> + <int key="NSCellFlags2">272630784</int> + <string key="NSContents">Name:</string> + <object class="NSFont" key="NSSupport" id="11363697"> + <string key="NSName">LucidaGrande</string> + <double key="NSSize">1.300000e+01</double> + <int key="NSfFlags">1044</int> + </object> + <reference key="NSControlView" ref="1000877900"/> + <object class="NSColor" key="NSBackgroundColor"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">controlColor</string> + <object class="NSColor" key="NSColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC42NjY2NjY2OQA</bytes> + </object> + </object> + <object class="NSColor" key="NSTextColor"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">controlTextColor</string> + <object class="NSColor" key="NSColor" id="200541051"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MAA</bytes> + </object> + </object> + </object> + </object> + <object class="NSTextField" id="781907324"> + <reference key="NSNextResponder" ref="1006"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{67, 60}, {393, 22}}</string> + <reference key="NSSuperview" ref="1006"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="80375196"> + <int key="NSCellFlags">-1804468671</int> + <int key="NSCellFlags2">272630784</int> + <string key="NSContents"/> + <reference key="NSSupport" ref="11363697"/> + <reference key="NSControlView" ref="781907324"/> + <bool key="NSDrawsBackground">YES</bool> + <object class="NSColor" key="NSBackgroundColor"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">textBackgroundColor</string> + <object class="NSColor" key="NSColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MQA</bytes> + </object> + </object> + <object class="NSColor" key="NSTextColor"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">textColor</string> + <reference key="NSColor" ref="200541051"/> + </object> + </object> + </object> + <object class="NSButton" id="810399603"> + <reference key="NSNextResponder" ref="1006"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{370, 12}, {96, 32}}</string> + <reference key="NSSuperview" ref="1006"/> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="869818464"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134217728</int> + <string key="NSContents">OK</string> + <reference key="NSSupport" ref="11363697"/> + <reference key="NSControlView" ref="810399603"/> + <int key="NSButtonFlags">-2038284033</int> + <int key="NSButtonFlags2">129</int> + <string key="NSAlternateContents"/> + <string type="base64-UTF8" key="NSKeyEquivalent">DQ</string> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + <object class="NSButton" id="166877485"> + <reference key="NSNextResponder" ref="1006"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{274, 12}, {96, 32}}</string> + <reference key="NSSuperview" ref="1006"/> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="1061805124"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134217728</int> + <string key="NSContents">Cancel</string> + <reference key="NSSupport" ref="11363697"/> + <reference key="NSControlView" ref="166877485"/> + <int key="NSButtonFlags">-2038284033</int> + <int key="NSButtonFlags2">268435585</int> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent">.</string> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + </object> + <string key="NSFrameSize">{480, 102}</string> + <reference key="NSSuperview"/> + </object> + <string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string> + <string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string> + </object> + </object> + <object class="IBObjectContainer" key="IBDocument.Objects"> + <object class="NSMutableArray" key="connectionRecords"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nameField_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="781907324"/> + </object> + <int key="connectionID">11</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">cancel:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="166877485"/> + </object> + <int key="connectionID">12</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">ok:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="810399603"/> + </object> + <int key="connectionID">13</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">window</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="1005"/> + </object> + <int key="connectionID">14</int> + </object> + </object> + <object class="IBMutableOrderedSet" key="objectRecords"> + <object class="NSArray" key="orderedObjects"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBObjectRecord"> + <int key="objectID">0</int> + <object class="NSArray" key="object" id="1002"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + <reference key="children" ref="1000"/> + <nil key="parent"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">-2</int> + <reference key="object" ref="1001"/> + <reference key="parent" ref="1002"/> + <string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">-1</int> + <reference key="object" ref="1003"/> + <reference key="parent" ref="1002"/> + <string key="objectName">First Responder</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">-3</int> + <reference key="object" ref="1004"/> + <reference key="parent" ref="1002"/> + <string key="objectName">Application</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">1</int> + <reference key="object" ref="1005"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="1006"/> + </object> + <reference key="parent" ref="1002"/> + <string key="objectName">Add Folder</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">2</int> + <reference key="object" ref="1006"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="1000877900"/> + <reference ref="810399603"/> + <reference ref="166877485"/> + <reference ref="781907324"/> + </object> + <reference key="parent" ref="1005"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">3</int> + <reference key="object" ref="1000877900"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="383706794"/> + </object> + <reference key="parent" ref="1006"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">4</int> + <reference key="object" ref="383706794"/> + <reference key="parent" ref="1000877900"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5</int> + <reference key="object" ref="781907324"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="80375196"/> + </object> + <reference key="parent" ref="1006"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">6</int> + <reference key="object" ref="80375196"/> + <reference key="parent" ref="781907324"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">7</int> + <reference key="object" ref="810399603"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="869818464"/> + </object> + <reference key="parent" ref="1006"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">8</int> + <reference key="object" ref="869818464"/> + <reference key="parent" ref="810399603"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">9</int> + <reference key="object" ref="166877485"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="1061805124"/> + </object> + <reference key="parent" ref="1006"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">10</int> + <reference key="object" ref="1061805124"/> + <reference key="parent" ref="166877485"/> + </object> + </object> + </object> + <object class="NSMutableDictionary" key="flattenedProperties"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>-1.IBPluginDependency</string> + <string>-2.IBPluginDependency</string> + <string>-3.IBPluginDependency</string> + <string>1.IBEditorWindowLastContentRect</string> + <string>1.IBPluginDependency</string> + <string>1.IBWindowTemplateEditedContentRect</string> + <string>1.NSWindowTemplate.visibleAtLaunch</string> + <string>1.WindowOrigin</string> + <string>1.editorWindowContentRectSynchronizationRect</string> + <string>10.IBPluginDependency</string> + <string>2.IBPluginDependency</string> + <string>3.IBPluginDependency</string> + <string>4.IBPluginDependency</string> + <string>5.IBPluginDependency</string> + <string>6.IBPluginDependency</string> + <string>7.IBPluginDependency</string> + <string>8.IBPluginDependency</string> + <string>9.IBPluginDependency</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{816, 841}, {480, 102}}</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{816, 841}, {480, 102}}</string> + <boolean value="NO"/> + <string>{196, 240}</string> + <string>{{357, 418}, {480, 270}}</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + </object> + </object> + <object class="NSMutableDictionary" key="unlocalizedProperties"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + </object> + <nil key="activeLocalization"/> + <object class="NSMutableDictionary" key="localizations"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + </object> + <nil key="sourceID"/> + <int key="maxID">14</int> + </object> + <object class="IBClassDescriber" key="IBDocument.Classes"> + <object class="NSMutableArray" key="referencedPartialClassDescriptions"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBPartialClassDescription"> + <string key="className">BookmarkNameFolderController</string> + <string key="superclassName">NSWindowController</string> + <object class="NSMutableDictionary" key="actions"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>cancel:</string> + <string>ok:</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>id</string> + </object> + </object> + <object class="NSMutableDictionary" key="outlets"> + <string key="NS.key.0">nameField_</string> + <string key="NS.object.0">NSTextField</string> + </object> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/bookmark_name_folder_controller.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/status_bubble_mac.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/tab_strip_model_observer_bridge.h</string> + </object> + </object> + </object> + </object> + <int key="IBDocument.localizationMode">0</int> + <string key="IBDocument.LastKnownRelativeProjectPath">../../chrome.xcodeproj</string> + <int key="IBDocument.defaultPropertyAccessControl">3</int> + </data> +</archive> diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h index 6e57bfa..67ecf67 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.h +++ b/chrome/browser/cocoa/bookmark_bar_controller.h @@ -96,6 +96,7 @@ class PrefService; - (IBAction)openAllBookmarks:(id)sender; // Or from a context menu over either the bar or a button. - (IBAction)addPage:(id)sender; +- (IBAction)addOrRenameFolder:(id)sender; @end diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index 65a8135..fd2e0fe 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -13,6 +13,7 @@ #import "chrome/browser/cocoa/bookmark_bar_view.h" #import "chrome/browser/cocoa/bookmark_button_cell.h" #import "chrome/browser/cocoa/bookmark_editor_controller.h" +#import "chrome/browser/cocoa/bookmark_name_folder_controller.h" #include "chrome/browser/profile.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -194,11 +195,13 @@ const CGFloat kBookmarkHorizontalPadding = 1.0; } } +// Return nil if menuItem has no delegate. - (BookmarkNode*)nodeFromMenuItem:(id)menuItem { NSCell* cell = [[menuItem menu] delegate]; + if (!cell) + return nil; BookmarkNode* node = static_cast<BookmarkNode*>( [[cell representedObject] pointerValue]); - DCHECK(node); return node; } @@ -236,6 +239,15 @@ const CGFloat kBookmarkHorizontalPadding = 1.0; - (IBAction)editBookmark:(id)sender { BookmarkNode* node = [self nodeFromMenuItem:sender]; + + // TODO(jrg): on windows, folder "buttons" use the bar's context + // menu (but with extra items enabled, like Rename). For now we do + // a cheat and redirect so we have the functionality available. + if (node->is_folder()) { + [self addOrRenameFolder:sender]; + return; + } + // There is no real need to jump to a platform-common routine at // this point (which just jumps back to objc) other than consistency // across platforms. @@ -286,6 +298,22 @@ const CGFloat kBookmarkHorizontalPadding = 1.0; nil); } +// Might be from the context menu over the bar OR over a button. +- (IBAction)addOrRenameFolder:(id)sender { + // node is NULL if we were invoked from the bar, and that's fine. + BookmarkNode* node = [self nodeFromMenuItem:sender]; + BookmarkNameFolderController* controller = + [[BookmarkNameFolderController alloc] + initWithParentWindow:[[self view] window] + profile:profile_ + node:node]; + [controller runModal]; + + // runModal will run the window as a sheet. The + // BookmarkNameFolderController will release itself when the sheet + // ends. +} + // Delete all bookmarks from the bookmark bar. - (void)clearBookmarkBar { [buttons_ makeObjectsPerformSelector:@selector(removeFromSuperview)]; diff --git a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm index c6bfa83..8400b9c 100644 --- a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm @@ -17,8 +17,6 @@ class BookmarkEditorControllerTest : public testing::Test { scoped_nsobject<BookmarkEditorController> bar_; }; -// Lots TODO here. - TEST_F(BookmarkEditorControllerTest, NoNodeNoTree) { BookmarkModel* model = helper_.profile()->GetBookmarkModel(); const BookmarkNode* parent = model->GetBookmarkBarNode(); diff --git a/chrome/browser/cocoa/bookmark_name_folder_controller.h b/chrome/browser/cocoa/bookmark_name_folder_controller.h new file mode 100644 index 0000000..64c3183 --- /dev/null +++ b/chrome/browser/cocoa/bookmark_name_folder_controller.h @@ -0,0 +1,38 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_BOOKMARK_NAME_FOLDER_CONTROLLER_H_ +#define CHROME_BROWSER_COCOA_BOOKMARK_NAME_FOLDER_CONTROLLER_H_ + +#import <Cocoa/Cocoa.h> + +#include "base/scoped_ptr.h" +#include "base/scoped_nsobject.h" +#include "chrome/browser/bookmarks/bookmark_model.h" + +// A controller for dialog to let the user creating a new folder or +// renaming an existing folder. Accessible from a context menu on a +// bookmark button or the bookmark bar. +@interface BookmarkNameFolderController : NSWindowController { + @private + IBOutlet NSTextField* nameField_; + + NSWindow* parentWindow_; // weak + Profile* profile_; // weak + const BookmarkNode* node_; // weak; owned by the model + scoped_nsobject<NSString> initialName_; +} +- (id)initWithParentWindow:(NSWindow*)window + profile:(Profile*)profile + node:(const BookmarkNode*)node; +- (void)runModal; +- (IBAction)cancel:(id)sender; +- (IBAction)ok:(id)sender; +@end + +@interface BookmarkNameFolderController(TestingAPI) +- (void)setFolderName:(NSString*)name; +@end + +#endif /* CHROME_BROWSER_COCOA_BOOKMARK_NAME_FOLDER_CONTROLLER_H_ */ diff --git a/chrome/browser/cocoa/bookmark_name_folder_controller.mm b/chrome/browser/cocoa/bookmark_name_folder_controller.mm new file mode 100644 index 0000000..fa24ac5 --- /dev/null +++ b/chrome/browser/cocoa/bookmark_name_folder_controller.mm @@ -0,0 +1,85 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/mac_util.h" +#include "base/sys_string_conversions.h" +#include "chrome/browser/profile.h" +#import "chrome/browser/cocoa/bookmark_name_folder_controller.h" + +@implementation BookmarkNameFolderController + +- (id)initWithParentWindow:(NSWindow*)window + profile:(Profile*)profile + node:(const BookmarkNode*)node { + NSString* nibpath = [mac_util::MainAppBundle() + pathForResource:@"BookmarkNameFolder" + ofType:@"nib"]; + if ((self = [super initWithWindowNibPath:nibpath owner:self])) { + parentWindow_ = window; + profile_ = profile; + node_ = node; + if (node_) { + initialName_.reset([base::SysWideToNSString(node_->GetTitle()) retain]); + } else { + initialName_.reset([@"" retain]); + } + } + return self; +} + +- (void)awakeFromNib { + [nameField_ setStringValue:initialName_.get()]; + if (node_) { + // TODO(jrg)?: on Windows the dialog is named either New Folder or + // Edit Folder Name. However, since we're a sheet on the Mac, the + // title is never seen. If we switch from a sheet, correct the + // title right here. + } +} + +// TODO(jrg): consider NSModalSession. +- (void)runModal { + [NSApp beginSheet:[self window] + modalForWindow:parentWindow_ + modalDelegate:self + didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) + contextInfo:nil]; +} + +- (IBAction)cancel:(id)sender { + [NSApp endSheet:[self window]]; +} + +- (IBAction)ok:(id)sender { + NSString* name = [nameField_ stringValue]; + if (![name isEqual:initialName_.get()]) { + BookmarkModel* model = profile_->GetBookmarkModel(); + if (node_) { + model->SetTitle(node_, base::SysNSStringToWide(name)); + } else { + // TODO(jrg): check sender to accomodate creating a folder while + // NOT over the bar (e.g. when over an expanded folder itself). + // Need to wait until I add folders before I can do that + // properly. + // For now only add the folder at the top level. + model->AddGroup(model->GetBookmarkBarNode(), + model->GetBookmarkBarNode()->GetChildCount(), + base::SysNSStringToWide(name)); + } + } + [NSApp endSheet:[self window]]; +} + +- (void)didEndSheet:(NSWindow*)sheet + returnCode:(int)returnCode + contextInfo:(void*)contextInfo { + [[self window] orderOut:self]; + [self autorelease]; +} + +- (void)setFolderName:(NSString*)name { + [nameField_ setStringValue:name]; +} + +@end // BookmarkNameFolderController diff --git a/chrome/browser/cocoa/bookmark_name_folder_controller_unittest.mm b/chrome/browser/cocoa/bookmark_name_folder_controller_unittest.mm new file mode 100644 index 0000000..bf00f68 --- /dev/null +++ b/chrome/browser/cocoa/bookmark_name_folder_controller_unittest.mm @@ -0,0 +1,63 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> + +#include "base/scoped_nsobject.h" +#import "chrome/browser/cocoa/bookmark_name_folder_controller.h" +#include "chrome/browser/cocoa/browser_test_helper.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "testing/gtest/include/gtest/gtest.h" + +class BookmarkNameFolderControllerTest : public testing::Test { + public: + CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... + BrowserTestHelper helper_; +}; + + +TEST_F(BookmarkNameFolderControllerTest, AddAndRename) { + BookmarkModel* model = helper_.profile()->GetBookmarkModel(); + const BookmarkNode* parent = model->GetBookmarkBarNode(); + const BookmarkNode* node = NULL; + EXPECT_EQ(0, parent->GetChildCount()); + + scoped_nsobject<BookmarkNameFolderController> + controller([[BookmarkNameFolderController alloc] + initWithParentWindow:cocoa_helper_.window() + profile:helper_.profile() + node:node]); + [controller window]; // force nib load + + // Do nothing. + [controller cancel:nil]; + EXPECT_EQ(0, parent->GetChildCount()); + + // Change name then cancel. + [controller setFolderName:@"Bozo"]; + [controller cancel:nil]; + EXPECT_EQ(0, parent->GetChildCount()); + + // Add a new folder. + [controller ok:nil]; + EXPECT_EQ(1, parent->GetChildCount()); + EXPECT_TRUE(parent->GetChild(0)->is_folder()); + EXPECT_EQ(L"Bozo", parent->GetChild(0)->GetTitle()); + + // Rename the folder by creating a controller that originates from + // the node. + node = parent->GetChild(0); + controller.reset([[BookmarkNameFolderController alloc] + initWithParentWindow:cocoa_helper_.window() + profile:helper_.profile() + node:node]); + [controller window]; // force nib load + + [controller setFolderName:@"Zobo"]; + [controller ok:nil]; + EXPECT_EQ(1, parent->GetChildCount()); + EXPECT_TRUE(parent->GetChild(0)->is_folder()); + EXPECT_EQ(L"Zobo", parent->GetChild(0)->GetTitle()); +} + diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 2f04d15..8c930c4 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -773,6 +773,8 @@ 'browser/cocoa/bookmark_menu_bridge.mm', 'browser/cocoa/bookmark_menu_cocoa_controller.h', 'browser/cocoa/bookmark_menu_cocoa_controller.mm', + 'browser/cocoa/bookmark_name_folder_controller.h', + 'browser/cocoa/bookmark_name_folder_controller.mm', 'browser/cocoa/browser_test_helper.h', 'browser/cocoa/browser_window.h', 'browser/cocoa/browser_window.mm', @@ -2645,6 +2647,7 @@ 'app/nibs/About.xib', 'app/nibs/BookmarkBar.xib', 'app/nibs/BookmarkEditor.xib', + 'app/nibs/BookmarkNameFolder.xib', 'app/nibs/BrowserWindow.xib', 'app/nibs/ClearBrowsingData.xib', 'app/nibs/DownloadItem.xib', @@ -3697,6 +3700,7 @@ 'browser/cocoa/bookmark_editor_controller_unittest.mm', 'browser/cocoa/bookmark_menu_bridge_unittest.mm', 'browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm', + 'browser/cocoa/bookmark_name_folder_controller_unittest.mm', 'browser/cocoa/browser_window_cocoa_unittest.mm', 'browser/cocoa/browser_window_controller_unittest.mm', 'browser/cocoa/clear_browsing_data_controller_unittest.mm', |