diff options
author | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2023-11-23 16:49:43 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2023-11-27 10:39:58 +0100 |
commit | 45217ca5ba0d4e78b462a10072a4334342cc402c (patch) | |
tree | 2168edaebd52ba5c25ad549208d02ff5bf7a7e42 | |
parent | 272c3548c4d2362eb737947c8cbb017e2d55aae1 (diff) |
tdf#157438 Make int/double lists editable in expert config
Change-Id: I4334917e8ac6ae4deb5b15de326b083a4a1c1a0f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159863
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
-rw-r--r-- | cui/source/dialogs/dlgname.cxx | 40 | ||||
-rw-r--r-- | cui/source/options/optaboutconfig.cxx | 126 | ||||
-rw-r--r-- | cui/source/options/optaboutconfig.hxx | 1 | ||||
-rw-r--r-- | include/cui/dlgname.hxx | 14 |
4 files changed, 136 insertions, 45 deletions
diff --git a/cui/source/dialogs/dlgname.cxx b/cui/source/dialogs/dlgname.cxx index a06833bb6ce6..8164bf1c2b40 100644 --- a/cui/source/dialogs/dlgname.cxx +++ b/cui/source/dialogs/dlgname.cxx @@ -148,6 +148,7 @@ IMPL_LINK_NOARG(SvxObjectTitleDescDialog, DecorativeHdl, weld::Toggleable&, void SvxListDialog::SvxListDialog(weld::Window* pParent) : GenericDialogController(pParent, "cui/ui/listdialog.ui", "ListDialog") + , m_aMode(ListMode::String) , m_xList(m_xBuilder->weld_tree_view("assignlist")) , m_xAddBtn(m_xBuilder->weld_button("addbtn")) , m_xRemoveBtn(m_xBuilder->weld_button("removebtn")) @@ -168,7 +169,7 @@ SvxListDialog::~SvxListDialog() {} IMPL_LINK_NOARG(SvxListDialog, AddHdl_Impl, weld::Button&, void) { - SvxNameDialog aNameDlg(m_xDialog.get(), "", "blabla"); + SvxNameDialog aNameDlg(m_xDialog.get(), "", ""); if (!aNameDlg.run()) return; @@ -213,7 +214,7 @@ void SvxListDialog::SelectionChanged() m_xEditBtn->set_sensitive(bEnable); } -std::vector<OUString> SvxListDialog::GetEntries() const +std::vector<OUString> SvxListDialog::GetEntries() { int nCount = m_xList->n_children(); std::vector<OUString> aList; @@ -240,11 +241,36 @@ void SvxListDialog::EditEntry() return; OUString sOldText(m_xList->get_selected_text()); - SvxNameDialog aNameDlg(m_xDialog.get(), sOldText, "blabla"); + OUString sNewText; + + if (m_aMode == ListMode::String) + { + SvxNameDialog aNameDlg(m_xDialog.get(), sOldText, ""); + if (!aNameDlg.run()) + return; + sNewText = comphelper::string::strip(aNameDlg.GetName(), ' '); + } + else if (m_aMode == ListMode::Int16 || m_aMode == ListMode::Int32 || m_aMode == ListMode::Int64) + { + sal_Int64 nMin = m_aMode == ListMode::Int16 + ? SAL_MIN_INT16 + : m_aMode == ListMode::Int32 ? SAL_MIN_INT32 : SAL_MIN_INT64; + sal_Int64 nMax = m_aMode == ListMode::Int16 + ? SAL_MAX_INT16 + : m_aMode == ListMode::Int32 ? SAL_MAX_INT32 : SAL_MAX_INT64; + SvxNumberDialog aNumberDlg(m_xDialog.get(), "", sOldText.toInt64(), nMin, nMax); + if (!aNumberDlg.run()) + return; + sNewText = OUString::number(aNumberDlg.GetNumber()); + } + else if (m_aMode == ListMode::Double) + { + SvxDecimalNumberDialog aNumberDlg(m_xDialog.get(), "", sOldText.toDouble()); + if (!aNumberDlg.run()) + return; + sNewText = OUString::number(aNumberDlg.GetNumber()); + } - if (!aNameDlg.run()) - return; - OUString sNewText = comphelper::string::strip(aNameDlg.GetName(), ' '); if (!sNewText.isEmpty() && sNewText != sOldText) { m_xList->remove(nPos); @@ -253,4 +279,6 @@ void SvxListDialog::EditEntry() } } +void SvxListDialog::SetMode(ListMode aMode) { m_aMode = aMode; }; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/options/optaboutconfig.cxx b/cui/source/options/optaboutconfig.cxx index 68fa56ccd5ac..f191a59bd2ee 100644 --- a/cui/source/options/optaboutconfig.cxx +++ b/cui/source/options/optaboutconfig.cxx @@ -259,6 +259,54 @@ OUString lcl_StringListToString(const uno::Sequence<OUString>& seq) } return sBuffer.makeStringAndClear(); } + +OUString lcl_IntListToString(const uno::Sequence<sal_Int16>& seq) +{ + OUStringBuffer sBuffer; + for (sal_Int32 i = 0; i != seq.getLength(); ++i) + { + if (i != 0) + sBuffer.append(","); + sBuffer.append(OUString::number(seq[i])); + } + return sBuffer.makeStringAndClear(); +} + +OUString lcl_IntListToString(const uno::Sequence<sal_Int32>& seq) +{ + OUStringBuffer sBuffer; + for (sal_Int32 i = 0; i != seq.getLength(); ++i) + { + if (i != 0) + sBuffer.append(","); + sBuffer.append(OUString::number(seq[i])); + } + return sBuffer.makeStringAndClear(); +} + +OUString lcl_IntListToString(const uno::Sequence<sal_Int64>& seq) +{ + OUStringBuffer sBuffer; + for (sal_Int32 i = 0; i != seq.getLength(); ++i) + { + if (i != 0) + sBuffer.append(","); + sBuffer.append(OUString::number(seq[i])); + } + return sBuffer.makeStringAndClear(); +} + +OUString lcl_DoubleListToString(const uno::Sequence<double>& seq) +{ + OUStringBuffer sBuffer; + for (sal_Int32 i = 0; i != seq.getLength(); ++i) + { + if (i != 0) + sBuffer.append(","); + sBuffer.append(OUString::number(seq[i])); + } + return sBuffer.makeStringAndClear(); +} } void CuiAboutConfigTabPage::FillItems(const Reference<XNameAccess>& xNameAccess, @@ -724,68 +772,69 @@ IMPL_LINK_NOARG(CuiAboutConfigTabPage, StandardHdl_Impl, weld::Button&, void) } else if (sPropertyType == "short-list") { - SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); - aNameDialog.SetCheckNameHdl(LINK(this, CuiAboutConfigTabPage, ValidNameHdl)); - if (aNameDialog.run() == RET_OK) + SvxListDialog aListDialog(m_pParent); + aListDialog.SetEntries(commaStringToSequence(sDialogValue)); + aListDialog.SetMode(ListMode::Int16); + if (aListDialog.run() == RET_OK) { - sDialogValue = aNameDialog.GetName(); - //create string sequence from comma separated string - //uno::Sequence< OUString > seqStr; - std::vector<OUString> seqStr = commaStringToSequence(sDialogValue); - - //create appropriate sequence with same size as string sequence + std::vector<OUString> seqStr = aListDialog.GetEntries(); uno::Sequence<sal_Int16> seqShort(seqStr.size()); - //convert all strings to appropriate type std::transform( seqStr.begin(), seqStr.end(), seqShort.getArray(), [](const auto& str) { return static_cast<sal_Int16>(str.toInt32()); }); pProperty->Value <<= seqShort; + sDialogValue = lcl_IntListToString(seqShort); bSaveChanges = true; } } else if (sPropertyType == "int-list") { - SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); - aNameDialog.SetCheckNameHdl(LINK(this, CuiAboutConfigTabPage, ValidNameHdl)); - if (aNameDialog.run() == RET_OK) + SvxListDialog aListDialog(m_pParent); + aListDialog.SetEntries(commaStringToSequence(sDialogValue)); + aListDialog.SetMode(ListMode::Int32); + if (aListDialog.run() == RET_OK) { - sDialogValue = aNameDialog.GetName(); - std::vector<OUString> seqStrLong = commaStringToSequence(sDialogValue); - - uno::Sequence<sal_Int32> seqLong(seqStrLong.size()); - std::transform(seqStrLong.begin(), seqStrLong.end(), seqLong.getArray(), - [](const auto& str) { return str.toInt32(); }); - pProperty->Value <<= seqLong; + std::vector<OUString> seqStr = aListDialog.GetEntries(); + uno::Sequence<sal_Int32> seq(seqStr.size()); + std::transform( + seqStr.begin(), seqStr.end(), seq.getArray(), + [](const auto& str) { return static_cast<sal_Int32>(str.toInt32()); }); + pProperty->Value <<= seq; + sDialogValue = lcl_IntListToString(seq); bSaveChanges = true; } } else if (sPropertyType == "long-list") { - SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); - aNameDialog.SetCheckNameHdl(LINK(this, CuiAboutConfigTabPage, ValidNameHdl)); - if (aNameDialog.run() == RET_OK) + SvxListDialog aListDialog(m_pParent); + aListDialog.SetEntries(commaStringToSequence(sDialogValue)); + aListDialog.SetMode(ListMode::Int64); + if (aListDialog.run() == RET_OK) { - sDialogValue = aNameDialog.GetName(); - std::vector<OUString> seqStrHyper = commaStringToSequence(sDialogValue); - uno::Sequence<sal_Int64> seqHyper(seqStrHyper.size()); - std::transform(seqStrHyper.begin(), seqStrHyper.end(), seqHyper.getArray(), - [](const auto& str) { return str.toInt64(); }); - pProperty->Value <<= seqHyper; + std::vector<OUString> seqStr = aListDialog.GetEntries(); + uno::Sequence<sal_Int64> seq(seqStr.size()); + std::transform( + seqStr.begin(), seqStr.end(), seq.getArray(), + [](const auto& str) { return static_cast<sal_Int64>(str.toInt32()); }); + pProperty->Value <<= seq; + sDialogValue = lcl_IntListToString(seq); bSaveChanges = true; } } else if (sPropertyType == "double-list") { - SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); - aNameDialog.SetCheckNameHdl(LINK(this, CuiAboutConfigTabPage, ValidNameHdl)); - if (aNameDialog.run() == RET_OK) + SvxListDialog aListDialog(m_pParent); + aListDialog.SetEntries(commaStringToSequence(sDialogValue)); + aListDialog.SetMode(ListMode::Double); + if (aListDialog.run() == RET_OK) { - sDialogValue = aNameDialog.GetName(); - std::vector<OUString> seqStrDoub = commaStringToSequence(sDialogValue); - uno::Sequence<double> seqDoub(seqStrDoub.size()); - std::transform(seqStrDoub.begin(), seqStrDoub.end(), seqDoub.getArray(), - [](const auto& str) { return str.toDouble(); }); - pProperty->Value <<= seqDoub; + std::vector<OUString> seqStr = aListDialog.GetEntries(); + uno::Sequence<double> seq(seqStr.size()); + std::transform( + seqStr.begin(), seqStr.end(), seq.getArray(), + [](const auto& str) { return static_cast<double>(str.toDouble()); }); + pProperty->Value <<= seq; + sDialogValue = lcl_DoubleListToString(seq); bSaveChanges = true; } } @@ -793,6 +842,7 @@ IMPL_LINK_NOARG(CuiAboutConfigTabPage, StandardHdl_Impl, weld::Button&, void) { SvxListDialog aListDialog(m_pParent); aListDialog.SetEntries(commaStringToSequence(sDialogValue)); + aListDialog.SetMode(ListMode::String); if (aListDialog.run() == RET_OK) { auto seq = comphelper::containerToSequence(aListDialog.GetEntries()); diff --git a/cui/source/options/optaboutconfig.hxx b/cui/source/options/optaboutconfig.hxx index 0175ee1301ca..17aea23a997e 100644 --- a/cui/source/options/optaboutconfig.hxx +++ b/cui/source/options/optaboutconfig.hxx @@ -65,6 +65,7 @@ private: DECL_LINK(ExpandingHdl_Impl, const weld::TreeIter&, bool); DECL_LINK(HeaderBarClick, int, void); DECL_STATIC_LINK(CuiAboutConfigTabPage, ValidNameHdl, SvxNameDialog&, bool); + DECL_LINK(EditNumberHdl, SvxListDialog&, OUString); public: explicit CuiAboutConfigTabPage(weld::Window* pParent); diff --git a/include/cui/dlgname.hxx b/include/cui/dlgname.hxx index eb3ac6b3ec17..e06c56c0f010 100644 --- a/include/cui/dlgname.hxx +++ b/include/cui/dlgname.hxx @@ -146,10 +146,21 @@ public: bool IsDecorative() const { return m_xDecorativeCB->get_active(); } }; +enum class ListMode +{ + String, + Int64, + Int32, + Int16, + Double +}; + /** Generic dialog to edit lists */ class SvxListDialog : public weld::GenericDialogController { private: + ListMode m_aMode; + Link<SvxListDialog&, OUString> m_aEditHdl; std::unique_ptr<weld::TreeView> m_xList; std::unique_ptr<weld::Button> m_xAddBtn; std::unique_ptr<weld::Button> m_xRemoveBtn; @@ -167,9 +178,10 @@ public: explicit SvxListDialog(weld::Window* pParent); virtual ~SvxListDialog() override; - std::vector<OUString> GetEntries() const; + std::vector<OUString> GetEntries(); void SetEntries(std::vector<OUString> const& rParams); void EditEntry(); + void SetMode(ListMode aMode); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |