21#include <osl/file.hxx>
26#include <com/sun/star/awt/XTopWindow.hpp>
27#include <com/sun/star/uno/Reference.h>
28#include <com/sun/star/uno/Exception.hpp>
39#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
40#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
60struct DocumentTypeData
64 DocumentTypeData (OUString aURL, OUString aExt) : aStrURL(
std::move(
aURL)), aStrExt(
std::move(aExt))
72 bool bIsValidURL = !rPath.isEmpty();
75 aURLObject.
SetURL( rPath );
76 if ( aURLObject.
GetProtocol() == INetProtocol::NotValid )
81 aURLObject =
base.smartRel2Abs(
83 RTL_TEXTENCODING_UTF8,
true);
85 bIsValidURL = aURLObject.
GetProtocol() != INetProtocol::NotValid;
89 if ( aBase.isEmpty() || ( aBase[0] ==
'.' ) )
111 , m_xRbtEditNow(xBuilder->weld_radio_button(
"editnow"))
112 , m_xRbtEditLater(xBuilder->weld_radio_button(
"editlater"))
113 , m_xCbbPath(new
SvxHyperURLBox(xBuilder->weld_combo_box(
"path")))
114 , m_xBtCreate(xBuilder->weld_button(
"create"))
115 , m_xLbDocTypes(xBuilder->weld_tree_view(
"types"))
117 m_xCbbPath->SetSmartProtocol(INetProtocol::File);
139 for (sal_Int32
n = 0, nEntryCount =
m_xLbDocTypes->n_children();
n < nEntryCount; ++
n)
162 for (
const SvtDynMenuEntry & rDynamicMenuEntry : aDynamicMenuEntries )
164 OUString aDocumentUrl = rDynamicMenuEntry.sURL;
165 OUString aTitle = rDynamicMenuEntry.sTitle;
168 if( aDocumentUrl ==
"private:factory/swriter?slot=21051" ||
169 aDocumentUrl ==
"private:factory/swriter?slot=21052" ||
170 aDocumentUrl ==
"private:factory/sdatabase?Interactive" )
174 if ( !aDocumentUrl.isEmpty() )
176 if ( aDocumentUrl ==
"private:factory/simpress?slot=6686" )
177 aDocumentUrl =
"private:factory/simpress";
184 OUString aTitleName = aTitle.replaceFirst(
"~",
"" );
186 OUString aStrDefExt(pFilter->GetDefaultExtension());
187 DocumentTypeData *pTypeData =
new DocumentTypeData(aDocumentUrl, aStrDefExt.copy(2));
203 OUString& aStrIntName, OUString& aStrFrame,
225 return std::make_unique<SvxHyperlinkNewDocTp>(pWindow, pDlg, pItemSet);
245 OUString aStrDocName;
247 css::uno::Reference<css::frame::XFrame>
xFrame;
254 std::unique_ptr<ExecuteInfo> xExecuteInfo(
static_cast<ExecuteInfo*
>(
p));
255 if (!xExecuteInfo->xFrame.is())
260 css::uno::Reference<css::awt::XTopWindow>(xExecuteInfo->xFrame->getContainerWindow(), css::uno::UNO_QUERY_THROW);
269 OUString aStrFlags(
'S');
270 if (xExecuteInfo->bRbtEditLater)
277 const SfxPoolItem* pReturn = xExecuteInfo->pDispatcher->ExecuteList(
278 SID_OPENDOC, SfxCallMode::SYNCHRON,
279 { &
aName, &aFlags, &aFrame, &aReferer });
291 SID_SAVEASDOC, SfxCallMode::SYNCHRON,
292 { &aNewName }, { &aDocFrame });
296 if (xExecuteInfo->bRbtEditNow)
298 css::uno::Reference<css::awt::XTopWindow> xWindow(xExecuteInfo->xFrame->getContainerWindow(), css::uno::UNO_QUERY);
303 if (pViewFrame && xExecuteInfo->bRbtEditLater)
324 OUString aStrNewName =
m_xCbbPath->get_active_text();
326 if ( aStrNewName.isEmpty() )
342 bool bOk = pIStm && ( pIStm->GetError() ==
ERRCODE_NONE);
349 VclMessageType::Warning, VclButtonsType::YesNo,
350 CuiResId(RID_CUISTR_HYPERDLG_QUERYOVERWRITE)));
351 bCreate = xWarn->run() ==
RET_YES;
354 catch (
const uno::Exception&)
358 if (!bCreate || aStrNewName.isEmpty())
361 ExecuteInfo* pExecuteInfo =
new ExecuteInfo;
369 pExecuteInfo->aURL =
aURL;
370 pExecuteInfo->aStrDocName = weld::fromId<DocumentTypeData*>(
m_xLbDocTypes->get_id(
nPos))->aStrURL;
386 DisableClose(
true );
391 OUString aTempStrURL( m_xCbbPath->get_active_text() );
392 osl::FileBase::getFileURLFromSystemPath( aTempStrURL, aStrURL );
394 OUString aStrPath = aStrURL;
395 bool bZeroPath = aStrPath.isEmpty();
396 bool bHandleFileName = bZeroPath;
401 else if( !::utl::UCBContentHelper::IsFolder( aStrURL ) )
402 bHandleFileName =
true;
404 xFolderPicker->setDisplayDirectory( aStrPath );
405 sal_Int16 nResult = xFolderPicker->execute();
406 DisableClose(
false );
407 if( ExecutableDialogResults::OK != nResult )
410 char const sSlash[] =
"/";
414 if( bHandleFileName )
415 aStrName = bZeroPath? aTempStrURL :
aURL.getName();
417 m_xCbbPath->SetBaseURL( xFolderPicker->getDirectory() );
418 OUString aStrTmp( xFolderPicker->getDirectory() );
420 if( aStrTmp[ aStrTmp.getLength() - 1 ] != sSlash[0] )
424 if( bHandleFileName )
429 if (!aStrName.isEmpty() && !aNewURL.
getExtension().isEmpty() &&
430 m_xLbDocTypes->get_selected_index() != -1)
433 const sal_Int32
nPos = m_xLbDocTypes->get_selected_index();
434 aNewURL.
setExtension(weld::fromId<DocumentTypeData*>(m_xLbDocTypes->get_id(
nPos))->aStrExt);
446 m_xCbbPath->set_entry_text( aStrTmp );
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void SetExtension(std::u16string_view rTheExtension)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
bool setExtension(std::u16string_view rTheExtension, sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void SetExchangeSupport()
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxViewFrame * GetFrame() const
static std::shared_ptr< const SfxFilter > GetDefaultFilterFromFactory(const OUString &rServiceName)
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
SfxViewFrame * GetFrame() const
SfxDispatcher * GetDispatcher()
SfxFrame & GetFrame() const
virtual SfxObjectShell * GetObjectShell() override
const OUString & GetWorkPath() const
ComboBox-Control for URL's with History and Autocompletion.
SvxHyperlinkNewDocTp(weld::Container *pParent, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
void GetCurrentItemData(OUString &rStrURL, OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode) override
std::unique_ptr< weld::Button > m_xBtCreate
bool ImplGetURLObject(const OUString &rPath, std::u16string_view rBase, INetURLObject &aURLObject) const
std::unique_ptr< SvxHyperURLBox > m_xCbbPath
std::unique_ptr< weld::RadioButton > m_xRbtEditLater
virtual void SetInitFocus() override
std::unique_ptr< weld::TreeView > m_xLbDocTypes
virtual void DoApply() override
virtual ~SvxHyperlinkNewDocTp() override
void FillDlgFields(const OUString &rStrURL) override
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
std::unique_ptr< weld::RadioButton > m_xRbtEditNow
SfxDispatcher * GetDispatcher() const
void GetDataFromCommonFields(OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
OUString CuiResId(TranslateId aKey)
IMPL_STATIC_LINK(SvxHyperlinkNewDocTp, DispatchDocument, void *, p, void)
IMPL_LINK_NOARG(SvxHyperlinkNewDocTp, ClickNewHdl_Impl, weld::Button &, void)
#define LINK(Instance, Class, Member)
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
OUString toId(const void *pValue)
Reference< XFrame > xFrame