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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager_commands.js

Issue 12857002: Files.app: Add subfolders in the left nav (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
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 var CommandUtil = {}; 5 var CommandUtil = {};
6 6
7 /** 7 /**
8 * Extracts root on which command event was dispatched. 8 * Extracts root on which command event was dispatched.
9 * 9 *
10 * @param {Event} event Command event for which to retrieve root to operate on. 10 * @param {Event} event Command event for which to retrieve root to operate on.
11 * @param {cr.ui.List} rootsList Root list to extract root node. 11 * @param {DirectoryTree} directoryTree Directory tree to extract root node.
12 * @return {DirectoryEntry} Found root. 12 * @return {?DirectoryEntry} Found root.
mtomasz 2013/03/14 02:52:05 AFAIK objects do not need ? in jsdoc.
yoshiki 2013/03/14 07:57:53 Oops, removed.
13 */ 13 */
14 CommandUtil.getCommandRoot = function(event, rootsList) { 14 CommandUtil.getCommandRoot = function(event, directoryTree) {
15 var result = rootsList.dataModel.item( 15 var entry = directoryTree.selectedItem;
16 rootsList.getIndexOfListItem(event.target)) ||
17 rootsList.selectedItem;
18 16
19 return result; 17 if (entry && PathUtil.isRootPath(entry.fullPath))
18 return entry;
19 else
20 return null;
20 }; 21 };
21 22
22 /** 23 /**
23 * @param {Event} event Command event for which to retrieve root type. 24 * @param {Event} event Command event for which to retrieve root type.
24 * @param {cr.ui.List} rootsList Root list to extract root node. 25 * @param {DirectoryTree} directoryTree Directory tree to extract root node.
25 * @return {string} Found root. 26 * @return {?string} Found root.
26 */ 27 */
27 CommandUtil.getCommandRootType = function(event, rootsList) { 28 CommandUtil.getCommandRootType = function(event, directoryTree) {
28 var root = CommandUtil.getCommandRoot(event, rootsList); 29 var root = CommandUtil.getCommandRoot(event, directoryTree);
29 30
30 return root && PathUtil.getRootType(root.fullPath); 31 return root && PathUtil.getRootType(root.fullPath);
31 }; 32 };
32 33
33 /** 34 /**
34 * Checks if command can be executed on drive. 35 * Checks if command can be executed on drive.
35 * @param {Event} event Command event to mark. 36 * @param {Event} event Command event to mark.
36 * @param {FileManager} fileManager FileManager to use. 37 * @param {FileManager} fileManager FileManager to use.
37 */ 38 */
38 CommandUtil.canExecuteEnabledOnDriveOnly = function(event, fileManager) { 39 CommandUtil.canExecuteEnabledOnDriveOnly = function(event, fileManager) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 }, 122 },
122 canExecute: function(event, document) { 123 canExecute: function(event, document) {
123 event.canExecute = document.queryCommandEnabled(event.command.id); 124 event.canExecute = document.queryCommandEnabled(event.command.id);
124 } 125 }
125 }; 126 };
126 127
127 /** 128 /**
128 * Unmounts external drive. 129 * Unmounts external drive.
129 */ 130 */
130 Commands.unmountCommand = { 131 Commands.unmountCommand = {
131 execute: function(event, rootsList, fileManager) { 132 /**
132 var root = CommandUtil.getCommandRoot(event, rootsList); 133 * @param {Event} event Command event.
134 * @param {DirectoryTree} directoryTree Target directory tree.
135 */
136 execute: function(event, directoryTree, fileManager) {
137 var root = CommandUtil.getCommandRoot(event, directoryTree);
133 if (root) 138 if (root)
134 fileManager.unmountVolume(PathUtil.getRootPath(root.fullPath)); 139 fileManager.unmountVolume(PathUtil.getRootPath(root.fullPath));
135 }, 140 },
136 canExecute: function(event, rootsList) { 141 /**
137 var rootType = CommandUtil.getCommandRootType(event, rootsList); 142 * @param {Event} event Command event.
143 * @param {DirectoryTree} directoryTree Target directory tree.
144 */
145 canExecute: function(event, directoryTree) {
146 var rootType = CommandUtil.getCommandRootType(event, directoryTree);
138 147
139 event.canExecute = (rootType == RootType.ARCHIVE || 148 event.canExecute = (rootType === RootType.ARCHIVE ||
mtomasz 2013/03/14 02:52:05 Is this change necessary? RootType.* values are ne
yoshiki 2013/03/14 07:57:53 Done.
140 rootType == RootType.REMOVABLE); 149 rootType === RootType.REMOVABLE);
141 event.command.label = rootType == RootType.ARCHIVE ? 150 event.command.label = rootType == RootType.ARCHIVE ?
142 str('CLOSE_ARCHIVE_BUTTON_LABEL') : 151 str('CLOSE_ARCHIVE_BUTTON_LABEL') :
143 str('UNMOUNT_DEVICE_BUTTON_LABEL'); 152 str('UNMOUNT_DEVICE_BUTTON_LABEL');
144 } 153 }
145 }; 154 };
146 155
147 /** 156 /**
148 * Formats external drive. 157 * Formats external drive.
149 */ 158 */
150 Commands.formatCommand = { 159 Commands.formatCommand = {
151 execute: function(event, rootsList, fileManager) { 160 /**
152 var root = CommandUtil.getCommandRoot(event, rootsList); 161 * @param {Event} event Command event.
162 * @param {DirectoryTree} directoryTree Target directory tree.
163 */
164 execute: function(event, directoryTree, fileManager) {
165 var root = CommandUtil.getCommandRoot(event, directoryTree);
153 166
154 if (root) { 167 if (root) {
155 var url = util.makeFilesystemUrl(PathUtil.getRootPath(root.fullPath)); 168 var url = util.makeFilesystemUrl(PathUtil.getRootPath(root.fullPath));
156 fileManager.confirm.show( 169 fileManager.confirm.show(
157 loadTimeData.getString('FORMATTING_WARNING'), 170 loadTimeData.getString('FORMATTING_WARNING'),
158 chrome.fileBrowserPrivate.formatDevice.bind(null, url)); 171 chrome.fileBrowserPrivate.formatDevice.bind(null, url));
159 } 172 }
160 }, 173 },
161 canExecute: function(event, rootsList, fileManager, directoryModel) { 174 /**
162 var root = CommandUtil.getCommandRoot(event, rootsList); 175 * @param {Event} event Command event.
176 * @param {DirectoryTree} directoryTree Target directory tree.
177 */
178 canExecute: function(event, directoryTree, fileManager, directoryModel) {
179 var root = CommandUtil.getCommandRoot(event, directoryTree);
163 var removable = root && 180 var removable = root &&
164 PathUtil.getRootType(root.fullPath) == RootType.REMOVABLE; 181 PathUtil.getRootType(root.fullPath) == RootType.REMOVABLE;
165 var isReadOnly = root && directoryModel.isPathReadOnly(root.fullPath); 182 var isReadOnly = root && directoryModel.isPathReadOnly(root.fullPath);
166 event.canExecute = removable && !isReadOnly; 183 event.canExecute = removable && !isReadOnly;
167 event.command.setHidden(!removable); 184 event.command.setHidden(!removable);
168 } 185 }
169 }; 186 };
170 187
171 /** 188 /**
172 * Imports photos from external drive 189 * Imports photos from external drive
173 */ 190 */
174 Commands.importCommand = { 191 Commands.importCommand = {
175 execute: function(event, rootsList) { 192 /**
176 var root = CommandUtil.getCommandRoot(event, rootsList); 193 * @param {Event} event Command event.
194 * @param {DirectoryTree} directoryTree Target directory tree.
195 */
196 execute: function(event, directoryTree) {
197 var root = CommandUtil.getCommandRoot(event, directoryTree);
177 if (!root) 198 if (!root)
178 return; 199 return;
179 200
180 chrome.windows.getCurrent(undefined, function(window) { 201 chrome.windows.getCurrent(undefined, function(window) {
181 chrome.windows.create( 202 chrome.windows.create(
182 { url: chrome.extension.getURL('photo_import.html') + 203 { url: chrome.extension.getURL('photo_import.html') +
183 '?' + window.id + '#' + PathUtil.getRootPath(root.fullPath), 204 '?' + window.id + '#' + PathUtil.getRootPath(root.fullPath),
184 type: 'popup' }); 205 type: 'popup' });
185 }.bind(this)); 206 }.bind(this));
186 }, 207 },
187 canExecute: function(event, rootsList) { 208 /**
188 event.canExecute = 209 * @param {Event} event Command event.
189 (CommandUtil.getCommandRootType(event, rootsList) != RootType.DRIVE); 210 * @param {DirectoryTree} directoryTree Target directory tree.
211 */
212 canExecute: function(event, directoryTree) {
213 var rootType = CommandUtil.getCommandRootType(event, directoryTree);
214 event.canExecute = (rootType != RootType.DRIVE);
190 } 215 }
191 }; 216 };
192 217
193 /** 218 /**
194 * Initiates new folder creation. 219 * Initiates new folder creation.
195 */ 220 */
196 Commands.newFolderCommand = { 221 Commands.newFolderCommand = {
197 execute: function(event, fileManager) { 222 execute: function(event, fileManager) {
198 fileManager.createNewFolder(); 223 fileManager.createNewFolder();
199 }, 224 },
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 fileManager.copyManager_.zipSelection(dirEntry, fileManager.isOnDrive(), 428 fileManager.copyManager_.zipSelection(dirEntry, fileManager.isOnDrive(),
404 selectionEntries); 429 selectionEntries);
405 }, 430 },
406 canExecute: function(event, fileManager) { 431 canExecute: function(event, fileManager) {
407 var selection = fileManager.getSelection(); 432 var selection = fileManager.getSelection();
408 event.canExecute = !fileManager.isOnReadonlyDirectory() && 433 event.canExecute = !fileManager.isOnReadonlyDirectory() &&
409 !fileManager.isOnDrive() && 434 !fileManager.isOnDrive() &&
410 selection && selection.totalCount > 0; 435 selection && selection.totalCount > 0;
411 } 436 }
412 }; 437 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698