vcl/source/gdi/print3.cxx      |   12 ++----------
 vcl/source/window/printdlg.cxx |    2 --
 2 files changed, 2 insertions(+), 12 deletions(-)

New commits:
commit 2d6aa340faf5409f1beb50193590b411f515d004
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Aug 1 11:04:56 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Aug 2 06:47:56 2024 +0200

    tdf#162289 Update printer info before getting default printer
    
    Move the call to `Printer::updatePrinters` to update the printer
    infos from the print dialog ctor to the beginning of
    `Printer::PreparePrintJob` (which is the only method
    potentially creating a print dialog) to make
    sure that the printer infos (including the default printer)
    are already up to date there.
    
    This e.g. makes sure that the current CUPS default printer on
    Linux gets preselected the next time the print dialog gets
    opened if it was changed while LO is running.
    (Otherwise, it would only be preselected as expected when
    the print dialog gets opened, closed and reopened again.)
    
    For macOS, there was already code to explicitly call
    `Printer::updatePrinters` in case the dialog was not shown.
    Drop that, as it happens unconditionally at the beginning
    now.
    
    Change-Id: I5cd530c0c9801bde88e40f5ac2220feb0e8d4247
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171371
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index 4c86484c8a3b..5b5226717774 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -341,6 +341,8 @@ void Printer::PrintJob(const 
std::shared_ptr<PrinterController>& i_xController,
 bool Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
                            const JobSetup& i_rInitSetup)
 {
+    Printer::updatePrinters();
+
     // check if there is a default printer; if not, show an error box (if 
appropriate)
     if( GetDefaultPrinterName().isEmpty() )
     {
@@ -537,16 +539,6 @@ bool 
Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
         {
         }
     }
-#ifdef MACOSX
-    else
-    {
-        // The PrintDialog updates the printer list in its constructor so do
-        // the same for printers that bring up their own dialog since. Not
-        // sure if this is needed or not on Windows or X11, so limit only to
-        // macOS for now.
-        Printer::updatePrinters();
-    }
-#endif
 
     xController->pushPropertiesToPrinter();
     return true;
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index faa8d7179cb6..9e24b7c7d5c6 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -591,8 +591,6 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, 
std::shared_ptr<PrinterControl
 
     maPageStr = mxNumPagesText->get_label();
 
-    Printer::updatePrinters();
-
     mxPrinters->append_text(maPrintToFileText);
     // fill printer listbox
     std::vector< OUString > rQueues( Printer::GetPrinterQueues() );

Reply via email to