[Libreoffice-commits] core.git: sw/qa sw/source
Justin Luth (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jan 21 08:21:04 UTC 2021
sw/qa/uitest/writer_tests5/titlePageWizard.py | 83 +++++++++++++++++++++++++-
sw/source/ui/misc/titlepage.cxx | 47 ++++++++++----
2 files changed, 116 insertions(+), 14 deletions(-)
New commits:
commit 22ee887346ef870fbf9b758fe2bcaa9aeae04a82
Author: Justin Luth <justin.luth at collabora.com>
AuthorDate: Mon Dec 28 17:15:06 2020 +0300
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Jan 21 09:20:16 2021 +0100
tdf#138907 sw TitlePageDlg: Goto correct (existing) page
If the starting page for the new Title pages is
beyond the end of the document, then insert the
new pages after the last page.
Also, handle the "physical" blank pages
which threw off calculations for Index pages.
1.) It was wrongly inserting before the last page.
2.) Cap InsertPosition() to document-end.
3.) An odd/even blank filler page would cause
missing or mis-applied styles.
NOTE: The wizard is still completely useless
when adding pages, because GotoPage does not
recognize that the document has inserted pages,
and so it goes by pre-wizard page coordinates.
This is just the first step in correcting
the overall problem (which I don't know how
to do).
make UITest_writer_tests5 UITEST_TEST_NAME=\
titlePageWizard.tdf138907.test_tdf138907
Change-Id: Ie138c4ab3126bc6d3fae16028b41a80bda329f1c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108332
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth at sil.org>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/qa/uitest/writer_tests5/titlePageWizard.py b/sw/qa/uitest/writer_tests5/titlePageWizard.py
index ca391a6d4010..24d3ff4c53cb 100644
--- a/sw/qa/uitest/writer_tests5/titlePageWizard.py
+++ b/sw/qa/uitest/writer_tests5/titlePageWizard.py
@@ -8,7 +8,9 @@ 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
-# This tests the Format->Title Page wizard, specifically the reset page number portion.
+# This tests the Format->Title Page wizard, specifically the reset page number portion,
+# replacing some pages with title pages,
+# and inserting at the very end of the document.
class tdf138907(UITestCase):
def test_tdf138907(self):
self.ui_test.load_file(get_url_for_data_file("tdf138907_titlePageDialog.odt"))
@@ -23,6 +25,16 @@ class tdf138907(UITestCase):
Para2 = Paragraphs.nextElement()
self.assertEqual(Para2.String, "7")
self.assertEqual(Para2.PageDescName, None)
+ Para3 = Paragraphs.nextElement()
+ self.assertEqual(Para3.String, "8")
+ self.assertEqual(Para3.PageDescName, None)
+ Para4 = Paragraphs.nextElement()
+ self.assertEqual(Para4.String, "9")
+ self.assertEqual(Para4.PageDescName, None)
+ Para5 = Paragraphs.nextElement()
+ self.assertEqual(Para5.String, "10")
+ self.assertEqual(Para5.PageDescName, None)
+
#dialog Title Page
self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog")
@@ -54,7 +66,7 @@ class tdf138907(UITestCase):
# 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.String, "6")
self.assertEqual(Para1.PageDescName, "First Page")
Para2 = Paragraphs.nextElement()
self.assertEqual(Para2.String, "2")
@@ -63,6 +75,73 @@ class tdf138907(UITestCase):
#Note: 6 virtual pages, including blank, even page seen in book view
self.assertEqual(document.CurrentController.PageCount, 6)
+ #Now test replacing several pages with title and index styles
+
+ #dialog Title Page
+ self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog")
+ xDialog = self.xUITest.getTopFocusWindow()
+ print(xDialog.getChildren())
+ #Insert thre title/index pages at page two.
+ xPageCount = xDialog.getChild("NF_PAGE_COUNT")
+ for _ in range(0,2):
+ xPageCount.executeAction("UP", tuple())
+ xUseStartingPage = xDialog.getChild("RB_PAGE_START")
+ xUseStartingPage.executeAction("CLICK", tuple())
+ xStartingPage = xDialog.getChild("NF_PAGE_START")
+ xStartingPage.executeAction("UP", tuple()) #Start at page 2.
+
+ xOKBtn = xDialog.getChild("ok")
+ self.ui_test.close_dialog_through_button(xOKBtn)
+
+ Paragraphs = document.Text.createEnumeration()
+ Para1 = Paragraphs.nextElement()
+ self.assertEqual(Para1.String, "6")
+ self.assertEqual(Para1.PageDescName, "First Page")
+ # Without the fix, the following results are all off by one.
+ Para2 = Paragraphs.nextElement()
+ self.assertEqual(Para2.String, "6")
+ self.assertEqual(Para2.PageDescName, "First Page")
+ Para3 = Paragraphs.nextElement()
+ self.assertEqual(Para3.String, "7")
+ self.assertEqual(Para3.PageDescName, "Index")
+ Para4 = Paragraphs.nextElement()
+ self.assertEqual(Para4.String, "8")
+ self.assertEqual(Para4.PageDescName, "Index")
+ Para5 = Paragraphs.nextElement()
+ self.assertEqual(Para5.String, "2")
+ self.assertEqual(Para5.PageDescName, "Landscape")
+
+ #Now test inserting at the end of the document
+
+ #dialog Title Page
+ self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog")
+ xDialog = self.xUITest.getTopFocusWindow()
+ print(xDialog.getChildren())
+ #Insert title/index pages at the end of the document.
+ newPages = xDialog.getChild("RB_INSERT_NEW_PAGES")
+ newPages.executeAction("CLICK", tuple())
+ xPageCount = xDialog.getChild("NF_PAGE_COUNT")
+ for _ in range(0,2):
+ xPageCount.executeAction("UP", tuple())
+ xUseStartingPage = xDialog.getChild("RB_PAGE_START")
+ xUseStartingPage.executeAction("CLICK", tuple())
+ xStartingPage = xDialog.getChild("NF_PAGE_START")
+ for _ in range(0,18):
+ xStartingPage.executeAction("UP", tuple()) #Start at mythical page 20.
+
+ xOKBtn = xDialog.getChild("ok")
+ self.ui_test.close_dialog_through_button(xOKBtn)
+
+ # Without the fix, the pages were being inserted before the last page.
+ # NOTE: there are still LOTS of problems here that still need fixing.
+ text = document.Text.String.replace('\r\n', '\n')
+ self.assertEqual(text[0:1], "6")
+ self.assertEqual(text[2:3], "6")
+ self.assertEqual(text[4:5], "7")
+ self.assertEqual(text[6:7], "8")
+ # Without the fix, the new pages were inserted before the last page.
+ self.assertFalse("\n" in text[8:9])
+
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 a05165fe063a..eb431a35d757 100644
--- a/sw/source/ui/misc/titlepage.cxx
+++ b/sw/source/ui/misc/titlepage.cxx
@@ -91,7 +91,33 @@ namespace
rSh.GetPageNumber(0, true, nPhyNum, nVirtNum, sDummy);
return nPhyNum;
}
+
+bool lcl_GotoPage(SwWrtShell& rSh, const sal_uInt16 nStartingPage, sal_uInt16 nOffset = 0)
+{
+ rSh.GotoPage(nStartingPage, /*bRecord=*/false);
+
+ sal_uInt16 nCurrentPage = lcl_GetCurrentPage(rSh);
+ // return false if at document end (unless that was the requested destination)
+ if (nCurrentPage == rSh.GetPageCnt())
+ return nCurrentPage == nStartingPage + nOffset;
+
+ if (nCurrentPage != nStartingPage)
+ {
+ assert(nStartingPage != 1 && "Physical page 1 couldn't be found/moved to?");
+ // Probably there is an auto-inserted blank page to handle odd/even, which Goto doesn't understand.
+ rSh.GotoPage(nStartingPage + 1, /*bRecord=*/false);
+
+ nCurrentPage = lcl_GetCurrentPage(rSh);
+ assert(nCurrentPage == nStartingPage + 1 && "Impossible, since unknown goes to last page");
+ if (nCurrentPage != nStartingPage + 1)
+ return false;
+ }
+ // Now that we have the correct starting point, move to the correct offset.
+ while (nOffset--)
+ rSh.SttNxtPg();
+ return true;
}
+} // namespace
/*
* Only include the Index page in the list if the page count implies one
@@ -113,8 +139,6 @@ 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;
@@ -139,6 +163,7 @@ SwTitlePageDlg::SwTitlePageDlg(weld::Window *pParent)
m_xOkPB->connect_clicked(LINK(this, SwTitlePageDlg, OKHdl));
m_xRestartNumberingCB->connect_toggled(LINK(this, SwTitlePageDlg, RestartNumberingHdl));
m_xSetPageNumberCB->connect_toggled(LINK(this, SwTitlePageDlg, SetPageNumberHdl));
+ m_xPageStartNF->set_max(mrSh.GetPageCnt() + 1);
sal_uInt16 nSetPage = 1;
sal_uInt16 nResetPage = 1;
@@ -237,8 +262,6 @@ 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(mrSh);
mrSh.StartUndo();
@@ -253,17 +276,17 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
sal_uInt16 nNumTitlePages = 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.
- mrSh.GotoPage(GetInsertPosition(), false);
+ // Assuming that a failure to GotoPage means the end of the document,
+ // insert new pages after the last page.
+ if (!lcl_GotoPage(mrSh, GetInsertPosition()))
+ mrSh.EndPg();
// FIXME: These new pages cannot be accessed currently with GotoPage. It doesn't know they exist.
for (sal_uInt16 nI = 0; nI < nNumTitlePages; ++nI)
mrSh.InsertPageBreak();
}
- mrSh.GotoPage(GetInsertPosition(), false);
- mrSh.SetAttrItem(aTitleDesc);
- // FIXME: GotoPage is pointing to a page after the newly created index pages, so the wrong pages are getting Index style.
+ if (lcl_GotoPage(mrSh, GetInsertPosition()))
+ mrSh.SetAttrItem(aTitleDesc);
for (sal_uInt16 nI = 1; nI < nNumTitlePages; ++nI)
{
if (mrSh.SttNxtPg())
@@ -281,14 +304,14 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
{
sal_uInt16 nPgNo = m_xRestartNumberingCB->get_active() ? m_xRestartNumberingNF->get_value() : 0;
const SwPageDesc* pNewDesc = nNumTitlePages > 1 ? mpNormalDesc : nullptr;
- mrSh.GotoPage(GetInsertPosition() + nNumTitlePages, false);
+ lcl_GotoPage(mrSh, GetInsertPosition(), nNumTitlePages);
lcl_ChangePage(mrSh, nPgNo, pNewDesc);
}
mrSh.EndUndo();
lcl_PopCursor(mrSh);
if (!m_xUseExistingPagesRB->get_active())
- mrSh.GotoPage(GetInsertPosition(), false);
+ lcl_GotoPage(mrSh, GetInsertPosition());
m_xDialog->response(RET_OK);
}
More information about the Libreoffice-commits
mailing list