Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: chrome/browser/cocoa/browser_window_controller.mm

Issue 363017: Added menu items for sync to Chrome/wrench menu (Closed)
Patch Set: Fixed release-mode warnings. Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <Carbon/Carbon.h> 5 #include <Carbon/Carbon.h>
6 6
7 #include "app/l10n_util_mac.h"
7 #include "base/mac_util.h" 8 #include "base/mac_util.h"
8 #include "base/scoped_nsdisable_screen_updates.h" 9 #include "base/scoped_nsdisable_screen_updates.h"
9 #import "base/scoped_nsobject.h" 10 #import "base/scoped_nsobject.h"
10 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
11 #include "chrome/app/chrome_dll_resource.h" // IDC_* 12 #include "chrome/app/chrome_dll_resource.h" // IDC_*
12 #include "chrome/browser/bookmarks/bookmark_editor.h" 13 #include "chrome/browser/bookmarks/bookmark_editor.h"
13 #include "chrome/browser/browser.h" 14 #include "chrome/browser/browser.h"
14 #include "chrome/browser/browser_list.h" 15 #include "chrome/browser/browser_list.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/encoding_menu_controller.h" 17 #include "chrome/browser/encoding_menu_controller.h"
(...skipping 15 matching lines...) Expand all
32 #include "chrome/browser/cocoa/find_bar_bridge.h" 33 #include "chrome/browser/cocoa/find_bar_bridge.h"
33 #import "chrome/browser/cocoa/fullscreen_window.h" 34 #import "chrome/browser/cocoa/fullscreen_window.h"
34 #import "chrome/browser/cocoa/infobar_container_controller.h" 35 #import "chrome/browser/cocoa/infobar_container_controller.h"
35 #import "chrome/browser/cocoa/status_bubble_mac.h" 36 #import "chrome/browser/cocoa/status_bubble_mac.h"
36 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" 37 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h"
37 #import "chrome/browser/cocoa/tab_strip_view.h" 38 #import "chrome/browser/cocoa/tab_strip_view.h"
38 #import "chrome/browser/cocoa/tab_strip_controller.h" 39 #import "chrome/browser/cocoa/tab_strip_controller.h"
39 #import "chrome/browser/cocoa/tab_view.h" 40 #import "chrome/browser/cocoa/tab_view.h"
40 #import "chrome/browser/cocoa/toolbar_controller.h" 41 #import "chrome/browser/cocoa/toolbar_controller.h"
41 #import "chrome/browser/browser_theme_provider.h" 42 #import "chrome/browser/browser_theme_provider.h"
43 #include "chrome/browser/sync/sync_status_ui_helper.h"
42 #include "chrome/common/pref_service.h" 44 #include "chrome/common/pref_service.h"
43 #import "chrome/browser/cocoa/background_gradient_view.h" 45 #import "chrome/browser/cocoa/background_gradient_view.h"
46 #include "grit/generated_resources.h"
44 #include "grit/theme_resources.h" 47 #include "grit/theme_resources.h"
45 #import "third_party/GTM/AppKit/GTMTheme.h" 48 #import "third_party/GTM/AppKit/GTMTheme.h"
46 49
47 namespace { 50 namespace {
48 51
49 // Size of the gradient. Empirically determined so that the gradient looks 52 // Size of the gradient. Empirically determined so that the gradient looks
50 // like what the heuristic does when there are just a few tabs. 53 // like what the heuristic does when there are just a few tabs.
51 const int kWindowGradientHeight = 24; 54 const int kWindowGradientHeight = 24;
52 55
53 } 56 }
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow]; 575 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow];
573 break; 576 break;
574 case IDC_RESTORE_TAB: 577 case IDC_RESTORE_TAB:
575 // We have to ask the Browser manually if we can restore. The 578 // We have to ask the Browser manually if we can restore. The
576 // command updater doesn't know. 579 // command updater doesn't know.
577 enable &= browser_->CanRestoreTab(); 580 enable &= browser_->CanRestoreTab();
578 break; 581 break;
579 case IDC_FULLSCREEN: 582 case IDC_FULLSCREEN:
580 enable &= [self supportsFullscreen]; 583 enable &= [self supportsFullscreen];
581 break; 584 break;
585 case IDC_SYNC_BOOKMARKS:
586 {
587 Profile* profile = browser_->profile()->GetOriginalProfile();
588 ProfileSyncService* syncService = profile->GetProfileSyncService();
589 // TODO(timsteele): Need a ui helper method to just get the type
590 // without needing labels.
591 string16 label, link;
592 SyncStatusUIHelper::MessageType status =
593 SyncStatusUIHelper::GetLabels(syncService, &label, &link);
594 enable &= (syncService != NULL);
595 [self updateSyncItem:item syncEnabled:enable status:status];
596 }
597 break;
582 default: 598 default:
583 // Special handling for the contents of the Text Encoding submenu. On 599 // Special handling for the contents of the Text Encoding submenu. On
584 // Mac OS, instead of enabling/disabling the top-level menu item, we 600 // Mac OS, instead of enabling/disabling the top-level menu item, we
585 // enable/disable the submenu's contents (per Apple's HIG). 601 // enable/disable the submenu's contents (per Apple's HIG).
586 EncodingMenuController encoding_controller; 602 EncodingMenuController encoding_controller;
587 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) { 603 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) {
588 enable &= browser_->command_updater()->IsCommandEnabled( 604 enable &= browser_->command_updater()->IsCommandEnabled(
589 IDC_ENCODING_MENU) ? YES : NO; 605 IDC_ENCODING_MENU) ? YES : NO;
590 } 606 }
591 } 607 }
592 608
593 // If the item is toggleable, find its toggle state and 609 // If the item is toggleable, find its toggle state and
594 // try to update it. This is a little awkward, but the alternative is 610 // try to update it. This is a little awkward, but the alternative is
595 // to check after a commandDispatch, which seems worse. 611 // to check after a commandDispatch, which seems worse.
596 [self updateToggleStateWithTag:tag forItem:item]; 612 [self updateToggleStateWithTag:tag forItem:item];
597 } 613 }
598 } 614 }
599 return enable; 615 return enable;
600 } 616 }
601 617
618 // TODO(akalin): We need to add a menu item to the main Chrome menu (near
619 // "Clear browsing data..."). However, this is tricky as no browsers may
620 // actually be open. Refactor the sync UI code so that it doesn't depend
621 // on a browser being present.
622
623 - (void)updateSyncItem:(id)syncItem
624 syncEnabled:(BOOL)syncEnabled
625 status:(SyncStatusUIHelper::MessageType)status {
626 DCHECK([syncItem isKindOfClass:[NSMenuItem class]]);
627 NSMenuItem* syncMenuItem = (NSMenuItem*)syncItem;
628 // Look for a separator immediately after the menu item.
629 NSMenuItem* followingSeparator = nil;
630 NSMenu* menu = [syncItem menu];
631 if (menu) {
632 NSInteger syncItemIndex = [menu indexOfItem:syncMenuItem];
633 DCHECK_NE(syncItemIndex, -1);
634 if ((syncItemIndex + 1) < [menu numberOfItems]) {
635 NSMenuItem* menuItem = [menu itemAtIndex:(syncItemIndex + 1)];
636 if ([menuItem isSeparatorItem]) {
637 followingSeparator = menuItem;
638 }
639 }
640 }
641
642 // TODO(akalin): consolidate this code with the equivalent Windows code in
643 // chrome/browser/views/toolbar_view.cc.
644 int titleId;
645 switch (status) {
646 case SyncStatusUIHelper::SYNCED:
647 titleId = IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL;
648 break;
649 case SyncStatusUIHelper::SYNC_ERROR:
650 titleId = IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL;
651 break;
652 case SyncStatusUIHelper::PRE_SYNCED:
653 titleId = IDS_SYNC_START_SYNC_BUTTON_LABEL;
654 break;
655 default:
656 NOTREACHED();
657 // Needed to prevent release-mode warnings.
658 titleId = IDS_SYNC_START_SYNC_BUTTON_LABEL;
659 break;
660 }
661 NSString* title = l10n_util::GetNSStringWithFixup(titleId);
662 [syncMenuItem setTitle:title];
663
664 // If we don't have a sync service, hide any sync-related menu
665 // items. However, sync_menu_item is enabled/disabled outside of this
666 // function so we don't touch it here, and separators are always disabled.
667 [syncMenuItem setHidden:!syncEnabled];
668 [followingSeparator setHidden:!syncEnabled];
669 }
670
602 // Called when the user picks a menu or toolbar item when this window is key. 671 // Called when the user picks a menu or toolbar item when this window is key.
603 // Calls through to the browser object to execute the command. This assumes that 672 // Calls through to the browser object to execute the command. This assumes that
604 // the command is supported and doesn't check, otherwise it would have been 673 // the command is supported and doesn't check, otherwise it would have been
605 // disabled in the UI in validateUserInterfaceItem:. 674 // disabled in the UI in validateUserInterfaceItem:.
606 - (void)commandDispatch:(id)sender { 675 - (void)commandDispatch:(id)sender {
607 NSInteger tag = [sender tag]; 676 NSInteger tag = [sender tag];
608 switch (tag) { 677 switch (tag) {
609 case IDC_RELOAD: 678 case IDC_RELOAD:
610 if ([sender isKindOfClass:[NSButton class]]) { 679 if ([sender isKindOfClass:[NSButton class]]) {
611 // We revert the bar when the reload button is pressed, but don't when 680 // We revert the bar when the reload button is pressed, but don't when
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 if (frameOverlayInactiveImage) { 1622 if (frameOverlayInactiveImage) {
1554 [theme setValue:frameOverlayInactiveImage 1623 [theme setValue:frameOverlayInactiveImage
1555 forAttribute:@"overlay" 1624 forAttribute:@"overlay"
1556 style:GTMThemeStyleWindow 1625 style:GTMThemeStyleWindow
1557 state:GTMThemeStateInactiveWindow]; 1626 state:GTMThemeStateInactiveWindow];
1558 } 1627 }
1559 1628
1560 return theme; 1629 return theme;
1561 } 1630 }
1562 @end 1631 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.h ('k') | chrome/browser/cocoa/browser_window_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698