tdf#104487 - Function wizard: remember last used function category

Change-Id: I978dd63553e3528e7b9b853dbb438304f1f680cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151565
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index c125342..123642c 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -828,7 +828,8 @@ void FormulaDlg_Impl::FillListboxes()
    }
    else if ( pData )
    {
        m_xFuncPage->SetCategory( 1 );
        // tdf#104487 - remember last used function category
        m_xFuncPage->SetCategory(FuncPage::GetRememeberdFunctionCategory());
        m_xFuncPage->SetFunction( -1 );
    }
    FuncSelHdl(*m_xFuncPage);
diff --git a/formula/source/ui/dlg/funcpage.cxx b/formula/source/ui/dlg/funcpage.cxx
index 3013b84..dbdb494 100644
--- a/formula/source/ui/dlg/funcpage.cxx
+++ b/formula/source/ui/dlg/funcpage.cxx
@@ -37,6 +37,9 @@ IMPL_LINK(FuncPage, KeyInputHdl, const KeyEvent&, rKEvt, bool)
    return false;
}

// tdf#104487 - remember last used function category - set default to All category
sal_Int32 FuncPage::m_nRememberedFunctionCategory = 1;

FuncPage::FuncPage(weld::Container* pParent, const IFunctionManager* _pFunctionManager)
    : m_xBuilder(Application::CreateBuilder(pParent, "formula/ui/functionpage.ui"))
    , m_xContainer(m_xBuilder->weld_container("FunctionPage"))
@@ -58,7 +61,8 @@ FuncPage::FuncPage(weld::Container* pParent, const IFunctionManager* _pFunctionM
        m_xLbCategory->append(sId, pCategory->getName());
    }

    m_xLbCategory->set_active(1);
    // tdf#104487 - remember last used function category
    m_xLbCategory->set_active(m_nRememberedFunctionCategory);
    OUString searchStr = m_xLbFunctionSearchString->get_text();
    UpdateFunctionList(searchStr);
    // lock to its initial size
@@ -96,6 +100,8 @@ void FuncPage::UpdateFunctionList(const OUString& aStr)
    m_xLbFunction->freeze();

    const sal_Int32 nSelPos = m_xLbCategory->get_active();
    // tdf#104487 - remember last used function category
    m_nRememberedFunctionCategory = nSelPos;

    if (aStr.isEmpty() || nSelPos == 0)
    {
@@ -217,6 +223,8 @@ IMPL_LINK_NOARG(FuncPage, ModifyHdl, weld::Entry&, void)

void FuncPage::SetCategory(sal_Int32 nCat)
{
    // tdf#104487 - remember last used function category
    m_nRememberedFunctionCategory = nCat;
    m_xLbCategory->set_active(nCat);
    UpdateFunctionList(OUString());
}
diff --git a/formula/source/ui/dlg/funcpage.hxx b/formula/source/ui/dlg/funcpage.hxx
index 1e91b61..e7ca248 100644
--- a/formula/source/ui/dlg/funcpage.hxx
+++ b/formula/source/ui/dlg/funcpage.hxx
@@ -48,6 +48,9 @@ private:
    ::std::vector< TFunctionDesc >  aLRUList;
    OUString    m_aHelpId;

    // tdf#104487 - remember last used function category
    static sal_Int32 m_nRememberedFunctionCategory;

    void impl_addFunctions(const IFunctionCategory* _pCategory);

    DECL_LINK(SelComboBoxHdl, weld::ComboBox&, void);
@@ -71,6 +74,9 @@ public:
    sal_Int32       GetFunction() const;
    sal_Int32       GetFunctionEntryCount() const;

    // tdf#104487 - remember last used function category
    static sal_Int32 GetRememeberdFunctionCategory() { return m_nRememberedFunctionCategory; };

    sal_Int32       GetFuncPos(const IFunctionDescription* _pDesc);
    const IFunctionDescription* GetFuncDesc( sal_Int32  nPos ) const;
    OUString        GetSelFunctionName() const;
diff --git a/sc/qa/uitest/function_wizard/tdf104487.py b/sc/qa/uitest/function_wizard/tdf104487.py
new file mode 100755
index 0000000..8b563bc
--- /dev/null
+++ b/sc/qa/uitest/function_wizard/tdf104487.py
@@ -0,0 +1,28 @@
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# 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, select_pos

class tdf104487(UITestCase):
    def test_tdf104487_remember_function_category(self):
        with self.ui_test.create_doc_in_start_center("calc"):
            # Open function dialog and select select a function category
            with self.ui_test.execute_modeless_dialog_through_command(".uno:FunctionDialog") as xDialog:
                xCategory = xDialog.getChild("category")
                select_pos(xCategory, "3")

            # Open function dialog again and check whether function category was remembered
            with self.ui_test.execute_modeless_dialog_through_command(".uno:FunctionDialog") as xDialog:
                xCategory = xDialog.getChild("category")
                # Without the fix in place, this test would have failed with
                # AssertionError: '3' != '1'
                # i.e. the last used function category in the function wizard was not remembered
                self.assertEqual("3", get_state_as_dict(xCategory)["SelectEntryPos"])

# vim: set shiftwidth=4 softtabstop=4 expandtab: