[File Manager] Properly enable/disable Copy and Open for GData files in the offline mode.

In the offline GData mode Copy context menu is enabled only if all selected files are cached locally.
In Open dialog "Open" button is enabled only if the selected file(s) is(are) cached locally.

BUG=chromium-os:29611
TEST=

Review URL: https://chromiumcodereview.appspot.com/10184005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133903 0039d316-1c4b-4281-b951-d872f2087c98
parent d5e5ec8e
...@@ -102,6 +102,13 @@ DirectoryModel.prototype.getFileList = function() { ...@@ -102,6 +102,13 @@ DirectoryModel.prototype.getFileList = function() {
return this.fileList_; return this.fileList_;
}; };
/**
* @return {MetadataCache} Metadata cache.
*/
DirectoryModel.prototype.getMetadataCache = function() {
return this.metadataCache_;
};
/** /**
* Sort the file list. * Sort the file list.
* @param {string} sortField Sort field. * @param {string} sortField Sort field.
...@@ -153,7 +160,7 @@ DirectoryModel.prototype.isPathReadOnly = function(path) { ...@@ -153,7 +160,7 @@ DirectoryModel.prototype.isPathReadOnly = function(path) {
case DirectoryModel.RootType.DOWNLOADS: case DirectoryModel.RootType.DOWNLOADS:
return false; return false;
case DirectoryModel.RootType.GDATA: case DirectoryModel.RootType.GDATA:
return !navigator.onLine; return util.isOffline();
default: default:
return true; return true;
} }
......
...@@ -1989,7 +1989,9 @@ FileManager.prototype = { ...@@ -1989,7 +1989,9 @@ FileManager.prototype = {
this.displaySizeInDiv_(listItem.querySelector('.size'), props); this.displaySizeInDiv_(listItem.querySelector('.size'), props);
this.displayTypeInDiv_(listItem.querySelector('.type'), props); this.displayTypeInDiv_(listItem.querySelector('.type'), props);
} else if (type == 'gdata') { } else if (type == 'gdata') {
this.displayOfflineInDiv_(listItem.querySelector('.offline'), props); var offline = listItem.querySelector('.offline');
if (offline) // This column is only present in full page mode.
this.displayOfflineInDiv_(offline, props);
this.displayGDataStyleInItem_(listItem, entry, props); this.displayGDataStyleInItem_(listItem, entry, props);
} }
} }
...@@ -2041,6 +2043,7 @@ FileManager.prototype = { ...@@ -2041,6 +2043,7 @@ FileManager.prototype = {
directoryCount: 0, directoryCount: 0,
bytes: 0, bytes: 0,
showBytes: false, showBytes: false,
allGDataFilesPresent: false,
iconType: null, iconType: null,
indexes: this.currentList_.selectionModel.selectedIndexes indexes: this.currentList_.selectionModel.selectedIndexes
}; };
...@@ -2155,6 +2158,25 @@ FileManager.prototype = { ...@@ -2155,6 +2158,25 @@ FileManager.prototype = {
this.dispatchEvent(new cr.Event('selection-summarized')); this.dispatchEvent(new cr.Event('selection-summarized'));
}.bind(this)); }.bind(this));
if (this.isOnGData()) {
this.metadataCache_.get(selection.urls, 'gdata', function(props) {
selection.allGDataFilesPresent =
props.filter(function(p) {return !p.availableOffline}).length == 0;
this.updateOkButton_();
}.bind(this));
}
};
/**
* Check if all the files in the current selection are available. The only
* case when files might be not available is when the selection contains
* uncached GData files and the browser is offline.
* @return {boolean} True if all files in the current selection are
* available.
*/
FileManager.prototype.isSelectionAvailable = function() {
return !this.isOnGDataOffline() || this.selection.allGDataFilesPresent;
}; };
/** /**
...@@ -2466,17 +2488,15 @@ FileManager.prototype = { ...@@ -2466,17 +2488,15 @@ FileManager.prototype = {
FileManager.prototype.executeIfAvailable_ = function(urls, callback) { FileManager.prototype.executeIfAvailable_ = function(urls, callback) {
if (this.isOnGDataOffline()) { if (this.isOnGDataOffline()) {
this.metadataCache_.get(urls, 'gdata', function(props) { this.metadataCache_.get(urls, 'gdata', function(props) {
for (var i = 0; i != props.length; i++) { if (props.filter(function(p) {return !p.availableOffline}).length) {
if (!props[i].availableOffline) { this.alert.showHtml(
this.alert.showHtml( str('OFFLINE_HEADER'),
str('OFFLINE_HEADER'), strf(
strf( urls.length == 1 ?
urls.length == 1 ? 'OFFLINE_MESSAGE' :
'OFFLINE_MESSAGE' : 'OFFLINE_MESSAGE_PLURAL',
'OFFLINE_MESSAGE_PLURAL', str('OFFLINE_COLUMN_LABEL')));
str('OFFLINE_COLUMN_LABEL'))); return;
return;
}
} }
callback(urls); callback(urls);
}.bind(this)); }.bind(this));
...@@ -2485,12 +2505,8 @@ FileManager.prototype = { ...@@ -2485,12 +2505,8 @@ FileManager.prototype = {
} }
}; };
FileManager.prototype.isOffline = function() {
return !navigator.onLine;
};
FileManager.prototype.onOnlineOffline_ = function() { FileManager.prototype.onOnlineOffline_ = function() {
if (this.isOffline()) { if (util.isOffline()) {
console.log('OFFLINE'); console.log('OFFLINE');
this.dialogContainer_.setAttribute('offline', true); this.dialogContainer_.setAttribute('offline', true);
} else { } else {
...@@ -2500,7 +2516,7 @@ FileManager.prototype = { ...@@ -2500,7 +2516,7 @@ FileManager.prototype = {
}; };
FileManager.prototype.isOnGDataOffline = function() { FileManager.prototype.isOnGDataOffline = function() {
return this.isOnGData() && this.isOffline(); return this.isOnGData() && util.isOffline();
}; };
FileManager.prototype.isOnReadonlyDirectory = function() { FileManager.prototype.isOnReadonlyDirectory = function() {
...@@ -3076,7 +3092,7 @@ FileManager.prototype = { ...@@ -3076,7 +3092,7 @@ FileManager.prototype = {
} }
var pin = checkbox.checked; var pin = checkbox.checked;
this.metadataCache_.get(entry, 'gdata', function(gdata) { this.metadataCache_.get(entry, 'gdata', function(gdata) {
if (self.isOffline() && pin && !gdata.present) { if (util.isOffline() && pin && !gdata.present) {
// If we are offline, we cannot pin a file that is not already present. // If we are offline, we cannot pin a file that is not already present.
checkbox.checked = false; // Revert the default action. checkbox.checked = false; // Revert the default action.
self.alert.showHtml( self.alert.showHtml(
...@@ -3189,11 +3205,13 @@ FileManager.prototype = { ...@@ -3189,11 +3205,13 @@ FileManager.prototype = {
selectable = this.selection.directoryCount == 1 && selectable = this.selection.directoryCount == 1 &&
this.selection.fileCount == 0; this.selection.fileCount == 0;
} else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) {
selectable = (this.selection.directoryCount == 0 && selectable = (this.isSelectionAvailable() &&
this.selection.directoryCount == 0 &&
this.selection.fileCount == 1); this.selection.fileCount == 1);
} else if (this.dialogType_ == } else if (this.dialogType_ ==
FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { FileManager.DialogType.SELECT_OPEN_MULTI_FILE) {
selectable = (this.selection.directoryCount == 0 && selectable = (this.isSelectionAvailable() &&
this.selection.directoryCount == 0 &&
this.selection.fileCount >= 1); this.selection.fileCount >= 1);
} else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) {
if (this.isOnReadonlyDirectory()) { if (this.isOnReadonlyDirectory()) {
......
...@@ -75,6 +75,7 @@ FileTransferController.prototype = { ...@@ -75,6 +75,7 @@ FileTransferController.prototype = {
doc.addEventListener('cut', this.onCut_.bind(this)); doc.addEventListener('cut', this.onCut_.bind(this));
doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this)); doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this));
doc.addEventListener('paste', this.onPaste_.bind(this)); doc.addEventListener('paste', this.onPaste_.bind(this));
this.copyCommand_ = doc.querySelector('command#copy');
}, },
/** /**
...@@ -85,7 +86,7 @@ FileTransferController.prototype = { ...@@ -85,7 +86,7 @@ FileTransferController.prototype = {
* |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove'). * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove').
*/ */
cutOrCopy: function(dataTransfer, effectAllowed) { cutOrCopy: function(dataTransfer, effectAllowed) {
var directories = []; var directories = [];
var files = []; var files = [];
var entries = this.selectedEntries_; var entries = this.selectedEntries_;
for (var i = 0; i < entries.length; i++) { for (var i = 0; i < entries.length; i++) {
...@@ -264,6 +265,8 @@ FileTransferController.prototype = { ...@@ -264,6 +265,8 @@ FileTransferController.prototype = {
}, },
canCopyOrDrag_: function() { canCopyOrDrag_: function() {
if (this.isOnGData && util.isOffline() && !this.allGDataFilesAvailable)
return false;
return this.selectedEntries_.length > 0; return this.selectedEntries_.length > 0;
}, },
...@@ -383,6 +386,22 @@ FileTransferController.prototype = { ...@@ -383,6 +386,22 @@ FileTransferController.prototype = {
if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT) if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT)
dragNodes.push(new this.dragNodeConstructor_(entries[i])); dragNodes.push(new this.dragNodeConstructor_(entries[i]));
} }
if (this.isOnGData) {
this.allGDataFilesAvailable = false;
var urls = entries.map(function(e) { return e.toURL() });
this.directoryModel_.getMetadataCache().get(
urls, 'gdata', function(props) {
// We consider directories not available offline for the purposes of
// file transfer since we cannot afford to recursive traversal.
this.allGDataFilesAvailable =
entries.filter(function(e) {return e.isDirectory}).length == 0 &&
props.filter(function(p) {return !p.availableOffline}).length == 0;
// |Copy| is the only menu item affected by allGDataFilesAvailable.
// It could be open right now, update its UI.
this.copyCommand_.disabled = !this.canCopyOrDrag_();
}.bind(this));
}
}, },
get currentDirectory() { get currentDirectory() {
......
...@@ -491,5 +491,13 @@ var util = { ...@@ -491,5 +491,13 @@ var util = {
(event.altKey ? 'Alt-' : '') + (event.altKey ? 'Alt-' : '') +
(event.shiftKey ? 'Shift-' : '') + (event.shiftKey ? 'Shift-' : '') +
(event.metaKey ? 'Meta-' : ''); (event.metaKey ? 'Meta-' : '');
},
/**
* A wrapper for navigator.onLine that allows for easy debug override.
* @return {boolean} True if offline.
*/
isOffline: function() {
return !navigator.onLine;
} }
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment