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

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 22 07:36:23 UTC 2020


 loleaflet/Makefile.am                              |    2 
 loleaflet/src/control/Control.DocumentNameInput.js |  109 +++++++++++++++++++++
 loleaflet/src/control/Control.Toolbar.js           |   88 ----------------
 loleaflet/src/control/Control.UIManager.js         |    1 
 4 files changed, 112 insertions(+), 88 deletions(-)

New commits:
commit 43f19fa57e8e8dbec9dd091d009f2dfec8f29759
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Mon Apr 20 13:55:35 2020 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Wed Apr 22 09:36:03 2020 +0200

    Move DocumentNameInput to separate file
    
    Change-Id: I20b5620269b46902a612d2b43346d3b02c3636cd
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92622
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index d38c7953a..517ca3e2b 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -279,6 +279,7 @@ LOLEAFLET_JS =\
 	src/control/Control.SigningBar.js \
 	src/control/Control.TopToolbar.js \
 	src/control/Control.UIManager.js \
+	src/control/Control.DocumentNameInput.js \
 	src/control/Control.Layers.js \
 	src/control/Search.js \
 	src/control/Permission.js \
@@ -546,6 +547,7 @@ pot:
 		src/control/Control.TopToolbar.js \
 		src/control/Control.UserList.js \
 		src/control/Control.UIManager.js \
+		src/control/Control.DocumentNameInput.js \
 		src/control/Ruler.js \
 		src/control/Signing.js \
 		src/control/Toolbar.js \
diff --git a/loleaflet/src/control/Control.DocumentNameInput.js b/loleaflet/src/control/Control.DocumentNameInput.js
new file mode 100644
index 000000000..3e2b20ec2
--- /dev/null
+++ b/loleaflet/src/control/Control.DocumentNameInput.js
@@ -0,0 +1,109 @@
+/* -*- js-indent-level: 8 -*- */
+/*
+ * L.Control.DocumentNameInput
+ */
+
+/* global $ */
+L.Control.DocumentNameInput = L.Control.extend({
+
+	onAdd: function (map) {
+		this.map = map;
+
+		map.on('doclayerinit', this.onDocLayerInit, this);
+		map.on('wopiprops', this.onWopiProps, this);
+	},
+
+	documentNameConfirm: function() {
+		var value = $('#document-name-input').val();
+		if (value !== null && value != '' && value != this.map['wopi'].BaseFileName) {
+			if (this.map['wopi'].UserCanRename && this.map['wopi'].SupportsRename) {
+				if (value.lastIndexOf('.') > 0) {
+					var fname = this.map['wopi'].BaseFileName;
+					var ext = fname.substr(fname.lastIndexOf('.')+1, fname.length);
+					// check format conversion
+					if (ext != value.substr(value.lastIndexOf('.')+1, value.length)) {
+						this.map.saveAs(value);
+					} else {
+						// same extension, just rename the file
+						// file name must be without the extension for rename
+						value = value.substr(0, value.lastIndexOf('.'));
+						this.map.sendUnoCommand('.uno:Save');
+						this.map._RenameFile = value;
+					}
+				}
+			} else {
+				// saveAs for rename
+				this.map.saveAs(value);
+			}
+		}
+		this.map._onGotFocus();
+	},
+
+	documentNameCancel: function() {
+		$('#document-name-input').val(this.map['wopi'].BaseFileName);
+		this.map._onGotFocus();
+	},
+
+	onDocumentNameKeyPress: function(e) {
+		$('#document-name-input').css('width',(($('#document-name-input').val().length + 1) * 10) + 'px');
+		if (e.keyCode === 13) { // Enter key
+			this.documentNameConfirm();
+		} else if (e.keyCode === 27) { // Escape key
+			this.documentNameCancel();
+		}
+	},
+	
+	onDocumentNameFocus: function() {
+		// hide the caret in the main document
+		this.map._onLostFocus();
+	},
+
+	onDocLayerInit: function() {
+		if (window.mode.isMobile() || window.mode.isTablet()) {
+			if (!window.ThisIsAMobileApp)
+				$('#document-name-input').hide();
+			else
+				$('#document-name-input').show();
+		} else {
+			$('#document-name-input').show();
+		}
+	
+		if (window.ThisIsAMobileApp) {
+			// We can now set the document name in the menu bar
+			$('#document-name-input').prop('disabled', false);
+			$('#document-name-input').removeClass('editable');
+			$('#document-name-input').focus(function() { $(this).blur(); });
+			// Call decodecodeURIComponent twice: Reverse both our encoding and the encoding of
+			// the name in the file system.
+			$('#document-name-input').val(decodeURIComponent(decodeURIComponent(this.map.options.doc.replace(/.*\//, '')))
+							  // To conveniently see the initial visualViewport scale and size, un-comment the following line.
+							  // + ' (' + window.visualViewport.scale + '*' + window.visualViewport.width + 'x' + window.visualViewport.height + ')'
+							  // TODO: Yes, it would be better to see it change as you rotate the device or invoke Split View.
+							 );
+		}
+	},
+
+	onWopiProps: function(e) {
+		if (e.BaseFileName !== null) {
+			// set the document name into the name field
+			$('#document-name-input').val(e.BaseFileName);
+		}
+	
+		if (e.UserCanNotWriteRelative === false) {
+			// Save As allowed
+			$('#document-name-input').prop('disabled', false);
+			$('#document-name-input').addClass('editable');
+			$('#document-name-input').off('keypress', this.onDocumentNameKeyPress).on('keypress', this.onDocumentNameKeyPress.bind(this));
+			$('#document-name-input').off('focus', this.onDocumentNameFocus).on('focus', this.onDocumentNameFocus.bind(this));
+			$('#document-name-input').off('blur', this.documentNameCancel).on('blur', this.documentNameCancel.bind(this));
+		} else {
+			$('#document-name-input').prop('disabled', true);
+			$('#document-name-input').removeClass('editable');
+			$('#document-name-input').off('keypress', this.onDocumentNameKeyPress);
+		}
+	}
+});
+
+L.control.documentNameInput = function () {
+	return new L.Control.DocumentNameInput();
+};
diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js
index a70d4d78e..021065f43 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -690,51 +690,6 @@ function onSearchBlur() {
 	map._onGotFocus();
 }
 
-function documentNameConfirm() {
-	var value = $('#document-name-input').val();
-	if (value !== null && value != '' && value != map['wopi'].BaseFileName) {
-		if (map['wopi'].UserCanRename && map['wopi'].SupportsRename) {
-			if (value.lastIndexOf('.') > 0) {
-				var fname = map['wopi'].BaseFileName;
-				var ext = fname.substr(fname.lastIndexOf('.')+1, fname.length);
-				// check format conversion
-				if (ext != value.substr(value.lastIndexOf('.')+1, value.length)) {
-					map.saveAs(value);
-				} else {
-					// same extension, just rename the file
-					// file name must be without the extension for rename
-					value = value.substr(0, value.lastIndexOf('.'));
-					map.sendUnoCommand('.uno:Save');
-					map._RenameFile = value;
-				}
-			}
-		} else {
-			// saveAs for rename
-			map.saveAs(value);
-		}
-	}
-	map._onGotFocus();
-}
-
-function documentNameCancel() {
-	$('#document-name-input').val(map['wopi'].BaseFileName);
-	map._onGotFocus();
-}
-
-function onDocumentNameKeyPress(e) {
-	$('#document-name-input').css('width',(($('#document-name-input').val().length + 1) * 10) + 'px');
-	if (e.keyCode === 13) { // Enter key
-		documentNameConfirm();
-	} else if (e.keyCode === 27) { // Escape key
-		documentNameCancel();
-	}
-}
-
-function onDocumentNameFocus() {
-	// hide the caret in the main document
-	map._onLostFocus();
-}
-
 function onInsertFile() {
 	var insertGraphic = L.DomUtil.get('insertgraphic');
 	if ('files' in insertGraphic) {
@@ -774,48 +729,6 @@ function onWopiProps(e) {
 			evt.preventDefault();
 		});
 	}
-	if (e.BaseFileName !== null) {
-		// set the document name into the name field
-		$('#document-name-input').val(e.BaseFileName);
-	}
-
-	if (e.UserCanNotWriteRelative === false) {
-		// Save As allowed
-		$('#document-name-input').prop('disabled', false);
-		$('#document-name-input').addClass('editable');
-		$('#document-name-input').off('keypress', onDocumentNameKeyPress).on('keypress', onDocumentNameKeyPress);
-		$('#document-name-input').off('focus', onDocumentNameFocus).on('focus', onDocumentNameFocus);
-		$('#document-name-input').off('blur', documentNameCancel).on('blur', documentNameCancel);
-	} else {
-		$('#document-name-input').prop('disabled', true);
-		$('#document-name-input').removeClass('editable');
-		$('#document-name-input').off('keypress', onDocumentNameKeyPress);
-	}
-}
-
-function onDocLayerInit() {
-	if (window.mode.isMobile() || window.mode.isTablet()) {
-		if (!window.ThisIsAMobileApp)
-			$('#document-name-input').hide();
-		else
-			$('#document-name-input').show();
-	} else {
-		$('#document-name-input').show();
-	}
-
-	if (window.ThisIsAMobileApp) {
-		// We can now set the document name in the menu bar
-		$('#document-name-input').prop('disabled', false);
-		$('#document-name-input').removeClass('editable');
-		$('#document-name-input').focus(function() { $(this).blur(); });
-		// Call decodecodeURIComponent twice: Reverse both our encoding and the encoding of
-		// the name in the file system.
-		$('#document-name-input').val(decodeURIComponent(decodeURIComponent(map.options.doc.replace(/.*\//, '')))
-					      // To conveniently see the initial visualViewport scale and size, un-comment the following line.
-					      // + ' (' + window.visualViewport.scale + '*' + window.visualViewport.width + 'x' + window.visualViewport.height + ')'
-					      // TODO: Yes, it would be better to see it change as you rotate the device or invoke Split View.
-					     );
-	}
 }
 
 function onCommandStateChanged(e) {
@@ -1101,7 +1014,6 @@ function setupToolbar(e) {
 		}
 	});
 
-	map.on('doclayerinit', onDocLayerInit);
 	map.on('updatepermission', onUpdatePermission);
 	map.on('wopiprops', onWopiProps);
 	map.on('commandresult', onCommandResult);
diff --git a/loleaflet/src/control/Control.UIManager.js b/loleaflet/src/control/Control.UIManager.js
index 8e4967481..f3cad662e 100644
--- a/loleaflet/src/control/Control.UIManager.js
+++ b/loleaflet/src/control/Control.UIManager.js
@@ -32,6 +32,7 @@ L.Control.UIManager = L.Control.extend({
 
 		setupToolbar(this.map);
 
+		this.map.addControl(L.control.documentNameInput());
 		this.map.addControl(L.control.scroll());
 		this.map.addControl(L.control.alertDialog());
 		this.map.addControl(L.control.mobileWizard());


More information about the Libreoffice-commits mailing list