diff options
author | serya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 13:39:51 +0000 |
---|---|---|
committer | serya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 13:39:51 +0000 |
commit | 3ed181387bf2a84dea714b1177f77dcc56b2e1fb (patch) | |
tree | 564923ed1e0cc8a50ed620145bcc20bd3ff2fdfa | |
parent | dc3df6b5b0ddb97909e9d6bc79d82582dd8355f4 (diff) | |
download | chromium_src-3ed181387bf2a84dea714b1177f77dcc56b2e1fb.zip chromium_src-3ed181387bf2a84dea714b1177f77dcc56b2e1fb.tar.gz chromium_src-3ed181387bf2a84dea714b1177f77dcc56b2e1fb.tar.bz2 |
Skeleton for pinning/unpinning gdata files.
BUG=chromium-os:27135
TEST=Manual test.
Review URL: https://chromiumcodereview.appspot.com/9621002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125383 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 97 insertions, 3 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 1dcabe4..965fa16 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -9927,6 +9927,9 @@ Some features may be unavailable. Please check that the profile exists and you <message name="IDS_FILE_BROWSER_PREVIEW_COLUMN_LABEL" desc="Preview column label."> Preview </message> + <message name="IDS_FILE_BROWSER_OFFLINE_COLUMN_LABEL" desc="Available offline column label."> + Available offline + </message> <message name="IDS_FILE_BROWSER_ERROR_CREATING_FOLDER" desc="Message displayed when we can't create a folder."> Unable to create folder "$1": $2 diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_browser_private_api.cc index 2e3f6bf..9cc235d 100644 --- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc +++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc @@ -1757,6 +1757,7 @@ bool FileDialogStringsFunction::RunImpl() { SET_STRING(IDS_FILE_BROWSER, TYPE_COLUMN_LABEL); SET_STRING(IDS_FILE_BROWSER, DATE_COLUMN_LABEL); SET_STRING(IDS_FILE_BROWSER, PREVIEW_COLUMN_LABEL); + SET_STRING(IDS_FILE_BROWSER, OFFLINE_COLUMN_LABEL); SET_STRING(IDS_FILE_BROWSER, DOWNLOADS_DIRECTORY_WARNING); diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js index 910e8e2..a3ae0a6 100644 --- a/chrome/browser/resources/file_manager/js/file_manager.js +++ b/chrome/browser/resources/file_manager/js/file_manager.js @@ -314,6 +314,49 @@ FileManager.prototype = { callback.bind(null, false, {})); } + function cacheGDataProps(entry, successCallback, + opt_errorCallback, opt_sync) { + if ('gdata_' in entry) { + invokeCallback(successCallback, !!opt_sync, entry); + return; + } + + entry.getGDataFileProperties = entry.getGDataFileProperties || + function(callback) { + var queue = cacheGDataProps.queue_; + queue.callbacks.push(callback); + queue.urls.push(entry.toURL()); + if (!queue.scheduled) { + queue.scheduled = true; + setTimeout(function() { + queue.scheduled = false; + var callbacks = queue.callbacks; + var urls = queue.urls; + chrome.fileBrowserPrivate.getGDataFileProperties(urls, + function(props) { + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](props[i]); + } + }); + queue.callbacks = []; + queue.urls = []; + }, 0); + } + }; + + batchAsyncCall(entry, 'getGDataFileProperties', function(props) { + entry.gdata_ = props; + if (successCallback) + successCallback(entry); + }, opt_errorCallback); + } + + cacheGDataProps.queue_ = { + callbacks: [], + urls: [], + scheduled: false + }; + function removeChildren(element) { element.textContent = ''; } @@ -1134,6 +1177,7 @@ FileManager.prototype = { } this.listType_ = type; + this.updateColumnModel_(); this.onResize_(); this.table_.list.endBatchUpdates(); @@ -1180,13 +1224,18 @@ FileManager.prototype = { this.renderNameColumnHeader_.bind(this, columns[0].name); } - this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); + this.regularColumnModel_ = new cr.ui.table.TableColumnModel(columns); + + columns.push( + new cr.ui.table.TableColumn('offline', str('OFFLINE_COLUMN_LABEL'), 21)); + columns[4].renderFunction = this.renderOffline_.bind(this); + + this.gdataColumnModel_ = new cr.ui.table.TableColumnModel(columns); + // Don't pay attention to double clicks on the table header. this.table_.querySelector('.list').addEventListener( 'dblclick', this.onDetailDoubleClick_.bind(this)); - this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); - cr.ui.contextMenuHandler.addContextMenuProperty( this.table_.querySelector('.list')); this.table_.querySelector('.list').contextMenu = this.fileContextMenu_; @@ -1277,6 +1326,15 @@ FileManager.prototype = { } }; + + FileManager.prototype.updateColumnModel_ = function() { + if (this.listType_ != FileManager.ListType.DETAIL) + return; + this.table_.columnModel = + this.directoryModel_.rootType == DirectoryModel.RootType.GDATA ? + this.gdataColumnModel_ : this.regularColumnModel_; + }; + /** * Respond to a command being executed. */ @@ -1828,6 +1886,24 @@ FileManager.prototype = { }, null, true); }; + FileManager.prototype.renderOffline_ = function(entry, columnId, table) { + var doc = this.document_; + var div = doc.createElement('div'); + div.className = 'offline'; + + var checkbox = doc.createElement('input'); + checkbox.type = 'checkbox'; + checkbox.addEventListener('click', + this.onPinClick_.bind(this, checkbox, entry)); + + cacheGDataProps(entry, function(entry) { + checkbox.checked = entry.gdata_.isPinned; + div.appendChild(checkbox); + }); + // this.updateDate_(div, entry); + return div; + }; + /** * Restore the item which is being renamed while refreshing the file list. Do * nothing if no item is being renamed or such an item disappeared. @@ -2979,6 +3055,18 @@ FileManager.prototype = { } }; + FileManager.prototype.onPinClick_ = function(checkbox, entry, event) { + function callback(props) { + checkbox.checked = entry.gdata_.isPinned = props[0].isPinned; + } + + if (checkbox.checked) { + chrome.fileBrowserPrivate.pinGDataFile([entry.toURL()], callback); + console.log('Pinning file ', entry.toURL()); + } + event.preventDefault(); + }; + FileManager.prototype.selectDefaultPathInFilenameInput_ = function() { var input = this.filenameInput_; input.focus(); @@ -3189,6 +3277,7 @@ FileManager.prototype = { this.updateCommands_(); this.updateOkButton_(); this.updateBreadcrumbs_(); + this.updateColumnModel_(); // Updated when a user clicks on the label of a file, used to detect // when a click is eligible to trigger a rename. Can be null, or diff --git a/chrome/browser/resources/file_manager/js/mock_chrome.js b/chrome/browser/resources/file_manager/js/mock_chrome.js index 31258b4..384a6e2 100644 --- a/chrome/browser/resources/file_manager/js/mock_chrome.js +++ b/chrome/browser/resources/file_manager/js/mock_chrome.js @@ -301,6 +301,7 @@ chrome.fileBrowserPrivate = { TYPE_COLUMN_LABEL: 'Type', DATE_COLUMN_LABEL: 'Date', PREVIEW_COLUMN_LABEL: 'Preview', + OFFILE_COLUMN_LABEL: 'Available offline', ERROR_CREATING_FOLDER: 'Unable to create folder "$1": $2', ERROR_INVALID_CHARACTER: 'Invalid character: $1', |