From 847db3fa1244c2707e1966d3e6579258bb6d8924 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 16 Nov 2023 21:33:25 +0100 Subject: tdf#157438 Make string lists editable in expert config Change-Id: Ia8b8553d547e760c18624c5c599951523b74ac82 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159523 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- cui/UIConfig_cui.mk | 1 + cui/source/dialogs/dlgname.cxx | 109 ++++++++++++++++ cui/source/options/optaboutconfig.cxx | 37 +++--- cui/uiconfig/ui/listdialog.ui | 231 ++++++++++++++++++++++++++++++++++ 4 files changed, 363 insertions(+), 15 deletions(-) create mode 100644 cui/uiconfig/ui/listdialog.ui (limited to 'cui') diff --git a/cui/UIConfig_cui.mk b/cui/UIConfig_cui.mk index 97a4a56f3ecc..10acd83c8c39 100644 --- a/cui/UIConfig_cui.mk +++ b/cui/UIConfig_cui.mk @@ -113,6 +113,7 @@ $(eval $(call gb_UIConfig_add_uifiles,cui,\ cui/uiconfig/ui/linetabpage \ cui/uiconfig/ui/lineendstabpage \ cui/uiconfig/ui/linestyletabpage \ + cui/uiconfig/ui/listdialog \ cui/uiconfig/ui/macroassigndialog \ cui/uiconfig/ui/macroassignpage \ cui/uiconfig/ui/macroselectordialog \ diff --git a/cui/source/dialogs/dlgname.cxx b/cui/source/dialogs/dlgname.cxx index a96b59290bbd..a06833bb6ce6 100644 --- a/cui/source/dialogs/dlgname.cxx +++ b/cui/source/dialogs/dlgname.cxx @@ -19,6 +19,8 @@ #include +#include + /************************************************************************* |* |* Dialog for editing a name @@ -144,4 +146,111 @@ IMPL_LINK_NOARG(SvxObjectTitleDescDialog, DecorativeHdl, weld::Toggleable&, void m_xDescriptionFT->set_sensitive(bEnable); } +SvxListDialog::SvxListDialog(weld::Window* pParent) + : GenericDialogController(pParent, "cui/ui/listdialog.ui", "ListDialog") + , m_xList(m_xBuilder->weld_tree_view("assignlist")) + , m_xAddBtn(m_xBuilder->weld_button("addbtn")) + , m_xRemoveBtn(m_xBuilder->weld_button("removebtn")) + , m_xEditBtn(m_xBuilder->weld_button("editbtn")) +{ + m_xList->set_size_request(m_xList->get_approximate_digit_width() * 54, + m_xList->get_height_rows(6)); + m_xAddBtn->connect_clicked(LINK(this, SvxListDialog, AddHdl_Impl)); + m_xRemoveBtn->connect_clicked(LINK(this, SvxListDialog, RemoveHdl_Impl)); + m_xEditBtn->connect_clicked(LINK(this, SvxListDialog, EditHdl_Impl)); + m_xList->connect_changed(LINK(this, SvxListDialog, SelectHdl_Impl)); + m_xList->connect_row_activated(LINK(this, SvxListDialog, DblClickHdl_Impl)); + + SelectionChanged(); +} + +SvxListDialog::~SvxListDialog() {} + +IMPL_LINK_NOARG(SvxListDialog, AddHdl_Impl, weld::Button&, void) +{ + SvxNameDialog aNameDlg(m_xDialog.get(), "", "blabla"); + + if (!aNameDlg.run()) + return; + OUString sNewText = comphelper::string::strip(aNameDlg.GetName(), ' '); + if (!sNewText.isEmpty()) + { + m_xList->insert_text(-1, sNewText); + m_xList->select(-1); + } +} + +IMPL_LINK_NOARG(SvxListDialog, EditHdl_Impl, weld::Button&, void) { EditEntry(); } + +IMPL_LINK_NOARG(SvxListDialog, SelectHdl_Impl, weld::TreeView&, void) { SelectionChanged(); } + +IMPL_LINK_NOARG(SvxListDialog, DblClickHdl_Impl, weld::TreeView&, bool) +{ + EditEntry(); + return true; +} + +IMPL_LINK_NOARG(SvxListDialog, RemoveHdl_Impl, weld::Button&, void) +{ + int nPos = m_xList->get_selected_index(); + if (nPos == -1) + return; + m_xList->remove(nPos); + int nCount = m_xList->n_children(); + if (nCount) + { + if (nPos >= nCount) + nPos = nCount - 1; + m_xList->select(nPos); + } + SelectionChanged(); +} + +void SvxListDialog::SelectionChanged() +{ + bool bEnable = m_xList->get_selected_index() != -1; + m_xRemoveBtn->set_sensitive(bEnable); + m_xEditBtn->set_sensitive(bEnable); +} + +std::vector SvxListDialog::GetEntries() const +{ + int nCount = m_xList->n_children(); + std::vector aList; + aList.reserve(nCount); + for (int i = 0; i < nCount; ++i) + aList.push_back(m_xList->get_text(i)); + return aList; +} + +void SvxListDialog::SetEntries(std::vector const& rEntries) +{ + m_xList->clear(); + for (auto const& sEntry : rEntries) + { + m_xList->append_text(sEntry); + } + SelectionChanged(); +} + +void SvxListDialog::EditEntry() +{ + int nPos = m_xList->get_selected_index(); + if (nPos == -1) + return; + + OUString sOldText(m_xList->get_selected_text()); + SvxNameDialog aNameDlg(m_xDialog.get(), sOldText, "blabla"); + + if (!aNameDlg.run()) + return; + OUString sNewText = comphelper::string::strip(aNameDlg.GetName(), ' '); + if (!sNewText.isEmpty() && sNewText != sOldText) + { + m_xList->remove(nPos); + m_xList->insert_text(nPos, sNewText); + m_xList->select(nPos); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/options/optaboutconfig.cxx b/cui/source/options/optaboutconfig.cxx index 362af44cfd7d..bb002d55d0d1 100644 --- a/cui/source/options/optaboutconfig.cxx +++ b/cui/source/options/optaboutconfig.cxx @@ -245,6 +245,21 @@ void CuiAboutConfigTabPage::FillItemSet() } } +namespace +{ +OUString lcl_StringListToString(const uno::Sequence& seq) +{ + OUStringBuffer sBuffer; + for (sal_Int32 i = 0; i != seq.getLength(); ++i) + { + if (i != 0) + sBuffer.append(","); + sBuffer.append(seq[i]); + } + return sBuffer.makeStringAndClear(); +} +} + void CuiAboutConfigTabPage::FillItems(const Reference& xNameAccess, const weld::TreeIter* pParentEntry, int lineage, bool bLoadAll) @@ -484,15 +499,7 @@ void CuiAboutConfigTabPage::FillItems(const Reference& xNameAccess, } else if (sType == "oor:string-list") { - uno::Sequence seq = aNode.get>(); - for (sal_Int32 j = 0; j != seq.getLength(); ++j) - { - if (j != 0) - { - sValue.append(","); - } - sValue.append(seq[j]); - } + sValue = lcl_StringListToString(aNode.get>()); sType = "string-list"; } else if (sType == "oor:hexBinary-list") @@ -778,13 +785,13 @@ IMPL_LINK_NOARG(CuiAboutConfigTabPage, StandardHdl_Impl, weld::Button&, void) } else if (sPropertyType == "string-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)); + if (aListDialog.run() == RET_OK) { - sDialogValue = aNameDialog.GetName(); - pProperty->Value - <<= comphelper::containerToSequence(commaStringToSequence(sDialogValue)); + auto seq = comphelper::containerToSequence(aListDialog.GetEntries()); + sDialogValue = lcl_StringListToString(seq); + pProperty->Value <<= seq; bSaveChanges = true; } } diff --git a/cui/uiconfig/ui/listdialog.ui b/cui/uiconfig/ui/listdialog.ui new file mode 100644 index 000000000000..18fffa18640d --- /dev/null +++ b/cui/uiconfig/ui/listdialog.ui @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + False + 6 + Edit List + True + 0 + 0 + dialog + + + False + True + True + vertical + 12 + + + False + end + + + _OK + True + True + True + True + True + True + + + False + True + 0 + + + + + _Cancel + True + True + True + True + + + False + True + 1 + + + + + _Help + True + True + True + True + + + False + True + 2 + True + + + + + False + True + end + 0 + + + + + True + False + True + True + 6 + + + + True + False + True + True + 6 + 6 + + + True + True + True + True + in + + + True + True + True + liststore1 + False + False + 0 + False + + + + + + + + + 0 + + + + + + + + + 0 + 1 + + + + + True + False + vertical + 6 + + + _Add + True + True + True + True + + + False + True + 0 + + + + + _Edit + True + True + True + start + True + + + False + True + 1 + + + + + _Remove + True + True + True + start + True + + + False + True + 2 + + + + + 1 + 1 + + + + + True + False + True + assignlist + 0 + + + 0 + 0 + 2 + + + + + False + True + 1 + + + + + False + True + 1 + + + + + + ok + cancel + help + + + -- cgit