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

Side by Side Diff: ui/file_manager/file_manager/foreground/js/toolbar_controller.js

Issue 951443002: Files.app: Make delete button on the toolbar standard button instead of CommandButton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add @const for const members of ToolbarController. Created 5 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** 5 /**
6 * This class controls wires toolbar UI and selection model. When selection 6 * This class controls wires toolbar UI and selection model. When selection
7 * status is changed, this class changes the view of toolbar. If cancel 7 * status is changed, this class changes the view of toolbar. If cancel
8 * selection button is pressed, this class clears the selection. 8 * selection button is pressed, this class clears the selection.
9 * @param {!HTMLElement} cancelSelectionButton Button to cancel selection. 9 * @param {!HTMLElement} toolbar Toolbar element which contains controls.
10 * @param {!HTMLElement} cancelSelectionButtonWrapper Wapper for the button,
11 * which works as a spacer for the filesSelectionLabel.
12 * @param {!HTMLElement} filesSelectedLabel Label to show how many files are
13 * selected.
14 * @param {!HTMLElement} navigationList Navigation list on the left pane. The 10 * @param {!HTMLElement} navigationList Navigation list on the left pane. The
15 * position of silesSelectedLabel depends on the navitaion list's width. 11 * position of silesSelectedLabel depends on the navitaion list's width.
16 * @param {!FileSelectionHandler} selectionHandler 12 * @param {!FileSelectionHandler} selectionHandler
17 * @param {!cr.ui.ListSelectionModel|!cr.ui.ListSingleSelectionModel} 13 * @param {!DirectoryModel} directoryModel
18 * selectionModel
19 * @constructor 14 * @constructor
20 * @struct 15 * @struct
21 */ 16 */
22 function ToolbarController(cancelSelectionButton, 17 function ToolbarController(toolbar,
23 cancelSelectionButtonWrapper,
24 filesSelectedLabel,
25 navigationList, 18 navigationList,
26 selectionHandler, 19 selectionHandler,
27 selectionModel) { 20 directoryModel) {
28 /** @private {!HTMLElement} */ 21 /**
29 this.cancelSelectionButtonWrapper_ = cancelSelectionButtonWrapper; 22 * @private {!HTMLElement}
23 * @const
24 */
25 this.toolbar_ = toolbar;
30 26
31 /** @private {!HTMLElement} */ 27 /**
32 this.filesSelectedLabel_ = filesSelectedLabel; 28 * @private {!HTMLElement}
29 * @const
30 */
31 this.cancelSelectionButton_ =
32 queryRequiredElement(this.toolbar_, '#cancel-selection-button');
33 33
34 /** @private {!HTMLElement} */ 34 /**
35 * @private {!HTMLElement}
36 * @const
37 */
38 this.cancelSelectionButtonWrapper_ =
39 queryRequiredElement(this.toolbar_, '#cancel-selection-button-wrapper');
40
41 /**
42 * @private {!HTMLElement}
43 * @const
44 */
45 this.filesSelectedLabel_ =
46 queryRequiredElement(this.toolbar_, '#files-selected-label');
47
48 /**
49 * @private {!HTMLElement}
50 * @const
51 */
52 this.deleteButton_ = queryRequiredElement(this.toolbar_, '#delete-button');
53
54 /**
55 * @private {!cr.ui.Command}
56 * @const
57 */
58 this.deleteCommand_ = assertInstanceof(
59 queryRequiredElement(assert(this.toolbar_.ownerDocument), '#delete'),
60 cr.ui.Command);
61
62 /**
63 * @private {!HTMLElement}
64 * @const
65 */
35 this.navigationList_ = navigationList; 66 this.navigationList_ = navigationList;
36 67
37 /** @private {!FileSelectionHandler} */ 68 /**
69 * @private {!FileSelectionHandler}
70 * @const
71 */
38 this.selectionHandler_ = selectionHandler; 72 this.selectionHandler_ = selectionHandler;
39 73
40 /** @private {!cr.ui.ListSelectionModel|!cr.ui.ListSingleSelectionModel} */ 74 /**
41 this.selectionModel_ = selectionModel; 75 * @private {!DirectoryModel}
76 * @const
77 */
78 this.directoryModel_ = directoryModel;
42 79
43 this.selectionHandler_.addEventListener( 80 this.selectionHandler_.addEventListener(
44 FileSelectionHandler.EventType.CHANGE, 81 FileSelectionHandler.EventType.CHANGE,
45 this.onSelectionChanged_.bind(this)); 82 this.onSelectionChanged_.bind(this));
46 83
47 cancelSelectionButton.addEventListener( 84 this.cancelSelectionButton_.addEventListener(
48 'click', this.onCancelSelectionButtonClicked_.bind(this)); 85 'click', this.onCancelSelectionButtonClicked_.bind(this));
49 86
87 this.deleteButton_.addEventListener(
88 'click', this.onDeleteButtonClicked_.bind(this));
89
50 this.navigationList_.addEventListener( 90 this.navigationList_.addEventListener(
51 'relayout', this.onNavigationListRelayout_.bind(this)); 91 'relayout', this.onNavigationListRelayout_.bind(this));
52 } 92 }
53 93
54 /** 94 /**
55 * Handles selection's change event to update the UI. 95 * Handles selection's change event to update the UI.
56 * @private 96 * @private
57 */ 97 */
58 ToolbarController.prototype.onSelectionChanged_ = function() { 98 ToolbarController.prototype.onSelectionChanged_ = function() {
59 var selection = this.selectionHandler_.selection; 99 var selection = this.selectionHandler_.selection;
60 100
61 // Update the label "x files selected." on the header. 101 // Update the label "x files selected." on the header.
62 if (selection.totalCount === 0) { 102 if (selection.totalCount === 0) {
63 this.filesSelectedLabel_.textContent = ''; 103 this.filesSelectedLabel_.textContent = '';
64 } else { 104 } else {
65 var text; 105 var text;
66 if (selection.directoryCount == 0) 106 if (selection.directoryCount == 0)
67 text = strf('MANY_FILES_SELECTED', selection.fileCount); 107 text = strf('MANY_FILES_SELECTED', selection.fileCount);
68 else if (selection.fileCount == 0) 108 else if (selection.fileCount == 0)
69 text = strf('MANY_DIRECTORIES_SELECTED', selection.directoryCount); 109 text = strf('MANY_DIRECTORIES_SELECTED', selection.directoryCount);
70 else 110 else
71 text = strf('MANY_ENTRIES_SELECTED', selection.totalCount); 111 text = strf('MANY_ENTRIES_SELECTED', selection.totalCount);
72 this.filesSelectedLabel_.textContent = text; 112 this.filesSelectedLabel_.textContent = text;
73 } 113 }
74 114
115 // Update visibility of the delete button.
116 this.deleteButton_.hidden =
117 selection.totalCount === 0 || this.directoryModel_.isReadOnly();
118
75 // Set .selecting class to containing element to change the view accordingly. 119 // Set .selecting class to containing element to change the view accordingly.
76 // TODO(fukino): This code changes the state of body, not the toolbar, to 120 // TODO(fukino): This code changes the state of body, not the toolbar, to
77 // update the checkmark visibility on grid view. This should be moved to a 121 // update the checkmark visibility on grid view. This should be moved to a
78 // controller which controls whole app window. Or, both toolbar and FileGrid 122 // controller which controls whole app window. Or, both toolbar and FileGrid
79 // should listen to the FileSelectionHandler. 123 // should listen to the FileSelectionHandler.
80 this.filesSelectedLabel_.ownerDocument.body.classList.toggle( 124 this.filesSelectedLabel_.ownerDocument.body.classList.toggle(
81 'selecting', selection.totalCount > 0); 125 'selecting', selection.totalCount > 0);
82 } 126 }
83 127
84 /** 128 /**
85 * Handles click event for cancel button to change the selection state. 129 * Handles click event for cancel button to change the selection state.
86 * @private 130 * @private
87 */ 131 */
88 ToolbarController.prototype.onCancelSelectionButtonClicked_ = function() { 132 ToolbarController.prototype.onCancelSelectionButtonClicked_ = function() {
89 this.selectionModel_.unselectAll(); 133 this.directoryModel_.selectEntries([]);
90 } 134 }
91 135
92 /** 136 /**
137 * Handles click event for delete button to execute the delete command.
138 * @private
139 */
140 ToolbarController.prototype.onDeleteButtonClicked_ = function() {
141 this.deleteCommand_.execute();
142 }
143
144 /**
93 * Handles the relayout event occured on the navigation list. 145 * Handles the relayout event occured on the navigation list.
94 * @private 146 * @private
95 */ 147 */
96 ToolbarController.prototype.onNavigationListRelayout_ = function() { 148 ToolbarController.prototype.onNavigationListRelayout_ = function() {
97 // Make the width of spacer same as the width of navigation list. 149 // Make the width of spacer same as the width of navigation list.
98 var navWidth = parseFloat( 150 var navWidth = parseFloat(
99 window.getComputedStyle(this.navigationList_).width); 151 window.getComputedStyle(this.navigationList_).width);
100 this.cancelSelectionButtonWrapper_.style.width = navWidth + 'px'; 152 this.cancelSelectionButtonWrapper_.style.width = navWidth + 'px';
101 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698