Related tdf#173496: fix regression from previous patch on Pages

The regression was when clicking on Pages, it was impossible to type a range.

But following https://bugs.documentfoundation.org/show_bug.cgi?id=173496#c17
from Heiko, if we use placeholder instead + keep what the user may typed,
it simplifies the pb.

So here are the changes:
- display placeholder when clicking "Pages" except if user typed something.
Also preserve what the user typed whatever it happens then (e.g. changing page
orientation)
=> change UI test to correspond to the whole change abovev

- add a delay mechanism for the preview when on Pages.
Indeed, when typing first character, placeholder was still in background for a brief time
+ there was a slight lag when typing a character

These changes have been proposed by GPT 5.6 Luna but I could test them
and make UITest_calc_dialogs is ok for me (we'll see on Jenkins).

Change-Id: Ifa57a8d1fded24cc03ed8f0589828931e897d641
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211738
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
This commit is contained in:
Julien Nabet
2026-10-03 23:24:07 +02:00
parent 889c92e926
commit 8f2eee739d
3 changed files with 42 additions and 31 deletions
+18 -16
View File
@@ -7,7 +7,7 @@
# 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, get_url_for_data_file, select_by_text
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, select_by_text, mkPropertyValues
class printDialog(UITestCase):
def test_printDialog(self):
@@ -22,11 +22,11 @@ class printDialog(UITestCase):
xPortraiTotalNumberPages = xDialog.getChild("totalnumpages")
self.assertEqual(get_state_as_dict(xPortraiTotalNumberPages)["Text"], "/ 2")
xPortraiPageRange = xDialog.getChild("pagerange")
self.assertEqual(get_state_as_dict(xPortraiPageRange)["Text"], "1-2")
xPageRange = xDialog.getChild("pagerange")
self.assertEqual(get_state_as_dict(xPageRange)["Text"], "")
xpageorientationbox = xDialog.getChild("pageorientationbox")
select_by_text(xpageorientationbox, "Landscape")
xPageOrientationBox = xDialog.getChild("pageorientationbox")
select_by_text(xPageOrientationBox, "Landscape")
# Without the fix in place, this test would have failed with
# Expected: "/ 1"
@@ -34,17 +34,19 @@ class printDialog(UITestCase):
xLandscapeTotalNumberPages = xDialog.getChild("totalnumpages")
self.assertEqual(get_state_as_dict(xLandscapeTotalNumberPages)["Text"], "/ 1")
# Without the fix in place, this test would have failed with
# Expected: "1"
# Actual : "1-2"
xLandscapePageRange = xDialog.getChild("pagerange")
self.assertEqual(get_state_as_dict(xLandscapePageRange)["Text"], "1")
# Page range is empty by default and must not be populated automatically
self.assertEqual(get_state_as_dict(xPageRange)["Text"], "")
# check that when reselecting Portrait, the range is again 1-2
# Expected: "1-2"
# Actual : "1"
select_by_text(xpageorientationbox, "Portrait")
xPortraitPageRange = xDialog.getChild("pagerange")
self.assertEqual(get_state_as_dict(xPortraitPageRange)["Text"], "1-2")
select_by_text(xPageOrientationBox, "Portrait")
# Page range must remain empty when the number of pages changes.
self.assertEqual(get_state_as_dict(xPageRange)["Text"], "")
# User enters a page range.
xPageRange.executeAction("TYPE", mkPropertyValues({"TEXT": "2-3"}))
select_by_text(xPageOrientationBox, "Landscape")
select_by_text(xPageOrientationBox, "Portrait")
self.assertEqual(get_state_as_dict(xPageRange)["Text"], "2-3")
# vim: set shiftwidth=4 softtabstop=4 expandtab:
+3
View File
@@ -224,6 +224,9 @@ namespace vcl
Idle maUpdatePreviewIdle;
DECL_LINK(updatePreviewIdle, Timer*, void);
Timer maPageRangeUpdateTimer;
DECL_LINK(PageRangeUpdateTimerHdl, Timer*, void);
DECL_LINK(ClickOKCancelHdl, weld::Button&, void);
DECL_LINK(ClickForwardHdl, weld::Button&, void);
DECL_LINK(ClickBackwardHdl, weld::Button&, void);
+21 -15
View File
@@ -586,6 +586,7 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl
, mbShowLayoutFrame( true )
, mbHasCustomPaperEntry( false )
, maUpdatePreviewIdle("Print Dialog Update Preview Idle")
, maPageRangeUpdateTimer("PageRangeUpdateTimer")
{
// Retrieve current page, it'll be used later in updatePageRange method
PropertyValue* pPageRange = maPController->getValue(u"PageRange"_ustr);
@@ -663,6 +664,10 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl
maUpdatePreviewIdle.SetPriority(TaskPriority::POST_PAINT);
maUpdatePreviewIdle.SetInvokeHandler(LINK( this, PrintDialog, updatePreviewIdle));
maPageRangeUpdateTimer.SetTimeout(EDIT_UPDATEDATA_TIMEOUT);
maPageRangeUpdateTimer.SetInvokeHandler(LINK(this, PrintDialog, PageRangeUpdateTimerHdl));
initFromMultiPageSetup( maPController->getMultipage() );
// setup optional UI options set by application
@@ -1031,6 +1036,12 @@ IMPL_LINK_NOARG(PrintDialog, updatePreviewIdle, Timer*, void)
preparePreview(std::exchange(mbUseCacheForPreview, true));
}
IMPL_LINK_NOARG(PrintDialog, PageRangeUpdateTimerHdl, Timer*, void)
{
schedulePreviewUpdate(false);
}
void PrintDialog::preparePreview( bool i_bMayUseCache )
{
VclPtr<Printer> aPrt( maPController->getPrinter() );
@@ -1169,17 +1180,7 @@ void PrintDialog::updatePageRange(sal_Int32 nPages)
pContentVal->Value >>= nContent;
if (nContent == 1)
{
OUString sRange;
if (nPages == 1)
sRange = u"1"_ustr;
else
sRange = u"1-"_ustr + OUString::number(nPages);
mxPageRangeEdit->set_text(sRange);
maPController->setValue(u"PageRange"_ustr, Any(sRange));
return;
}
return; // User-controlled page range
OUString sRange;
@@ -1203,7 +1204,6 @@ void PrintDialog::updatePageRange(sal_Int32 nPages)
return;
}
mxPageRangeEdit->set_text(sRange);
maPController->setValue(u"PageRange"_ustr, Any(sRange));
}
@@ -1899,7 +1899,10 @@ void PrintDialog::setupOptionalUI()
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= aCurVal;
xField->set_text( aCurVal );
if (aPropertyName != "PageRange")
{
xField->set_text( aCurVal );
}
xField->connect_changed( LINK( this, PrintDialog, UIOption_EntryModifyHdl ) );
xField->show();
@@ -2495,8 +2498,11 @@ IMPL_LINK(PrintDialog, UIOption_EntryModifyHdl, weld::TextWidget&, i_rBox, void)
checkOptionalControlDependencies();
// update preview and page settings
schedulePreviewUpdate(false);
if (pVal->Name == "PageRange")
maPageRangeUpdateTimer.Start();
else
schedulePreviewUpdate(false);
}
}