2019-08-18 16:23:51 +02:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <DiagramDialog.hxx>
|
|
|
|
|
2019-08-30 10:20:38 +02:00
|
|
|
#include <comphelper/dispatchcommand.hxx>
|
2019-08-18 16:23:51 +02:00
|
|
|
#include <svx/DiagramDataInterface.hxx>
|
2019-08-30 10:20:38 +02:00
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
2019-08-18 16:23:51 +02:00
|
|
|
|
|
|
|
DiagramDialog::DiagramDialog(weld::Window* pWindow,
|
|
|
|
std::shared_ptr<DiagramDataInterface> pDiagramData)
|
|
|
|
: GenericDialogController(pWindow, "cui/ui/diagramdialog.ui", "DiagramDialog")
|
|
|
|
, mpDiagramData(pDiagramData)
|
|
|
|
, mpBtnOk(m_xBuilder->weld_button("btnOk"))
|
|
|
|
, mpBtnCancel(m_xBuilder->weld_button("btnCancel"))
|
2019-08-30 10:20:38 +02:00
|
|
|
, mpBtnAdd(m_xBuilder->weld_button("btnAdd"))
|
2019-09-20 12:53:45 +02:00
|
|
|
, mpBtnRemove(m_xBuilder->weld_button("btnRemove"))
|
2019-08-27 08:47:26 +02:00
|
|
|
, mpTreeDiagram(m_xBuilder->weld_tree_view("treeDiagram"))
|
2019-08-30 10:20:38 +02:00
|
|
|
, mpTextAdd(m_xBuilder->weld_text_view("textAdd"))
|
2019-08-18 16:23:51 +02:00
|
|
|
{
|
2019-08-30 10:20:38 +02:00
|
|
|
mpBtnAdd->connect_clicked(LINK(this, DiagramDialog, OnAddClick));
|
2019-09-20 12:53:45 +02:00
|
|
|
mpBtnRemove->connect_clicked(LINK(this, DiagramDialog, OnRemoveClick));
|
2019-08-30 10:20:38 +02:00
|
|
|
|
2019-08-27 08:47:26 +02:00
|
|
|
populateTree(nullptr, OUString());
|
|
|
|
|
|
|
|
// expand all items
|
|
|
|
weld::TreeView* pTreeDiagram = mpTreeDiagram.get();
|
|
|
|
pTreeDiagram->all_foreach([pTreeDiagram](weld::TreeIter& rEntry) {
|
|
|
|
pTreeDiagram->expand_row(rEntry);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:20:38 +02:00
|
|
|
IMPL_LINK_NOARG(DiagramDialog, OnAddClick, weld::Button&, void)
|
|
|
|
{
|
|
|
|
OUString sText = mpTextAdd->get_text();
|
2022-02-18 16:07:28 +01:00
|
|
|
static bool bAdvancedSmartArt(nullptr != getenv("SAL_ENABLE_ADVANCED_SMART_ART"));
|
|
|
|
|
2019-08-30 10:20:38 +02:00
|
|
|
if (!sText.isEmpty())
|
|
|
|
{
|
2019-09-20 12:53:45 +02:00
|
|
|
OUString sNodeId = mpDiagramData->addNode(sText);
|
2019-08-30 10:20:38 +02:00
|
|
|
std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
|
2020-06-05 10:57:25 +01:00
|
|
|
mpTreeDiagram->insert(nullptr, -1, &sText, &sNodeId, nullptr, nullptr, false, pEntry.get());
|
2019-08-30 10:20:38 +02:00
|
|
|
mpTreeDiagram->select(*pEntry);
|
|
|
|
comphelper::dispatchCommand(".uno:RegenerateDiagram", {});
|
2022-02-18 16:07:28 +01:00
|
|
|
}
|
|
|
|
else if (bAdvancedSmartArt)
|
|
|
|
{
|
|
|
|
// For test purposes re-layout without change
|
|
|
|
comphelper::dispatchCommand(".uno:RegenerateDiagram", {});
|
2019-08-30 10:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-20 12:53:45 +02:00
|
|
|
IMPL_LINK_NOARG(DiagramDialog, OnRemoveClick, weld::Button&, void)
|
|
|
|
{
|
|
|
|
std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
|
|
|
|
if (mpTreeDiagram->get_selected(pEntry.get()))
|
|
|
|
{
|
|
|
|
if (mpDiagramData->removeNode(mpTreeDiagram->get_id(*pEntry)))
|
|
|
|
{
|
|
|
|
mpTreeDiagram->remove(*pEntry);
|
|
|
|
comphelper::dispatchCommand(".uno:RegenerateDiagram", {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:07:56 +02:00
|
|
|
void DiagramDialog::populateTree(const weld::TreeIter* pParent, const OUString& rParentId)
|
2019-08-27 08:47:26 +02:00
|
|
|
{
|
|
|
|
auto aItems = mpDiagramData->getChildren(rParentId);
|
|
|
|
for (auto& aItem : aItems)
|
|
|
|
{
|
|
|
|
std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
|
2020-06-05 10:57:25 +01:00
|
|
|
mpTreeDiagram->insert(pParent, -1, &aItem.second, &aItem.first, nullptr, nullptr, false,
|
|
|
|
pEntry.get());
|
2019-08-27 08:47:26 +02:00
|
|
|
populateTree(pEntry.get(), aItem.first);
|
|
|
|
}
|
2019-08-18 16:23:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DiagramDialog::~DiagramDialog() {}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|