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

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

Issue 10146008: Remember current directory for each volume. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 * 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 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 this.rootsList_.startBatchUpdates(); 794 this.rootsList_.startBatchUpdates();
795 795
796 var self = this; 796 var self = this;
797 this.rootsList_.itemConstructor = function(entry) { 797 this.rootsList_.itemConstructor = function(entry) {
798 return self.renderRoot_(entry); 798 return self.renderRoot_(entry);
799 }; 799 };
800 800
801 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; 801 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection;
802 802
803 // TODO(dgozman): add "Add a drive" item. 803 // TODO(dgozman): add "Add a drive" item.
804 this.rootsList_.dataModel = this.directoryModel_.rootsList; 804 this.rootsList_.dataModel = this.directoryModel_.getRootsList();
805 this.directoryModel_.updateRoots(function() { 805 this.directoryModel_.updateRoots(function() {
806 self.rootsList_.endBatchUpdates(); 806 self.rootsList_.endBatchUpdates();
807 }, false); 807 }, false);
808 }; 808 };
809 809
810 /** 810 /**
811 * @param {boolean} dirChanged True if we just changed to GData directory, 811 * @param {boolean} dirChanged True if we just changed to GData directory,
812 * False if "Retry" button clicked. 812 * False if "Retry" button clicked.
813 */ 813 */
814 FileManager.prototype.initGData_ = function(dirChanged) { 814 FileManager.prototype.initGData_ = function(dirChanged) {
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 1919
1920 if (path == '/' + DirectoryModel.GDATA_DIRECTORY) 1920 if (path == '/' + DirectoryModel.GDATA_DIRECTORY)
1921 return str('GDATA_DIRECTORY_LABEL'); 1921 return str('GDATA_DIRECTORY_LABEL');
1922 1922
1923 return path; 1923 return path;
1924 }; 1924 };
1925 1925
1926 FileManager.prototype.renderRoot_ = function(entry) { 1926 FileManager.prototype.renderRoot_ = function(entry) {
1927 var li = this.document_.createElement('li'); 1927 var li = this.document_.createElement('li');
1928 li.className = 'root-item'; 1928 li.className = 'root-item';
1929 li.addEventListener('click', this.onRootClick_.bind(this, entry)); 1929 this.directoryModel_.registerRootClickListener_(li, entry);
1930 1930
1931 var rootType = DirectoryModel.getRootType(entry.fullPath); 1931 var rootType = DirectoryModel.getRootType(entry.fullPath);
1932 1932
1933 var div = this.document_.createElement('div'); 1933 var div = this.document_.createElement('div');
1934 div.className = 'root-label'; 1934 div.className = 'root-label';
1935 1935
1936 var icon = rootType; 1936 var icon = rootType;
1937 var deviceNumber = this.getDeviceNumber(entry); 1937 var deviceNumber = this.getDeviceNumber(entry);
1938 1938
1939 if (deviceNumber != undefined) { 1939 if (deviceNumber != undefined) {
(...skipping 23 matching lines...) Expand all
1963 1963
1964 cr.ui.contextMenuHandler.setContextMenu(li, this.rootsContextMenu_); 1964 cr.ui.contextMenuHandler.setContextMenu(li, this.rootsContextMenu_);
1965 } 1965 }
1966 1966
1967 cr.defineProperty(li, 'lead', cr.PropertyKind.BOOL_ATTR); 1967 cr.defineProperty(li, 'lead', cr.PropertyKind.BOOL_ATTR);
1968 cr.defineProperty(li, 'selected', cr.PropertyKind.BOOL_ATTR); 1968 cr.defineProperty(li, 'selected', cr.PropertyKind.BOOL_ATTR);
1969 return li; 1969 return li;
1970 }; 1970 };
1971 1971
1972 /** 1972 /**
1973 * Handler for root item being clicked.
1974 * @param {Entry} entry to navigate to.
1975 * @param {Event} event The event.
1976 */
1977 FileManager.prototype.onRootClick_ = function(entry, event) {
1978 var path = this.directoryModel_.currentEntry.fullPath;
1979 if (path.indexOf(entry.fullPath) == 0 && path != entry.fullPath) {
1980 this.directoryModel_.changeDirectory(entry.fullPath);
1981 }
1982 };
1983
1984 /**
1985 * Unmounts device. 1973 * Unmounts device.
1986 * @param {string} url The url of removable storage to unmount. 1974 * @param {string} url The url of removable storage to unmount.
1987 */ 1975 */
1988 FileManager.prototype.unmountVolume_ = function(entry) { 1976 FileManager.prototype.unmountVolume_ = function(entry) {
1989 this.unmountRequests_.push(entry.fullPath); 1977 this.unmountRequests_.push(entry.fullPath);
1990 chrome.fileBrowserPrivate.removeMount(entry.toURL()); 1978 chrome.fileBrowserPrivate.removeMount(entry.toURL());
1991 }; 1979 };
1992 1980
1993 FileManager.prototype.styleGDataItem_ = function(entry, listItem) { 1981 FileManager.prototype.styleGDataItem_ = function(entry, listItem) {
1994 if (!this.isOnGData()) 1982 if (!this.isOnGData())
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 } 2438 }
2451 2439
2452 function setVisibility(visibility) { 2440 function setVisibility(visibility) {
2453 panel.setAttribute('visibility', visibility); 2441 panel.setAttribute('visibility', visibility);
2454 } 2442 }
2455 }; 2443 };
2456 2444
2457 2445
2458 FileManager.prototype.isOnGData = function() { 2446 FileManager.prototype.isOnGData = function() {
2459 return this.directoryModel_ && 2447 return this.directoryModel_ &&
2460 this.directoryModel_.rootPath == '/' + DirectoryModel.GDATA_DIRECTORY; 2448 this.directoryModel_.getCurrentRootPath() ==
2449 '/' + DirectoryModel.GDATA_DIRECTORY;
2461 }; 2450 };
2462 2451
2463 FileManager.prototype.getMetadataProvider = function() { 2452 FileManager.prototype.getMetadataProvider = function() {
2464 return this.metadataProvider_; 2453 return this.metadataProvider_;
2465 }; 2454 };
2466 2455
2467 /** 2456 /**
2468 * Callback called when tasks for selected files are determined. 2457 * Callback called when tasks for selected files are determined.
2469 * @param {Object} selection Selection is passed here, since this.selection 2458 * @param {Object} selection Selection is passed here, since this.selection
2470 * can change before tasks were found, and we should be accurate. 2459 * can change before tasks were found, and we should be accurate.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2712 }; 2701 };
2713 // Not calling clearGDataLoadingTimer_ here because we want to keep 2702 // Not calling clearGDataLoadingTimer_ here because we want to keep
2714 // "Loading Google Docs" message until the directory loads. It is OK if 2703 // "Loading Google Docs" message until the directory loads. It is OK if
2715 // the timer fires after the mount because onDirectoryChanged_ will hide 2704 // the timer fires after the mount because onDirectoryChanged_ will hide
2716 // the unmounted panel. 2705 // the unmounted panel.
2717 if (this.setupCurrentDirectoryPostponed_) { 2706 if (this.setupCurrentDirectoryPostponed_) {
2718 this.setupCurrentDirectoryPostponed_(false /* execute */); 2707 this.setupCurrentDirectoryPostponed_(false /* execute */);
2719 } else if (this.isOnGData() && 2708 } else if (this.isOnGData() &&
2720 this.directoryModel_.currentEntry.unmounted) { 2709 this.directoryModel_.currentEntry.unmounted) {
2721 // We are currently on an unmounted GData directory, force a rescan. 2710 // We are currently on an unmounted GData directory, force a rescan.
2722 changeDirectoryTo = this.directoryModel_.rootPath; 2711 changeDirectoryTo = this.directoryModel_.getCurrentRootPath();
2723 } 2712 }
2724 } else { 2713 } else {
2725 this.gdataMounted_ = false; 2714 this.gdataMounted_ = false;
2726 this.gdataMountInfo_ = null; 2715 this.gdataMountInfo_ = null;
2727 this.clearGDataLoadingTimer_(); 2716 this.clearGDataLoadingTimer_();
2728 this.onGDataUnreachable_('GData mount failed: ' + event.status); 2717 this.onGDataUnreachable_('GData mount failed: ' + event.status);
2729 if (this.setupCurrentDirectoryPostponed_) { 2718 if (this.setupCurrentDirectoryPostponed_) {
2730 this.setupCurrentDirectoryPostponed_(true /* cancel */); 2719 this.setupCurrentDirectoryPostponed_(true /* cancel */);
2731 // Change to unmounted GData root. 2720 // Change to unmounted GData root.
2732 changeDirectoryTo = '/' + DirectoryModel.GDATA_DIRECTORY; 2721 changeDirectoryTo = '/' + DirectoryModel.GDATA_DIRECTORY;
(...skipping 25 matching lines...) Expand all
2758 if (event.eventType == 'unmount') { 2747 if (event.eventType == 'unmount') {
2759 // Unmount request finished - remove it. 2748 // Unmount request finished - remove it.
2760 var index = self.unmountRequests_.indexOf(event.mountPath); 2749 var index = self.unmountRequests_.indexOf(event.mountPath);
2761 if (index != -1) { 2750 if (index != -1) {
2762 self.unmountRequests_.splice(index, 1); 2751 self.unmountRequests_.splice(index, 1);
2763 if (event.status != 'success') 2752 if (event.status != 'success')
2764 self.alert.show(strf('UNMOUNT_FAILED', event.status)); 2753 self.alert.show(strf('UNMOUNT_FAILED', event.status));
2765 } 2754 }
2766 2755
2767 if (event.status == 'success' && 2756 if (event.status == 'success' &&
2768 event.mountPath == self.directoryModel_.rootPath) { 2757 event.mountPath == self.directoryModel_.getCurrentRootPath()) {
2769 if (self.params_.mountTriggered && index == -1) { 2758 if (self.params_.mountTriggered && index == -1) {
2770 // This device mount was the reason this File Manager instance was 2759 // This device mount was the reason this File Manager instance was
2771 // created. Now the device is unmounted from another instance 2760 // created. Now the device is unmounted from another instance
2772 // or the user removed the device manually. Close this instance. 2761 // or the user removed the device manually. Close this instance.
2773 // window.close() sometimes doesn't work. 2762 // window.close() sometimes doesn't work.
2774 chrome.tabs.getCurrent(function(tab) { 2763 chrome.tabs.getCurrent(function(tab) {
2775 chrome.tabs.remove(tab.id); 2764 chrome.tabs.remove(tab.id);
2776 }); 2765 });
2777 return; 2766 return;
2778 } 2767 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2910 2899
2911 galleryFrame.onload = function() { 2900 galleryFrame.onload = function() {
2912 galleryFrame.contentWindow.ImageUtil.metrics = metrics; 2901 galleryFrame.contentWindow.ImageUtil.metrics = metrics;
2913 galleryFrame.contentWindow.FileType = FileType; 2902 galleryFrame.contentWindow.FileType = FileType;
2914 galleryFrame.contentWindow.util = util; 2903 galleryFrame.contentWindow.util = util;
2915 2904
2916 // Gallery shoud treat GData folder as readonly even when online 2905 // Gallery shoud treat GData folder as readonly even when online
2917 // until we learn to save files directly to GData. 2906 // until we learn to save files directly to GData.
2918 var readonly = self.isOnReadonlyDirectory() || self.isOnGData(); 2907 var readonly = self.isOnReadonlyDirectory() || self.isOnGData();
2919 var currentDir = self.directoryModel_.currentEntry; 2908 var currentDir = self.directoryModel_.currentEntry;
2920 var downloadsDir = self.directoryModel_.rootsList.item(0); 2909 var downloadsDir = self.directoryModel_.getRootsList().item(0);
2921 2910
2922 var context = { 2911 var context = {
2923 // We show the root label in readonly warning (e.g. archive name). 2912 // We show the root label in readonly warning (e.g. archive name).
2924 readonlyDirName: 2913 readonlyDirName:
2925 readonly ? 2914 readonly ?
2926 (self.isOnGData() ? 2915 (self.isOnGData() ?
2927 self.getRootLabel_(currentDir.fullPath) : 2916 self.getRootLabel_(currentDir.fullPath) :
2928 self.directoryModel_.rootName) : 2917 self.directoryModel_.rootName) :
2929 null, 2918 null,
2930 saveDirEntry: readonly ? downloadsDir : currentDir, 2919 saveDirEntry: readonly ? downloadsDir : currentDir,
(...skipping 15 matching lines...) Expand all
2946 this.openFilePopup_(galleryFrame); 2935 this.openFilePopup_(galleryFrame);
2947 }; 2936 };
2948 2937
2949 /** 2938 /**
2950 * Update the breadcrumb display to reflect the current directory. 2939 * Update the breadcrumb display to reflect the current directory.
2951 */ 2940 */
2952 FileManager.prototype.updateBreadcrumbs_ = function() { 2941 FileManager.prototype.updateBreadcrumbs_ = function() {
2953 var bc = this.dialogDom_.querySelector('.breadcrumbs'); 2942 var bc = this.dialogDom_.querySelector('.breadcrumbs');
2954 removeChildren(bc); 2943 removeChildren(bc);
2955 2944
2956 var rootPath = this.directoryModel_.rootPath; 2945 var rootPath = this.directoryModel_.getCurrentRootPath();
2957 var relativePath = this.directoryModel_.currentEntry.fullPath. 2946 var relativePath = this.directoryModel_.currentEntry.fullPath.
2958 substring(rootPath.length).replace(/\/$/, ''); 2947 substring(rootPath.length).replace(/\/$/, '');
2959 2948
2960 var pathNames = relativePath.replace(/\/$/, '').split('/'); 2949 var pathNames = relativePath.replace(/\/$/, '').split('/');
2961 if (pathNames[0] == '') 2950 if (pathNames[0] == '')
2962 pathNames.splice(0, 1); 2951 pathNames.splice(0, 1);
2963 2952
2964 // We need a first breadcrumb for root, so placing last name from 2953 // We need a first breadcrumb for root, so placing last name from
2965 // rootPath as first name of relativePath. 2954 // rootPath as first name of relativePath.
2966 var rootPathNames = rootPath.replace(/\/$/, '').split('/'); 2955 var rootPathNames = rootPath.replace(/\/$/, '').split('/');
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4381 4370
4382 handleSplitterDragEnd: function(e) { 4371 handleSplitterDragEnd: function(e) {
4383 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); 4372 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments);
4384 this.ownerDocument.documentElement.classList.remove('col-resize'); 4373 this.ownerDocument.documentElement.classList.remove('col-resize');
4385 } 4374 }
4386 }; 4375 };
4387 4376
4388 customSplitter.decorate(splitterElement); 4377 customSplitter.decorate(splitterElement);
4389 }; 4378 };
4390 })(); 4379 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698