/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * 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/.
*/
void ScriptContainersListBox::Remove(const weld::TreeIter* pEntryIter, bool bRemoveEntryIter)
{ // remove all children of pEntryIter
std::unique_ptr<weld::TreeIter> xIter = m_xTreeView->make_iterator(pEntryIter); if (m_xTreeView->iter_has_child(*pEntryIter) && m_xTreeView->iter_children(*xIter))
{ // set xIter to the last child of pEntryIter do
{
std::unique_ptr<weld::TreeIter> xChildIter = m_xTreeView->make_iterator(xIter.get()); while (m_xTreeView->iter_next_sibling(*xChildIter))
m_xTreeView->copy_iterator(*xChildIter, *xIter);
} while (m_xTreeView->iter_has_child(*xIter) && m_xTreeView->iter_children(*xIter));
// children must be removed from the tree in reverse order
std::unique_ptr<weld::TreeIter> xRemoveIter = m_xTreeView->make_iterator(); while (m_xTreeView->iter_compare(*xIter, *pEntryIter) != 0)
{
m_xTreeView->copy_iterator(*xIter, *xRemoveIter);
(void)m_xTreeView->iter_previous(*xIter);
ScriptContainerInfo* pScriptContainerInfo
= weld::fromId<ScriptContainerInfo*>(m_xTreeView->get_id(*xRemoveIter)); if (pScriptContainerInfo)
{ if (pScriptContainerInfo->pBrowseNode)
pScriptContainerInfo->pBrowseNode->release(); delete pScriptContainerInfo;
}
m_xTreeView->remove(*xRemoveIter);
}
}
// maybe remove the entry if (bRemoveEntryIter)
{
ScriptContainerInfo* pScriptContainerInfo
= weld::fromId<ScriptContainerInfo*>(m_xTreeView->get_id(*pEntryIter)); if (pScriptContainerInfo)
{ if (pScriptContainerInfo->pBrowseNode)
pScriptContainerInfo->pBrowseNode->release(); delete pScriptContainerInfo;
}
m_xTreeView->remove(*pEntryIter);
}
}
if (xNode->hasChildNodes())
{ // tdf#120362: Don't ask to enable disabled Java when filling script list
css::uno::ContextLayer layer(comphelper::NoEnableJavaInteractionContext());
//To mimic current starbasic behaviour we //need to make sure that only the current document //is displayed in the config tree. Tests below //set the bDisplay flag to FALSE if the current //node is a first level child of the Root and is NOT //either the current document, user or share // // NOTE: This approach doesn't work for open documents with the same name, for example // Untitled 1.odt and Untitled 1.ods will both be included as root containers.
OUString currentDocTitle; if (css::uno::Reference<css::frame::XController> xController = m_xFrame->getController();
xController.is())
{
css::uno::Reference<css::frame::XModel> xModel = xController->getModel(); if (xModel.is())
currentDocTitle = comphelper::DocumentInfo::getDocumentTitle(xModel);
}
const css::uno::Sequence<css::uno::Reference<css::script::browse::XBrowseNode>> children
= xNode->getChildNodes(); for (css::uno::Reference<css::script::browse::XBrowseNode> const& theChild : children)
{ if (!theChild.is()) continue;
if (theChild->getType() == css::script::browse::BrowseNodeTypes::SCRIPT) // we only want containers in this list box continue; if (theChild->getName() == uno_packages) continue;
OUString uiName = theChild->getName(); if (bIsRootNode)
{ if (uiName == user)
{
uiName = CuiResId(RID_CUISTR_MYMACROS);
} elseif (uiName == share)
{
uiName = CuiResId(RID_CUISTR_PRODMACROS);
} elseif (uiName != currentDocTitle)
{ // as noted above // NOTE: This approach doesn't work for open documents with the same name, for // example, Untitled 1.odt and Untitled 1.ods will both be included as root // containers. continue;
}
}
// We call acquire on the XBrowseNode so that it does not // get autodestructed and become invalid when accessed later.
theChild->acquire();
bool bChildOnDemand = false;
if (theChild->hasChildNodes())
{ const css::uno::Sequence<css::uno::Reference<css::script::browse::XBrowseNode>>
grandchildren = theChild->getChildNodes(); for (constauto& rxNode : grandchildren)
{ if (!rxNode.is()) continue; if (rxNode->getType() == css::script::browse::BrowseNodeTypes::CONTAINER)
{
bChildOnDemand = true; break;
}
}
}
// set password and linked image only for Basic libraries if (m_xTreeView->get_iter_depth(*xNewEntryIter) == 2) // library
{
std::unique_ptr<weld::TreeIter> xLanguageIter
= m_xTreeView->make_iterator(xNewEntryIter.get());
m_xTreeView->iter_parent(*xLanguageIter); if (m_xTreeView->get_text(*xLanguageIter) == "Basic")
{
basctl::ScriptDocument aDocument = GetScriptDocument(xNewEntryIter.get()); if (!aDocument.isAlive()) return;
css::uno::Reference<css::script::XLibraryContainer2> xModLibContainer(
aDocument.getLibraryContainer(basctl::E_SCRIPTS)); if (xModLibContainer.is() && xModLibContainer->hasByName(aLibName))
{
css::uno::Reference<css::script::XLibraryContainerPassword> xPasswd(
xModLibContainer, css::uno::UNO_QUERY); if (xPasswd.is() && xPasswd->isLibraryPasswordProtected(aLibName))
{ // password protected
m_xTreeView->set_image(*xNewEntryIter, RID_CUIBMP_LOCKED);
} elseif (xModLibContainer->isLibraryLink(aLibName))
{ // linked
m_xTreeView->set_image(*xNewEntryIter, RID_CUIBMP_LINKED);
}
}
}
} if (pRet)
pRet = xNewEntryIter.get();
}
// fills the scripts list box // inspired by code in void CommandCategoryListBox::addChildren // cui/source/customize/CommandCategoryListBox.cxx // and void CuiConfigGroupListBox::GroupSelected() // cui/source/customize/cfgutil.cxx void ScriptContainersListBox::ScriptContainerSelected()
{
std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator()); if (!m_xTreeView->get_selected(xIter.get())) return;
if (!m_xTreeView->iter_has_child(*xIter) && !m_xTreeView->get_children_on_demand(*xIter))
{ // maybe the browse node has children and those children are most likely script nodes
ScriptContainerInfo* pScriptContainerInfo
= weld::fromId<ScriptContainerInfo*>(m_xTreeView->get_id(*xIter));
css::uno::Reference<css::script::browse::XBrowseNode> xBrowseNode(
pScriptContainerInfo->pBrowseNode); try
{ if (xBrowseNode->hasChildNodes())
{ const css::uno::Sequence<css::uno::Reference<css::script::browse::XBrowseNode>>
children = xBrowseNode->getChildNodes();
for (const css::uno::Reference<css::script::browse::XBrowseNode>& childNode :
children)
{ if (!childNode.is()) continue;
if (childNode->getType() == css::script::browse::BrowseNodeTypes::SCRIPT)
{
css::uno::Reference<css::beans::XPropertySet> xPropSet(childNode,
css::uno::UNO_QUERY); if (!xPropSet.is())
{ continue;
}
OUString sURI; try
{
css::uno::Any value = xPropSet->getPropertyValue(u"URI"_ustr);
value >>= sURI;
} catch (css::uno::Exception&)
{ // do nothing, the URI will be empty
}
OUString sDescription; try
{
css::uno::Any value = xPropSet->getPropertyValue(u"Description"_ustr);
value >>= sDescription;
} catch (css::uno::Exception&)
{ // do nothing, the description will be empty
}
childNode->acquire();
m_pScriptsListBox->aArr.push_back(
std::make_unique<ScriptInfo>(childNode.get(), sURI, sDescription));
OUString sId(weld::toId(m_pScriptsListBox->aArr.back().get()));
m_pScriptsListBox->append(sId, childNode->getName(), RID_CUIBMP_MACRO);
}
}
}
} catch (css::uno::RuntimeException&)
{ // do nothing, the entry will not be displayed in the UI
}
}
m_pScriptsListBox->thaw();
if (m_pScriptsListBox->n_children())
m_pScriptsListBox->select(0);
}
// for use to restore the script container tree scroll position int nOldScrollPos = rScriptContainersTreeView.vadjustment_get_value();
// save the current path of the selection in the script containers list for reselection // and the selected entry in the scripts list box
OUString sScriptContainersListBoxSelectedEntryPath;
OUString sScriptsListBoxSelectedEntry; if (rScriptContainersTreeView.get_selected(xIter.get()))
{
sScriptContainersListBoxSelectedEntryPath = get_path(xIter.get());
sScriptsListBoxSelectedEntry = m_xScriptsListBox->GetSelectedScriptName();
}
// create a set containing paths for use to restore the script containers tree expand state
std::unordered_set<OUString> aExpandedSet; if (!rScriptContainersTreeView.get_iter_first(*xIter)) // no entries? return; do
{ if (rScriptContainersTreeView.get_row_expanded(*xIter))
aExpandedSet.insert(get_path(xIter.get()));
} while (rScriptContainersTreeView.iter_next(*xIter));
// fill
rScriptContainersTreeView.freeze();
m_xScriptContainersListBox->Fill(nullptr);
rScriptContainersTreeView.thaw();
// restore script container tree expand state or at least try if (!rScriptContainersTreeView.get_iter_first(*xIter))
{
UpdateUI(); return;
} do
{ if (aExpandedSet.erase(get_path(xIter.get())))
rScriptContainersTreeView.expand_row(*xIter);
} while (aExpandedSet.size() && rScriptContainersTreeView.iter_next(*xIter));
// restore the script containers tree scroll position
rScriptContainersTreeView.vadjustment_set_value(nOldScrollPos);
// if possible select the saved scripts container list entry if (sScriptContainersListBoxSelectedEntryPath.isEmpty())
{
UpdateUI(); return;
} bool bFound = false; while (true)
{ if (!rScriptContainersTreeView.get_iter_first(*xIter))
{
UpdateUI(); return;
} do
{ if (get_path(xIter.get()) == sScriptContainersListBoxSelectedEntryPath)
{
rScriptContainersTreeView.select(*xIter);
bFound = true; break;
}
} while (rScriptContainersTreeView.iter_next(*xIter)); if (bFound) break; // when not found remove the last node from path and try again auto i = sScriptContainersListBoxSelectedEntryPath.lastIndexOf('|'); if (i == -1)
{ // didn't find
UpdateUI(); return;
}
sScriptContainersListBoxSelectedEntryPath
= sScriptContainersListBoxSelectedEntryPath.copy(0, i);
}
// fill the scripts list box and set label
m_xScriptContainersListBox->ScriptContainerSelected();
m_xScriptsListBoxLabel->set_label(m_aScriptsListBoxLabelBaseStr + " "
+ rScriptContainersTreeView.get_text(*xIter));
// reselect the macro in the scripts list box if (!sScriptsListBoxSelectedEntry.isEmpty())
{
weld::TreeView& rScriptsTreeView = m_xScriptsListBox->get_widget();
xIter = rScriptsTreeView.make_iterator(); if (!rScriptsTreeView.get_iter_first(*xIter))
{
UpdateUI(); return;
} bool bIsIterValid = true; while (bIsIterValid
&& rScriptsTreeView.get_text(*xIter) != sScriptsListBoxSelectedEntry)
bIsIterValid = rScriptsTreeView.iter_next_sibling(*xIter); if (bIsIterValid)
{
rScriptsTreeView.scroll_to_row(*xIter);
rScriptsTreeView.select(*xIter);
}
}
if (nSelectedEntryDepth > 1)
{ if (nSelectedEntryDepth > (!bBasic ? 1 : 2))
{
ScriptContainerInfo* pScriptContainerInfo
= weld::fromId<ScriptContainerInfo*>(rTreeView.get_id(*xSelectedEntryIter)); // pBrowseNode is nullptr for Basic Dialog entries if (pScriptContainerInfo->pBrowseNode)
{ // fill the scripts list box and set the label
m_xScriptContainersListBox->ScriptContainerSelected();
m_xScriptsListBoxLabel->set_label(m_aScriptsListBoxLabelBaseStr + " "
+ rTreeView.get_text(*xSelectedEntryIter));
}
}
}
}
UpdateUI();
}
try
{ // create library container for modules
rDocument.getOrCreateLibrary(basctl::E_SCRIPTS, aLibName);
// create a module
OUString aModName = rDocument.createObjectName(basctl::E_SCRIPTS, aLibName);
OUString sModuleCode; if (!rDocument.createModule(aLibName, aModName, true, sModuleCode)) throw css::uno::Exception("could not create module " + aModName, nullptr);
// tdf#151741 - store all libraries to the file system, otherwise they // cannot be renamed/moved since the SfxLibraryContainer::renameLibrary // moves the folders/files on the file system
css::uno::Reference<css::script::XLibraryContainer2> xModLibContainer(
rDocument.getLibraryContainer(basctl::E_SCRIPTS));
css::uno::Reference<css::script::XPersistentLibraryContainer> xModPersLibContainer(
xModLibContainer, css::uno::UNO_QUERY); if (xModPersLibContainer.is())
xModPersLibContainer->storeLibraries();
void MacroManagerDialog::BasicScriptsCreateModule(const basctl::ScriptDocument& rDocument)
{ // library name is the selected tree entry
weld::TreeView& rTreeView = m_xScriptContainersListBox->get_widget();
std::unique_ptr<weld::TreeIter> xSelectedIter = rTreeView.make_iterator(); if (!rTreeView.get_selected(xSelectedIter.get())) return; // should never happen
void MacroManagerDialog::BasicScriptsCreateDialog(const basctl::ScriptDocument& rDocument)
{ // library name is the selected tree entry
weld::TreeView& rTreeView = m_xScriptContainersListBox->get_widget();
std::unique_ptr<weld::TreeIter> xSelectedIter = rTreeView.make_iterator(); if (!rTreeView.get_selected(xSelectedIter.get())) return; // should never happen
void MacroManagerDialog::BasicScriptsLibraryModuleDialogEdit( const basctl::ScriptDocument& rDocument)
{
weld::TreeView& rTreeView = m_xScriptContainersListBox->get_widget();
std::unique_ptr<weld::TreeIter> xSelectedIter = rTreeView.make_iterator(); if (!rTreeView.get_selected(xSelectedIter.get())) return; // should never happen
m_xDialog->hide();
// show the Basic IDE
SfxAllItemSet aArgs(SfxGetpApp()->GetPool());
SfxRequest aRequest(SID_BASICIDE_APPEAR, SfxCallMode::SYNCHRON, aArgs);
SfxGetpApp()->ExecuteSlot(aRequest);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.