summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2020-12-26 10:52:08 +0300
committerXisco Fauli <xiscofauli@libreoffice.org>2021-01-04 12:03:52 +0100
commit4f7d5b0ed8df89dec6cc2ae45be5885f5f4ebae6 (patch)
tree4854f3c1873a4fe27dfebd9dfd17c34c9d78080a
parent8971b4ca5db46720079dd3239c9465dcc2d42190 (diff)
tdf#138907 sw TitlePageDlg: fix round-tripping
This Format -> Title Pages dialog is completely broken, so I threw in lots of FIXME notes. At least for the case of just using the existing pages and setting them up as title/follow page, fix: 1.) the ability to round-trip page number restart if a numbering restart without a page style already existed. (Yes, this likely is an odd case of someone messing around. In any case, a page number restart REQUIRES a page style) make UITest_writer_tests5 UITEST_TEST_NAME=\ titlePageWizard.tdf138907.test_tdf138907 Change-Id: I544145e9f749f471b54fa6686242e93bc98f50be Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108322 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> (cherry picked from commit ccfd8e9d09f9ac0a0ea92d0f378391006faaf934) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108346 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sw/qa/uitest/data/tdf138907_titlePageDialog.odtbin0 -> 11320 bytes
-rw-r--r--sw/qa/uitest/writer_tests5/titlePageWizard.py73
-rw-r--r--sw/source/ui/misc/titlepage.cxx19
3 files changed, 84 insertions, 8 deletions
diff --git a/sw/qa/uitest/data/tdf138907_titlePageDialog.odt b/sw/qa/uitest/data/tdf138907_titlePageDialog.odt
new file mode 100644
index 000000000000..837e0d0132cb
--- /dev/null
+++ b/sw/qa/uitest/data/tdf138907_titlePageDialog.odt
Binary files differ
diff --git a/sw/qa/uitest/writer_tests5/titlePageWizard.py b/sw/qa/uitest/writer_tests5/titlePageWizard.py
new file mode 100644
index 000000000000..f23c79c68768
--- /dev/null
+++ b/sw/qa/uitest/writer_tests5/titlePageWizard.py
@@ -0,0 +1,73 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# 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 uitest.uihelper.common import get_state_as_dict
+from libreoffice.uno.propertyvalue import mkPropertyValues
+import org.libreoffice.unotest
+import pathlib
+
+def get_url_for_data_file(file_name):
+ return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+# This tests the Format->Title Page wizard, specifically the reset page number portion.
+class tdf138907(UITestCase):
+ def test_tdf138907(self):
+ self.ui_test.load_file(get_url_for_data_file("tdf138907_titlePageDialog.odt"))
+ document = self.ui_test.get_component()
+
+ # Confirm the starting state. Just a page break, without a valid restart page number on page 2
+ self.assertEqual(document.CurrentController.PageCount, 5)
+ Paragraphs = document.Text.createEnumeration()
+ Para1 = Paragraphs.nextElement()
+ self.assertEqual(Para1.String, "6")
+ self.assertEqual(Para1.PageDescName, "First Page")
+ Para2 = Paragraphs.nextElement()
+ self.assertEqual(Para2.String, "7")
+ self.assertEqual(Para2.PageDescName, None)
+
+ #dialog Title Page
+ self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog")
+ xDialog = self.xUITest.getTopFocusWindow()
+ #set restart page number to 2. With this doc, it defaults to resetting to 1.
+ xRestartNumbering = xDialog.getChild("NF_RESTART_NUMBERING")
+ xRestartNumbering.executeAction("UP", tuple()) # restart numbering at 2
+ xOKBtn = xDialog.getChild("ok")
+ self.ui_test.close_dialog_through_button(xOKBtn)
+
+ # This correctly reset the starting page number for page 2 as "1".
+ # It wasn't persistent across round-trips though
+ Paragraphs = document.Text.createEnumeration()
+ Para1 = Paragraphs.nextElement()
+ self.assertEqual(Para1.String, "6")
+ self.assertEqual(Para1.PageDescName, "First Page")
+ self.assertEqual(Para2.String, "2")
+ Para2 = Paragraphs.nextElement()
+ # Without this fix, there was no PageDescName specified, just Landscape as default.
+ self.assertEqual(Para2.PageDescName, "Landscape")
+
+ #re-run dialog Title Page
+ self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog")
+ xDialog = self.xUITest.getTopFocusWindow()
+ #accept defaults and OK without making any changes.
+ xOKBtn = xDialog.getChild("ok")
+ self.ui_test.close_dialog_through_button(xOKBtn)
+
+ # Without this fix, re-running the wizard was failing with the title page restarting at page 2.
+ Paragraphs = document.Text.createEnumeration()
+ Para1 = Paragraphs.nextElement()
+ #self.assertEqual(Para1.String, "6")
+ self.assertEqual(Para1.PageDescName, "First Page")
+ Para2 = Paragraphs.nextElement()
+ self.assertEqual(Para2.String, "2")
+ self.assertEqual(Para2.PageDescName, "Landscape")
+
+ #Note: 6 virtual pages, including blank, even page seen in book view
+ self.assertEqual(document.CurrentController.PageCount, 6)
+
+ self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/misc/titlepage.cxx b/sw/source/ui/misc/titlepage.cxx
index 26fa4bdeb564..bba63c73c264 100644
--- a/sw/source/ui/misc/titlepage.cxx
+++ b/sw/source/ui/misc/titlepage.cxx
@@ -76,15 +76,9 @@ namespace
}
// If we want a new descriptor then set it, otherwise reuse the existing one
- if (!pNewDesc)
+ if (pNewDesc || nPgNo)
{
- SwFormatPageDesc aPageFormatDesc(pPageFormatDesc ? *pPageFormatDesc : &rCurrentDesc);
- if (nPgNo) aPageFormatDesc.SetNumOffset(nPgNo);
- pSh->SetAttrItem(aPageFormatDesc);
- }
- else
- {
- SwFormatPageDesc aPageFormatDesc(pNewDesc);
+ SwFormatPageDesc aPageFormatDesc(pNewDesc ? pNewDesc : &rCurrentDesc);
if (nPgNo) aPageFormatDesc.SetNumOffset(nPgNo);
pSh->SetAttrItem(aPageFormatDesc);
}
@@ -133,6 +127,8 @@ void SwTitlePageDlg::FillList()
sal_uInt16 SwTitlePageDlg::GetInsertPosition() const
{
sal_uInt16 nPage = 1;
+ // FIXME: If GetInsertPosition is greater than the current number of pages,
+ // it needs to be reduced to page-count + 1.
if (m_xPageStartNF->get_sensitive())
nPage = m_xPageStartNF->get_value();
return nPage;
@@ -255,6 +251,8 @@ IMPL_LINK_NOARG(SwTitlePageDlg, EditHdl, weld::Button&, void)
IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
{
+ // FIXME: This wizard is almost completely non-functional for inserting new pages.
+
lcl_PushCursor(mpSh);
mpSh->StartUndo();
@@ -269,12 +267,16 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
sal_uInt16 nNoPages = m_xPageCountNF->get_value();
if (!m_xUseExistingPagesRB->get_active())
{
+ // FIXME: If the starting page number is larger than the last page,
+ // probably should add pages AFTER the last page, not before it.
mpSh->GotoPage(GetInsertPosition(), false);
+ // FIXME: These new pages cannot be accessed currently with GotoPage. It doesn't know they exist.
for (sal_uInt16 nI=0; nI < nNoPages; ++nI)
mpSh->InsertPageBreak();
}
mpSh->GotoPage(GetInsertPosition(), false);
+ // FIXME: GotoPage is pointing to a page after the newly created index pages, so the wrong pages are getting Index style.
for (sal_uInt16 nI=1; nI < nNoPages; ++nI)
{
if (mpSh->SttNxtPg())
@@ -286,6 +288,7 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
if (nNoPages > 1 && mpSh->GotoPage(GetInsertPosition() + nNoPages, false))
{
+ // FIXME: By definition, GotoPage(x,bRecord=false) returns false. This is dead code.
SwFormatPageDesc aPageFormatDesc(mpNormalDesc);
mpSh->SetAttrItem(aPageFormatDesc);
}