OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
| 6 #include "app/l10n_util_mac.h" |
6 #include "base/mac_util.h" | 7 #include "base/mac_util.h" |
7 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
8 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
9 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h" | 10 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h" |
10 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
11 | 12 |
12 @implementation BookmarkNameFolderController | 13 @implementation BookmarkNameFolderController |
13 | 14 |
14 - (id)initWithParentWindow:(NSWindow*)window | 15 - (id)initWithParentWindow:(NSWindow*)window |
15 profile:(Profile*)profile | 16 profile:(Profile*)profile |
16 node:(const BookmarkNode*)node { | 17 node:(const BookmarkNode*)node { |
17 NSString* nibpath = [mac_util::MainAppBundle() | 18 NSString* nibpath = [mac_util::MainAppBundle() |
18 pathForResource:@"BookmarkNameFolder" | 19 pathForResource:@"BookmarkNameFolder" |
19 ofType:@"nib"]; | 20 ofType:@"nib"]; |
20 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 21 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
21 parentWindow_ = window; | 22 parentWindow_ = window; |
22 profile_ = profile; | 23 profile_ = profile; |
23 node_ = node; | 24 node_ = node; |
24 std::wstring newFolderString = | 25 if (node_) { |
25 l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME); | 26 initialName_.reset([base::SysWideToNSString(node_->GetTitle()) retain]); |
26 initialName_.reset([base::SysWideToNSString(newFolderString) retain]); | 27 } else { |
| 28 NSString* newString = |
| 29 l10n_util::GetNSStringWithFixup(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME); |
| 30 initialName_.reset([newString retain]); |
| 31 } |
27 } | 32 } |
28 return self; | 33 return self; |
29 } | 34 } |
30 | 35 |
31 - (void)awakeFromNib { | 36 - (void)awakeFromNib { |
32 [nameField_ setStringValue:initialName_.get()]; | 37 [nameField_ setStringValue:initialName_.get()]; |
33 [self controlTextDidChange:nil]; | 38 [self controlTextDidChange:nil]; |
34 } | 39 } |
35 | 40 |
36 // Called as a side-effect of being the delegate of the text field. Ensure the | 41 // Called as a side-effect of being the delegate of the text field. Ensure the |
(...skipping 10 matching lines...) Expand all Loading... |
47 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) | 52 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) |
48 contextInfo:nil]; | 53 contextInfo:nil]; |
49 } | 54 } |
50 | 55 |
51 - (IBAction)cancel:(id)sender { | 56 - (IBAction)cancel:(id)sender { |
52 [NSApp endSheet:[self window]]; | 57 [NSApp endSheet:[self window]]; |
53 } | 58 } |
54 | 59 |
55 - (IBAction)ok:(id)sender { | 60 - (IBAction)ok:(id)sender { |
56 NSString* name = [nameField_ stringValue]; | 61 NSString* name = [nameField_ stringValue]; |
57 if (![name isEqual:initialName_.get()]) { | 62 BookmarkModel* model = profile_->GetBookmarkModel(); |
58 BookmarkModel* model = profile_->GetBookmarkModel(); | 63 if (node_) { |
59 if (node_) { | 64 model->SetTitle(node_, base::SysNSStringToWide(name)); |
60 model->SetTitle(node_, base::SysNSStringToWide(name)); | 65 } else { |
61 } else { | 66 // TODO(jrg): check sender to accomodate creating a folder while |
62 // TODO(jrg): check sender to accomodate creating a folder while | 67 // NOT over the bar (e.g. when over an expanded folder itself). |
63 // NOT over the bar (e.g. when over an expanded folder itself). | 68 // Need to wait until I add folders before I can do that |
64 // Need to wait until I add folders before I can do that | 69 // properly. |
65 // properly. | 70 // For now only add the folder at the top level. |
66 // For now only add the folder at the top level. | 71 model->AddGroup(model->GetBookmarkBarNode(), |
67 model->AddGroup(model->GetBookmarkBarNode(), | 72 model->GetBookmarkBarNode()->GetChildCount(), |
68 model->GetBookmarkBarNode()->GetChildCount(), | 73 base::SysNSStringToWide(name)); |
69 base::SysNSStringToWide(name)); | |
70 } | |
71 } | 74 } |
72 [NSApp endSheet:[self window]]; | 75 [NSApp endSheet:[self window]]; |
73 } | 76 } |
74 | 77 |
75 - (void)didEndSheet:(NSWindow*)sheet | 78 - (void)didEndSheet:(NSWindow*)sheet |
76 returnCode:(int)returnCode | 79 returnCode:(int)returnCode |
77 contextInfo:(void*)contextInfo { | 80 contextInfo:(void*)contextInfo { |
78 [[self window] orderOut:self]; | 81 [[self window] orderOut:self]; |
79 [self autorelease]; | 82 [self autorelease]; |
80 } | 83 } |
81 | 84 |
| 85 - (NSString*)folderName { |
| 86 return [nameField_ stringValue]; |
| 87 } |
| 88 |
82 - (void)setFolderName:(NSString*)name { | 89 - (void)setFolderName:(NSString*)name { |
83 [nameField_ setStringValue:name]; | 90 [nameField_ setStringValue:name]; |
84 [self controlTextDidChange:nil]; | 91 [self controlTextDidChange:nil]; |
85 } | 92 } |
86 | 93 |
87 - (NSButton*)okButton { | 94 - (NSButton*)okButton { |
88 return okButton_; | 95 return okButton_; |
89 } | 96 } |
90 | 97 |
91 @end // BookmarkNameFolderController | 98 @end // BookmarkNameFolderController |
OLD | NEW |