sw/qa/uitest/navigator/tdf134960.py | 8 ++- sw/qa/uitest/navigator/tdf137274.py | 10 +++- sw/qa/uitest/navigator/tdf140661.py | 8 ++- sw/qa/uitest/navigator/tdf144672.py | 10 +++- sw/qa/uitest/navigator/tdf148198.py | 10 +++- sw/qa/uitest/navigator/tdf149268.py | 8 ++- sw/qa/uitest/navigator/tdf149916.py | 8 ++- sw/qa/uitest/navigator/tdf154521.py | 90 ++++++++++++++++++++++++++++++++++++ sw/qa/uitest/navigator/tdf40427.py | 8 ++- sw/source/uibase/utlui/content.cxx | 2 10 files changed, 151 insertions(+), 11 deletions(-)
New commits: commit b2d8fca2e177931ab00f7ee7e33463aefbaf9a91 Author: László Németh <nem...@numbertext.org> AuthorDate: Fri Mar 31 19:08:50 2023 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Sun Apr 2 22:59:16 2023 +0200 tdf#154521 sw Navigator: fix selection change event of bookmark In Navigator, double click or enter on a bookmark name selects the bookmark in the text, but the triggered selectionChanged event didn't give access to the actual selection, but only to the start of the previous one. Note: newly enabled Navigator tree item "Bookmarks" is not stateless on some test platform, so adjust unit tests according to the (now) unknown index of the requested tree items. Change-Id: Iade4ea40c524a1eb14737669bb3d21f22b556c76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149895 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 117b1fcdf94eb7959240c09c544cb6754d8c7b44) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149880 Tested-by: László Németh <nem...@numbertext.org> diff --git a/sw/qa/uitest/navigator/tdf134960.py b/sw/qa/uitest/navigator/tdf134960.py index db864d2d5b18..8388b63e40f9 100644 --- a/sw/qa/uitest/navigator/tdf134960.py +++ b/sw/qa/uitest/navigator/tdf134960.py @@ -12,6 +12,12 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf134960_hyperlinks(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def launch_sidebar(self, xWriterEdit): self.xUITest.executeCommand(".uno:Sidebar") @@ -22,7 +28,7 @@ class tdf134960_hyperlinks(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild("contenttree") - xHyperlinks = xContentTree.getChild('7') + xHyperlinks = self.get_item(xContentTree, 'Hyperlinks') self.assertEqual('Hyperlinks', get_state_as_dict(xHyperlinks)['Text']) xHyperlinks.executeAction("EXPAND", tuple()) diff --git a/sw/qa/uitest/navigator/tdf137274.py b/sw/qa/uitest/navigator/tdf137274.py index a25f449abe9b..5192045b8264 100644 --- a/sw/qa/uitest/navigator/tdf137274.py +++ b/sw/qa/uitest/navigator/tdf137274.py @@ -12,6 +12,12 @@ from uitest.uihelper.common import get_state_as_dict class tdf137274(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def test_tdf137274(self): with self.ui_test.create_doc_in_start_center("writer"): @@ -36,7 +42,7 @@ class tdf137274(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild("contenttree") - xComments = xContentTree.getChild('10') + xComments = self.get_item(xContentTree, 'Comments') self.assertEqual('Comments', get_state_as_dict(xComments)['Text']) xComments.executeAction("EXPAND", tuple()) @@ -53,7 +59,7 @@ class tdf137274(UITestCase): self.ui_test.wait_until_child_is_available('Comment2') # xComments needs reassigned after content tree change - xComments = xContentTree.getChild('10') + xComments = self.get_item(xContentTree, 'Comments') self.assertEqual('Comments', get_state_as_dict(xComments)['Text']) xComments.executeAction("EXPAND", tuple()) diff --git a/sw/qa/uitest/navigator/tdf140661.py b/sw/qa/uitest/navigator/tdf140661.py index da585a9ebc9b..c3689f51cf66 100644 --- a/sw/qa/uitest/navigator/tdf140661.py +++ b/sw/qa/uitest/navigator/tdf140661.py @@ -12,6 +12,12 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf140661(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def launch_navigator(self, bIsBeforeUngroup): xMainWindow = self.xUITest.getTopFocusWindow() xWriterEdit = xMainWindow.getChild("writer_edit") @@ -24,7 +30,7 @@ class tdf140661(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild("contenttree") - xDrawings = xContentTree.getChild('11') + xDrawings = self.get_item(xContentTree, 'Drawing objects') self.assertEqual('Drawing objects', get_state_as_dict(xDrawings)['Text']) xDrawings.executeAction("EXPAND", tuple()) diff --git a/sw/qa/uitest/navigator/tdf144672.py b/sw/qa/uitest/navigator/tdf144672.py index fdef04ca37dc..4bded66dcb08 100644 --- a/sw/qa/uitest/navigator/tdf144672.py +++ b/sw/qa/uitest/navigator/tdf144672.py @@ -13,6 +13,12 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf144672(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def test_Tdf144672(self): with self.ui_test.load_file(get_url_for_data_file("tdf144672.odt")): @@ -28,14 +34,14 @@ class tdf144672(UITestCase): xContentTree = xNavigatorPanel.getChild("contenttree") - xReferences = xContentTree.getChild('8') + xReferences = self.get_item(xContentTree, 'References') self.assertEqual('References', get_state_as_dict(xReferences)['Text']) # tdf#129625: Without the fix in place, this test would have failed with # AssertionError: 'true' != 'false' self.assertEqual('true', get_state_as_dict(xReferences)['IsSemiTransparent']) - xIndexes = xContentTree.getChild('9') + xIndexes = self.get_item(xContentTree, 'Indexes') self.assertEqual('Indexes', get_state_as_dict(xIndexes)['Text']) self.assertEqual('false', get_state_as_dict(xIndexes)['IsSemiTransparent']) diff --git a/sw/qa/uitest/navigator/tdf148198.py b/sw/qa/uitest/navigator/tdf148198.py index d273bb6b5e2b..3e7b00e7d5e0 100644 --- a/sw/qa/uitest/navigator/tdf148198.py +++ b/sw/qa/uitest/navigator/tdf148198.py @@ -13,6 +13,12 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf148198(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def test_tdf148198(self): sHyperlink0 = 'a hyperlink with an anchor, different character styles, a footnote1, a field This is a bookmark, and a rsid' sHyperlink1 = 'another hyperlink' @@ -28,7 +34,7 @@ class tdf148198(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild('contenttree') - xHyperlinks = xContentTree.getChild('7') + xHyperlinks = self.get_item(xContentTree, 'Hyperlinks') self.assertEqual('Hyperlinks', get_state_as_dict(xHyperlinks)['Text']) xHyperlinks.executeAction('EXPAND', tuple()) @@ -45,7 +51,7 @@ class tdf148198(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild('contenttree') - xHyperlinks = xContentTree.getChild('7') + xHyperlinks = self.get_item(xContentTree, 'Hyperlinks') self.assertEqual('Hyperlinks', get_state_as_dict(xHyperlinks)['Text']) xHyperlinks.executeAction('EXPAND', tuple()) diff --git a/sw/qa/uitest/navigator/tdf149268.py b/sw/qa/uitest/navigator/tdf149268.py index 3a0943c76fed..38b42c376e96 100644 --- a/sw/qa/uitest/navigator/tdf149268.py +++ b/sw/qa/uitest/navigator/tdf149268.py @@ -13,6 +13,12 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf149268(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def test_tdf149268(self): with self.ui_test.load_file(get_url_for_data_file("tdf149268.odt")): xWriterDoc = self.xUITest.getTopFocusWindow() @@ -27,7 +33,7 @@ class tdf149268(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild("contenttree") - xHyperlinks = xContentTree.getChild('7') + xHyperlinks = self.get_item(xContentTree, 'Hyperlinks') self.assertEqual('Hyperlinks', get_state_as_dict(xHyperlinks)['Text']) xHyperlinks.executeAction("EXPAND", tuple()) diff --git a/sw/qa/uitest/navigator/tdf149916.py b/sw/qa/uitest/navigator/tdf149916.py index 176bdb4d0b57..cce7b8a12284 100644 --- a/sw/qa/uitest/navigator/tdf149916.py +++ b/sw/qa/uitest/navigator/tdf149916.py @@ -13,6 +13,12 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf149916(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def test_tdf149916(self): with self.ui_test.load_file(get_url_for_data_file('tdf149916.odt')): @@ -26,7 +32,7 @@ class tdf149916(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild('contenttree') - xFields = xContentTree.getChild('12') + xFields = self.get_item(xContentTree, 'Fields') self.assertEqual('Fields', get_state_as_dict(xFields)['Text']) xFields.executeAction('EXPAND', tuple()) diff --git a/sw/qa/uitest/navigator/tdf154521.py b/sw/qa/uitest/navigator/tdf154521.py new file mode 100644 index 000000000000..0dca50379fab --- /dev/null +++ b/sw/qa/uitest/navigator/tdf154521.py @@ -0,0 +1,90 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from uitest.framework import UITestCase +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict +from com.sun.star.view import XSelectionChangeListener +import unohelper + +selectionChangedResult = 0 + +class XSelectionChangeListenerExtended(unohelper.Base, XSelectionChangeListener): + # is invoked when a text selected, e.g. by selecting a bookmark in the Navigator + @classmethod + def selectionChanged(self, event): + global selectionChangedResult + selection = event.Source.getSelection() + if selection.supportsService("com.sun.star.text.TextRanges"): + textRange = selection.getByIndex(0) + if textRange.getString() == "foo": + selectionChangedResult = 1 + else: + selectionChangedResult = -1 + + @classmethod + def disposing(self, event): + pass + +class tdf154521(UITestCase): + + def test_tdf154521(self): + global selectionChangedResult + with self.ui_test.create_doc_in_start_center("writer") as xDoc: + + # type "foo", and create a bookmark on it + + self.xUITest.executeCommand(".uno:Escape") + + # click on the bookmark name in the Navigator + + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + + self.xUITest.executeCommand(".uno:Sidebar") + xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"})) + + xNavigatorPanel = xWriterEdit.getChild("NavigatorPanel") + xToolBar = xNavigatorPanel.getChild("content5") + xToolBar.executeAction("CLICK", mkPropertyValues({"POS": "0"})) # 'root' button + + xDoc.Text.insertString(xDoc.Text.getStart(), "foo", False) + self.xUITest.executeCommand(".uno:SelectAll") + + with self.ui_test.execute_dialog_through_command(".uno:InsertBookmark", close_button="insert"): + pass + + xWriterEdit.executeAction("FOCUS", tuple()) + + # add XSelectionChangeListener + + xListener = XSelectionChangeListenerExtended() + self.assertIsNotNone(xListener) + xDoc.CurrentController.addSelectionChangeListener(xListener) + + xContentTree = xNavigatorPanel.getChild("contenttree") + + self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 1") + self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 1") + self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1") + + # select bookmark to trigger selectionChanged event + + xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + + # wait for handling the selectionChanged event + while selectionChangedResult == 0: + pass + + # This was -1 (missing selection because of early broadcasting) + self.assertEqual(selectionChangedResult, 1) + + self.xUITest.executeCommand(".uno:Sidebar") + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/qa/uitest/navigator/tdf40427.py b/sw/qa/uitest/navigator/tdf40427.py index 3192dc71d2c1..f394bf37aa06 100644 --- a/sw/qa/uitest/navigator/tdf40427.py +++ b/sw/qa/uitest/navigator/tdf40427.py @@ -13,6 +13,12 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf40427(UITestCase): + def get_item(self, xTree, name): + for i in xTree.getChildren(): + xItem = xTree.getChild(i) + if name == get_state_as_dict(xItem)['Text']: + return xItem + def test_tdf40427(self): with self.ui_test.load_file(get_url_for_data_file("tdf40427_SectionPositions.odt")) as document: xMainWindow = self.xUITest.getTopFocusWindow() @@ -44,7 +50,7 @@ class tdf40427(UITestCase): xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') xContentTree = xNavigatorPanel.getChild("contenttree") - xSections = xContentTree.getChild('6') + xSections = self.get_item(xContentTree, 'Sections') self.assertEqual('Sections', get_state_as_dict(xSections)['Text']) xSections.executeAction("EXPAND", ()) diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index 1f49c3a8dbfd..7f8b0ff200d6 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -5316,7 +5316,9 @@ void SwContentTree::GotoContent(const SwContent* pCnt) break; case ContentTypeId::BOOKMARK: { + m_pActiveShell->StartAction(); m_pActiveShell->GotoMark(pCnt->GetName()); + m_pActiveShell->EndAction(); } break; case ContentTypeId::REGION :