cui/source/options/optgdlg.cxx |   52 +++++++++++++++++++++++------------------
 cui/source/options/optgdlg.hxx |    2 +
 2 files changed, 32 insertions(+), 22 deletions(-)

New commits:
commit 648c70ac2caf2646ee8ff49bd8d846016d289b38
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Sun Oct 23 22:03:46 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Sun Oct 23 23:42:27 2022 +0200

    Related: tdf#147817 Extract validateDatePatterns() from DatePatternsHdl()
    
    To be able to reuse it.
    
    Change-Id: I11932708a3f1d04180f806f8de12ff42e3d13954
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141688
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx
index 7b887b4e6965..38b6ae8181e6 100644
--- a/cui/source/options/optgdlg.cxx
+++ b/cui/source/options/optgdlg.cxx
@@ -1695,16 +1695,34 @@ IMPL_LINK_NOARG(OfaLanguagesTabPage, LocaleSettingHdl, 
weld::ComboBox&, void)
 
 IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, weld::Entry&, rEd, void )
 {
-    const OUString aPatterns(rEd.get_text());
-    OUStringBuffer aBuf( aPatterns);
-    sal_Int32 nChar = 0;
-    bool bValid = true;
+    OUString aPatterns(rEd.get_text());
     bool bModified = false;
-    if (!aPatterns.isEmpty())
+    const bool bValid = validateDatePatterns( bModified, aPatterns);
+    if (bModified)
     {
+        // gtk3 keeps the cursor position on equal length set_text() but at
+        // least the 'gen' backend does not and resets to 0.
+        const int nCursorPos = rEd.get_position();
+        rEd.set_text(aPatterns);
+        rEd.set_position(nCursorPos);
+    }
+    if (bValid)
+        rEd.set_message_type(weld::EntryMessageType::Normal);
+    else
+        rEd.set_message_type(weld::EntryMessageType::Error);
+    m_bDatePatternsValid = bValid;
+}
+
+bool OfaLanguagesTabPage::validateDatePatterns( bool& rbModified, OUString& 
rPatterns )
+{
+    bool bValid = true;
+    if (!rPatterns.isEmpty())
+    {
+        OUStringBuffer aBuf( rPatterns);
+        sal_Int32 nChar = 0;
         for (sal_Int32 nIndex=0; nIndex >= 0 && bValid; ++nChar)
         {
-            const OUString aPat( aPatterns.getToken( 0, ';', nIndex));
+            const OUString aPat( rPatterns.getToken( 0, ';', nIndex));
             if (aPat.isEmpty() && nIndex < 0)
             {
                 // Indicating failure when about to append a pattern is too
@@ -1745,7 +1763,7 @@ IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, 
weld::Entry&, rEd, void )
                             else if (c == 'y')
                             {
                                 aBuf[nChar] = 'Y';
-                                bModified = true;
+                                rbModified = true;
                             }
                             bY = true;
                             bSep = false;
@@ -1757,7 +1775,7 @@ IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, 
weld::Entry&, rEd, void )
                             else if (c == 'm')
                             {
                                 aBuf[nChar] = 'M';
-                                bModified = true;
+                                rbModified = true;
                             }
                             bM = true;
                             bSep = false;
@@ -1769,7 +1787,7 @@ IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, 
weld::Entry&, rEd, void )
                             else if (c == 'd')
                             {
                                 aBuf[nChar] = 'D';
-                                bModified = true;
+                                rbModified = true;
                             }
                             bD = true;
                             bSep = false;
@@ -1787,20 +1805,10 @@ IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, 
weld::Entry&, rEd, void )
                 bValid &= (bY || bM || bD);
             }
         }
+        if (rbModified)
+            rPatterns = aBuf.makeStringAndClear();
     }
-    if (bModified)
-    {
-        // gtk3 keeps the cursor position on equal length set_text() but at
-        // least the 'gen' backend does not and resets to 0.
-        const int nCursorPos = rEd.get_position();
-        rEd.set_text(aBuf.makeStringAndClear());
-        rEd.set_position(nCursorPos);
-    }
-    if (bValid)
-        rEd.set_message_type(weld::EntryMessageType::Normal);
-    else
-        rEd.set_message_type(weld::EntryMessageType::Error);
-    m_bDatePatternsValid = bValid;
+    return bValid;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/options/optgdlg.hxx b/cui/source/options/optgdlg.hxx
index 75f29c6c5a34..ca41fb6bd478 100644
--- a/cui/source/options/optgdlg.hxx
+++ b/cui/source/options/optgdlg.hxx
@@ -168,6 +168,8 @@ class OfaLanguagesTabPage : public SfxTabPage
     DECL_LINK(LocaleSettingHdl, weld::ComboBox&, void);
     DECL_LINK(DatePatternsHdl, weld::Entry&, void);
 
+    bool validateDatePatterns( bool& rbModified, OUString& rPatterns );
+
 public:
     OfaLanguagesTabPage(weld::Container* pPage, weld::DialogController* 
pController, const SfxItemSet& rSet);
     virtual ~OfaLanguagesTabPage() override;

Reply via email to