Skip to content

Commit

Permalink
clipboard: don't show full warning on paste
Browse files Browse the repository at this point in the history
if complex selection was copied in one window
then we try to paste in other document, then
the same dialog appeared. this commit shows
only progressbar step for "paste" operation
as we don't need to do anything else.

Signed-off-by: Szymon Kłos <[email protected]>
Change-Id: Id9c33261dbdfb282d142cdfdf2217b30111263b1
  • Loading branch information
eszkadev committed Oct 9, 2023
1 parent 231a94b commit ef440ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
31 changes: 25 additions & 6 deletions browser/src/control/Control.DownloadProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ L.Control.DownloadProgress = L.Control.extend({
this._started = false;
this._complete = false;
this._closed = false;
this._isLargeCopy = false;
},

_userAlreadyWarned: function () {
Expand Down Expand Up @@ -77,15 +78,22 @@ L.Control.DownloadProgress = L.Control.extend({
_showDownloadProgress: function (inSnackbar) {
var modalId = this._getDownloadProgressDialogId();
var msg = _('Downloading clipboard content');
var buttonText = _('Copy') + ' (Ctrl + C)'; // TODO: on Mac Ctrl == Command?
var buttonText = _('Cancel');

if (inSnackbar) {
this._map.uiManager.showProgressBar(msg, buttonText, this._onClose.bind(this));
} else {
} else if (this._isLargeCopy) {
// downloading for copy, next: show download complete dialog
buttonText = _('Copy') + ' (Ctrl + C)'; // TODO: on Mac Ctrl == Command?

this._map.uiManager.showProgressBarDialog(modalId, this._getDialogTitle(), msg,
buttonText, this._onConfirmCopyAction.bind(this), 0, this._onClose.bind(this));

JSDialog.enableButtonInModal(modalId, modalId + '-response', false);
} else {
// downloading for paste, next: dialog will dissapear
this._map.uiManager.showProgressBarDialog(modalId, this._getDialogTitle(), msg,
'', this._onClose.bind(this), 0, this._onClose.bind(this));
}
},

Expand Down Expand Up @@ -126,22 +134,30 @@ L.Control.DownloadProgress = L.Control.extend({

setupKeyboardShortcutForDialog: function (modalId) {
var dialogId = this._map.uiManager.generateModalId(modalId);
this._setupKeyboardShortcutForElement(dialogId, modalId + '-response');
var buttonId = modalId + '-response';
this._setupKeyboardShortcutForElement(dialogId, buttonId);
document.getElementById(buttonId).focus();
},

setupKeyboardShortcutForSnackbar: function () {
this._setupKeyboardShortcutForElement('snackbar', 'button');
},

show: function () {
// isLargeCopy specifies if we are copying and have to explain user the process
// if it is false we do paste so only show download progress
show: function (isLargeCopy) {
window.app.console.log('DownloadProgress.show');
// better to init the following state variables here,
// since the widget could be re-used without having been destroyed
this._started = false;
this._complete = false;
this._closed = false;
this._isLargeCopy = isLargeCopy;

this._showLargeCopyPasteWarning(this._userAlreadyWarned());
if (isLargeCopy)
this._showLargeCopyPasteWarning(this._userAlreadyWarned());
else
this._showDownloadProgress(this._userAlreadyWarned());
},

isClosed: function () {
Expand Down Expand Up @@ -224,7 +240,10 @@ L.Control.DownloadProgress = L.Control.extend({
this._complete = true;
this._started = false;

this._showDownloadComplete(this._userAlreadyWarned());
if (this._isLargeCopy)
this._showDownloadComplete(this._userAlreadyWarned());
else
this._closeDownloadProgressDialog();
},

_onConfirmCopyAction: function () {
Expand Down
2 changes: 1 addition & 1 deletion browser/src/control/Control.UIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ L.Control.UIManager = L.Control.extend({
vertical: false,
layoutstyle: 'end'
},
], responseButtonId);
], buttonText ? responseButtonId : cancelButtonId);

var that = this;
this.showModal(json, [
Expand Down
8 changes: 4 additions & 4 deletions browser/src/map/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ L.Clipboard = L.Class.extend({

// avoid to invoke the following code if the download widget depends on user interaction
if (!that._downloadProgress || that._downloadProgress.isClosed()) {
that._startProgress();
that._startProgress(false);
that._downloadProgress.startProgressMode();
}
request.onload = function() {
Expand Down Expand Up @@ -801,12 +801,12 @@ L.Clipboard = L.Class.extend({
this._scheduleHideDownload();
},

_startProgress: function() {
_startProgress: function(isLargeCopy) {
if (!this._downloadProgress) {
this._downloadProgress = L.control.downloadProgress();
this._map.addControl(this._downloadProgress);
}
this._downloadProgress.show();
this._downloadProgress.show(isLargeCopy);
},

_onDownloadOnLargeCopyPaste: function () {
Expand All @@ -815,7 +815,7 @@ L.Clipboard = L.Class.extend({
// Otherwise, it's easier to flash the widget or something.
this._warnLargeCopyPasteAlreadyStarted();
} else {
this._startProgress();
this._startProgress(true);
}
},

Expand Down

0 comments on commit ef440ea

Please sign in to comment.