summaryrefslogtreecommitdiff
path: root/sw/qa/uitest/styleInspector
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2021-05-23 12:46:09 +0200
committerLászló Németh <nemeth@numbertext.org>2021-05-23 18:51:58 +0200
commita8a9b4f4635bff3f1b7ec63b62f661bc15196cd6 (patch)
tree03b0f7ce90c36b5fce9e73015f5c951cc936e444 /sw/qa/uitest/styleInspector
parenta04ac0ecea9468cedea3bba85fb65cad5f911a2a (diff)
tdf#142448 sw offapi: add custom color metadata field shading
using the new com::sun::star::rdf::URIs::LO_EXT_SHADING URI (modelled after odf:prefix and odf:suffix). Custom color field shading of text:meta annotated text ranges and text:meta-field metadata fields allows quick visual check of metadata categories. For example, RDF triple content.xml#id1753384014 urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading FF0000 sets red (FF0000) shading color for the text span with xml:id="id1753384014". Pressing Ctrl-F8 or View->Field Shadings can disable custom color metadata field shading on the UI. Note: neither LO_EXT_SHADING, nor odf:prefix and odf:suffix changes invalidate the View (MetaPortion), but run-time update of shading color can be triggered without save and reload of the document e.g. by using (temporary) bookmarks on the annotated text spans. To run unit test with enabled visibility, use (cd sw && make UITest_sw_styleInspector UITEST_TEST_NAME="styleInspector.styleNavigator.test_metadata_shading_color" SAL_USE_VCLPLUGIN=gen) in Linux command line. Change-Id: I5de93cfa32ac6793d7dbdc7b64e6f4beacb2e8d7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116015 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/qa/uitest/styleInspector')
-rw-r--r--sw/qa/uitest/styleInspector/styleInspector.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/sw/qa/uitest/styleInspector/styleInspector.py b/sw/qa/uitest/styleInspector/styleInspector.py
index 6afc4483e911..9c4abaf7191f 100644
--- a/sw/qa/uitest/styleInspector/styleInspector.py
+++ b/sw/qa/uitest/styleInspector/styleInspector.py
@@ -7,6 +7,7 @@
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
from libreoffice.uno.propertyvalue import mkPropertyValues
+from com.sun.star.rdf.URIs import RDF_TYPE, RDFS_COMMENT, RDFS_LABEL, ODF_PREFIX, ODF_SUFFIX, LO_EXT_SHADING
class styleNavigator(UITestCase):
@@ -246,4 +247,110 @@ class styleNavigator(UITestCase):
self.xUITest.executeCommand(".uno:Sidebar")
self.ui_test.close_doc()
+ def test_metadata_shading_color(self):
+ writer_doc = self.ui_test.load_file(get_url_for_data_file("metacolor.odt"))
+ xWriterDoc = self.xUITest.getTopFocusWindow()
+ xWriterEdit = xWriterDoc.getChild("writer_edit")
+
+ self.xUITest.executeCommand(".uno:Sidebar")
+ xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "InspectorTextPanel"}))
+
+ xListBox = xWriterEdit.getChild('listbox_fonts')
+
+ # The cursor is on text without metadata
+ self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
+ self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
+ self.assertEqual(136, len(xListBox.getChild('0').getChild('0').getChildren()))
+ self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
+ self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
+
+ # go to next word with RDF annotation
+ self.xUITest.executeCommand(".uno:GoToNextWord")
+ self.xUITest.executeCommand(".uno:GoRight")
+
+ # FIXME jump over the control character (not visible in getString(), but it affects
+ # cursor position and availability of NestedTextContent)
+ self.xUITest.executeCommand(".uno:GoRight")
+
+ # The cursor is on text with annotated text range
+ xDirFormatting = xListBox.getChild('3')
+ self.assertEqual(2, len(xDirFormatting.getChildren()))
+ self.assertEqual("Metadata Reference\t", get_state_as_dict(xDirFormatting.getChild('0'))['Text'])
+ self.assertEqual("Nested Text Content\tipsum", get_state_as_dict(xDirFormatting.getChild('1'))['Text'])
+
+ xMetadata = xDirFormatting.getChild('0')
+ self.assertEqual(2, len(xMetadata.getChildren()))
+ self.assertEqual("xml:id\tID-f1a8a096-7a43-4bda-a462-d73c2800dd9a", get_state_as_dict(xMetadata.getChild('0'))['Text'])
+ # RGB code of the custom shading color of the annotated text range is FFB7E9
+ self.assertEqual("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading\tFFB7E9", get_state_as_dict(xMetadata.getChild('1'))['Text'])
+
+ self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
+ self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
+
+ # go to next word with RDF annotation
+ self.xUITest.executeCommand(".uno:GoToNextWord")
+ self.xUITest.executeCommand(".uno:GoToNextWord")
+ self.xUITest.executeCommand(".uno:GoToNextWord")
+ self.xUITest.executeCommand(".uno:GoRight")
+
+ # The cursor is on text with annotated text range
+ xDirFormatting = xListBox.getChild('3')
+ self.assertEqual(2, len(xDirFormatting.getChildren()))
+ self.assertEqual("Metadata Reference\t", get_state_as_dict(xDirFormatting.getChild('0'))['Text'])
+ self.assertEqual("Nested Text Content\tames", get_state_as_dict(xDirFormatting.getChild('1'))['Text'])
+
+ xMetadata = xDirFormatting.getChild('0')
+ print(get_state_as_dict(xMetadata))
+ self.assertEqual(2, len(xMetadata.getChildren()))
+ self.assertEqual("xml:id\tID-24478193-9630-4d03-8976-9e097c843a0b", get_state_as_dict(xMetadata.getChild('0'))['Text'])
+ # RGB code of the custom shading color of the annotated text range is 97E1E9 (the code can be lower case, see STRtoRGB)
+ self.assertEqual("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading\t97e1e9", get_state_as_dict(xMetadata.getChild('1'))['Text'])
+
+ self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
+ self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
+
+ # add a new annotated text range and check it in the Style Inspector
+ self.xUITest.executeCommand(".uno:GoToStartOfDoc")
+
+ # create annotated text range on "Lorem"
+ viewCursor = writer_doc.CurrentController.getViewCursor()
+ viewCursor.goRight(5, True)
+ rdf = writer_doc.createInstance("com.sun.star.text.InContentMetadata")
+ writer_doc.Text.insertTextContent(viewCursor, rdf, True)
+
+ # set its custom shading color using the new URI const LO_EXT_SHADING
+ repository = writer_doc.getRDFRepository()
+ # get metadata graph of file "custom.rdf" stored in the test document
+ xCustomGraph = [repository.getGraph(i) for i in repository.getGraphNames() if i.LocalName == "custom.rdf"]
+ self.assertEqual(1, len(xCustomGraph))
+
+ smgr = self.xContext.ServiceManager
+ xShadingURI = smgr.createInstance('com.sun.star.rdf.URI')
+ xShadingURI.initialize((LO_EXT_SHADING,))
+ xShadingColor = smgr.createInstance('com.sun.star.rdf.Literal')
+ xShadingColor.initialize(('BBFF88',))
+ xCustomGraph[0].addStatement(rdf, xShadingURI, xShadingColor)
+
+ # remove the selection
+ self.xUITest.executeCommand(".uno:GoLeft")
+
+ # FIXME: neither LO_EXT_SHADING, nor odf:prefix/odf:suffix changes update the View,
+ # so add a temporary bookmark to the text range to trigger the color change immediately
+ self.ui_test.execute_dialog_through_command(".uno:InsertBookmark")
+ xBookDlg = self.xUITest.getTopFocusWindow()
+ xInsertBtn = xBookDlg.getChild("insert")
+ xInsertBtn.executeAction("CLICK", tuple()) # first bookmark
+ self.xUITest.executeCommand(".uno:Undo")
+
+ xDirFormatting = xListBox.getChild('3')
+ xMetadata = xDirFormatting.getChild('0')
+ self.assertEqual(2, len(xMetadata.getChildren()))
+ # RGB code of the custom shading color of the annotated text range is BBFF88
+ self.assertEqual("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading\tBBFF88", get_state_as_dict(xMetadata.getChild('1'))['Text'])
+
+ self.xUITest.executeCommand(".uno:Sidebar")
+ self.ui_test.close_doc()
+
+
+
# vim: set shiftwidth=4 softtabstop=4 expandtab: