[Libreoffice-commits] online.git: 2 commits - loleaflet/src

Pranav Kant pranavk at collabora.co.uk
Fri Mar 30 14:16:22 UTC 2018


 loleaflet/src/core/LOUtil.js |    7 +++++++
 loleaflet/src/core/Socket.js |   34 ++++++++++++++++++++++++++++------
 loleaflet/src/map/Map.js     |    8 +++++++-
 3 files changed, 42 insertions(+), 7 deletions(-)

New commits:
commit 7b16ab5f94083e688d623cffff085452727616cd
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Mar 30 19:26:55 2018 +0530

    Ask to save unsaved changes to a new file
    
    ... when document is changed externally.
    
    Change-Id: Ieaad5f0ed5cd4ee3bf5385f2a5cd297b7758a43e

diff --git a/loleaflet/src/core/LOUtil.js b/loleaflet/src/core/LOUtil.js
index 286f2fa4e..fad8ad527 100644
--- a/loleaflet/src/core/LOUtil.js
+++ b/loleaflet/src/core/LOUtil.js
@@ -78,5 +78,12 @@ L.LOUtil = {
 			}
 		}
 		return rectangles;
+	},
+
+	/// oldFileName = Example.odt, suffix = new
+	/// returns: Example_new.odt
+	generateNewFileName: function(oldFileName, suffix) {
+		var idx = oldFileName.lastIndexOf('.');
+		return oldFileName.substring(0, idx) + suffix + oldFileName.substring(idx);
 	}
 };
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index e45ba55ac..9604131f3 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -435,21 +435,41 @@ L.Socket = L.Class.extend({
 					vex.close(id);
 				}
 
-				vex.dialog.confirm({
-					message: _('Document has been changed in storage. Do you want to discard your changes, and load the document from the storage?'),
+				vex.dialog.open({
+					message: _('Document has been changed in storage. What would you like to do with your unsaved changes?'),
 					escapeButtonCloses: false,
 					overlayClosesOnClick: false,
+					contentCSS: { width: '700px' },
 					buttons: [
-						$.extend({}, vex.dialog.buttons.YES, { text: _('Discard changes') }),
-						$.extend({}, vex.dialog.buttons.NO, { text: _('Overwrite document') })
+						$.extend({}, vex.dialog.buttons.YES, { text: _('Discard'),
+						                                      click: function($vexContent) {
+							                                      $vexContent.data().vex.value = 'discard';
+							                                      vex.close($vexContent.data().vex.id);
+						                                      }}),
+						$.extend({}, vex.dialog.buttons.YES, { text: _('Overwrite'),
+						                                      click: function($vexContent) {
+							                                      $vexContent.data().vex.value = 'overwrite';
+							                                      vex.close($vexContent.data().vex.id);
+						                                      }}),
+						$.extend({}, vex.dialog.buttons.YES, { text: _('Save to new file'),
+						                                      click: function($vexContent) {
+							                                      $vexContent.data().vex.value = 'saveas';
+							                                      vex.close($vexContent.data().vex.id);
+						                                      }})
 					],
 					callback: L.bind(function(value) {
-						if (value) {
+						if (value === 'discard') {
 							// They want to refresh the page and load document again for all
 							this.sendMessage('closedocument');
-						} else {
+						} else if (value === 'overwrite') {
 							// They want to overwrite
 							this.sendMessage('savetostorage force=1');
+						} else if (value === 'saveas') {
+							var filename = this._map['wopi'].BaseFileName;
+							if (filename) {
+								filename = L.LOUtil.generateNewFileName(filename, '_new');
+								this._map.saveAs(filename);
+							}
 						}
 					}, this)
 				});
commit 49bc55e2a716288fb45f98af4f3c2644b5bfec5d
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Mar 30 18:54:44 2018 +0530

    loleaflet: Don't close dialog on just getting the focus
    
    User should explicitly click on individual buttons to be able to close
    the dialog.
    
    Change-Id: Ie78e057a92677c392fd97c637248c1da5597ad84

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 536774041..e45ba55ac 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -437,6 +437,8 @@ L.Socket = L.Class.extend({
 
 				vex.dialog.confirm({
 					message: _('Document has been changed in storage. Do you want to discard your changes, and load the document from the storage?'),
+					escapeButtonCloses: false,
+					overlayClosesOnClick: false,
 					buttons: [
 						$.extend({}, vex.dialog.buttons.YES, { text: _('Discard changes') }),
 						$.extend({}, vex.dialog.buttons.NO, { text: _('Overwrite document') })
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index b513b8138..36f1175a9 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -849,7 +849,7 @@ L.Map = L.Evented.extend({
 
 	_activate: function () {
 		if (this._serverRecycling || this._documentIdle) {
-			return;
+			return false;
 		}
 
 		console.debug('_activate:');
@@ -864,8 +864,14 @@ L.Map = L.Evented.extend({
 				if (this._docLayer) {
 					this._docLayer._onMessage('invalidatetiles: EMPTY', null);
 				}
+
 				if (vex.dialogID > 0) {
 					var id = vex.dialogID;
+
+					var options = vex.getVexByID(id).data().vex;
+					if (!options.overlayClosesOnClick || !options.escapeButtonCloses)
+						return false;
+
 					vex.dialogID = -1;
 					this._startInactiveTimer();
 					this.focus();


More information about the Libreoffice-commits mailing list