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

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

Issue 10914075: [filemanager] Implementing undo delete functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Merge to head Created 8 years, 3 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 /** 5 /**
6 * pyautoAPI object provides a set of functions used by PyAuto tests 6 * pyautoAPI object provides a set of functions used by PyAuto tests
7 * to drive the file manager. 7 * to drive the file manager.
8 * 8 *
9 * Refer to chrome/test/functional/chromeos_file_browser.py for examples 9 * Refer to chrome/test/functional/chromeos_file_browser.py for examples
10 * of how this API is used. 10 * of how this API is used.
11 * 11 *
12 * TODO(olege): Fix style warnings. 12 * TODO(olege): Fix style warnings.
13 */ 13 */
14 var pyautoAPI = { 14 var pyautoAPI = {
15 /** 15 /**
16 * Add the item with given name to the current selection. 16 * Add the item with given name to the current selection.
17 *
18 * @param {string} name Name of the item to add to selection 17 * @param {string} name Name of the item to add to selection
19 * @return {boolean} Whether item exists.
20 */ 18 */
21 addItemToSelection: function(name) { 19 addItemToSelection: function(name) {
22 var entryExists = false; 20 var entryExists = false;
23 var dm = fileManager.directoryModel_.getFileList(); 21 var dm = fileManager.directoryModel_.getFileList();
24 for (var i = 0; i < dm.length; i++) { 22 for (var i = 0; i < dm.length; i++) {
25 if (dm.item(i).name == name) { 23 if (dm.item(i).name == name) {
26 fileManager.currentList_.selectionModel.setIndexSelected(i, true); 24 fileManager.currentList_.selectionModel.setIndexSelected(i, true);
27 fileManager.currentList_.scrollIndexIntoView(i); 25 fileManager.currentList_.scrollIndexIntoView(i);
28 fileManager.focusCurrentList_(); 26 fileManager.focusCurrentList_();
29 entryExists = true; 27 entryExists = true;
30 break; 28 break;
31 } 29 }
32 } 30 }
33 this.sendValue_(entryExists); 31 this.sendValue_(entryExists);
34 }, 32 },
35 33
36 /** 34 /**
37 * List all items in the current directory. 35 * List all items in the current directory.
38 * We assume names do not contain '|' charecter. 36 * We assume names do not contain '|' charecter.
39 *
40 * @return {object} A a list of item names.
41 */ 37 */
42 listDirectory: function() { 38 listDirectory: function() {
43 var list = []; 39 var list = [];
44 var dm = fileManager.directoryModel_.getFileList(); 40 var dm = fileManager.directoryModel_.getFileList();
45 for (var i = 0; i < dm.length; i++) { 41 for (var i = 0; i < dm.length; i++) {
46 list.push(dm.item(i).name); 42 list.push(dm.item(i).name);
47 } 43 }
48 this.sendJSONValue_(list); 44 this.sendJSONValue_(list);
49 }, 45 },
50 46
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 fileManager.selection.tasks.executeDefault(); 85 fileManager.selection.tasks.executeDefault();
90 else 86 else
91 throw new Error('Cannot execute a task on an empty selection.'); 87 throw new Error('Cannot execute a task on an empty selection.');
92 break; 88 break;
93 default: 89 default:
94 throw new Error('Cannot execute a task in this dialog type.'); 90 throw new Error('Cannot execute a task in this dialog type.');
95 } 91 }
96 this.sendDone_(); 92 this.sendDone_();
97 }, 93 },
98 94
95 /**
96 * Executes the clipboard command.
97 * @param {string} command Command name.
98 */
99 executeClipboardCommand_: function(command) { 99 executeClipboardCommand_: function(command) {
100 // Input should not be focused, or the cut/cop/paste command 100 // Input should not be focused, or the cut/cop/paste command
101 // will be treated as textual editing. 101 // will be treated as textual editing.
102 fileManager.filenameInput_.blur(); 102 fileManager.filenameInput_.blur();
103 fileManager.document_.execCommand(command); 103 fileManager.document_.execCommand(command);
104 }, 104 },
105 105
106 /** 106 /**
107 * Copy selected items to clipboard. 107 * Copy selected items to clipboard.
108 */ 108 */
(...skipping 19 matching lines...) Expand all
128 dm.removeEventListener('rescan-completed', onRescan); 128 dm.removeEventListener('rescan-completed', onRescan);
129 this.sendDone_(); 129 this.sendDone_();
130 }.bind(this); 130 }.bind(this);
131 131
132 dm.addEventListener('rescan-completed', onRescan); 132 dm.addEventListener('rescan-completed', onRescan);
133 this.executeClipboardCommand_('paste'); 133 this.executeClipboardCommand_('paste');
134 }, 134 },
135 135
136 /** 136 /**
137 * Rename selected item. 137 * Rename selected item.
138 *
139 * @param {string} name New name of the item. 138 * @param {string} name New name of the item.
140 */ 139 */
141 renameItem: function(name) { 140 renameItem: function(name) {
142 var entry = fileManager.selection.entries[0]; 141 var entry = fileManager.selection.entries[0];
143 fileManager.directoryModel_.renameEntry(entry, name, this.sendDone_, 142 fileManager.directoryModel_.renameEntry(entry, name, this.sendDone_,
144 this.sendDone_); 143 this.sendDone_);
145 }, 144 },
146 145
147 /** 146 /**
148 * Delete selected entries. 147 * Delete selected entries.
149 */ 148 */
150 deleteItems: function() { 149 deleteItems: function() {
151 var entries = fileManager.selection.entries; 150 var dm = fileManager.directoryModel_;
152 fileManager.deleteEntries(entries, true, this.sendDone_); 151 var onRescan = function() {
152 dm.removeEventListener('rescan-completed', onRescan);
153 this.sendDone_();
154 }.bind(this);
155
156 dm.addEventListener('rescan-completed', onRescan);
157 fileManager.deleteSelection();
153 }, 158 },
154 159
155 /** 160 /**
156 * Create directory. 161 * Create directory.
157 *
158 * @param {string} name Name of the directory. 162 * @param {string} name Name of the directory.
159 */ 163 */
160 createDirectory: function(name) { 164 createDirectory: function(name) {
161 var dm = fileManager.directoryModel_; 165 var dm = fileManager.directoryModel_;
162 var onRescan = function() { 166 var onRescan = function() {
163 dm.removeEventListener('rescan-completed', onRescan); 167 dm.removeEventListener('rescan-completed', onRescan);
164 this.sendDone_(); 168 this.sendDone_();
165 }.bind(this); 169 }.bind(this);
166 170
167 dm.addEventListener('rescan-completed', onRescan); 171 dm.addEventListener('rescan-completed', onRescan);
168 fileManager.directoryModel_.createDirectory(name, function(){}); 172 fileManager.directoryModel_.createDirectory(name, function() {});
169 }, 173 },
170 174
171 /** 175 /**
172 * Change to a directory. 176 * Change to a directory.
173 *
174 * A path starting with '/' * is absolute, otherwise it is relative to the 177 * A path starting with '/' * is absolute, otherwise it is relative to the
175 * current directory. 178 * current directory.
176 *
177 * @param {string} path Path to directory. 179 * @param {string} path Path to directory.
178 */ 180 */
179 changeDirectory: function(path) { 181 changeDirectory: function(path) {
180 if (path.charAt(0) != '/') 182 if (path.charAt(0) != '/')
181 path = fileManager.getCurrentDirectory() + '/' + path; 183 path = fileManager.getCurrentDirectory() + '/' + path;
182 var dm = fileManager.directoryModel_; 184 var dm = fileManager.directoryModel_;
183 185
184 var onChanged = function() { 186 var onChanged = function() {
185 dm.removeEventListener('directory-changed', onChanged); 187 dm.removeEventListener('directory-changed', onChanged);
186 this.sendDone_(); 188 this.sendDone_();
187 }.bind(this); 189 }.bind(this);
188 190
189 dm.addEventListener('directory-changed', onChanged); 191 dm.addEventListener('directory-changed', onChanged);
190 dm.changeDirectory(path); 192 dm.changeDirectory(path);
191 }, 193 },
192 194
193 /** 195 /**
194 * Get the absolute path of current directory. 196 * Get the absolute path of current directory.
195 *
196 * @return {string} Path to the current directory.
197 */ 197 */
198 currentDirectory: function() { 198 currentDirectory: function() {
199 this.sendValue_(fileManager.getCurrentDirectory()); 199 this.sendValue_(fileManager.getCurrentDirectory());
200 }, 200 },
201 201
202 /** 202 /**
203 * Get remaining and total size of selected directory. 203 * Get remaining and total size of selected directory.
204 *
205 * @return {object} remaining and total size in KB.
206 */ 204 */
207 getSelectedDirectorySizeStats: function() { 205 getSelectedDirectorySizeStats: function() {
208 var directoryURL = fileManager.selection.entries[0].toURL(); 206 var directoryURL = fileManager.selection.entries[0].toURL();
209 chrome.fileBrowserPrivate.getSizeStats(directoryURL, function(stats) { 207 chrome.fileBrowserPrivate.getSizeStats(directoryURL, function(stats) {
210 this.sendJSONValue_(stats); 208 this.sendJSONValue_(stats);
211 }.bind(this)); 209 }.bind(this));
212 }, 210 },
213 211
214 /** 212 /**
215 * Returns whether the file manager is initialized. 213 * Returns whether the file manager is initialized.
216 *
217 * This function is polled by pyauto before calling any 214 * This function is polled by pyauto before calling any
218 * of the functions above. 215 * of the functions above.
219 *
220 * @return {boolean} Whether file manager is initialized.
221 */ 216 */
222 isInitialized: function() { 217 isInitialized: function() {
223 var initialized = fileManager && 218 var initialized = fileManager &&
224 fileManager.workerInitialized_ && 219 fileManager.workerInitialized_ &&
225 fileManager.getCurrentDirectory(); 220 fileManager.getCurrentDirectory();
226 this.sendValue_(!!initialized); 221 this.sendValue_(!!initialized);
227 }, 222 },
228 223
229 /** 224 /**
230 * Callback function for returning primitiv types (int, string, boolean) 225 * Callback function for returning primitiv types (int, string, boolean)
231 */ 226 */
232 sendValue_: function(value) { 227 sendValue_: function(value) {
233 window.domAutomationController.send(value); 228 window.domAutomationController.send(value);
234 }, 229 },
235 230
236 /** 231 /**
237 * Callback function for returning a JSON encoded value. 232 * Callback function for returning a JSON encoded value.
238 */ 233 */
239 sendJSONValue_: function(value) { 234 sendJSONValue_: function(value) {
240 window.domAutomationController.send(JSON.stringify(value)); 235 window.domAutomationController.send(JSON.stringify(value));
241 }, 236 },
242 237
243 /** 238 /**
244 * Callback function signalling completion of operation. 239 * Callback function signalling completion of operation.
245 */ 240 */
246 sendDone_: function() { 241 sendDone_: function() {
247 window.domAutomationController.send('done'); 242 window.domAutomationController.send('done');
248 } 243 }
249 }; 244 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698