OLD | NEW |
---|---|
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 * FileManager constructor. | 6 * FileManager constructor. |
7 * | 7 * |
8 * FileManager objects encapsulate the functionality of the file selector | 8 * FileManager objects encapsulate the functionality of the file selector |
9 * dialogs, as well as the full screen file manager application (though the | 9 * dialogs, as well as the full screen file manager application (though the |
10 * latter is not yet implemented). | 10 * latter is not yet implemented). |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 FileManager.prototype.initRootsList_ = function() { | 761 FileManager.prototype.initRootsList_ = function() { |
762 this.rootsList_ = this.dialogDom_.querySelector('.roots-list'); | 762 this.rootsList_ = this.dialogDom_.querySelector('.roots-list'); |
763 cr.ui.List.decorate(this.rootsList_); | 763 cr.ui.List.decorate(this.rootsList_); |
764 this.rootsList_.startBatchUpdates(); | 764 this.rootsList_.startBatchUpdates(); |
765 | 765 |
766 var self = this; | 766 var self = this; |
767 this.rootsList_.itemConstructor = function(entry) { | 767 this.rootsList_.itemConstructor = function(entry) { |
768 return self.renderRoot_(entry); | 768 return self.renderRoot_(entry); |
769 }; | 769 }; |
770 | 770 |
771 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; | 771 this.rootsList_.selectionModel = |
772 this.directoryModel_.getRootsListSelectionModel(); | |
772 | 773 |
773 // TODO(dgozman): add "Add a drive" item. | 774 // TODO(dgozman): add "Add a drive" item. |
774 this.rootsList_.dataModel = this.directoryModel_.rootsList; | 775 this.rootsList_.dataModel = this.directoryModel_.getRootsList(); |
775 this.directoryModel_.updateRoots(function() { | 776 this.directoryModel_.updateRoots(function() { |
776 self.rootsList_.endBatchUpdates(); | 777 self.rootsList_.endBatchUpdates(); |
777 }, false); | 778 }, false); |
778 }; | 779 }; |
779 | 780 |
780 /** | 781 /** |
781 * @param {boolean} dirChanged True if we just changed to GData directory, | 782 * @param {boolean} dirChanged True if we just changed to GData directory, |
782 * False if "Retry" button clicked. | 783 * False if "Retry" button clicked. |
783 */ | 784 */ |
784 FileManager.prototype.initGData_ = function(dirChanged) { | 785 FileManager.prototype.initGData_ = function(dirChanged) { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 | 1111 |
1111 case 'newfolder': | 1112 case 'newfolder': |
1112 return !readonly && | 1113 return !readonly && |
1113 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || | 1114 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || |
1114 this.dialogType_ == FileManager.DialogType.FULL_PAGE); | 1115 this.dialogType_ == FileManager.DialogType.FULL_PAGE); |
1115 | 1116 |
1116 case 'unmount': | 1117 case 'unmount': |
1117 return true; | 1118 return true; |
1118 | 1119 |
1119 case 'format': | 1120 case 'format': |
1120 var entry = | 1121 var entry = this.directoryModel_.getCurrentRootDirEntry(); |
1121 this.getRootEntry_(this.rootsList_.selectionModel.selectedIndex); | |
1122 | 1122 |
1123 return entry && DirectoryModel.getRootType(entry.fullPath) == | 1123 return entry && DirectoryModel.getRootType(entry.fullPath) == |
1124 DirectoryModel.RootType.REMOVABLE; | 1124 DirectoryModel.RootType.REMOVABLE; |
1125 } | 1125 } |
1126 }; | 1126 }; |
1127 | 1127 |
1128 FileManager.prototype.getRootEntry_ = function(index) { | 1128 FileManager.prototype.getRootEntry_ = function(index) { |
1129 if (index == -1) | 1129 if (index == -1) |
1130 return null; | 1130 return null; |
1131 | 1131 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1400 | 1400 |
1401 case 'delete': | 1401 case 'delete': |
1402 this.deleteEntries(this.selection.entries); | 1402 this.deleteEntries(this.selection.entries); |
1403 return; | 1403 return; |
1404 | 1404 |
1405 case 'newfolder': | 1405 case 'newfolder': |
1406 this.onNewFolderCommand_(event); | 1406 this.onNewFolderCommand_(event); |
1407 return; | 1407 return; |
1408 | 1408 |
1409 case 'unmount': | 1409 case 'unmount': |
1410 var entry = | 1410 this.unmountVolume_(this.directoryModel_.getCurrentRootDirEntry()); |
1411 this.getRootEntry_(this.rootsList_.selectionModel.selectedIndex); | |
1412 | |
1413 this.unmountVolume_(entry); | |
1414 return; | 1411 return; |
1415 | 1412 |
1416 case 'format': | 1413 case 'format': |
1417 var entry = | 1414 var entry = this.directoryModel_.getCurrentRootDirEntry(); |
1418 this.getRootEntry_(this.rootsList_.selectionModel.selectedIndex); | |
1419 | |
1420 this.confirm.show(str('FORMATTING_WARNING'), function() { | 1415 this.confirm.show(str('FORMATTING_WARNING'), function() { |
1421 chrome.fileBrowserPrivate.formatDevice(entry.toURL()); | 1416 chrome.fileBrowserPrivate.formatDevice(entry.toURL()); |
1422 }); | 1417 }); |
1423 | 1418 |
1424 return; | 1419 return; |
1425 } | 1420 } |
1426 }; | 1421 }; |
1427 | 1422 |
1428 /** | 1423 /** |
1429 * Respond to the back and forward buttons. | 1424 * Respond to the back and forward buttons. |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1816 return str('REMOVABLE_DIRECTORY_LABEL'); | 1811 return str('REMOVABLE_DIRECTORY_LABEL'); |
1817 if (isParentPath('/' + DirectoryModel.REMOVABLE_DIRECTORY, path)) | 1812 if (isParentPath('/' + DirectoryModel.REMOVABLE_DIRECTORY, path)) |
1818 return path.substring(DirectoryModel.REMOVABLE_DIRECTORY.length + 2); | 1813 return path.substring(DirectoryModel.REMOVABLE_DIRECTORY.length + 2); |
1819 | 1814 |
1820 if (path == '/' + DirectoryModel.GDATA_DIRECTORY) | 1815 if (path == '/' + DirectoryModel.GDATA_DIRECTORY) |
1821 return str('GDATA_DIRECTORY_LABEL'); | 1816 return str('GDATA_DIRECTORY_LABEL'); |
1822 | 1817 |
1823 return path; | 1818 return path; |
1824 }; | 1819 }; |
1825 | 1820 |
1821 /** | |
1822 * Handler for root item being clicked. | |
1823 * @private | |
1824 * @param {Entry} entry Entry to navigate to. | |
1825 * @param {Event} event The event. | |
1826 */ | |
1827 FileManager.prototype.onRootClick_ = function(entry, event) { | |
1828 var new_path = entry.fullPath; | |
1829 if (entry.fullPath == this.directoryModel_.getCurrentRootPath()) { | |
1830 this.directoryModel_.changeDirectory(entry.fullPath); | |
SeRya
2012/04/23 14:23:43
I think this code would be much more clear:
dm.ch
Oleg Eterevsky
2012/04/23 14:33:04
I don't see how will it make the code simpler. The
| |
1831 } else { | |
1832 this.directoryModel_.changeRoot(entry.fullPath); | |
1833 } | |
1834 }; | |
1835 | |
1826 FileManager.prototype.renderRoot_ = function(entry) { | 1836 FileManager.prototype.renderRoot_ = function(entry) { |
1827 var li = this.document_.createElement('li'); | 1837 var li = this.document_.createElement('li'); |
1828 li.className = 'root-item'; | 1838 li.className = 'root-item'; |
1829 li.addEventListener('click', this.onRootClick_.bind(this, entry)); | 1839 li.addEventListener('click', this.onRootClick_.bind(this, entry)); |
1830 | 1840 |
1831 var rootType = DirectoryModel.getRootType(entry.fullPath); | 1841 var rootType = DirectoryModel.getRootType(entry.fullPath); |
1832 | 1842 |
1833 var div = this.document_.createElement('div'); | 1843 var div = this.document_.createElement('div'); |
1834 div.className = 'root-label'; | 1844 div.className = 'root-label'; |
1835 | 1845 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1867 cr.ui.contextMenuHandler.setContextMenu(li, this.rootsContextMenu_); | 1877 cr.ui.contextMenuHandler.setContextMenu(li, this.rootsContextMenu_); |
1868 } | 1878 } |
1869 } | 1879 } |
1870 | 1880 |
1871 cr.defineProperty(li, 'lead', cr.PropertyKind.BOOL_ATTR); | 1881 cr.defineProperty(li, 'lead', cr.PropertyKind.BOOL_ATTR); |
1872 cr.defineProperty(li, 'selected', cr.PropertyKind.BOOL_ATTR); | 1882 cr.defineProperty(li, 'selected', cr.PropertyKind.BOOL_ATTR); |
1873 return li; | 1883 return li; |
1874 }; | 1884 }; |
1875 | 1885 |
1876 /** | 1886 /** |
1877 * Handler for root item being clicked. | |
1878 * @param {Entry} entry to navigate to. | |
1879 * @param {Event} event The event. | |
1880 */ | |
1881 FileManager.prototype.onRootClick_ = function(entry, event) { | |
1882 var path = this.directoryModel_.currentEntry.fullPath; | |
1883 if (path.indexOf(entry.fullPath) == 0 && path != entry.fullPath) { | |
1884 this.directoryModel_.changeDirectory(entry.fullPath); | |
1885 } | |
1886 }; | |
1887 | |
1888 /** | |
1889 * Unmounts device. | 1887 * Unmounts device. |
1890 * @param {Entry} entry The entry to unmount. | 1888 * @param {Entry} entry The entry to unmount. |
1891 */ | 1889 */ |
1892 FileManager.prototype.unmountVolume_ = function(entry) { | 1890 FileManager.prototype.unmountVolume_ = function(entry) { |
1893 this.directoryModel_.prepareUnmount(entry.fullPath); | 1891 this.directoryModel_.prepareUnmount(entry.fullPath); |
1894 this.unmountRequests_.push(entry.fullPath); | 1892 this.unmountRequests_.push(entry.fullPath); |
1895 chrome.fileBrowserPrivate.removeMount(entry.toURL()); | 1893 chrome.fileBrowserPrivate.removeMount(entry.toURL()); |
1896 }; | 1894 }; |
1897 | 1895 |
1898 FileManager.prototype.styleGDataItem_ = function(entry, listItem) { | 1896 FileManager.prototype.styleGDataItem_ = function(entry, listItem) { |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2380 } | 2378 } |
2381 | 2379 |
2382 function setVisibility(visibility) { | 2380 function setVisibility(visibility) { |
2383 panel.setAttribute('visibility', visibility); | 2381 panel.setAttribute('visibility', visibility); |
2384 } | 2382 } |
2385 }; | 2383 }; |
2386 | 2384 |
2387 | 2385 |
2388 FileManager.prototype.isOnGData = function() { | 2386 FileManager.prototype.isOnGData = function() { |
2389 return this.directoryModel_ && | 2387 return this.directoryModel_ && |
2390 this.directoryModel_.rootPath == '/' + DirectoryModel.GDATA_DIRECTORY; | 2388 this.directoryModel_.getCurrentRootPath() == |
2389 '/' + DirectoryModel.GDATA_DIRECTORY; | |
2391 }; | 2390 }; |
2392 | 2391 |
2393 FileManager.prototype.getMetadataProvider = function() { | 2392 FileManager.prototype.getMetadataProvider = function() { |
2394 return this.metadataProvider_; | 2393 return this.metadataProvider_; |
2395 }; | 2394 }; |
2396 | 2395 |
2397 /** | 2396 /** |
2398 * Callback called when tasks for selected files are determined. | 2397 * Callback called when tasks for selected files are determined. |
2399 * @param {Object} selection Selection is passed here, since this.selection | 2398 * @param {Object} selection Selection is passed here, since this.selection |
2400 * can change before tasks were found, and we should be accurate. | 2399 * can change before tasks were found, and we should be accurate. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2642 }; | 2641 }; |
2643 // Not calling clearGDataLoadingTimer_ here because we want to keep | 2642 // Not calling clearGDataLoadingTimer_ here because we want to keep |
2644 // "Loading Google Docs" message until the directory loads. It is OK if | 2643 // "Loading Google Docs" message until the directory loads. It is OK if |
2645 // the timer fires after the mount because onDirectoryChanged_ will hide | 2644 // the timer fires after the mount because onDirectoryChanged_ will hide |
2646 // the unmounted panel. | 2645 // the unmounted panel. |
2647 if (this.setupCurrentDirectoryPostponed_) { | 2646 if (this.setupCurrentDirectoryPostponed_) { |
2648 this.setupCurrentDirectoryPostponed_(false /* execute */); | 2647 this.setupCurrentDirectoryPostponed_(false /* execute */); |
2649 } else if (this.isOnGData() && | 2648 } else if (this.isOnGData() && |
2650 this.directoryModel_.currentEntry.unmounted) { | 2649 this.directoryModel_.currentEntry.unmounted) { |
2651 // We are currently on an unmounted GData directory, force a rescan. | 2650 // We are currently on an unmounted GData directory, force a rescan. |
2652 changeDirectoryTo = this.directoryModel_.rootPath; | 2651 changeDirectoryTo = this.directoryModel_.getCurrentRootPath(); |
2653 } | 2652 } |
2654 } else { | 2653 } else { |
2655 this.gdataMounted_ = false; | 2654 this.gdataMounted_ = false; |
2656 this.gdataMountInfo_ = null; | 2655 this.gdataMountInfo_ = null; |
2657 this.clearGDataLoadingTimer_(); | 2656 this.clearGDataLoadingTimer_(); |
2658 this.onGDataUnreachable_('GData mount failed: ' + event.status); | 2657 this.onGDataUnreachable_('GData mount failed: ' + event.status); |
2659 if (this.setupCurrentDirectoryPostponed_) { | 2658 if (this.setupCurrentDirectoryPostponed_) { |
2660 this.setupCurrentDirectoryPostponed_(true /* cancel */); | 2659 this.setupCurrentDirectoryPostponed_(true /* cancel */); |
2661 // Change to unmounted GData root. | 2660 // Change to unmounted GData root. |
2662 changeDirectoryTo = '/' + DirectoryModel.GDATA_DIRECTORY; | 2661 changeDirectoryTo = '/' + DirectoryModel.GDATA_DIRECTORY; |
(...skipping 25 matching lines...) Expand all Loading... | |
2688 if (event.eventType == 'unmount') { | 2687 if (event.eventType == 'unmount') { |
2689 // Unmount request finished - remove it. | 2688 // Unmount request finished - remove it. |
2690 var index = self.unmountRequests_.indexOf(event.mountPath); | 2689 var index = self.unmountRequests_.indexOf(event.mountPath); |
2691 if (index != -1) { | 2690 if (index != -1) { |
2692 self.unmountRequests_.splice(index, 1); | 2691 self.unmountRequests_.splice(index, 1); |
2693 if (event.status != 'success') | 2692 if (event.status != 'success') |
2694 self.alert.show(strf('UNMOUNT_FAILED', event.status)); | 2693 self.alert.show(strf('UNMOUNT_FAILED', event.status)); |
2695 } | 2694 } |
2696 | 2695 |
2697 if (event.status == 'success' && | 2696 if (event.status == 'success' && |
2698 event.mountPath == self.directoryModel_.rootPath) { | 2697 event.mountPath == self.directoryModel_.getCurrentRootPath()) { |
2699 if (self.params_.mountTriggered && index == -1) { | 2698 if (self.params_.mountTriggered && index == -1) { |
2700 // This device mount was the reason this File Manager instance was | 2699 // This device mount was the reason this File Manager instance was |
2701 // created. Now the device is unmounted from another instance | 2700 // created. Now the device is unmounted from another instance |
2702 // or the user removed the device manually. Close this instance. | 2701 // or the user removed the device manually. Close this instance. |
2703 // window.close() sometimes doesn't work. | 2702 // window.close() sometimes doesn't work. |
2704 chrome.tabs.getCurrent(function(tab) { | 2703 chrome.tabs.getCurrent(function(tab) { |
2705 chrome.tabs.remove(tab.id); | 2704 chrome.tabs.remove(tab.id); |
2706 }); | 2705 }); |
2707 return; | 2706 return; |
2708 } | 2707 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2840 | 2839 |
2841 galleryFrame.onload = function() { | 2840 galleryFrame.onload = function() { |
2842 galleryFrame.contentWindow.ImageUtil.metrics = metrics; | 2841 galleryFrame.contentWindow.ImageUtil.metrics = metrics; |
2843 galleryFrame.contentWindow.FileType = FileType; | 2842 galleryFrame.contentWindow.FileType = FileType; |
2844 galleryFrame.contentWindow.util = util; | 2843 galleryFrame.contentWindow.util = util; |
2845 | 2844 |
2846 // Gallery shoud treat GData folder as readonly even when online | 2845 // Gallery shoud treat GData folder as readonly even when online |
2847 // until we learn to save files directly to GData. | 2846 // until we learn to save files directly to GData. |
2848 var readonly = self.isOnReadonlyDirectory() || self.isOnGData(); | 2847 var readonly = self.isOnReadonlyDirectory() || self.isOnGData(); |
2849 var currentDir = self.directoryModel_.currentEntry; | 2848 var currentDir = self.directoryModel_.currentEntry; |
2850 var downloadsDir = self.directoryModel_.rootsList.item(0); | 2849 var downloadsDir = self.directoryModel_.getRootsList().item(0); |
2851 | 2850 |
2852 var context = { | 2851 var context = { |
2853 // We show the root label in readonly warning (e.g. archive name). | 2852 // We show the root label in readonly warning (e.g. archive name). |
2854 readonlyDirName: | 2853 readonlyDirName: |
2855 readonly ? | 2854 readonly ? |
2856 (self.isOnGData() ? | 2855 (self.isOnGData() ? |
2857 self.getRootLabel_(currentDir.fullPath) : | 2856 self.getRootLabel_(currentDir.fullPath) : |
2858 self.directoryModel_.rootName) : | 2857 self.directoryModel_.rootName) : |
2859 null, | 2858 null, |
2860 saveDirEntry: readonly ? downloadsDir : currentDir, | 2859 saveDirEntry: readonly ? downloadsDir : currentDir, |
(...skipping 15 matching lines...) Expand all Loading... | |
2876 this.openFilePopup_(galleryFrame); | 2875 this.openFilePopup_(galleryFrame); |
2877 }; | 2876 }; |
2878 | 2877 |
2879 /** | 2878 /** |
2880 * Update the breadcrumb display to reflect the current directory. | 2879 * Update the breadcrumb display to reflect the current directory. |
2881 */ | 2880 */ |
2882 FileManager.prototype.updateBreadcrumbs_ = function() { | 2881 FileManager.prototype.updateBreadcrumbs_ = function() { |
2883 var bc = this.dialogDom_.querySelector('.breadcrumbs'); | 2882 var bc = this.dialogDom_.querySelector('.breadcrumbs'); |
2884 removeChildren(bc); | 2883 removeChildren(bc); |
2885 | 2884 |
2886 var rootPath = this.directoryModel_.rootPath; | 2885 var rootPath = this.directoryModel_.getCurrentRootPath(); |
2887 var relativePath = this.directoryModel_.currentEntry.fullPath. | 2886 var relativePath = this.directoryModel_.currentEntry.fullPath. |
2888 substring(rootPath.length).replace(/\/$/, ''); | 2887 substring(rootPath.length).replace(/\/$/, ''); |
2889 | 2888 |
2890 var pathNames = relativePath.replace(/\/$/, '').split('/'); | 2889 var pathNames = relativePath.replace(/\/$/, '').split('/'); |
2891 if (pathNames[0] == '') | 2890 if (pathNames[0] == '') |
2892 pathNames.splice(0, 1); | 2891 pathNames.splice(0, 1); |
2893 | 2892 |
2894 // We need a first breadcrumb for root, so placing last name from | 2893 // We need a first breadcrumb for root, so placing last name from |
2895 // rootPath as first name of relativePath. | 2894 // rootPath as first name of relativePath. |
2896 var rootPathNames = rootPath.replace(/\/$/, '').split('/'); | 2895 var rootPathNames = rootPath.replace(/\/$/, '').split('/'); |
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4323 | 4322 |
4324 handleSplitterDragEnd: function(e) { | 4323 handleSplitterDragEnd: function(e) { |
4325 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); | 4324 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); |
4326 this.ownerDocument.documentElement.classList.remove('col-resize'); | 4325 this.ownerDocument.documentElement.classList.remove('col-resize'); |
4327 } | 4326 } |
4328 }; | 4327 }; |
4329 | 4328 |
4330 customSplitter.decorate(splitterElement); | 4329 customSplitter.decorate(splitterElement); |
4331 }; | 4330 }; |
4332 })(); | 4331 })(); |
OLD | NEW |