summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_name_folder_controller.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 18:18:56 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 18:18:56 +0000
commit1d379a14439d1ba1753a3fbe91d3fd4bcd6e21ba (patch)
treec765a5a2b54b9d408056cb151aebe421300e8199 /chrome/browser/cocoa/bookmark_name_folder_controller.mm
parent51cb4f57e5143cdf7c0a46ce86c6b3091f66e7f3 (diff)
downloadchromium_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
Diffstat (limited to 'chrome/browser/cocoa/bookmark_name_folder_controller.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_name_folder_controller.mm85
1 files changed, 85 insertions, 0 deletions
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