2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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 "doclinkdialog.hxx"
|
2011-11-30 16:08:23 +01:00
|
|
|
|
|
|
|
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
|
2012-09-14 18:08:57 +02:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2017-06-11 20:56:30 +01:00
|
|
|
#include <strings.hrc>
|
2009-10-31 00:36:06 +01:00
|
|
|
#include <svl/filenotation.hxx>
|
2014-08-18 08:50:54 +01:00
|
|
|
#include <vcl/layout.hxx>
|
2009-10-31 00:36:06 +01:00
|
|
|
#include <ucbhelper/content.hxx>
|
2009-11-02 20:49:14 +01:00
|
|
|
#include <dialmgr.hxx>
|
2009-10-31 00:36:06 +01:00
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#include <sfx2/filedlghelper.hxx>
|
|
|
|
#include <sfx2/docfilt.hxx>
|
2014-02-25 18:04:51 +01:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
namespace svx
|
|
|
|
{
|
2014-02-25 18:04:51 +01:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2011-11-30 16:08:23 +01:00
|
|
|
using namespace ::com::sun::star;
|
2009-10-31 00:36:06 +01:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::ucb;
|
|
|
|
using namespace ::svt;
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
ODocumentLinkDialog::ODocumentLinkDialog( vcl::Window* _pParent, bool _bCreateNew )
|
2014-02-03 00:25:16 +00:00
|
|
|
: ModalDialog(_pParent, "DatabaseLinkDialog",
|
|
|
|
"cui/ui/databaselinkdialog.ui")
|
2009-10-31 00:36:06 +01:00
|
|
|
,m_bCreatingNew(_bCreateNew)
|
|
|
|
{
|
2014-02-03 00:25:16 +00:00
|
|
|
get(m_pURL, "url");
|
|
|
|
get(m_pOK, "ok");
|
|
|
|
get(m_pName, "name");
|
|
|
|
get(m_pBrowseFile, "browse");
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
if (!m_bCreatingNew)
|
|
|
|
SetText(get<FixedText>("alttitle")->GetText());
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pURL->SetFilter("*.odb");
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pName->SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
|
|
|
|
m_pURL->SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
|
|
|
|
m_pBrowseFile->SetClickHdl( LINK(this, ODocumentLinkDialog, OnBrowseFile) );
|
|
|
|
m_pOK->SetClickHdl( LINK(this, ODocumentLinkDialog, OnOk) );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pURL->SetDropDownLineCount(10);
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
validate();
|
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pURL->SetDropDownLineCount( 5 );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2015-03-09 14:29:30 +02:00
|
|
|
ODocumentLinkDialog::~ODocumentLinkDialog()
|
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-03-09 14:29:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ODocumentLinkDialog::dispose()
|
|
|
|
{
|
|
|
|
m_pURL.clear();
|
|
|
|
m_pBrowseFile.clear();
|
|
|
|
m_pName.clear();
|
|
|
|
m_pOK.clear();
|
|
|
|
ModalDialog::dispose();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
void ODocumentLinkDialog::setLink( const OUString& _rName, const OUString& _rURL )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pName->SetText(_rName);
|
|
|
|
m_pURL->SetText(_rURL);
|
2009-10-31 00:36:06 +01:00
|
|
|
validate();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
void ODocumentLinkDialog::getLink( OUString& _rName, OUString& _rURL ) const
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2014-02-03 00:25:16 +00:00
|
|
|
_rName = m_pName->GetText();
|
|
|
|
_rURL = m_pURL->GetText();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
void ODocumentLinkDialog::validate( )
|
|
|
|
{
|
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pOK->Enable( ( !m_pName->GetText().isEmpty()) && ( !m_pURL->GetText().isEmpty() ) );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG(ODocumentLinkDialog, OnOk, Button*, void)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
// get the current URL
|
2014-02-03 00:25:16 +00:00
|
|
|
OUString sURL = m_pURL->GetText();
|
2009-10-31 00:36:06 +01:00
|
|
|
OFileNotation aTransformer(sURL);
|
|
|
|
sURL = aTransformer.get(OFileNotation::N_URL);
|
|
|
|
|
|
|
|
// check for the existence of the selected file
|
2014-04-16 11:39:08 +02:00
|
|
|
bool bFileExists = false;
|
2009-10-31 00:36:06 +01:00
|
|
|
try
|
|
|
|
{
|
2012-09-14 18:08:57 +02:00
|
|
|
::ucbhelper::Content aFile(sURL, Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext());
|
2009-10-31 00:36:06 +01:00
|
|
|
if (aFile.isDocument())
|
2014-04-16 11:39:08 +02:00
|
|
|
bFileExists = true;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
catch(Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bFileExists)
|
|
|
|
{
|
2017-05-18 21:14:00 +01:00
|
|
|
OUString sMsg = CuiResId(STR_LINKEDDOC_DOESNOTEXIST);
|
2014-02-03 00:25:16 +00:00
|
|
|
sMsg = sMsg.replaceFirst("$file$", m_pURL->GetText());
|
2015-03-31 23:04:14 +01:00
|
|
|
ScopedVclPtrInstance< MessageDialog > aError(this, sMsg);
|
2015-02-11 14:42:23 +02:00
|
|
|
aError->Execute();
|
2015-08-19 09:11:34 +02:00
|
|
|
return;
|
2009-10-31 00:36:06 +01:00
|
|
|
} // if (!bFileExists)
|
|
|
|
INetURLObject aURL( sURL );
|
2015-04-02 18:32:36 +02:00
|
|
|
if ( aURL.GetProtocol() != INetProtocol::File )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2017-05-18 21:14:00 +01:00
|
|
|
OUString sMsg = CuiResId(STR_LINKEDDOC_NO_SYSTEM_FILE);
|
2014-02-03 00:25:16 +00:00
|
|
|
sMsg = sMsg.replaceFirst("$file$", m_pURL->GetText());
|
2015-03-31 23:04:14 +01:00
|
|
|
ScopedVclPtrInstance< MessageDialog > aError(this, sMsg);
|
2015-02-11 14:42:23 +02:00
|
|
|
aError->Execute();
|
2015-08-19 09:11:34 +02:00
|
|
|
return;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
OUString sCurrentText = m_pName->GetText();
|
2009-10-31 00:36:06 +01:00
|
|
|
if ( m_aNameValidator.IsSet() )
|
|
|
|
{
|
2015-09-25 13:38:06 +02:00
|
|
|
if ( !m_aNameValidator.Call( sCurrentText ) )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2017-05-18 21:14:00 +01:00
|
|
|
OUString sMsg = CuiResId(STR_NAME_CONFLICT);
|
2013-09-26 08:30:52 +02:00
|
|
|
sMsg = sMsg.replaceFirst("$file$", sCurrentText);
|
2016-05-31 14:25:11 +02:00
|
|
|
ScopedVclPtrInstance< MessageDialog > aError(this, sMsg, VclMessageType::Info);
|
2015-02-11 14:42:23 +02:00
|
|
|
aError->Execute();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pName->SetSelection(Selection(0,sCurrentText.getLength()));
|
|
|
|
m_pName->GrabFocus();
|
2015-08-19 09:11:34 +02:00
|
|
|
return;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EndDialog(RET_OK);
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG(ODocumentLinkDialog, OnBrowseFile, Button*, void)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2011-11-30 16:08:23 +01:00
|
|
|
::sfx2::FileDialogHelper aFileDlg(
|
2017-09-07 10:54:22 +01:00
|
|
|
ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION, FileDialogFlags::NONE, this);
|
2016-03-11 06:43:06 +01:00
|
|
|
std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetFilterByName("StarOffice XML (Base)");
|
2009-10-31 00:36:06 +01:00
|
|
|
if ( pFilter )
|
|
|
|
{
|
|
|
|
aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
|
|
|
|
aFileDlg.SetCurrentFilter(pFilter->GetUIName());
|
|
|
|
}
|
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
OUString sPath = m_pURL->GetText();
|
2013-09-26 08:30:52 +02:00
|
|
|
if (!sPath.isEmpty())
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
OFileNotation aTransformer( sPath, OFileNotation::N_SYSTEM );
|
|
|
|
aFileDlg.SetDisplayDirectory( aTransformer.get( OFileNotation::N_URL ) );
|
|
|
|
}
|
|
|
|
|
2017-06-14 13:34:55 +02:00
|
|
|
if (ERRCODE_NONE != aFileDlg.Execute())
|
2015-08-19 09:11:34 +02:00
|
|
|
return;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
if (m_pName->GetText().isEmpty())
|
2009-10-31 00:36:06 +01:00
|
|
|
{ // default the name to the base of the chosen URL
|
|
|
|
INetURLObject aParser;
|
|
|
|
|
2015-04-02 18:32:36 +02:00
|
|
|
aParser.SetSmartProtocol(INetProtocol::File);
|
2009-10-31 00:36:06 +01:00
|
|
|
aParser.SetSmartURL(aFileDlg.GetPath());
|
|
|
|
|
2016-12-05 08:47:18 +02:00
|
|
|
m_pName->SetText(aParser.getBase(INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset));
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pName->SetSelection(Selection(0,m_pName->GetText().getLength()));
|
|
|
|
m_pName->GrabFocus();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
else
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pURL->GrabFocus();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
// get the path in system notation
|
|
|
|
OFileNotation aTransformer(aFileDlg.GetPath(), OFileNotation::N_URL);
|
2014-02-03 00:25:16 +00:00
|
|
|
m_pURL->SetText(aTransformer.get(OFileNotation::N_SYSTEM));
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
validate();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG(ODocumentLinkDialog, OnTextModified, Edit&, void)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
validate( );
|
|
|
|
}
|
|
|
|
|
2014-02-25 18:04:51 +01:00
|
|
|
|
2015-05-15 13:27:19 +02:00
|
|
|
}
|
2014-02-25 18:04:51 +01:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2010-10-12 15:57:08 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|