sw/qa/uitest/data/tdf95495.docx |binary sw/qa/uitest/writer_tests2/bookmark.py | 31 ++++++++++++++++++++++++++++++- sw/source/ui/misc/bookmark.cxx | 17 +++++++++++++---- 3 files changed, 43 insertions(+), 5 deletions(-)
New commits: commit cb1f95e7e5781797a0f4485d4a835faff4a8cd8f Author: László Németh <nem...@numbertext.org> AuthorDate: Fri Sep 16 16:48:26 2022 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Mon Sep 19 09:57:25 2022 +0200 tdf#150955 sw InsertBookmark: add hidden status to hidden MSO fields In Insert -> Bookmark... dialog window, add hidden status to _Toc and _Ref hidden DOCX bookmarks to allow separating them from user-defined bookmarks using sorting. (In MSO, there is a checkbox to enable visibility of these hidden bookmarks in Insert bookmark dialog.) Note: UX field Hidden was only used for a lo:ext OpenDocument feature (with UNO-only creation of bookmarks with hidden anchor), see tdf#101856. This UX field was re-used for better handling of DOCX import of hidden (not user-defined) bookmarks created by MSO. Follow-up to fix for tdf#150956 in commit 5e71ec6aa0d4f9971f5e2b6f7091d18668c2f0b9 "tdf#150790 tdf#150791 tdf#150947 tdf#150956 sw, a11y: fix visible bookmarks". Change-Id: I52e9f2c0b65e62c14ac24138235f07fb213da737 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140079 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/qa/uitest/data/tdf95495.docx b/sw/qa/uitest/data/tdf95495.docx new file mode 100644 index 000000000000..21f534b11223 Binary files /dev/null and b/sw/qa/uitest/data/tdf95495.docx differ diff --git a/sw/qa/uitest/writer_tests2/bookmark.py b/sw/qa/uitest/writer_tests2/bookmark.py index 8eaf8e323e31..f9d75434ffcf 100644 --- a/sw/qa/uitest/writer_tests2/bookmark.py +++ b/sw/qa/uitest/writer_tests2/bookmark.py @@ -8,7 +8,7 @@ # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, type_text +from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, type_text from libreoffice.uno.propertyvalue import mkPropertyValues #test bookmark dialog class bookmarkDialog(UITestCase): @@ -121,4 +121,33 @@ class bookmarkDialog(UITestCase): self.assertEqual(xDoc.Text.String, "fubar") self.assertEqual(get_state_as_dict(x1stListEntry)["Text"], "1\tBookmark 1\tfubar\tNo\t") + def test_bookmark_dialog_hidden_from_DOCX_import(self): + with self.ui_test.load_file(get_url_for_data_file("tdf95495.docx")) as XDoc: + + # check Hidden field of the imported hidden bookmarks + with self.ui_test.execute_dialog_through_command(".uno:InsertBookmark", close_button="close") as xBookDlg: + xBmk = xBookDlg.getChild("bookmarks") + xFirstListEntry = xBmk.getChild("0") # select first bookmark + + # _Toc bookmark had Hidden == "No" + self.assertEqual(get_state_as_dict(xFirstListEntry)["Text"], "1\t_Toc448303248\t A. Comment-Based Help A.1 Introduction…\tYes\t") + + xSecondListEntry = xBmk.getChild("1") # select second bookmark + + # _Rec bookmark had Hidden == "No" + self.assertEqual(get_state_as_dict(xSecondListEntry)["Text"], "1\t_Ref463365573\t A. Comment-Based Help A.1 Introduction…\tYes\t") + + # insert a new bookmark with the default name + with self.ui_test.execute_dialog_through_command(".uno:InsertBookmark", close_button="insert"): + pass + + # check Hidden field of the newly inserted bookmark + with self.ui_test.execute_dialog_through_command(".uno:InsertBookmark", close_button="close") as xBookDlg: + xBmk = xBookDlg.getChild("bookmarks") + xFirstListEntry = xBmk.getChild("0") # select first bookmark + xFirstListEntry.executeAction("SELECT", tuple()) + + # Newly inserted bookmarks get Hidden = "No" + self.assertEqual(get_state_as_dict(xFirstListEntry)["Text"], "1\tBookmark 1\t\tNo\t") + # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/source/ui/misc/bookmark.cxx b/sw/source/ui/misc/bookmark.cxx index 363b861653a4..e68a612dc09d 100644 --- a/sw/source/ui/misc/bookmark.cxx +++ b/sw/source/ui/misc/bookmark.cxx @@ -517,13 +517,22 @@ void BookmarkTable::InsertBookmark(SwWrtShell& rSh, sw::mark::IMark* const pMark } const OUString& sHideCondition = pBookmark->GetHideCondition(); - OUString sHidden = SwResId(STR_BOOKMARK_NO); - if (pBookmark->IsHidden() || !sHideCondition.isEmpty()) - sHidden = SwResId(STR_BOOKMARK_YES); + const OUString& sName = pBookmark->GetName(); + OUString sHidden + = (pBookmark->IsHidden() || !sHideCondition.isEmpty() || + // tdf#150955 add "hidden" status to the imported OOXML _Toc and _Ref bookmarks + // to allow separating custom bookmarks by sorting based on their Hidden status. + // Note: this "hidden" means here only that these bookmarks haven't got + // visible bookmark formatting aids (gray I-shape or brackets), otherwise + // their anchor are still visible. + sName.startsWith("_Toc") || sName.startsWith("_Ref")) + ? SwResId(STR_BOOKMARK_YES) + : SwResId(STR_BOOKMARK_NO); + OUString sPageNum = OUString::number(SwPaM(pMark->GetMarkStart()).GetPageNum()); int nRow = m_xControl->n_children(); m_xControl->append(weld::toId(pMark), sPageNum); - m_xControl->set_text(nRow, pBookmark->GetName(), 1); + m_xControl->set_text(nRow, sName, 1); m_xControl->set_text(nRow, sBookmarkNodeText, 2); m_xControl->set_text(nRow, sHidden, 3); m_xControl->set_text(nRow, sHideCondition, 4);