29#include <bitmaps.hlst>
35#include <com/sun/star/uno/Exception.hpp>
36#include <com/sun/star/beans/PropertyAttribute.hpp>
37#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
39#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
40#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
41#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
42#include <com/sun/star/util/thePathSettings.hpp>
48using namespace css::beans;
49using namespace css::lang;
50using namespace css::ui::dialogs;
51using namespace css::uno;
77struct PathUserData_Impl
82 OUString sWritablePath;
87 , bItemStateSet(false)
93struct Handle2CfgNameMapping_Impl
96 const char* m_pCfgName;
113#if OSL_DEBUG_LEVEL > 1
137#define MULTIPATH_DELIMITER ';'
145 OUStringBuffer aReturn;
157 return aReturn.makeStringAndClear();
164#if OSL_DEBUG_LEVEL > 1
184 :
SfxTabPage( pPage, pController,
"cui/ui/optpathspage.ui",
"OptPathsPage", &
rSet)
186 , xDialogListener ( new ::
svt::DialogClosedListener() )
187 , m_xStandardBtn(m_xBuilder->weld_button(
"default"))
188 , m_xPathBtn(m_xBuilder->weld_button(
"edit"))
189 , m_xPathBox(m_xBuilder->weld_tree_view(
"paths"))
200 m_xPathBox->set_selection_mode(SelectionMode::Multiple);
207 bool bSortAtoZ = !m_xPathBox->get_sort_order();
208 m_xPathBox->set_sort_order(bSortAtoZ);
214 for (
int i = 0, nEntryCount =
m_xPathBox->n_children();
i < nEntryCount; ++
i)
215 delete weld::fromId<PathUserData_Impl*>(
m_xPathBox->get_id(
i));
221 return std::make_unique<SvxPathTabPage>( pPage, pController, *rAttrSet );
226 for (
int i = 0, nEntryCount =
m_xPathBox->n_children();
i < nEntryCount; ++
i)
228 PathUserData_Impl* pPathImpl = weld::fromId<PathUserData_Impl*>(
m_xPathBox->get_id(
i));
230 if (pPathImpl->bItemStateSet )
231 SetPathList( nRealId, pPathImpl->sUserPath, pPathImpl->sWritablePath );
241 std::unique_ptr<weld::TreeIter> xIter =
m_xPathBox->make_iterator();
254 pId = RID_CUISTR_KEY_AUTOCORRECT_DIR;
257 pId = RID_CUISTR_KEY_GLOSSARY_PATH;
260 pId = RID_CUISTR_KEY_BACKUP_PATH;
263 pId = RID_CUISTR_KEY_GALLERY_DIR;
266 pId = RID_CUISTR_KEY_GRAPHICS_PATH;
269 pId = RID_CUISTR_KEY_TEMP_PATH;
272 pId = RID_CUISTR_KEY_TEMPLATE_PATH;
275 pId = RID_CUISTR_KEY_DICTIONARY_PATH;
278 pId = RID_CUISTR_KEY_CLASSIFICATION_PATH;
280#if OSL_DEBUG_LEVEL > 1
282 pId = RID_CUISTR_KEY_LINGUISTIC_DIR;
286 pId = RID_CUISTR_KEY_WORK_PATH;
298 OUString sInternal, sUser, sWritable;
303 m_xPathBox->set_image(*xIter, RID_SVXBMP_LOCK);
305 OUString sTmpPath = sUser;
306 if ( !sTmpPath.isEmpty() && !sWritable.isEmpty() )
308 sTmpPath += sWritable;
313 const OUString aValueInternal =
Convert_Impl( sInternal );
315 m_xPathBox->set_text(*xIter, aValueInternal, 2);
322 pPathImpl->sUserPath = sUser;
323 pPathImpl->sWritablePath = sWritable;
338 bool bEnable =
false;
339 int nEntry = m_xPathBox->get_selected_index();
342 PathUserData_Impl* pPathImpl = weld::fromId<PathUserData_Impl*>(m_xPathBox->get_id(nEntry));
343 bEnable = !pPathImpl->bReadOnly;
345 sal_uInt16 nSelCount = m_xPathBox->count_selected_rows();
346 m_xPathBtn->set_sensitive(1 == nSelCount && bEnable);
347 m_xStandardBtn->set_sensitive(nSelCount > 0 && bEnable);
353 PathUserData_Impl* pPathImpl = weld::fromId<PathUserData_Impl*>(m_xPathBox->get_id(rEntry));
356 if ( !aOldPath.isEmpty() )
358 OUString sInternal, sUser, sWritable, sTemp;
360 GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable,
bReadOnly );
362 sal_Int32 nOldPos = 0;
367 if ( !sInternal.isEmpty() )
369 sal_Int32 nInternalPos = 0;
375 while ( !bFound && nInternalPos >= 0 );
379 if ( !sTemp.isEmpty() )
384 while ( nOldPos >= 0 );
386 OUString sWritablePath;
387 OUStringBuffer sUserPath;
388 if ( !sTemp.isEmpty() )
390 sal_Int32 nNextPos = 0;
397 sWritablePath = sToken;
400 if ( !sUserPath.isEmpty() )
402 sUserPath.append(sToken);
406 pPathImpl->bItemStateSet =
true;
407 pPathImpl->sUserPath = sUserPath.makeStringAndClear();
408 pPathImpl->sWritablePath = sWritablePath;
419 SAL_WARN(
"cui.options",
"SvxPathTabPage::ChangeCurrentEntry(): no entry" );
423 OUString sInternal, sUser, sWritable;
424 PathUserData_Impl* pPathImpl = weld::fromId<PathUserData_Impl*>(
m_xPathBox->get_id(nEntry));
427 sUser = pPathImpl->sUserPath;
428 sWritable = pPathImpl->sWritablePath;
432 bool bURL = ( aObj.
GetProtocol() != INetProtocol::NotValid );
437 OUString sNewPathStr = bURL ? _rFolder : aNewObj.
getFSysPath( FSysStyle::Detect );
442 ( sNewPathStr != sWritable );
444 !sNewPathStr.equalsIgnoreAsciiCase( sWritable );
451 pPathImpl->bItemStateSet =
true;
452 pPathImpl->sWritablePath = sNewPathStr;
467 PathHdl_Impl(*m_xPathBtn);
473 int nEntry = m_xPathBox->get_cursor_index();
474 PathUserData_Impl* pPathImpl = nEntry != -1 ? weld::fromId<PathUserData_Impl*>(m_xPathBox->get_id(nEntry)) :
nullptr;
475 if (!pPathImpl || pPathImpl->bReadOnly)
479 OUString sInternal, sUser, sWritable;
480 bool bPickFile =
false;
482 GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable,
bReadOnly );
483 sUser = pPathImpl->sUserPath;
484 sWritable = pPathImpl->sWritablePath;
493 OUString sPath( sUser );
494 if ( !sPath.isEmpty() )
497 pMultiDlg->SetPath( sPath );
499 const OUString sPathName = m_xPathBox->get_text(nEntry, 0);
500 const OUString sNewTitle = pImpl->m_sMultiPathDlg.replaceFirst(
VAR_ONE, sPathName );
501 pMultiDlg->SetTitle( sNewTitle );
503 if (pMultiDlg->Execute() ==
RET_OK)
508 OUString sNewPath = pMultiDlg->GetPath();
509 if ( !sNewPath.isEmpty() )
511 sal_Int32 nNextPos = 0;
521 if ( !sUser.isEmpty() )
526 if ( !sFullPath.isEmpty() )
528 sFullPath += sWritable;
531 m_xPathBox->set_text(nEntry,
Convert_Impl(sFullPath), 1);
533 pPathImpl->bItemStateSet =
true;
534 pPathImpl->sUserPath = sUser;
535 pPathImpl->sWritablePath = sWritable;
542 Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
548 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
549 if ( xAsyncDlg.is() )
550 xAsyncDlg->startExecuteModal( xDialogListener );
553 short nRet = xFolderPicker->execute();
554 if (ExecutableDialogResults::OK != nRet)
557 OUString sFolder(xFolderPicker->getDirectory());
558 ChangeCurrentEntry(sFolder);
563 TOOLS_WARN_EXCEPTION(
"cui.options",
"SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
572 xFilePicker->appendFilter(OUString(),
"*.xml");
573 if (xFilePicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
576 ChangeCurrentEntry(aPathSeq[0]);
579 catch (
const uno::Exception&)
588 if (
RET_OK == pEvt->DialogResult)
590 assert(xFolderPicker.is() &&
"SvxPathTabPage::DialogClosedHdl(): no folder picker");
591 OUString sURL = xFolderPicker->getDirectory();
592 ChangeCurrentEntry( sURL );
598 OUString& _rUserPath, OUString& _rWritablePath,
bool& _rReadOnly )
605 if ( !
pImpl->m_xPathSettings.is() )
608 pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
612 Any aAny =
pImpl->m_xPathSettings->getPropertyValue(
615 if ( aAny >>= aPathSeq )
618 const OUString* pPaths = aPathSeq.getConstArray();
622 if ( !_rInternalPath.isEmpty() )
623 _rInternalPath +=
";";
624 _rInternalPath += pPaths[
i];
628 aAny =
pImpl->m_xPathSettings->getPropertyValue(
630 if ( aAny >>= aPathSeq )
633 const OUString* pPaths = aPathSeq.getConstArray();
637 if ( !_rUserPath.isEmpty() )
639 _rUserPath += pPaths[
i];
643 aAny =
pImpl->m_xPathSettings->getPropertyValue(
645 OUString sWritablePath;
646 if ( aAny >>= sWritablePath )
647 _rWritablePath = sWritablePath;
651 Property aProp = xInfo->getPropertyByName(sCfgName);
652 _rReadOnly = ( ( aProp.Attributes & PropertyAttribute::READONLY ) == PropertyAttribute::READONLY );
669 if ( !
pImpl->m_xPathSettings.is() )
672 pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
678 OUString* pArray = aPathSeq.getArray();
682 Any aValue( aPathSeq );
683 pImpl->m_xPathSettings->setPropertyValue(
687 aValue <<= _rWritablePath;
688 pImpl->m_xPathSettings->setPropertyValue(
SfxApplication * SfxGetpApp()
OUString PathToFileName() const
INetProtocol GetProtocol() const
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
bool IsModuleInstalled(EModule eModule) const
virtual VclPtr< AbstractSvxMultiPathDialog > CreateSvxMultiPathDialog(weld::Window *pParent)=0
static SvxAbstractDialogFactory * Create()
std::unique_ptr< weld::TreeView > m_xPathBox
void GetPathList(SvtPathOptions::Paths _nPathHandle, OUString &_rInternalPath, OUString &_rUserPath, OUString &_rWritablePath, bool &_rReadOnly)
virtual bool FillItemSet(SfxItemSet *rSet) override
void SetPathList(SvtPathOptions::Paths _nPathHandle, std::u16string_view _rUserPath, const OUString &_rWritablePath)
void ChangeCurrentEntry(const OUString &_rFolder)
rtl::Reference< ::svt::DialogClosedListener > xDialogListener
std::unique_ptr< weld::Button > m_xStandardBtn
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
virtual ~SvxPathTabPage() override
std::unique_ptr< OptPath_Impl > pImpl
std::unique_ptr< weld::Button > m_xPathBtn
virtual void Reset(const SfxItemSet *rSet) override
SvxPathTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
OUString CuiResId(TranslateId aKey)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
const sal_Int32 m_nHandle
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
OUString GetDefaultPath(SvtPathOptions::Paths nId)
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
Reference< XComponentContext > getProcessComponentContext()
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
OUString toId(const void *pValue)
static OUString getCfgName_Impl(SvtPathOptions::Paths _nHandle)
constexpr OUStringLiteral POSTFIX_WRITABLE
static OUString Convert_Impl(std::u16string_view rValue)
IMPL_LINK_NOARG(SvxPathTabPage, PathSelect_Impl, weld::TreeView &, void)
constexpr OUStringLiteral POSTFIX_INTERNAL
constexpr OUStringLiteral VAR_ONE
constexpr OUStringLiteral POSTFIX_USER
constexpr OUStringLiteral IODLG_CONFIGNAME
static bool IsMultiPath_Impl(const SvtPathOptions::Paths nIndex)
Handle2CfgNameMapping_Impl const Hdl2CfgMap_Impl[]
IMPL_LINK(SvxPathTabPage, HeaderBarClick, int, nColumn, void)
#define MULTIPATH_DELIMITER
Reference< css::util::XPathSettings > m_xPathSettings