diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-30 17:59:24 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-30 17:59:24 +0000 |
commit | 4240438bc0860628bc93b59c291c9a4b6f69d2ff (patch) | |
tree | 6fa475044ba9b83cdb1e4290da649cb04ddaa9c7 /chrome | |
parent | 75e287db9508753ada184ee4252b679912f6f085 (diff) | |
download | chromium_src-4240438bc0860628bc93b59c291c9a4b6f69d2ff.zip chromium_src-4240438bc0860628bc93b59c291c9a4b6f69d2ff.tar.gz chromium_src-4240438bc0860628bc93b59c291c9a4b6f69d2ff.tar.bz2 |
Add a very basic preferences window controller with unit test. Fix the prefs nib to know the FileOwner is a NSWindowController and hook them together.
Review URL: http://codereview.chromium.org/102015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14958 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/nibs/en.lproj/Preferences.xib | 29 | ||||
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.h | 21 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.mm | 49 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller_unittest.mm | 36 | ||||
-rw-r--r-- | chrome/chrome.gyp | 3 |
6 files changed, 141 insertions, 7 deletions
diff --git a/chrome/app/nibs/en.lproj/Preferences.xib b/chrome/app/nibs/en.lproj/Preferences.xib index b6b4184..753db5e 100644 --- a/chrome/app/nibs/en.lproj/Preferences.xib +++ b/chrome/app/nibs/en.lproj/Preferences.xib @@ -25,7 +25,7 @@ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSCustomObject" id="1001"> - <string key="NSClassName">NSObject</string> + <string key="NSClassName">NSWindowController</string> </object> <object class="NSCustomObject" id="1003"> <string key="NSClassName">FirstResponder</string> @@ -37,7 +37,7 @@ <int key="NSWindowStyleMask">15</int> <int key="NSWindowBacking">2</int> <string key="NSWindowRect">{{196, 7}, {559, 503}}</string> - <int key="NSWTFlags">1677721600</int> + <int key="NSWTFlags">1677722624</int> <string key="NSWindowTitle">Preferences</string> <string key="NSWindowClass">NSWindow</string> <nil key="NSViewClass"/> @@ -2309,6 +2309,14 @@ ZGVkIGZpbGVzIGRvbid0IG9wZW4gYXV0b21hdGljYWxseS4</string> <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">window</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="871378074"/> + </object> + <int key="connectionID">252</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -3781,11 +3789,22 @@ ZGVkIGZpbGVzIGRvbid0IG9wZW4gYXV0b21hdGljYWxseS4</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">251</int> + <int key="maxID">252</int> + </object> + <object class="IBClassDescriber" key="IBDocument.Classes"> + <object class="NSMutableArray" key="referencedPartialClassDescriptions"> + <bool key="EncodedWithXMLCoder">YES</bool> + <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> - <object class="IBClassDescriber" key="IBDocument.Classes"/> <int key="IBDocument.localizationMode">0</int> - <nil key="IBDocument.LastKnownRelativeProjectPath"/> + <string key="IBDocument.LastKnownRelativeProjectPath">../../../chrome.xcodeproj</string> <int key="IBDocument.defaultPropertyAccessControl">3</int> </data> </archive> diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 2992289..082d0f5 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -13,6 +13,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_shutdown.h" #import "chrome/browser/cocoa/bookmark_menu_bridge.h" +#import "chrome/browser/cocoa/preferences_window_controller.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/profile_manager.h" #include "chrome/common/temp_scaffolding_stubs.h" @@ -184,7 +185,7 @@ void OpenURLs(const std::vector<GURL>& urls) { launch.OpenURLsInBrowser(BrowserList::GetLastActive(), false, urls); } -} +} // namespace - (void)getUrl:(NSAppleEventDescriptor*)event withReply:(NSAppleEventDescriptor*)reply { @@ -234,7 +235,12 @@ void OpenURLs(const std::vector<GURL>& urls) { // Show the preferences window, or bring it to the front if it's already // visible. - (IBAction)showPreferences:(id)sender { -// TODO(pinkerton): more goes here... + if (!prefsController_.get()) { + PrefService* prefs = [self defaultProfile]->GetPrefs(); + prefsController_.reset([[PreferencesWindowController alloc] + initWithPrefs:prefs]); + } + [prefsController_ showPreferences:sender]; } @end diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h new file mode 100644 index 0000000..f1bf625 --- /dev/null +++ b/chrome/browser/cocoa/preferences_window_controller.h @@ -0,0 +1,21 @@ +// 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> + +class PrefService; + +// A window controller that handles the preferences window. +@interface PreferencesWindowController : NSWindowController { + @private + PrefService* prefs_; // weak ref +} + +// Designated initializer. |prefs| should not be NULL. +- (id)initWithPrefs:(PrefService*)prefs; + +// Show the preferences window. +- (IBAction)showPreferences:(id)sender; + +@end diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm new file mode 100644 index 0000000..941d6b3 --- /dev/null +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -0,0 +1,49 @@ +// 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 "chrome/browser/cocoa/preferences_window_controller.h" + +#include "base/mac_util.h" +#include "chrome/common/pref_service.h" + +PreferencesWindowController* gPrefWindowSingleton = nil; + +@implementation PreferencesWindowController + +- (id)initWithPrefs:(PrefService*)prefs { + DCHECK(prefs); + // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we + // can override it in a unit test. + NSString *nibpath = [mac_util::MainAppBundle() + pathForResource:@"Preferences" + ofType:@"nib"]; + if ((self = [super initWithWindowNibPath:nibpath owner:self])) { + prefs_ = prefs; + } + return self; +} + +- (void)awakeFromNib { + +} + +// Synchronizes the window's UI elements with the values in |prefs_|. +- (void)syncWithPrefs { + // TODO(pinkerton): do it... +} + +// Show the preferences window. +- (IBAction)showPreferences:(id)sender { + [self syncWithPrefs]; + [self showWindow:sender]; +} + +// Called when the window is being closed. Send out a notification that the +// user is done editing preferences. +- (void)windowWillClose:(NSNotification *)notification { + // TODO(pinkerton): send notification. Write unit test that makes sure + // we receive it. +} + +@end diff --git a/chrome/browser/cocoa/preferences_window_controller_unittest.mm b/chrome/browser/cocoa/preferences_window_controller_unittest.mm new file mode 100644 index 0000000..85018b0 --- /dev/null +++ b/chrome/browser/cocoa/preferences_window_controller_unittest.mm @@ -0,0 +1,36 @@ +// 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> + +#import "base/scoped_nsobject.h" +#import "chrome/browser/cocoa/preferences_window_controller.h" +#include "chrome/browser/cocoa/browser_test_helper.h" +#include "chrome/browser/cocoa/cocoa_test_helper.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" + +namespace { + +class PrefsControllerTest : public PlatformTest { + public: + PrefsControllerTest() { + PrefService* prefs = browser_helper_.profile()->GetPrefs(); + pref_controller_.reset([[PreferencesWindowController alloc] + initWithPrefs:prefs]); + EXPECT_TRUE(pref_controller_.get()); + } + + BrowserTestHelper browser_helper_; + CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... + scoped_nsobject<PreferencesWindowController> pref_controller_; +}; + +// Test showing the preferences window and making sure it's visible +TEST_F(PrefsControllerTest, Show) { + [pref_controller_ showPreferences:nil]; + EXPECT_TRUE([[pref_controller_ window] isVisible]); +} + +} // namespace diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index bf05cde..3013a11 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -548,6 +548,8 @@ 'browser/cocoa/grow_box_view.m', 'browser/cocoa/location_bar_view_mac.h', 'browser/cocoa/location_bar_view_mac.mm', + 'browser/cocoa/preferences_window_controller.h', + 'browser/cocoa/preferences_window_controller.mm', 'browser/cocoa/sad_tab_view.h', 'browser/cocoa/sad_tab_view.mm', 'browser/cocoa/shell_dialogs_mac.mm', @@ -2265,6 +2267,7 @@ 'browser/cocoa/find_bar_view_unittest.mm', 'browser/cocoa/location_bar_view_mac_unittest.mm', 'browser/cocoa/grow_box_view_unittest.mm', + 'browser/cocoa/preferences_window_controller_unittest.mm', 'browser/cocoa/sad_tab_view_unittest.mm', 'browser/cocoa/status_bubble_mac_unittest.mm', 'browser/cocoa/tab_cell_unittest.mm', |