diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-16 08:19:55 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-16 15:26:22 +0200 |
commit | 92254b0a2feeb6326796e3f93c289db829eed896 (patch) | |
tree | 76bac36ca9c45e5f258f7d39d918a64432d49c5a /sw/source | |
parent | e6cca743556c2135d5e381cdbd883e937221eef9 (diff) |
sw content controls, dropdown: edit list items in the properties dialog
- add a weld::TreeView to show existing display name - value pairs
- add a button to add a new list item, together with a new
SwContentControlListItemDlg to specify the list item properties +
write the changed list back to the doc model
Change-Id: I9243be84eb0af65437eccfb48c6780787609bc68
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134379
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/txtnode/attrcontentcontrol.cxx | 5 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.cxx | 14 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.hxx | 24 | ||||
-rw-r--r-- | sw/source/ui/misc/contentcontroldlg.cxx | 72 | ||||
-rw-r--r-- | sw/source/ui/misc/contentcontrollistitemdlg.cxx | 46 | ||||
-rw-r--r-- | sw/source/uibase/inc/contentcontroldlg.hxx | 7 | ||||
-rw-r--r-- | sw/source/uibase/inc/contentcontrollistitemdlg.hxx | 40 |
7 files changed, 208 insertions, 0 deletions
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx index fd98947e3458..c249adffd819 100644 --- a/sw/source/core/txtnode/attrcontentcontrol.cxx +++ b/sw/source/core/txtnode/attrcontentcontrol.cxx @@ -256,6 +256,11 @@ OUString SwContentControlListItem::ToString() const return m_aValue; } +bool SwContentControlListItem::operator==(const SwContentControlListItem& rOther) const +{ + return m_aDisplayText == rOther.m_aDisplayText && m_aValue == rOther.m_aValue; +} + void SwContentControlListItem::ItemsToAny(const std::vector<SwContentControlListItem>& rItems, uno::Any& rVal) { diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx index 01795a8ff001..cac21458ef9f 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -34,6 +34,7 @@ #include <chrdlg.hxx> #include <colwd.hxx> #include <contentcontroldlg.hxx> +#include <contentcontrollistitemdlg.hxx> #include <convert.hxx> #include <cption.hxx> #include <dbinsdlg.hxx> @@ -208,6 +209,11 @@ short AbstractSwRenameXNamedDlg_Impl::Execute() return m_xDlg->run(); } +short AbstractSwContentControlListItemDlg_Impl::Execute() +{ + return m_xDlg->run(); +} + short AbstractSwModalRedlineAcceptDlg_Impl::Execute() { return m_xDlg->run(); @@ -841,6 +847,14 @@ VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwContentControlDl return VclPtr<AbstractGenericDialog_Impl>::Create(std::make_shared<SwContentControlDlg>(pParent, rSh)); } +VclPtr<AbstractSwContentControlListItemDlg> +SwAbstractDialogFactory_Impl::CreateSwContentControlListItemDlg(weld::Window* pParent, + SwContentControlListItem& rItem) +{ + return VclPtr<AbstractSwContentControlListItemDlg_Impl>::Create( + std::make_unique<SwContentControlListItemDlg>(pParent, rItem)); +} + std::shared_ptr<AbstractSwBreakDlg> SwAbstractDialogFactory_Impl::CreateSwBreakDlg(weld::Window* pParent, SwWrtShell &rSh) { return std::make_shared<AbstractSwBreakDlg_Impl>(std::make_unique<SwBreakDlg>(pParent, rSh)); diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx index 6eb68355762c..8690d9db8129 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -25,6 +25,7 @@ #include <ascfldlg.hxx> #include <cnttab.hxx> #include <colwd.hxx> +#include <contentcontrollistitemdlg.hxx> #include <convert.hxx> #include <DateFormFieldDialog.hxx> #include <dbinsdlg.hxx> @@ -409,6 +410,24 @@ public: css::uno::Reference< css::container::XNameAccess > & xThird ) override; }; +/** + * Implementation of AbstractSwContentControlListItemDlg, that is only visible to + * SwAbstractDialogFactory_Impl::CreateSwContentControlListItemDlg(). + */ +class AbstractSwContentControlListItemDlg_Impl : public AbstractSwContentControlListItemDlg +{ + std::unique_ptr<SwContentControlListItemDlg> m_xDlg; + +public: + explicit AbstractSwContentControlListItemDlg_Impl( + std::unique_ptr<SwContentControlListItemDlg> xDlg) + : m_xDlg(std::move(xDlg)) + { + } + + short Execute() override; +}; + class AbstractSwModalRedlineAcceptDlg_Impl : public AbstractSwModalRedlineAcceptDlg { std::unique_ptr<SwModalRedlineAcceptDlg> m_xDlg; @@ -659,6 +678,11 @@ public: SvStream* pStream) override; virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window *pParent, SwWrtShell &rSh) override; virtual VclPtr<VclAbstractDialog> CreateSwContentControlDlg(weld::Window *pParent, SwWrtShell &rSh) override; + + VclPtr<AbstractSwContentControlListItemDlg> + CreateSwContentControlListItemDlg(weld::Window* pParent, + SwContentControlListItem& rItem) override; + virtual std::shared_ptr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) override; virtual VclPtr<VclAbstractDialog> CreateSwChangeDBDlg(SwView& rVw) override; virtual VclPtr<SfxAbstractTabDialog> CreateSwCharDlg(weld::Window* pParent, SwView& pVw, const SfxItemSet& rCoreSet, diff --git a/sw/source/ui/misc/contentcontroldlg.cxx b/sw/source/ui/misc/contentcontroldlg.cxx index d18c3077f24d..7a066fb80d22 100644 --- a/sw/source/ui/misc/contentcontroldlg.cxx +++ b/sw/source/ui/misc/contentcontroldlg.cxx @@ -25,6 +25,7 @@ #include <ndtxt.hxx> #include <textcontentcontrol.hxx> #include <IDocumentState.hxx> +#include <swuiexp.hxx> using namespace com::sun::star; @@ -33,10 +34,19 @@ SwContentControlDlg::SwContentControlDlg(weld::Window* pParent, SwWrtShell& rWrt "ContentControlDialog") , m_rWrtShell(rWrtShell) , m_xShowingPlaceHolderCB(m_xBuilder->weld_check_button("showing_place_holder")) + , m_xListItemsFrame(m_xBuilder->weld_frame("listitemsframe")) + , m_xListItems(m_xBuilder->weld_tree_view("listitems")) + , m_xListItemButtons(m_xBuilder->weld_box("listitembuttons")) + , m_xInsertBtn(m_xBuilder->weld_button("add")) , m_xOk(m_xBuilder->weld_button("ok")) { m_xOk->connect_clicked(LINK(this, SwContentControlDlg, OkHdl)); + // Only 2 items would be visible by default. + m_xListItems->set_size_request(-1, m_xListItems->get_height_rows(8)); + + m_xInsertBtn->connect_clicked(LINK(this, SwContentControlDlg, InsertHdl)); + const SwPosition* pStart = rWrtShell.GetCursor()->Start(); SwTextNode* pTextNode = pStart->nNode.GetNode().GetTextNode(); if (!pTextNode) @@ -59,12 +69,33 @@ SwContentControlDlg::SwContentControlDlg(weld::Window* pParent, SwWrtShell& rWrt TriState eShowingPlaceHolder = bShowingPlaceHolder ? TRISTATE_TRUE : TRISTATE_FALSE; m_xShowingPlaceHolderCB->set_state(eShowingPlaceHolder); m_xShowingPlaceHolderCB->save_state(); + + if (m_pContentControl->HasListItems()) + { + for (const auto& rListItem : m_pContentControl->GetListItems()) + { + int nRow = m_xListItems->n_children(); + m_xListItems->append_text(rListItem.m_aDisplayText); + m_xListItems->set_text(nRow, rListItem.m_aValue, 1); + } + m_aSavedListItems = m_pContentControl->GetListItems(); + } + else + { + m_xListItemsFrame->set_visible(false); + m_xListItemButtons->set_visible(false); + } } SwContentControlDlg::~SwContentControlDlg() {} IMPL_LINK_NOARG(SwContentControlDlg, OkHdl, weld::Button&, void) { + if (!m_pContentControl) + { + return; + } + bool bChanged = false; if (m_xShowingPlaceHolderCB->get_state_changed_from_saved()) { @@ -73,6 +104,20 @@ IMPL_LINK_NOARG(SwContentControlDlg, OkHdl, weld::Button&, void) bChanged = true; } + std::vector<SwContentControlListItem> aItems; + for (int i = 0; i < m_xListItems->n_children(); ++i) + { + SwContentControlListItem aItem; + aItem.m_aDisplayText = m_xListItems->get_text(i, 0); + aItem.m_aValue = m_xListItems->get_text(i, 1); + aItems.push_back(aItem); + } + if (aItems != m_aSavedListItems) + { + m_pContentControl->SetListItems(aItems); + bChanged = true; + } + if (bChanged) { m_rWrtShell.GetDoc()->getIDocumentState().SetModified(); @@ -81,4 +126,31 @@ IMPL_LINK_NOARG(SwContentControlDlg, OkHdl, weld::Button&, void) m_xDialog->response(RET_OK); } +IMPL_LINK_NOARG(SwContentControlDlg, InsertHdl, weld::Button&, void) +{ + SwContentControlListItem aItem; + SwAbstractDialogFactory& rFact = swui::GetFactory(); + ScopedVclPtr<VclAbstractDialog> pDlg( + rFact.CreateSwContentControlListItemDlg(m_xDialog.get(), aItem)); + if (!pDlg->Execute()) + { + return; + } + + if (aItem.m_aDisplayText.isEmpty() && aItem.m_aValue.isEmpty()) + { + // Maintain the invariant that value can't be empty. + return; + } + + if (aItem.m_aValue.isEmpty()) + { + aItem.m_aValue = aItem.m_aDisplayText; + } + + int nRow = m_xListItems->n_children(); + m_xListItems->append_text(aItem.m_aDisplayText); + m_xListItems->set_text(nRow, aItem.m_aValue, 1); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/misc/contentcontrollistitemdlg.cxx b/sw/source/ui/misc/contentcontrollistitemdlg.cxx new file mode 100644 index 000000000000..ca6716b7b770 --- /dev/null +++ b/sw/source/ui/misc/contentcontrollistitemdlg.cxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <contentcontrollistitemdlg.hxx> + +#include <formatcontentcontrol.hxx> + +using namespace com::sun::star; + +SwContentControlListItemDlg::SwContentControlListItemDlg(weld::Widget* pParent, + SwContentControlListItem& rItem) + : GenericDialogController(pParent, "modules/swriter/ui/contentcontrollistitemdlg.ui", + "ContentControlListItemDialog") + , m_rItem(rItem) + , m_xDisplayNameED(m_xBuilder->weld_entry("displayname")) + , m_xValueED(m_xBuilder->weld_entry("value")) + , m_xOk(m_xBuilder->weld_button("ok")) +{ + m_xOk->connect_clicked(LINK(this, SwContentControlListItemDlg, OkHdl)); +} + +IMPL_LINK_NOARG(SwContentControlListItemDlg, OkHdl, weld::Button&, void) +{ + m_rItem.m_aDisplayText = m_xDisplayNameED->get_text(); + m_rItem.m_aValue = m_xValueED->get_text(); + + m_xDialog->response(RET_OK); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/inc/contentcontroldlg.hxx b/sw/source/uibase/inc/contentcontroldlg.hxx index 6b354a39e7c4..45a6659b4fbf 100644 --- a/sw/source/uibase/inc/contentcontroldlg.hxx +++ b/sw/source/uibase/inc/contentcontroldlg.hxx @@ -23,6 +23,7 @@ class SwWrtShell; class SwContentControl; +class SwContentControlListItem; /** * The content control dialog allows editing the properties of the content control under the @@ -32,10 +33,16 @@ class SwContentControlDlg final : public SfxDialogController { SwWrtShell& m_rWrtShell; std::shared_ptr<SwContentControl> m_pContentControl; + std::vector<SwContentControlListItem> m_aSavedListItems; std::unique_ptr<weld::CheckButton> m_xShowingPlaceHolderCB; + std::unique_ptr<weld::Frame> m_xListItemsFrame; + std::unique_ptr<weld::TreeView> m_xListItems; + std::unique_ptr<weld::Box> m_xListItemButtons; + std::unique_ptr<weld::Button> m_xInsertBtn; std::unique_ptr<weld::Button> m_xOk; + DECL_LINK(InsertHdl, weld::Button&, void); DECL_LINK(OkHdl, weld::Button&, void); public: diff --git a/sw/source/uibase/inc/contentcontrollistitemdlg.hxx b/sw/source/uibase/inc/contentcontrollistitemdlg.hxx new file mode 100644 index 000000000000..2367de4847b4 --- /dev/null +++ b/sw/source/uibase/inc/contentcontrollistitemdlg.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <vcl/weld.hxx> + +class SwContentControlListItem; + +/// Edits the properties of a sing list item in a (drop-down) content control. +class SwContentControlListItemDlg final : public weld::GenericDialogController +{ + SwContentControlListItem& m_rItem; + + std::unique_ptr<weld::Entry> m_xDisplayNameED; + std::unique_ptr<weld::Entry> m_xValueED; + std::unique_ptr<weld::Button> m_xOk; + + DECL_LINK(OkHdl, weld::Button&, void); + +public: + SwContentControlListItemDlg(weld::Widget* pParent, SwContentControlListItem& rItem); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |