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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.mm

Issue 2921083003: [Mac] Touch Bar Support for Dialogs (Closed)
Patch Set: Added test and renamed methods Created 3 years, 6 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stack> 5 #include <stack>
6 6
7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.h" 7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.h"
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac/bundle_locations.h" 11 #include "base/mac/bundle_locations.h"
12 #include "base/mac/foundation_util.h" 12 #include "base/mac/foundation_util.h"
13 #include "base/mac/mac_util.h"
14 #import "base/mac/sdk_forward_declarations.h"
13 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
15 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" 17 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
16 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser_dialogs.h" 19 #include "chrome/browser/ui/browser_dialogs.h"
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h" 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h"
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h"
20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h"
21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_tree_browser_cell.h" 23 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_tree_browser_cell.h"
22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 24 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
25 #include "chrome/common/chrome_features.h"
26 #include "chrome/grit/generated_resources.h"
23 #include "components/bookmarks/browser/bookmark_model.h" 27 #include "components/bookmarks/browser/bookmark_model.h"
24 #include "components/bookmarks/managed/managed_bookmark_service.h" 28 #include "components/bookmarks/managed/managed_bookmark_service.h"
25 #include "components/strings/grit/components_strings.h" 29 #include "components/strings/grit/components_strings.h"
30 #include "ui/base/cocoa/touch_bar_util.h"
26 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/l10n/l10n_util_mac.h" 32 #include "ui/base/l10n/l10n_util_mac.h"
28 #include "ui/base/material_design/material_design_controller.h" 33 #include "ui/base/material_design/material_design_controller.h"
34 #include "ui/strings/grit/ui_strings.h"
29 35
30 using bookmarks::BookmarkExpandedStateTracker; 36 using bookmarks::BookmarkExpandedStateTracker;
31 using bookmarks::BookmarkModel; 37 using bookmarks::BookmarkModel;
32 using bookmarks::BookmarkNode; 38 using bookmarks::BookmarkNode;
33 39
40 namespace {
41
42 // Touch bar identifier.
43 NSString* const kBookmarkEditDialogTouchBarId = @"bookmark-edit-dialog";
44
45 // Touch bar item identifiers.
46 NSString* const kNewFolderTouchBarId = @"NEW-FOLDER";
47 NSString* const kCancelTouchBarId = @"CANCEL";
48 NSString* const kSaveTouchBarId = @"SAVE";
49
50 } // end namespace
51
34 @interface BookmarkEditorBaseController () 52 @interface BookmarkEditorBaseController ()
35 53
36 // Return the folder tree object for the given path. 54 // Return the folder tree object for the given path.
37 - (BookmarkFolderInfo*)folderForIndexPath:(NSIndexPath*)path; 55 - (BookmarkFolderInfo*)folderForIndexPath:(NSIndexPath*)path;
38 56
39 // (Re)build the folder tree from the BookmarkModel's current state. 57 // (Re)build the folder tree from the BookmarkModel's current state.
40 - (void)buildFolderTree; 58 - (void)buildFolderTree;
41 59
42 // Notifies the controller that the bookmark model has changed. 60 // Notifies the controller that the bookmark model has changed.
43 // |selection| specifies if the current selection should be 61 // |selection| specifies if the current selection should be
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 [sheet close]; 352 [sheet close];
335 [[BrowserWindowController browserWindowControllerForWindow:parentWindow_] 353 [[BrowserWindowController browserWindowControllerForWindow:parentWindow_]
336 releaseToolbarVisibilityForOwner:self 354 releaseToolbarVisibilityForOwner:self
337 withAnimation:YES]; 355 withAnimation:YES];
338 } 356 }
339 357
340 - (void)windowWillClose:(NSNotification*)notification { 358 - (void)windowWillClose:(NSNotification*)notification {
341 [self autorelease]; 359 [self autorelease];
342 } 360 }
343 361
362 - (NSTouchBar*)makeTouchBar {
363 if (!base::FeatureList::IsEnabled(features::kBrowserTouchBar))
364 return nil;
365
366 base::scoped_nsobject<NSTouchBar> touchBar([[ui::NSTouchBar() alloc] init]);
367 [touchBar setCustomizationIdentifier:ui::GetTouchBarId(
368 kBookmarkEditDialogTouchBarId)];
369 [touchBar setDelegate:self];
370
371 NSArray* dialogItems = @[
372 ui::GetTouchBarItemId(kBookmarkEditDialogTouchBarId, kNewFolderTouchBarId),
373 ui::GetTouchBarItemId(kBookmarkEditDialogTouchBarId, kCancelTouchBarId),
374 ui::GetTouchBarItemId(kBookmarkEditDialogTouchBarId, kSaveTouchBarId)
375 ];
376
377 [touchBar setDefaultItemIdentifiers:dialogItems];
378 [touchBar setCustomizationAllowedItemIdentifiers:dialogItems];
379 return touchBar.autorelease();
380 }
381
382 - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
383 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier {
384 NSButton* button = nil;
385 if ([identifier hasSuffix:kNewFolderTouchBarId]) {
386 button =
387 [NSButton buttonWithTitle:l10n_util::GetNSString(
388 IDS_BOOKMARK_EDITOR_NEW_FOLDER_BUTTON)
389 target:self
390 action:@selector(newFolder:)];
391 } else if ([identifier hasSuffix:kCancelTouchBarId]) {
392 button = [NSButton buttonWithTitle:l10n_util::GetNSString(IDS_APP_CANCEL)
393 target:self
394 action:@selector(cancel:)];
395 } else if ([identifier hasSuffix:kSaveTouchBarId]) {
396 button = ui::GetBlueTouchBarButton(l10n_util::GetNSString(IDS_SAVE), self,
397 @selector(ok:));
398 } else {
399 return nil;
400 }
401
402 base::scoped_nsobject<NSCustomTouchBarItem> item(
403 [[ui::NSCustomTouchBarItem() alloc] initWithIdentifier:identifier]);
404 [item setView:button];
405 return item.autorelease();
406 }
407
344 #pragma mark Folder Tree Management 408 #pragma mark Folder Tree Management
345 409
346 - (BookmarkModel*)bookmarkModel { 410 - (BookmarkModel*)bookmarkModel {
347 return BookmarkModelFactory::GetForBrowserContext(profile_); 411 return BookmarkModelFactory::GetForBrowserContext(profile_);
348 } 412 }
349 413
350 - (Profile*)profile { 414 - (Profile*)profile {
351 return profile_; 415 return profile_;
352 } 416 }
353 417
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 [super dealloc]; 793 [super dealloc];
730 } 794 }
731 795
732 // Implementing isEqual: allows the NSTreeController to preserve the selection 796 // Implementing isEqual: allows the NSTreeController to preserve the selection
733 // and open/shut state of outline items when the data changes. 797 // and open/shut state of outline items when the data changes.
734 - (BOOL)isEqual:(id)other { 798 - (BOOL)isEqual:(id)other {
735 return [other isKindOfClass:[BookmarkFolderInfo class]] && 799 return [other isKindOfClass:[BookmarkFolderInfo class]] &&
736 folderNode_ == [(BookmarkFolderInfo*)other folderNode]; 800 folderNode_ == [(BookmarkFolderInfo*)other folderNode];
737 } 801 }
738 @end 802 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698