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

Dennis Francis (via logerrit) logerrit at kemper.freedesktop.org
Mon Feb 10 11:01:15 UTC 2020


 loleaflet/src/control/Control.Toolbar.js     |   31 ++++++++++++++++++++++-----
 loleaflet/src/layer/tile/ImpressTileLayer.js |    9 +++++--
 loleaflet/src/layer/tile/WriterTileLayer.js  |   12 +++++++---
 3 files changed, 41 insertions(+), 11 deletions(-)

New commits:
commit 1054dce67bf134f301aa2d3305f3aed3a99fb6fe
Author:     Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Thu Jan 30 19:00:37 2020 +0530
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Mon Feb 10 12:00:56 2020 +0100

    Adapt align commands based on selection type
    
    Use map._clip._selectionType to decide what align command to send
    when one clicks on one of the toolbar align buttons. selectionType
    is either 'text' or 'complex'; 'complex' by definition is set for
    non-text selections like images and charts.
    
    What is to be done next ?
    
    1. Need to setup statechange: messages from core.git for
    .uno:ObjectAlignLeft, .uno:AlignCenter, .uno:ObjectAlignRight
    from sw/ sd/ in Get*State() methods of the relevant shells. After
    this we need to make online toolbar align buttons to react to the
    correct statechange messages based on selectionType.
    
    2. _selectionType is not always correct. In Impress it
    is always 'text' regardless of selection type. In Writer, for
    shape selection, it is set to 'text'. SelectionType comes from
    XTransferable2::isComplex(). Its implementations in sw/ and sd/
    in core.git need fixing.
    
    PS: In Calc, aligning images/objects does not make sense w.r.t to the
    sheet in general. The align buttons are disabled in core-desktop
    when an image is selected.
    
    Change-Id: I8223cd03f864fa92523224bf88ccb992edfc2686
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/87739
    Tested-by: Jan Holesovsky <kendy at collabora.com>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js
index 80c4bd57f..6c718af9b 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -103,6 +103,21 @@ function _cancelSearch() {
 	map._onGotFocus();
 }
 
+function getUNOCommand(unoData) {
+	if (typeof unoData !== 'object')
+		return unoData;
+
+	if (!map._clip)
+		return unoData.textCommand;
+
+	var selectionType = map._clip._selectionType;
+
+	if (!selectionType || selectionType === 'text')
+		return unoData.textCommand;
+
+	return unoData.objectCommand;
+}
+
 function onClick(e, id, item, subItem) {
 	if (w2ui['editbar'].get(id) !== null) {
 		var toolbar = w2ui['editbar'];
@@ -152,7 +167,7 @@ function onClick(e, id, item, subItem) {
 			map.toggleCommandState(item.unosheet);
 		}
 		else {
-			map.toggleCommandState(item.uno);
+			map.toggleCommandState(getUNOCommand(item.uno));
 		}
 	}
 	else if (id === 'print') {
@@ -884,9 +899,15 @@ function initNormalToolbar() {
 		{type: 'color',  id: 'backcolor', img: 'backcolor', hint: _UNO('.uno:BackColor', 'text'), hidden: true},
 		{type: 'color',  id: 'backgroundcolor', img: 'backgroundcolor', hint: _UNO('.uno:BackgroundColor'), hidden: true},
 		{type: 'break' , id: 'breakcolor', mobile:false},
-		{type: 'button',  id: 'leftpara',  img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true), uno: 'LeftPara', hidden: true, unosheet: 'AlignLeft', disabled: true},
-		{type: 'button',  id: 'centerpara',  img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true), uno: 'CenterPara', hidden: true, unosheet: 'AlignHorizontalCenter', disabled: true},
-		{type: 'button',  id: 'rightpara',  img: 'alignright', hint: _UNO('.uno:RightPara', '', true), uno: 'RightPara', hidden: true, unosheet: 'AlignRight', disabled: true},
+		{type: 'button',  id: 'leftpara',  img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true),
+			uno: {textCommand: 'LeftPara', objectCommand: 'ObjectAlignLeft'},
+			hidden: true, unosheet: 'AlignLeft', disabled: true},
+		{type: 'button',  id: 'centerpara',  img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true),
+			uno: {textCommand: 'CenterPara', objectCommand: 'AlignCenter'},
+			hidden: true, unosheet: 'AlignHorizontalCenter', disabled: true},
+		{type: 'button',  id: 'rightpara',  img: 'alignright', hint: _UNO('.uno:RightPara', '', true),
+			uno: {textCommand: 'RightPara', objectCommand: 'ObjectAlignRight'},
+			hidden: true, unosheet: 'AlignRight', disabled: true},
 		{type: 'button',  id: 'justifypara',  img: 'alignblock', hint: _UNO('.uno:JustifyPara', '', true), uno: 'JustifyPara', hidden: true, unosheet: '', disabled: true},
 		{type: 'break', id: 'breakpara', hidden: true},
 		{type: 'drop',  id: 'setborderstyle',  img: 'setborderstyle', hint: _('Borders'), hidden: true,
@@ -2216,7 +2237,7 @@ function onUpdatePermission(e) {
 			var alwaysEnable = found.length !== 0;
 
 			if (e.perm === 'edit') {
-				var unoCmd = map.getDocType() === 'spreadsheet' ? items[idx].unosheet : items[idx].uno;
+				var unoCmd = map.getDocType() === 'spreadsheet' ? items[idx].unosheet : getUNOCommand(items[idx].uno);
 				var keepDisabled = map['stateChangeHandler'].getItemValue(unoCmd) === 'disabled';
 				if (!keepDisabled || alwaysEnable) {
 					toolbar.enable(items[idx].id);
diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js b/loleaflet/src/layer/tile/ImpressTileLayer.js
index ae3d65646..568796e47 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -124,9 +124,12 @@ L.ImpressTileLayer = L.TileLayer.extend({
 			{type: 'button',  id: 'fontcolor', img: 'textcolor', hint: _UNO('.uno:FontColor')},
 			{type: 'button',  id: 'backcolor', img: 'backcolor', hint: _UNO('.uno:BackgroundColor')},
 			{type: 'break'},
-			{type: 'button', id: 'leftpara', img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true), uno: 'LeftPara'},
-			{type: 'button', id: 'centerpara', img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true), uno: 'CenterPara'},
-			{type: 'button', id: 'rightpara', img: 'alignright', hint: _UNO('.uno:RigthPara', '', true), uno: 'RightPara'},
+			{type: 'button', id: 'leftpara', img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true),
+				uno: {textCommand: 'LeftPara', objectCommand: 'ObjectAlignLeft'}},
+			{type: 'button', id: 'centerpara', img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true),
+				uno: {textCommand: 'CenterPara', objectCommand: 'AlignCenter'}},
+			{type: 'button', id: 'rightpara', img: 'alignright', hint: _UNO('.uno:RigthPara', '', true),
+				uno: {textCommand: 'RightPara', objectCommand: 'ObjectAlignRight'}},
 			{type: 'button', id: 'justifypara', img: 'alignblock', hint: _UNO('.uno:JustifyPara', '', true), uno: 'JustifyPara'},
 			{type: 'break'},
 			{type: 'button',  id: 'defaultbullet',  img: 'bullet', hint: _UNO('.uno:DefaultBullet', '', true), uno: 'DefaultBullet', disabled: true},
diff --git a/loleaflet/src/layer/tile/WriterTileLayer.js b/loleaflet/src/layer/tile/WriterTileLayer.js
index 526e7a0af..846516022 100644
--- a/loleaflet/src/layer/tile/WriterTileLayer.js
+++ b/loleaflet/src/layer/tile/WriterTileLayer.js
@@ -62,9 +62,15 @@ L.WriterTileLayer = L.TileLayer.extend({
 			{type: 'break'},
 			{type: 'button',  id: 'fontcolor', img: 'textcolor', hint: _UNO('.uno:FontColor')},
 			{type: 'button',  id: 'backcolor', img: 'backcolor', hint: _UNO('.uno:BackgroundColor')},
-			{type: 'button',  id: 'leftpara',  img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true), uno: 'LeftPara', unosheet: 'AlignLeft', disabled: true},
-			{type: 'button',  id: 'centerpara',  img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true), uno: 'CenterPara', unosheet: 'AlignHorizontalCenter', disabled: true},
-			{type: 'button',  id: 'rightpara',  img: 'alignright', hint: _UNO('.uno:RightPara', '', true), uno: 'RightPara', unosheet: 'AlignRight', disabled: true},
+			{type: 'button',  id: 'leftpara',  img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true),
+				uno: {textCommand: 'LeftPara', objectCommand: 'ObjectAlignLeft'},
+				unosheet: 'AlignLeft', disabled: true},
+			{type: 'button',  id: 'centerpara',  img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true),
+				uno: {textCommand: 'CenterPara', objectCommand: 'AlignCenter'},
+				unosheet: 'AlignHorizontalCenter', disabled: true},
+			{type: 'button',  id: 'rightpara',  img: 'alignright', hint: _UNO('.uno:RightPara', '', true),
+				uno: {textCommand: 'RightPara', objectCommand: 'ObjectAlignRight'},
+				unosheet: 'AlignRight', disabled: true},
 			{type: 'button',  id: 'justifypara',  img: 'alignblock', hint: _UNO('.uno:JustifyPara', '', true), uno: 'JustifyPara', unosheet: '', disabled: true},
 			{type: 'break', id: 'breakspacing'},
 			{type: 'button',  id: 'defaultnumbering',  img: 'numbering', hint: _UNO('.uno:DefaultNumbering', '', true),uno: 'DefaultNumbering', disabled: true},


More information about the Libreoffice-commits mailing list