Files
libreoffice/cui/source/dialogs/linkdlg.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

645 lines
21 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: clarify Option->Language UI option Patch contributed by Herbert Duerr http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117709#: add missing string resource Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172348 cws mba34issues01: #i117716#: fix missing resources my removing unused code Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172345 re-add Crystal, Tango, Oxygen icon theme listings. correct method signature Patch contributed by Jean-Louis 'Hans' Fuchs http://svn.apache.org/viewvc?view=revision&revision=1306725 i#119063 - correct serf integration Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1300521 i#119036 - adapt serf integration -- use transfer-encoding 'chunked' on HTTPS -- switch transfer-encoding between 'chunked' and none on 413 HTTP status code -- refactoring -- improve user experience of certification dialog - only shown once Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1299727 118569: Use whole certification chain for verification. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1295493 serf integration: improve credential input handling Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1294557 warning-free ucb/source/ucp/webdav Patch contributed by Pavel Janik http://svn.apache.org/viewvc?view=revision&revision=1294086 some refactoring to PROPPATCH and PROPFIND requests Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1293281 i#118569: Replace neon with serf Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1292832 http://svn.apache.org/viewvc?view=revision&revision=1292794 remove OS/2 conditionals for now. re-enable webdav unit tests.
2012-10-04 11:25:41 +01:00
/*
* 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 .
*/
2009-10-31 00:36:06 +01:00
#include <linkdlg.hxx>
#include <o3tl/safeint.hxx>
2009-10-31 00:36:06 +01:00
#include <vcl/svapp.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <tools/debug.hxx>
2009-10-31 00:36:06 +01:00
#include <tools/urlobj.hxx>
#include <vcl/idle.hxx>
#include <vcl/timer.hxx>
#include <vcl/weld.hxx>
#include <vcl/weldutils.hxx>
2009-10-31 00:36:06 +01:00
migrate to boost::gettext * all .ui files go from <interface> to <interface domain="MODULE"> e.g. vcl * all .src files go away and the english source strings folded into the .hrc as NC_("context", "source string") * ResMgr is dropped in favour of std::locale imbued by boost::locale::generator pointed at matching MODULE .mo files * UIConfig translations are folded into the module .mo, so e.g. UIConfig_cui goes from l10n target to normal one, so the res/lang.zips of UI files go away * translation via Translation::get(hrc-define-key, imbued-std::locale) * python can now be translated with its inbuilt gettext support (we keep the name strings.hrc there to keep finding the .hrc file uniform) so magic numbers can go away there * java and starbasic components can be translated via the pre-existing css.resource.StringResourceWithLocation mechanism * en-US res files go away, their strings are now the .hrc keys in the source code * remaining .res files are replaced by .mo files * in .res/.ui-lang-zip files, the old scheme missing translations of strings results in inserting the english original so something can be found, now the standard fallback of using the english original from the source key is used, so partial translations shrink dramatically in size * extract .hrc strings with hrcex which backs onto xgettext -C --add-comments --keyword=NC_:1c,2 --from-code=UTF-8 --no-wrap * extract .ui strings with uiex which backs onto xgettext --add-comments --no-wrap * qtz for gettext translations is generated at runtime as ascii-ified crc32 of content + "|" + msgid * [API CHANGE] remove deprecated binary .res resouce loader related uno apis com::sun::star::resource::OfficeResourceLoader com::sun::star::resource::XResourceBundleLoader com::sun::star::resource::XResourceBundle when translating strings via uno apis com.sun.star.resource.StringResourceWithLocation can continue to be used Change-Id: Ia2594a2672b7301d9c3421fdf31b6cfe7f3f8d0a
2017-06-11 20:56:30 +01:00
#include <strings.hrc>
#include <sfx2/filedlghelper.hxx>
2009-10-31 00:36:06 +01:00
#include <sfx2/linkmgr.hxx>
#include <sfx2/linksrc.hxx>
#include <sfx2/lnkbase.hxx>
#include <sfx2/objsh.hxx>
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
#include <comphelper/processfactory.hxx>
#include <dialmgr.hxx>
2009-10-31 00:36:06 +01:00
using namespace sfx2;
using namespace ::com::sun::star;
2009-10-31 00:36:06 +01:00
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
namespace {
class SvBaseLinkMemberList {
private:
std::vector<SvBaseLink*> mLinks;
public:
~SvBaseLinkMemberList()
{
for (auto const& link : mLinks)
{
if( link )
link->ReleaseRef();
}
}
size_t size() const { return mLinks.size(); }
SvBaseLink *operator[](size_t i) const { return mLinks[i]; }
void push_back(SvBaseLink* p)
{
mLinks.push_back(p);
p->AddFirstRef();
}
};
2009-10-31 00:36:06 +01:00
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
}
SvBaseLinksDlg::SvBaseLinksDlg(weld::Window * pParent, LinkManager* pMgr, bool bHtmlMode)
: GenericDialogController(pParent, "cui/ui/baselinksdialog.ui", "BaseLinksDialog")
, aStrAutolink( CuiResId( STR_AUTOLINK ) )
, aStrManuallink( CuiResId( STR_MANUALLINK ) )
, aStrBrokenlink( CuiResId( STR_BROKENLINK ) )
, aStrCloselinkmsg( CuiResId( STR_CLOSELINKMSG ) )
, aStrCloselinkmsgMulti( CuiResId( STR_CLOSELINKMSG_MULTI ) )
, aStrWaitinglink( CuiResId( STR_WAITINGLINK ) )
, pLinkMgr( nullptr )
, aUpdateIdle("cui SvBaseLinksDlg UpdateIdle")
, m_xTbLinks(m_xBuilder->weld_tree_view("TB_LINKS"))
, m_xFtFullFileName(m_xBuilder->weld_link_button("FULL_FILE_NAME"))
, m_xFtFullSourceName(m_xBuilder->weld_label("FULL_SOURCE_NAME"))
, m_xFtFullTypeName(m_xBuilder->weld_label("FULL_TYPE_NAME"))
, m_xRbAutomatic(m_xBuilder->weld_radio_button("AUTOMATIC"))
, m_xRbManual(m_xBuilder->weld_radio_button("MANUAL"))
, m_xPbUpdateNow(m_xBuilder->weld_button("UPDATE_NOW"))
, m_xPbChangeSource(m_xBuilder->weld_button("CHANGE_SOURCE"))
, m_xPbBreakLink(m_xBuilder->weld_button("BREAK_LINK"))
, m_xVirDev(VclPtr<VirtualDevice>::Create())
2009-10-31 00:36:06 +01:00
{
// expand the point size of the desired font to the equivalent pixel size
weld::SetPointFont(*m_xVirDev, m_xTbLinks->get_font());
m_xTbLinks->set_size_request(m_xTbLinks->get_approximate_digit_width() * 90,
m_xTbLinks->get_height_rows(12));
m_xTbLinks->set_selection_mode(SelectionMode::Multiple);
std::vector<int> aWidths
{
o3tl::narrowing<int>(m_xTbLinks->get_approximate_digit_width() * 30),
o3tl::narrowing<int>(m_xTbLinks->get_approximate_digit_width() * 20),
o3tl::narrowing<int>(m_xTbLinks->get_approximate_digit_width() * 20)
};
m_xTbLinks->set_column_fixed_widths(aWidths);
2009-10-31 00:36:06 +01:00
// UpdateTimer for DDE-/Grf-links, which are waited for
aUpdateIdle.SetInvokeHandler( LINK( this, SvBaseLinksDlg, UpdateWaitingHdl ) );
aUpdateIdle.SetPriority( TaskPriority::LOWEST );
m_xTbLinks->connect_changed( LINK( this, SvBaseLinksDlg, LinksSelectHdl ) );
m_xTbLinks->connect_row_activated( LINK( this, SvBaseLinksDlg, LinksDoubleClickHdl ) );
m_xRbAutomatic->connect_toggled( LINK( this, SvBaseLinksDlg, ToggleHdl ) );
m_xRbManual->connect_toggled( LINK( this, SvBaseLinksDlg, ToggleHdl ) );
m_xPbUpdateNow->connect_clicked( LINK( this, SvBaseLinksDlg, UpdateNowClickHdl ) );
m_xPbChangeSource->connect_clicked( LINK( this, SvBaseLinksDlg, ChangeSourceClickHdl ) );
2009-10-31 00:36:06 +01:00
if(!bHtmlMode)
m_xPbBreakLink->connect_clicked( LINK( this, SvBaseLinksDlg, BreakLinkClickHdl ) );
2009-10-31 00:36:06 +01:00
else
m_xPbBreakLink->hide();
2009-10-31 00:36:06 +01:00
SetManager( pMgr );
}
SvBaseLinksDlg::~SvBaseLinksDlg()
{
}
/*************************************************************************
|* SvBaseLinksDlg::Handler()
*************************************************************************/
IMPL_LINK(SvBaseLinksDlg, LinksSelectHdl, weld::TreeView&, rTreeView, void)
{
LinksSelectHdl(&rTreeView);
}
void SvBaseLinksDlg::LinksSelectHdl(weld::TreeView* pSvTabListBox)
2009-10-31 00:36:06 +01:00
{
const int nSelectionCount = pSvTabListBox ?
pSvTabListBox->count_selected_rows() : 0;
if (nSelectionCount > 1)
2009-10-31 00:36:06 +01:00
{
// possibly deselect old entries in case of multi-selection
int nSelEntry = pSvTabListBox->get_selected_index();
SvBaseLink* pLink = weld::fromId<SvBaseLink*>(pSvTabListBox->get_id(nSelEntry));
SvBaseLinkObjectType nObjectType = pLink->GetObjType();
if(!isClientFileType(nObjectType))
2009-10-31 00:36:06 +01:00
{
pSvTabListBox->unselect_all();
pSvTabListBox->select(nSelEntry);
2009-10-31 00:36:06 +01:00
}
else
{
std::vector<int> aRows = pSvTabListBox->get_selected_rows();
for (auto nEntry : aRows)
2009-10-31 00:36:06 +01:00
{
pLink = weld::fromId<SvBaseLink*>(pSvTabListBox->get_id(nEntry));
DBG_ASSERT(pLink, "Where is the Link?");
if (!pLink)
continue;
if( !isClientFileType(pLink->GetObjType()) )
pSvTabListBox->unselect(nEntry);
2009-10-31 00:36:06 +01:00
}
}
m_xPbUpdateNow->set_sensitive(true);
m_xRbAutomatic->set_sensitive(false);
m_xRbManual->set_active(true);
m_xRbManual->set_sensitive(false);
2009-10-31 00:36:06 +01:00
}
else
{
int nPos;
2009-10-31 00:36:06 +01:00
SvBaseLink* pLink = GetSelEntry( &nPos );
if( !pLink )
return;
2009-10-31 00:36:06 +01:00
m_xPbUpdateNow->set_sensitive(true);
2009-10-31 00:36:06 +01:00
OUString sType, sLink;
OUString *pLinkNm = &sLink, *pFilter = nullptr;
2009-10-31 00:36:06 +01:00
if( isClientFileType(pLink->GetObjType()) )
2009-10-31 00:36:06 +01:00
{
m_xRbAutomatic->set_sensitive(false);
m_xRbManual->set_active(true);
m_xRbManual->set_sensitive(false);
if( SvBaseLinkObjectType::ClientGraphic == pLink->GetObjType() )
{
pLinkNm = nullptr;
pFilter = &sLink;
}
2009-10-31 00:36:06 +01:00
}
else
{
m_xRbAutomatic->set_sensitive(true);
m_xRbManual->set_sensitive(true);
2009-10-31 00:36:06 +01:00
if( SfxLinkUpdateMode::ALWAYS == pLink->GetUpdateMode() )
m_xRbAutomatic->set_active(true);
2009-10-31 00:36:06 +01:00
else
m_xRbManual->set_active(true);
2009-10-31 00:36:06 +01:00
}
OUString aFileName;
sfx2::LinkManager::GetDisplayNames( pLink, &sType, &aFileName, pLinkNm, pFilter );
aFileName = INetURLObject::decode(aFileName, INetURLObject::DecodeMechanism::Unambiguous);
m_xFtFullFileName->set_label( aFileName );
m_xFtFullFileName->set_uri( aFileName );
m_xFtFullSourceName->set_label( sLink );
m_xFtFullTypeName->set_label( sType );
2009-10-31 00:36:06 +01:00
}
}
IMPL_LINK_NOARG( SvBaseLinksDlg, LinksDoubleClickHdl, weld::TreeView&, bool )
2009-10-31 00:36:06 +01:00
{
ChangeSourceClickHdl(*m_xPbChangeSource);
return true;
2009-10-31 00:36:06 +01:00
}
IMPL_LINK(SvBaseLinksDlg, ToggleHdl, weld::Toggleable&, rButton, void)
2009-10-31 00:36:06 +01:00
{
if (!rButton.get_active())
return;
2009-10-31 00:36:06 +01:00
int nPos;
2009-10-31 00:36:06 +01:00
SvBaseLink* pLink = GetSelEntry( &nPos );
if (m_xRbAutomatic->get_active())
{
if( pLink && !isClientFileType( pLink->GetObjType() ) &&
SfxLinkUpdateMode::ALWAYS != pLink->GetUpdateMode() )
SetType( *pLink, nPos, SfxLinkUpdateMode::ALWAYS );
}
else
{
if( pLink && !isClientFileType( pLink->GetObjType() ) &&
SfxLinkUpdateMode::ONCALL != pLink->GetUpdateMode())
SetType( *pLink, nPos, SfxLinkUpdateMode::ONCALL );
}
2009-10-31 00:36:06 +01:00
}
IMPL_LINK_NOARG(SvBaseLinksDlg, UpdateNowClickHdl, weld::Button&, void)
2009-10-31 00:36:06 +01:00
{
std::vector< SvBaseLink* > aLnkArr;
std::vector< sal_Int16 > aPosArr;
2009-10-31 00:36:06 +01:00
std::vector<int> aRows = m_xTbLinks->get_selected_rows();
for (int nFndPos : aRows)
2009-10-31 00:36:06 +01:00
{
aLnkArr.push_back( weld::fromId<SvBaseLink*>( m_xTbLinks->get_id(nFndPos) ) );
aPosArr.push_back( nFndPos );
2009-10-31 00:36:06 +01:00
}
if( aLnkArr.empty() )
return;
for( size_t n = 0; n < aLnkArr.size(); ++n )
2009-10-31 00:36:06 +01:00
{
tools::SvRef<SvBaseLink> xLink = aLnkArr[ n ];
2009-10-31 00:36:06 +01:00
// first look for the entry in the array
for(const auto & i : pLinkMgr->GetLinks())
if( xLink == i )
{
SetType( *xLink, aPosArr[ n ], xLink->GetUpdateMode() );
break;
}
}
2009-10-31 00:36:06 +01:00
// if somebody is of the opinion to swap his links (SD)
LinkManager* pNewMgr = pLinkMgr;
pLinkMgr = nullptr;
SetManager( pNewMgr );
2009-10-31 00:36:06 +01:00
OUString sId = weld::toId(aLnkArr[0]);
int nE = m_xTbLinks->find_id(sId);
if (nE == -1)
nE = m_xTbLinks->get_selected_index();
int nSelEntry = m_xTbLinks->get_selected_index();
if (nE != nSelEntry)
m_xTbLinks->unselect(nSelEntry);
m_xTbLinks->select(nE);
m_xTbLinks->scroll_to_row(nE);
pNewMgr->CloseCachedComps();
2009-10-31 00:36:06 +01:00
}
IMPL_LINK_NOARG(SvBaseLinksDlg, ChangeSourceClickHdl, weld::Button&, void)
2009-10-31 00:36:06 +01:00
{
std::vector<int> aRows = m_xTbLinks->get_selected_rows();
if (aRows.size() > 1)
2009-10-31 00:36:06 +01:00
{
try
2009-10-31 00:36:06 +01:00
{
uno::Reference<ui::dialogs::XFolderPicker2> xFolderPicker = sfx2::createFolderPicker(
comphelper::getProcessComponentContext(), m_xDialog.get());
OUString sType, sFile, sLinkName;
OUString sFilter;
SvBaseLink* pLink = weld::fromId<SvBaseLink*>(m_xTbLinks->get_id(aRows[0]));
sfx2::LinkManager::GetDisplayNames( pLink, &sType, &sFile );
INetURLObject aUrl(sFile);
if(aUrl.GetProtocol() == INetProtocol::File)
{
OUString sOldPath(aUrl.PathToFileName());
sal_Int32 nLen = aUrl.GetLastName().getLength();
sOldPath = sOldPath.copy(0, sOldPath.getLength() - nLen);
xFolderPicker->setDisplayDirectory(sOldPath);
}
if (xFolderPicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
2009-10-31 00:36:06 +01:00
{
OUString aPath = xFolderPicker->getDirectory();
for (auto nRow : aRows)
{
pLink = weld::fromId<SvBaseLink*>(m_xTbLinks->get_id(nRow));
DBG_ASSERT(pLink,"Where is the link?");
if (!pLink)
continue;
sfx2::LinkManager::GetDisplayNames( pLink, &sType, &sFile, &sLinkName, &sFilter );
INetURLObject aUrl_(sFile);
INetURLObject aUrl2(aPath, INetProtocol::File);
aUrl2.insertName( aUrl_.getName() );
OUString sNewLinkName;
MakeLnkName( sNewLinkName, nullptr ,
aUrl2.GetMainURL(INetURLObject::DecodeMechanism::ToIUri), sLinkName, &sFilter);
pLink->SetLinkSourceName( sNewLinkName );
pLink->Update();
}
if( pLinkMgr->GetPersist() )
pLinkMgr->GetPersist()->SetModified();
LinkManager* pNewMgr = pLinkMgr;
pLinkMgr = nullptr;
SetManager( pNewMgr );
2009-10-31 00:36:06 +01:00
}
}
catch (const uno::Exception &)
{
TOOLS_WARN_EXCEPTION("cui.dialogs", "SvBaseLinksDlg");
2009-10-31 00:36:06 +01:00
}
}
else
{
int nPos;
2009-10-31 00:36:06 +01:00
SvBaseLink* pLink = GetSelEntry( &nPos );
if ( pLink && !pLink->GetLinkSourceName().isEmpty() )
pLink->Edit(m_xDialog.get(), LINK(this, SvBaseLinksDlg, EndEditHdl));
2009-10-31 00:36:06 +01:00
}
}
IMPL_LINK_NOARG( SvBaseLinksDlg, BreakLinkClickHdl, weld::Button&, void )
2009-10-31 00:36:06 +01:00
{
bool bModified = false;
if (m_xTbLinks->count_selected_rows() <= 1)
2009-10-31 00:36:06 +01:00
{
int nPos;
tools::SvRef<SvBaseLink> xLink = GetSelEntry( &nPos );
if( !xLink.is() )
return;
2009-10-31 00:36:06 +01:00
std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(),
VclMessageType::Question, VclButtonsType::YesNo,
aStrCloselinkmsg));
xQueryBox->set_default_response(RET_YES);
2009-10-31 00:36:06 +01:00
if (RET_YES == xQueryBox->run())
2009-10-31 00:36:06 +01:00
{
m_xTbLinks->remove(nPos);
2009-10-31 00:36:06 +01:00
// close object, if it's still existing
bool bNewLnkMgr = SvBaseLinkObjectType::ClientFile == xLink->GetObjType();
2009-10-31 00:36:06 +01:00
// tell the link that it will be resolved!
2009-10-31 00:36:06 +01:00
xLink->Closed();
// if somebody has forgotten to deregister himself
if( xLink.is() )
pLinkMgr->Remove( xLink.get() );
2009-10-31 00:36:06 +01:00
if( bNewLnkMgr )
{
2010-01-13 22:25:07 +01:00
LinkManager* pNewMgr = pLinkMgr;
pLinkMgr = nullptr;
2009-10-31 00:36:06 +01:00
SetManager( pNewMgr );
m_xTbLinks->set_cursor(nPos ? --nPos : 0);
2009-10-31 00:36:06 +01:00
}
bModified = true;
2009-10-31 00:36:06 +01:00
}
}
else
{
std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(),
VclMessageType::Question, VclButtonsType::YesNo,
aStrCloselinkmsgMulti));
xQueryBox->set_default_response(RET_YES);
2009-10-31 00:36:06 +01:00
if (RET_YES == xQueryBox->run())
2009-10-31 00:36:06 +01:00
{
std::vector<int> aRows = m_xTbLinks->get_selected_rows();
2009-10-31 00:36:06 +01:00
SvBaseLinkMemberList aLinkList;
for (auto nRow : aRows)
2009-10-31 00:36:06 +01:00
{
SvBaseLink* pLink = weld::fromId<SvBaseLink*>(m_xTbLinks->get_id(nRow));
if (pLink)
aLinkList.push_back(pLink);
2009-10-31 00:36:06 +01:00
}
std::sort(aRows.begin(), aRows.end());
for (auto it = aRows.rbegin(); it != aRows.rend(); ++it)
m_xTbLinks->remove(*it);
for (size_t i = 0; i < aLinkList.size(); ++i)
2009-10-31 00:36:06 +01:00
{
tools::SvRef<SvBaseLink> xLink = aLinkList[i];
// tell the link that it will be resolved!
2009-10-31 00:36:06 +01:00
xLink->Closed();
// if somebody has forgotten to deregister himself
pLinkMgr->Remove( xLink.get() );
bModified = true;
2009-10-31 00:36:06 +01:00
}
// then remove all selected entries
2009-10-31 00:36:06 +01:00
}
}
if(!bModified)
return;
if (!m_xTbLinks->n_children())
2009-10-31 00:36:06 +01:00
{
m_xRbAutomatic->set_sensitive(false);
m_xRbManual->set_sensitive(false);
m_xPbUpdateNow->set_sensitive(false);
m_xPbChangeSource->set_sensitive(false);
m_xPbBreakLink->set_sensitive(false);
m_xFtFullSourceName->set_label( "" );
m_xFtFullTypeName->set_label( "" );
2009-10-31 00:36:06 +01:00
}
if( pLinkMgr && pLinkMgr->GetPersist() )
pLinkMgr->GetPersist()->SetModified();
2009-10-31 00:36:06 +01:00
}
IMPL_LINK_NOARG( SvBaseLinksDlg, UpdateWaitingHdl, Timer*, void )
2009-10-31 00:36:06 +01:00
{
m_xTbLinks->freeze();
for (int nPos = m_xTbLinks->n_children(); nPos; --nPos)
2009-10-31 00:36:06 +01:00
{
tools::SvRef<SvBaseLink> xLink( weld::fromId<SvBaseLink*>(m_xTbLinks->get_id(nPos)) );
if( xLink.is() )
2009-10-31 00:36:06 +01:00
{
OUString sCur( ImplGetStateStr( *xLink ) ),
sOld( m_xTbLinks->get_text(nPos, 3) );
2009-10-31 00:36:06 +01:00
if( sCur != sOld )
m_xTbLinks->set_text(nPos, sCur, 3);
2009-10-31 00:36:06 +01:00
}
}
m_xTbLinks->thaw();
2009-10-31 00:36:06 +01:00
}
IMPL_LINK( SvBaseLinksDlg, EndEditHdl, sfx2::SvBaseLink&, _rLink, void )
2009-10-31 00:36:06 +01:00
{
int nPos;
2009-12-10 18:00:39 +01:00
GetSelEntry( &nPos );
2009-10-31 00:36:06 +01:00
if( !_rLink.WasLastEditOK() )
return;
2009-10-31 00:36:06 +01:00
// StarImpress/Draw swap the LinkObjects themselves!
// So search for the link in the manager; if it does not exist
// anymore, fill the list completely new. Otherwise only the
// edited link needs to be refreshed.
bool bLinkFnd = false;
for( size_t n = pLinkMgr->GetLinks().size(); n; )
if( &_rLink == &(*pLinkMgr->GetLinks()[ --n ]) )
2009-10-31 00:36:06 +01:00
{
bLinkFnd = true;
break;
2009-10-31 00:36:06 +01:00
}
if( bLinkFnd )
{
m_xTbLinks->remove(nPos);
int nToUnselect = m_xTbLinks->get_selected_index();
InsertEntry(_rLink, nPos, true);
if (nToUnselect != -1)
m_xTbLinks->unselect(nToUnselect);
2009-10-31 00:36:06 +01:00
}
else
{
LinkManager* pNewMgr = pLinkMgr;
pLinkMgr = nullptr;
SetManager( pNewMgr );
}
if (pLinkMgr && pLinkMgr->GetPersist())
pLinkMgr->GetPersist()->SetModified();
2009-10-31 00:36:06 +01:00
}
OUString SvBaseLinksDlg::ImplGetStateStr( const SvBaseLink& rLnk )
2009-10-31 00:36:06 +01:00
{
OUString sRet;
2009-10-31 00:36:06 +01:00
if( !rLnk.GetObj() )
sRet = aStrBrokenlink;
2009-10-31 00:36:06 +01:00
else if( rLnk.GetObj()->IsPending() )
{
sRet = aStrWaitinglink;
aUpdateIdle.Start();
2009-10-31 00:36:06 +01:00
}
else if( SfxLinkUpdateMode::ALWAYS == rLnk.GetUpdateMode() )
sRet = aStrAutolink;
2009-10-31 00:36:06 +01:00
else
sRet = aStrManuallink;
2009-10-31 00:36:06 +01:00
return sRet;
}
2010-01-13 22:25:07 +01:00
void SvBaseLinksDlg::SetManager( LinkManager* pNewMgr )
2009-10-31 00:36:06 +01:00
{
if( pLinkMgr == pNewMgr )
return;
if (pNewMgr)
{
// update has to be stopped before clear
m_xTbLinks->freeze();
}
2009-10-31 00:36:06 +01:00
m_xTbLinks->clear();
2009-10-31 00:36:06 +01:00
pLinkMgr = pNewMgr;
if( !pLinkMgr )
return;
SvBaseLinks& rLnks = const_cast<SvBaseLinks&>(pLinkMgr->GetLinks());
for( size_t n = 0; n < rLnks.size(); ++n )
2009-10-31 00:36:06 +01:00
{
tools::SvRef<SvBaseLink>& rLinkRef = rLnks[ n ];
if( !rLinkRef.is() )
2009-10-31 00:36:06 +01:00
{
rLnks.erase( rLnks.begin() + n );
--n;
continue;
2009-10-31 00:36:06 +01:00
}
if( rLinkRef->IsVisible() )
InsertEntry( *rLinkRef );
}
2009-10-31 00:36:06 +01:00
m_xTbLinks->thaw();
if( !rLnks.empty() )
{
m_xTbLinks->set_cursor(0);
m_xTbLinks->select(0);
LinksSelectHdl( nullptr );
2009-10-31 00:36:06 +01:00
}
}
void SvBaseLinksDlg::InsertEntry(const SvBaseLink& rLink, int nPos, bool bSelect)
2009-10-31 00:36:06 +01:00
{
OUString sFileNm, sLinkNm, sTypeNm, sFilter;
2009-10-31 00:36:06 +01:00
sfx2::LinkManager::GetDisplayNames( &rLink, &sTypeNm, &sFileNm, &sLinkNm, &sFilter );
2009-10-31 00:36:06 +01:00
auto nWidthPixel = m_xTbLinks->get_column_width(0);
OUString aTxt = m_xVirDev->GetEllipsisString(sFileNm, nWidthPixel, DrawTextFlags::PathEllipsis);
INetURLObject aPath( sFileNm, INetProtocol::File );
OUString aFileName = aPath.getName(
INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::Unambiguous);
2009-12-10 18:00:39 +01:00
if( aFileName.getLength() > aTxt.getLength() )
2009-10-31 00:36:06 +01:00
aTxt = aFileName;
else if (!aFileName.isEmpty() && aTxt.indexOf(aFileName, aTxt.getLength() - aFileName.getLength()) == -1)
2009-10-31 00:36:06 +01:00
// filename not in string
aTxt = aFileName;
if (nPos == -1)
nPos = m_xTbLinks->n_children();
m_xTbLinks->insert(nPos);
m_xTbLinks->set_text(nPos, aTxt, 0);
m_xTbLinks->set_id(nPos, weld::toId(&rLink));
if( SvBaseLinkObjectType::ClientGraphic == rLink.GetObjType() )
m_xTbLinks->set_text(nPos, sFilter, 1);
2009-10-31 00:36:06 +01:00
else
m_xTbLinks->set_text(nPos, sLinkNm, 1);
m_xTbLinks->set_text(nPos, sTypeNm, 2);
m_xTbLinks->set_text(nPos, ImplGetStateStr(rLink), 3);
if (bSelect)
m_xTbLinks->select(nPos);
2009-10-31 00:36:06 +01:00
}
SvBaseLink* SvBaseLinksDlg::GetSelEntry(int* pPos)
2009-10-31 00:36:06 +01:00
{
int nPos = m_xTbLinks->get_selected_index();
if (nPos != -1)
2009-10-31 00:36:06 +01:00
{
if (pPos)
2009-10-31 00:36:06 +01:00
*pPos = nPos;
return weld::fromId<SvBaseLink*>(m_xTbLinks->get_id(nPos));
2009-10-31 00:36:06 +01:00
}
return nullptr;
2009-10-31 00:36:06 +01:00
}
void SvBaseLinksDlg::SetType(SvBaseLink& rLink,
int nSelPos,
SfxLinkUpdateMode nType)
2009-10-31 00:36:06 +01:00
{
rLink.SetUpdateMode( nType );
rLink.Update();
m_xTbLinks->set_text(nSelPos, ImplGetStateStr(rLink), 3);
if (pLinkMgr->GetPersist())
2009-10-31 00:36:06 +01:00
pLinkMgr->GetPersist()->SetModified();
}
void SvBaseLinksDlg::SetActLink( SvBaseLink const * pLink )
2009-10-31 00:36:06 +01:00
{
if( !pLinkMgr )
return;
const SvBaseLinks& rLnks = pLinkMgr->GetLinks();
int nSelect = 0;
for(const auto & rLinkRef : rLnks)
2009-10-31 00:36:06 +01:00
{
// #109573# only visible links have been inserted into the TreeListBox,
// invisible ones have to be skipped here
if( rLinkRef->IsVisible() )
2009-10-31 00:36:06 +01:00
{
if( pLink == rLinkRef.get() )
2009-10-31 00:36:06 +01:00
{
m_xTbLinks->select(nSelect);
LinksSelectHdl( nullptr );
return ;
2009-10-31 00:36:06 +01:00
}
++nSelect;
2009-10-31 00:36:06 +01:00
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */