include/svx/dialog/gotodlg.hxx | 6 +----- svx/source/dialog/gotodlg.cxx | 25 ++----------------------- sw/qa/uitest/writer_tests3/goToPage.py | 4 ++-- 3 files changed, 5 insertions(+), 30 deletions(-)
New commits: commit 27c95bb44572fe3d9253c0ee2660e17590d0e705 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Nov 28 08:26:04 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Nov 28 11:57:33 2024 +0100 svx: Simplify "Go to Page" dialog, let SpinButton do its job Set the allowed range using weld::SpinButton::set_range so that weld::SpinButton makes sure that a value within the correct range is set, instead of having a custom handler called when the text of the spinbutton changes that effectively does the same thing (+ manually setting cursor to the end of the edit, but sticking to the toolkit default there instead makes sense to me for consistency). Adjust the test case to no longer type invalid input for the page number ("3a"), as SalInstanceSpinButton doesn't parse the number then, but would set the value to the minimum (here: 1) instead. (If a different behavior were intended here, that should be implemented in SalInstanceSpinButton or the underlying VCL widgets to be consistent across dialogs.) In GotoPageDlg::GetPageSelection, use weld::SpinButton::get_value to get the integer value right away, instead of getting the text and converting that into an integer manually. All that custom handling provided an interesting test case while implementing support for that dialog using native Qt widgets, see commits up to commit 70825e677f808437bd47651ebecc8a0c53955676 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Thu Nov 28 00:30:10 2024 +0100 tdf#130857 qt weld: Notify about spinbox combined value+text change , but apart from that (which is done now), I think that a more standard approach makes more sense. Change-Id: I06492b6629a4210c6325d50467da8e195daa4c94 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177463 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/svx/dialog/gotodlg.hxx b/include/svx/dialog/gotodlg.hxx index 304f1352b0db..5830acce28bc 100644 --- a/include/svx/dialog/gotodlg.hxx +++ b/include/svx/dialog/gotodlg.hxx @@ -30,16 +30,12 @@ public: GotoPageDlg(weld::Window* pParent, const OUString& title, const OUString& label, sal_uInt16 curPagePos, sal_uInt16 pageCnt); - sal_uInt16 GetPageSelection() const { return mxMtrPageCtrl->get_text().toUInt32(); } + sal_uInt16 GetPageSelection() const { return mxMtrPageCtrl->get_value(); } private: - sal_uInt16 mnMaxPageCnt; - std::unique_ptr<weld::SpinButton> mxMtrPageCtrl; std::unique_ptr<weld::Label> mxPageNumberLbl; std::unique_ptr<weld::Label> mxPageLbl; - - DECL_LINK(PageModifiedHdl, weld::Entry&, void); }; } diff --git a/svx/source/dialog/gotodlg.cxx b/svx/source/dialog/gotodlg.cxx index 82842ff4acc0..286536903eb5 100644 --- a/svx/source/dialog/gotodlg.cxx +++ b/svx/source/dialog/gotodlg.cxx @@ -26,7 +26,6 @@ namespace svx GotoPageDlg::GotoPageDlg(weld::Window* pParent, const OUString& title, const OUString& label, sal_uInt16 curPagePos, sal_uInt16 pageCnt) : GenericDialogController(pParent, u"svx/ui/gotopagedialog.ui"_ustr, u"GotoPageDialog"_ustr) - , mnMaxPageCnt(1) , mxMtrPageCtrl(m_xBuilder->weld_spin_button(u"page"_ustr)) , mxPageNumberLbl(m_xBuilder->weld_label(u"page_count"_ustr)) , mxPageLbl(m_xBuilder->weld_label(u"page_label"_ustr)) @@ -34,33 +33,13 @@ GotoPageDlg::GotoPageDlg(weld::Window* pParent, const OUString& title, const OUS set_title(title); mxPageLbl->set_label(label); + mxMtrPageCtrl->set_range(1, pageCnt); mxMtrPageCtrl->set_value(curPagePos); - sal_uInt16 nTotalPage = pageCnt; OUString sStr = mxPageNumberLbl->get_label(); - mxPageNumberLbl->set_label(sStr.replaceFirst("$1", OUString::number(nTotalPage))); - mnMaxPageCnt = nTotalPage; + mxPageNumberLbl->set_label(sStr.replaceFirst("$1", OUString::number(pageCnt))); - mxMtrPageCtrl->connect_changed(LINK(this, GotoPageDlg, PageModifiedHdl)); - mxMtrPageCtrl->set_position(-1); mxMtrPageCtrl->select_region(0, -1); } - -IMPL_LINK_NOARG(GotoPageDlg, PageModifiedHdl, weld::Entry&, void) -{ - if (mxMtrPageCtrl->get_text().isEmpty()) - return; - - auto page_value = mxMtrPageCtrl->get_text().toInt32(); - - if (page_value <= 0) - mxMtrPageCtrl->set_value(1); - else if (page_value > mnMaxPageCnt) - mxMtrPageCtrl->set_value(mnMaxPageCnt); - else - mxMtrPageCtrl->set_value(page_value); - - mxMtrPageCtrl->set_position(-1); -} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uitest/writer_tests3/goToPage.py b/sw/qa/uitest/writer_tests3/goToPage.py index 812402f89c57..ec0b1d0f2ea1 100644 --- a/sw/qa/uitest/writer_tests3/goToPage.py +++ b/sw/qa/uitest/writer_tests3/goToPage.py @@ -26,7 +26,7 @@ class GoToPage_dialog(UITestCase): with self.ui_test.execute_dialog_through_command(".uno:GotoPage") as xDialog: xPageText = xDialog.getChild("page") - xPageText.executeAction("TYPE", mkPropertyValues({"TEXT":"3a"})) + xPageText.executeAction("TYPE", mkPropertyValues({"TEXT":"3"})) self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3") @@ -36,4 +36,4 @@ class GoToPage_dialog(UITestCase): self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3") -# vim: set shiftwidth=4 softtabstop=4 expandtab: \ No newline at end of file +# vim: set shiftwidth=4 softtabstop=4 expandtab: