Commit 320967b2 authored by hirono@chromium.org's avatar hirono@chromium.org

Files.app: Show the "open in other desktop" dialog when the task is executed from the gallery.

Previously if the file is opened from the gallery, it does not hanlde the case
that the window is opened in the desktop of the running proifle.

This CL adds lines to handle the case in the gallery.

BUG=336093
TEST=Execute a file handler task from the gallery in the teleported window.

Review URL: https://codereview.chromium.org/143153009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251383 0039d316-1c4b-4281-b951-d872f2087c98
parent 80406237
...@@ -1185,6 +1185,46 @@ util.isTeleported = function(window) { ...@@ -1185,6 +1185,46 @@ util.isTeleported = function(window) {
}); });
}; };
/**
* Sets up and shows the alert to inform a user the task is opened in the
* desktop of the running profile.
*
* TODO(hirono): Move the function from the util namespace.
* @param {cr.ui.AlertDialog} alertDialog Alert dialog to be shown.
* @param {Array.<Entry>} entries List of opened entries.
*/
util.showOpenInOtherDesktopAlert = function(alertDialog, entries) {
if (!entries.length)
return;
chrome.fileBrowserPrivate.getProfiles(function(profiles,
currentId,
displayedId) {
// Find strings.
var displayName;
for (var i = 0; i < profiles.length; i++) {
if (profiles[i].profileId === currentId) {
displayName = profiles[i].displayName;
break;
}
}
if (!displayName) {
console.warn('Display name is not found.');
return;
}
var title = entries.size > 1 ?
entries[0].name + '\u2026' /* ellipsis */ : entries[0].name;
var message = strf(entries.size > 1 ?
'OPEN_IN_OTHER_DESKTOP_MESSAGE_PLURAL' :
'OPEN_IN_OTHER_DESKTOP_MESSAGE',
displayName,
currentId);
// Show the dialog.
alertDialog.showWithTitle(title, message);
}.bind(this));
};
/** /**
* Error type of VolumeManager. * Error type of VolumeManager.
* @enum {string} * @enum {string}
......
...@@ -379,8 +379,10 @@ FileTasks.prototype.executeDefaultInternal_ = function(entries, opt_callback) { ...@@ -379,8 +379,10 @@ FileTasks.prototype.executeDefaultInternal_ = function(entries, opt_callback) {
break; break;
case 'message_sent': case 'message_sent':
util.isTeleported(window).then(function(teleported) { util.isTeleported(window).then(function(teleported) {
if (teleported) if (teleported) {
this.fileManager_.ui.showOpenInOtherDesktopAlert(entries); util.showOpenInOtherDesktopAlert(
this.fileManager_.ui.alertDialog, entries);
}
}.bind(this)); }.bind(this));
callback(success, entries); callback(success, entries);
break; break;
...@@ -434,8 +436,10 @@ FileTasks.prototype.executeInternal_ = function(taskId, entries) { ...@@ -434,8 +436,10 @@ FileTasks.prototype.executeInternal_ = function(taskId, entries) {
if (result !== 'message_sent') if (result !== 'message_sent')
return; return;
util.isTeleported(window).then(function(teleported) { util.isTeleported(window).then(function(teleported) {
if (teleported) if (teleported) {
this.fileManager_.ui.showOpenInOtherDesktopAlert(entries); util.showOpenInOtherDesktopAlert(
this.fileManager_.ui.alertDialog, entries);
}
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
} }
...@@ -725,7 +729,7 @@ FileTasks.prototype.openGalleryInternal_ = function(entries) { ...@@ -725,7 +729,7 @@ FileTasks.prototype.openGalleryInternal_ = function(entries) {
onClose: onClose, onClose: onClose,
onMaximize: onMaximize, onMaximize: onMaximize,
onAppRegionChanged: onAppRegionChanged, onAppRegionChanged: onAppRegionChanged,
displayStringFunction: strf loadTimeData: fm.backgroundPage.background.stringData
}; };
galleryFrame.contentWindow.Gallery.open( galleryFrame.contentWindow.Gallery.open(
context, fm.volumeManager, allEntries, entries); context, fm.volumeManager, allEntries, entries);
......
...@@ -47,7 +47,7 @@ function Gallery(context, volumeManager) { ...@@ -47,7 +47,7 @@ function Gallery(context, volumeManager) {
this.dataModel_ = new cr.ui.ArrayDataModel([]); this.dataModel_ = new cr.ui.ArrayDataModel([]);
this.selectionModel_ = new cr.ui.ListSelectionModel(); this.selectionModel_ = new cr.ui.ListSelectionModel();
this.displayStringFunction_ = context.displayStringFunction; loadTimeData.data = context.loadTimeData;
this.initDom_(); this.initDom_();
this.initListeners_(); this.initListeners_();
...@@ -165,6 +165,10 @@ Gallery.prototype.onUnload = function(exiting) { ...@@ -165,6 +165,10 @@ Gallery.prototype.onUnload = function(exiting) {
* @private * @private
*/ */
Gallery.prototype.initDom_ = function() { Gallery.prototype.initDom_ = function() {
// Initialize the dialog label.
cr.ui.dialogs.BaseDialog.OK_LABEL = str('GALLERY_OK_LABEL');
cr.ui.dialogs.BaseDialog.CANCEL_LABEL = str('GALLERY_CANCEL_LABEL');
var content = util.createChild(this.container_, 'content'); var content = util.createChild(this.container_, 'content');
content.addEventListener('click', this.onContentClick_.bind(this)); content.addEventListener('click', this.onContentClick_.bind(this));
...@@ -208,8 +212,7 @@ Gallery.prototype.initDom_ = function() { ...@@ -208,8 +212,7 @@ Gallery.prototype.initDom_ = function() {
util.createChild(this.toolbar_, 'button-spacer'); util.createChild(this.toolbar_, 'button-spacer');
this.prompt_ = new ImageEditor.Prompt( this.prompt_ = new ImageEditor.Prompt(this.container_, str);
this.container_, this.displayStringFunction_);
this.modeButton_ = util.createChild(this.toolbar_, 'button mode', 'button'); this.modeButton_ = util.createChild(this.toolbar_, 'button mode', 'button');
this.modeButton_.addEventListener('click', this.modeButton_.addEventListener('click',
...@@ -230,7 +233,7 @@ Gallery.prototype.initDom_ = function() { ...@@ -230,7 +233,7 @@ Gallery.prototype.initDom_ = function() {
this.selectionModel_, this.selectionModel_,
this.context_, this.context_,
this.toggleMode_.bind(this), this.toggleMode_.bind(this),
this.displayStringFunction_); str);
this.slideMode_.addEventListener('image-displayed', function() { this.slideMode_.addEventListener('image-displayed', function() {
cr.dispatchSimpleEvent(this, 'image-displayed'); cr.dispatchSimpleEvent(this, 'image-displayed');
...@@ -267,7 +270,7 @@ Gallery.prototype.initDom_ = function() { ...@@ -267,7 +270,7 @@ Gallery.prototype.initDom_ = function() {
*/ */
Gallery.prototype.createToolbarButton_ = function(className, title) { Gallery.prototype.createToolbarButton_ = function(className, title) {
var button = util.createChild(this.toolbar_, className, 'button'); var button = util.createChild(this.toolbar_, className, 'button');
button.title = this.displayStringFunction_(title); button.title = str(title);
return button; return button;
}; };
...@@ -509,14 +512,10 @@ Gallery.prototype.delete_ = function() { ...@@ -509,14 +512,10 @@ Gallery.prototype.delete_ = function() {
this.document_.body.addEventListener('keydown', this.keyDownBound_); this.document_.body.addEventListener('keydown', this.keyDownBound_);
}.bind(this); }.bind(this);
cr.ui.dialogs.BaseDialog.OK_LABEL = this.displayStringFunction_(
'GALLERY_OK_LABEL');
cr.ui.dialogs.BaseDialog.CANCEL_LABEL =
this.displayStringFunction_('GALLERY_CANCEL_LABEL');
var confirm = new cr.ui.dialogs.ConfirmDialog(this.container_); var confirm = new cr.ui.dialogs.ConfirmDialog(this.container_);
confirm.show( confirm.show(str(plural ?
this.displayStringFunction_(plural ? 'GALLERY_CONFIRM_DELETE_SOME' : 'GALLERY_CONFIRM_DELETE_SOME' : 'GALLERY_CONFIRM_DELETE_ONE', param),
'GALLERY_CONFIRM_DELETE_ONE', param),
function() { function() {
restoreListener(); restoreListener();
this.selectionModel_.unselectAll(); this.selectionModel_.unselectAll();
...@@ -656,9 +655,7 @@ Gallery.prototype.updateSelectionAndState_ = function() { ...@@ -656,9 +655,7 @@ Gallery.prototype.updateSelectionAndState_ = function() {
// be recorded in the app state and the relaunch will just open the // be recorded in the app state and the relaunch will just open the
// gallery in the curDirEntry directory. // gallery in the curDirEntry directory.
window.top.document.title = this.context_.curDirEntry.name; window.top.document.title = this.context_.curDirEntry.name;
displayName = displayName = str('GALLERY_ITEMS_SELECTED', numSelectedItems);
this.displayStringFunction_('GALLERY_ITEMS_SELECTED',
numSelectedItems);
} }
} }
...@@ -825,7 +822,18 @@ Gallery.prototype.updateShareMenu_ = function() { ...@@ -825,7 +822,18 @@ Gallery.prototype.updateShareMenu_ = function() {
this.toggleShare_(); // Hide the menu. this.toggleShare_(); // Hide the menu.
// TODO(hirono): Use entries instead of URLs. // TODO(hirono): Use entries instead of URLs.
this.executeWhenReady( this.executeWhenReady(
api.executeTask.bind(api, taskId, util.entriesToURLs(entries))); api.executeTask.bind(
api,
taskId,
util.entriesToURLs(entries),
function(result) {
var alertDialog =
new cr.ui.dialogs.AlertDialog(this.container_);
util.isTeleported(window).then(function(teleported) {
if (teleported)
util.showOpenInOtherDesktopAlert(alertDialog, entries);
}.bind(this));
}.bind(this)));
}.bind(this, task.taskId)); }.bind(this, task.taskId));
} }
...@@ -867,7 +875,6 @@ Gallery.prototype.updateButtons_ = function() { ...@@ -867,7 +875,6 @@ Gallery.prototype.updateButtons_ = function() {
var oppositeMode = var oppositeMode =
this.currentMode_ === this.slideMode_ ? this.mosaicMode_ : this.currentMode_ === this.slideMode_ ? this.mosaicMode_ :
this.slideMode_; this.slideMode_;
this.modeButton_.title = this.modeButton_.title = str(oppositeMode.getTitle());
this.displayStringFunction_(oppositeMode.getTitle());
} }
}; };
...@@ -216,38 +216,3 @@ FileManagerUI.prototype.updateProfileBadge = function() { ...@@ -216,38 +216,3 @@ FileManagerUI.prototype.updateProfileBadge = function() {
profileBadge.removeAttribute('src'); profileBadge.removeAttribute('src');
}.bind(this)); }.bind(this));
}; };
/**
* Show the alert if the current window is in the other profile's desktop and
* the task is opened in the original desktop.
*
* @param {Array.<Entry>} entries List of opened entries.
*/
FileManagerUI.prototype.showOpenInOtherDesktopAlert = function(entries) {
if (!entries.length)
return;
chrome.fileBrowserPrivate.getProfiles(function(profiles,
currentId,
displayedId) {
// Find strings.
var displayName;
for (var i = 0; i < profiles.length; i++) {
if (profiles[i].profileId === currentId) {
displayName = profiles[i].displayName;
break;
}
}
if (!displayName)
throw new Error('Display name is not found.');
var title = entries.size > 1 ?
entries[0].name + '\u2026' /* ellipsis */ : entries[0].name;
var message = strf(entries.size > 1 ?
'OPEN_IN_OTHER_DESKTOP_MESSAGE_PLURAL' :
'OPEN_IN_OTHER_DESKTOP_MESSAGE',
displayName,
currentId);
// Show the dialog.
this.alertDialog.showWithTitle(title, message);
}.bind(this));
};
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