OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/preferences_window_controller.h" | 5 #import "chrome/browser/cocoa/preferences_window_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/l10n_util_mac.h" | 10 #include "app/l10n_util_mac.h" |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 @interface PreferencesWindowController(Private) | 323 @interface PreferencesWindowController(Private) |
324 // Callback when preferences are changed. |prefName| is the name of the | 324 // Callback when preferences are changed. |prefName| is the name of the |
325 // pref that has changed. | 325 // pref that has changed. |
326 - (void)prefChanged:(std::string*)prefName; | 326 - (void)prefChanged:(std::string*)prefName; |
327 // Callback when sync state has changed. syncService_ needs to be | 327 // Callback when sync state has changed. syncService_ needs to be |
328 // queried to find out what happened. | 328 // queried to find out what happened. |
329 - (void)syncStateChanged; | 329 - (void)syncStateChanged; |
330 // Record the user performed a certain action and save the preferences. | 330 // Record the user performed a certain action and save the preferences. |
331 - (void)recordUserAction:(const UserMetricsAction&) action; | 331 - (void)recordUserAction:(const UserMetricsAction&) action; |
332 - (void)registerPrefObservers; | 332 - (void)registerPrefObservers; |
333 - (void)unregisterPrefObservers; | |
334 | 333 |
335 // KVC setter methods. | 334 // KVC setter methods. |
336 - (void)setNewTabPageIsHomePageIndex:(NSInteger)val; | 335 - (void)setNewTabPageIsHomePageIndex:(NSInteger)val; |
337 - (void)setHomepageURL:(NSString*)urlString; | 336 - (void)setHomepageURL:(NSString*)urlString; |
338 - (void)setRestoreOnStartupIndex:(NSInteger)type; | 337 - (void)setRestoreOnStartupIndex:(NSInteger)type; |
339 - (void)setShowHomeButton:(BOOL)value; | 338 - (void)setShowHomeButton:(BOOL)value; |
340 - (void)setPasswordManagerEnabledIndex:(NSInteger)value; | 339 - (void)setPasswordManagerEnabledIndex:(NSInteger)value; |
341 - (void)setIsUsingDefaultTheme:(BOOL)value; | 340 - (void)setIsUsingDefaultTheme:(BOOL)value; |
342 - (void)setShowAlternateErrorPages:(BOOL)value; | 341 - (void)setShowAlternateErrorPages:(BOOL)value; |
343 - (void)setUseSuggest:(BOOL)value; | 342 - (void)setUseSuggest:(BOOL)value; |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 [NSColor colorWithCalibratedWhite:kBannerStrokeColor | 753 [NSColor colorWithCalibratedWhite:kBannerStrokeColor |
755 alpha:1.0]; | 754 alpha:1.0]; |
756 [managedPrefsBannerView_ setStrokeColor:bannerStrokeColor]; | 755 [managedPrefsBannerView_ setStrokeColor:bannerStrokeColor]; |
757 } | 756 } |
758 | 757 |
759 - (void)dealloc { | 758 - (void)dealloc { |
760 if (syncService_) { | 759 if (syncService_) { |
761 syncService_->RemoveObserver(observer_.get()); | 760 syncService_->RemoveObserver(observer_.get()); |
762 } | 761 } |
763 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 762 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
764 [self unregisterPrefObservers]; | |
765 [animation_ setDelegate:nil]; | 763 [animation_ setDelegate:nil]; |
766 [animation_ stopAnimation]; | 764 [animation_ stopAnimation]; |
767 [super dealloc]; | 765 [super dealloc]; |
768 } | 766 } |
769 | 767 |
770 // Xcode 3.1.x version of Interface Builder doesn't do a lot for editing | 768 // Xcode 3.1.x version of Interface Builder doesn't do a lot for editing |
771 // toolbars in XIB. So the toolbar's delegate is set to the controller so it | 769 // toolbars in XIB. So the toolbar's delegate is set to the controller so it |
772 // can tell the toolbar what items are selectable. | 770 // can tell the toolbar what items are selectable. |
773 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar { | 771 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar { |
774 DCHECK(toolbar == toolbar_); | 772 DCHECK(toolbar == toolbar_); |
775 return [[toolbar_ items] valueForKey:@"itemIdentifier"]; | 773 return [[toolbar_ items] valueForKey:@"itemIdentifier"]; |
776 } | 774 } |
777 | 775 |
778 // Register our interest in the preferences we're displaying so if anything | 776 // Register our interest in the preferences we're displaying so if anything |
779 // else in the UI changes them we will be updated. | 777 // else in the UI changes them we will be updated. |
780 - (void)registerPrefObservers { | 778 - (void)registerPrefObservers { |
781 if (!prefs_) return; | 779 if (!prefs_) return; |
782 | 780 |
783 // Basics panel | 781 // Basics panel |
784 prefs_->AddPrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get()); | 782 registrar_.Init(prefs_); |
| 783 registrar_.Add(prefs::kURLsToRestoreOnStartup, observer_.get()); |
785 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); | 784 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); |
786 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, | 785 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, |
787 prefs_, observer_.get()); | 786 prefs_, observer_.get()); |
788 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); | 787 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); |
789 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); | 788 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); |
790 | 789 |
791 // Personal Stuff panel | 790 // Personal Stuff panel |
792 askSavePasswords_.Init(prefs::kPasswordManagerEnabled, | 791 askSavePasswords_.Init(prefs::kPasswordManagerEnabled, |
793 prefs_, observer_.get()); | 792 prefs_, observer_.get()); |
794 autoFillEnabled_.Init(prefs::kAutoFillEnabled, prefs_, observer_.get()); | 793 autoFillEnabled_.Init(prefs::kAutoFillEnabled, prefs_, observer_.get()); |
(...skipping 21 matching lines...) Expand all Loading... |
816 metricsReporting_.Init(prefs::kMetricsReportingEnabled, | 815 metricsReporting_.Init(prefs::kMetricsReportingEnabled, |
817 local, observer_.get()); | 816 local, observer_.get()); |
818 defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_, | 817 defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_, |
819 observer_.get()); | 818 observer_.get()); |
820 askForSaveLocation_.Init(prefs::kPromptForDownload, prefs_, observer_.get()); | 819 askForSaveLocation_.Init(prefs::kPromptForDownload, prefs_, observer_.get()); |
821 | 820 |
822 // We don't need to observe changes in this value. | 821 // We don't need to observe changes in this value. |
823 lastSelectedPage_.Init(prefs::kOptionsWindowLastTabIndex, local, NULL); | 822 lastSelectedPage_.Init(prefs::kOptionsWindowLastTabIndex, local, NULL); |
824 } | 823 } |
825 | 824 |
826 // Clean up what was registered in -registerPrefObservers. We only have to | |
827 // clean up the non-PrefMember registrations. | |
828 - (void)unregisterPrefObservers { | |
829 if (!prefs_) return; | |
830 | |
831 // Basics | |
832 prefs_->RemovePrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get()); | |
833 | |
834 // Nothing to do for other panels... | |
835 } | |
836 | |
837 // Called when the window wants to be closed. | 825 // Called when the window wants to be closed. |
838 - (BOOL)windowShouldClose:(id)sender { | 826 - (BOOL)windowShouldClose:(id)sender { |
839 // Stop any animation and clear the delegate to avoid stale pointers. | 827 // Stop any animation and clear the delegate to avoid stale pointers. |
840 [animation_ setDelegate:nil]; | 828 [animation_ setDelegate:nil]; |
841 [animation_ stopAnimation]; | 829 [animation_ stopAnimation]; |
842 | 830 |
843 return YES; | 831 return YES; |
844 } | 832 } |
845 | 833 |
846 // Called when the user hits the escape key. Closes the window. | 834 // Called when the user hits the escape key. Closes the window. |
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2131 case OPTIONS_PAGE_ADVANCED: | 2119 case OPTIONS_PAGE_ADVANCED: |
2132 return underTheHoodView_; | 2120 return underTheHoodView_; |
2133 case OPTIONS_PAGE_DEFAULT: | 2121 case OPTIONS_PAGE_DEFAULT: |
2134 case OPTIONS_PAGE_COUNT: | 2122 case OPTIONS_PAGE_COUNT: |
2135 LOG(DFATAL) << "Invalid page value " << page; | 2123 LOG(DFATAL) << "Invalid page value " << page; |
2136 } | 2124 } |
2137 return basicsView_; | 2125 return basicsView_; |
2138 } | 2126 } |
2139 | 2127 |
2140 @end | 2128 @end |
OLD | NEW |