OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 var g_slideshow_data = null; | 10 var g_slideshow_data = null; |
(...skipping 2491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2502 return; | 2502 return; |
2503 | 2503 |
2504 this.metadataProvider_.fetch(entry.toURL(), function(metadata) { | 2504 this.metadataProvider_.fetch(entry.toURL(), function(metadata) { |
2505 callback(metadata.description); | 2505 callback(metadata.description); |
2506 }); | 2506 }); |
2507 }; | 2507 }; |
2508 | 2508 |
2509 FileManager.prototype.selectEntry = function(name) { | 2509 FileManager.prototype.selectEntry = function(name) { |
2510 for (var i = 0; i < this.dataModel_.length; i++) { | 2510 for (var i = 0; i < this.dataModel_.length; i++) { |
2511 if (this.dataModel_.item(i).name == name) { | 2511 if (this.dataModel_.item(i).name == name) { |
2512 this.currentList_.selectionModel.selectedIndex = i; | 2512 this.selectIndex(i); |
2513 this.currentList_.scrollIndexIntoView(i); | |
2514 this.currentList_.focus(); | |
2515 return; | 2513 return; |
2516 } | 2514 } |
2517 } | 2515 } |
2518 }; | 2516 }; |
2519 | 2517 |
| 2518 FileManager.prototype.selectIndex = function(index) { |
| 2519 this.currentList_.focus(); |
| 2520 if (index >= this.dataModel_.length) |
| 2521 return; |
| 2522 this.currentList_.selectionModel.selectedIndex = index; |
| 2523 this.currentList_.scrollIndexIntoView(index); |
| 2524 }; |
| 2525 |
2520 /** | 2526 /** |
2521 * Add the file/directory with given name to the current selection. | 2527 * Add the file/directory with given name to the current selection. |
2522 * | 2528 * |
2523 * @param {string} name The name of the entry to select. | 2529 * @param {string} name The name of the entry to select. |
2524 * @return {boolean} Whether entry exists. | 2530 * @return {boolean} Whether entry exists. |
2525 */ | 2531 */ |
2526 FileManager.prototype.addItemToSelection = function(name) { | 2532 FileManager.prototype.addItemToSelection = function(name) { |
2527 var entryExists = false; | 2533 var entryExists = false; |
2528 for (var i = 0; i < this.dataModel_.length; i++) { | 2534 for (var i = 0; i < this.dataModel_.length; i++) { |
2529 if (this.dataModel_.item(i).name == name) { | 2535 if (this.dataModel_.item(i).name == name) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2642 // with rewritable URLs (while does with history.pushState). It changes | 2648 // with rewritable URLs (while does with history.pushState). It changes |
2643 // window.location but doesn't change content of the ombibox. | 2649 // window.location but doesn't change content of the ombibox. |
2644 history.replaceState(undefined, dirEntry.fullPath, location); | 2650 history.replaceState(undefined, dirEntry.fullPath, location); |
2645 } | 2651 } |
2646 | 2652 |
2647 if (this.currentDirEntry_ && | 2653 if (this.currentDirEntry_ && |
2648 this.currentDirEntry_.fullPath == dirEntry.fullPath) { | 2654 this.currentDirEntry_.fullPath == dirEntry.fullPath) { |
2649 // Directory didn't actually change. | 2655 // Directory didn't actually change. |
2650 if (opt_selectedEntry) | 2656 if (opt_selectedEntry) |
2651 this.selectEntry(opt_selectedEntry); | 2657 this.selectEntry(opt_selectedEntry); |
| 2658 else |
| 2659 this.selectIndex(0); |
2652 return; | 2660 return; |
2653 } | 2661 } |
2654 | 2662 |
2655 var e = new cr.Event('directory-changed'); | 2663 var e = new cr.Event('directory-changed'); |
2656 e.previousDirEntry = this.currentDirEntry_; | 2664 e.previousDirEntry = this.currentDirEntry_; |
2657 e.newDirEntry = dirEntry; | 2665 e.newDirEntry = dirEntry; |
2658 e.saveHistory = opt_saveHistory; | 2666 e.saveHistory = opt_saveHistory; |
2659 e.selectedEntry = opt_selectedEntry; | 2667 e.selectedEntry = opt_selectedEntry; |
2660 e.opt_callback = opt_callback; | 2668 e.opt_callback = opt_callback; |
2661 this.currentDirEntry_ = dirEntry; | 2669 this.currentDirEntry_ = dirEntry; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3059 function(result) { | 3067 function(result) { |
3060 if (!result) { | 3068 if (!result) { |
3061 console.log('Failed to add file watch'); | 3069 console.log('Failed to add file watch'); |
3062 } | 3070 } |
3063 }); | 3071 }); |
3064 } | 3072 } |
3065 | 3073 |
3066 this.rescanDirectory_(function() { | 3074 this.rescanDirectory_(function() { |
3067 if (event.selectedEntry) | 3075 if (event.selectedEntry) |
3068 self.selectEntry(event.selectedEntry); | 3076 self.selectEntry(event.selectedEntry); |
| 3077 else |
| 3078 self.selectIndex(0); |
3069 if (event.opt_callback) { | 3079 if (event.opt_callback) { |
3070 try { | 3080 try { |
3071 event.opt_callback(); | 3081 event.opt_callback(); |
3072 } catch (ex) { | 3082 } catch (ex) { |
3073 console.error('Caught exception while inovking callback: ', ex); | 3083 console.error('Caught exception while inovking callback: ', ex); |
3074 } | 3084 } |
3075 } | 3085 } |
3076 // For tests that open the dialog to empty directories, everything | 3086 // For tests that open the dialog to empty directories, everything |
3077 // is loaded at this point. | 3087 // is loaded at this point. |
3078 chrome.test.sendMessage('directory-change-complete'); | 3088 chrome.test.sendMessage('directory-change-complete'); |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3972 }); | 3982 }); |
3973 }, onError); | 3983 }, onError); |
3974 | 3984 |
3975 function onError(err) { | 3985 function onError(err) { |
3976 console.log('Error while checking free space: ' + err); | 3986 console.log('Error while checking free space: ' + err); |
3977 setTimeout(doCheck, 1000 * 60); | 3987 setTimeout(doCheck, 1000 * 60); |
3978 } | 3988 } |
3979 } | 3989 } |
3980 } | 3990 } |
3981 })(); | 3991 })(); |
OLD | NEW |