32 #include <osl/diagnose.h>
40 #include <com/sun/star/text/AutoTextContainer.hpp>
41 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
42 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
62 #include <strings.hrc>
65 #include <officecfg/Office/Writer.hxx>
74 using namespace ::
sfx2;
78 const sal_Int32 nSz = rName.getLength();
84 while( rName[nStart-1]==
' ' && nStart < nSz )
88 aBuf.append(rName[nStart-1]);
90 for( ; nStart < nSz; ++nStart )
92 if( rName[nStart-1]==
' ' && rName[nStart]!=
' ')
93 aBuf.append(rName[nStart]);
95 return aBuf.makeStringAndClear();
117 std::unique_ptr<weld::Button>
m_xOk;
124 DECL_LINK(TextFilterHdl, OUString&,
bool);
128 const OUString& rOldName,
129 const OUString& rOldShort);
131 OUString
GetNewName()
const {
return m_xNewName->get_text(); }
137 rTest = m_aNoSpaceFilter.filter(rTest);
142 : GenericDialogController(pParent->getDialog(),
"modules/swriter/ui/renameautotextdialog.ui",
"RenameAutoTextDialog")
144 , m_xNewName(m_xBuilder->weld_entry(
"newname"))
145 , m_xNewShort(m_xBuilder->weld_entry(
"newsc"))
146 , m_xOk(m_xBuilder->weld_button(
"ok"))
147 , m_xOldName(m_xBuilder->weld_entry(
"oldname"))
148 , m_xOldShort(m_xBuilder->weld_entry(
"oldsc"))
175 rTest = m_aNoSpaceFilter.filter(rTest);
182 , m_sReadonlyPath(
SwResId(STR_READONLY_PATH))
183 , m_pGlossaryHdl(pGlosHdl)
185 , m_bSelection(pWrtShell->IsSelection())
188 , m_bIsDocReadOnly(
false)
190 , m_xInsertTipCB(m_xBuilder->weld_check_button(
"inserttip"))
191 , m_xNameED(m_xBuilder->weld_entry(
"name"))
192 , m_xShortNameLbl(m_xBuilder->weld_label(
"shortnameft"))
193 , m_xShortNameEdit(m_xBuilder->weld_entry(
"shortname"))
194 , m_xCategoryBox(m_xBuilder->weld_tree_view(
"category"))
195 , m_xFileRelCB(m_xBuilder->weld_check_button(
"relfile"))
196 , m_xNetRelCB(m_xBuilder->weld_check_button(
"relnet"))
197 , m_xInsertBtn(m_xBuilder->weld_button(
"ok"))
198 , m_xEditBtn(m_xBuilder->weld_menu_button(
"autotext"))
199 , m_xBibBtn(m_xBuilder->weld_button(
"categories"))
200 , m_xPathBtn(m_xBuilder->weld_button(
"path"))
248 OUString getCurrentGlossary()
264 std::unique_ptr<weld::TreeIter> xEntry = rBox.make_iterator();
265 if (!rBox.get_selected(xEntry.get()))
268 std::unique_ptr<weld::TreeIter> xParent = rBox.make_iterator(xEntry.get());
270 if (rBox.get_iter_depth(*xParent))
272 rBox.iter_parent(*xParent);
273 pParent = xParent.get();
276 pParent = xEntry.get();
277 GroupUserData* pGroupData = weld::fromId<GroupUserData*>(rBox.get_id(*pParent));
280 + OUString::number(pGroupData->
nPathIdx));
286 m_bIsOld = m_pGlossaryHdl->IsOld();
287 if( pParent != xEntry.get())
289 OUString
aName(rBox.get_text(*xEntry));
290 m_xNameED->set_text(
aName);
291 m_xShortNameEdit->set_text(rBox.get_id(*xEntry));
292 m_xInsertBtn->set_sensitive( !m_bIsDocReadOnly);
297 m_xNameED->set_text(
"");
298 m_xShortNameEdit->set_text(
"");
299 m_xShortNameEdit->set_sensitive(
false);
300 ShowAutoText(
"",
"");
303 NameModify(*m_xShortNameEdit);
314 short nRet = SfxDialogController::run();
323 if (!aGlosName.isEmpty())
344 std::u16string_view rShort)
347 std::unique_ptr<weld::TreeIter> xEntry =
m_xCategoryBox->make_iterator();
371 const OUString
aName(m_xNameED->get_text());
372 bool bNameED = &
rEdit == m_xNameED.get();
373 if(
aName.isEmpty() )
377 m_xInsertBtn->set_sensitive(
false);
380 const bool bNotFound = !DoesBlockExist(
aName, bNameED ? OUString() :
rEdit.
get_text());
391 m_xShortNameEdit->set_text(m_pGlossaryHdl->GetGlossaryShortName(
aName));
394 m_xInsertBtn->set_sensitive(!bNotFound && !m_bIsDocReadOnly);
401 m_xInsertBtn->set_sensitive(!m_bIsDocReadOnly);
408 std::unique_ptr<weld::TreeIter> xEntry = rBox.make_iterator();
409 if (rBox.get_selected(xEntry.get()) && rBox.get_iter_depth(*xEntry) && !m_bIsDocReadOnly)
416 std::unique_ptr<weld::TreeIter> xEntry = m_xCategoryBox->make_iterator();
417 bool bEntry = m_xCategoryBox->get_selected(xEntry.get());
419 const OUString aEditText(m_xNameED->get_text());
420 const bool bHasEntry = !aEditText.isEmpty() && !m_xShortNameEdit->get_text().isEmpty();
421 const bool bExists =
nullptr != DoesBlockExist(aEditText, m_xShortNameEdit->get_text());
422 const bool bIsGroup = bEntry && !m_xCategoryBox->get_iter_depth(*xEntry);
423 m_xEditBtn->set_item_visible(
"new", m_bSelection && bHasEntry && !bExists);
424 m_xEditBtn->set_item_visible(
"newtext", m_bSelection && bHasEntry && !bExists);
425 m_xEditBtn->set_item_visible(
"copy", bExists && !bIsGroup);
426 m_xEditBtn->set_item_visible(
"replace", m_bSelection && bExists && !bIsGroup && !m_bIsOld );
427 m_xEditBtn->set_item_visible(
"replacetext", m_bSelection && bExists && !bIsGroup && !m_bIsOld );
428 m_xEditBtn->set_item_visible(
"edit", bExists && !bIsGroup );
429 m_xEditBtn->set_item_visible(
"rename", bExists && !bIsGroup );
430 m_xEditBtn->set_item_visible(
"delete", bExists && !bIsGroup );
431 m_xEditBtn->set_item_visible(
"macro", bExists && !bIsGroup && !m_bIsOld &&
432 !m_pGlossaryHdl->IsReadOnly() );
433 m_xEditBtn->set_item_visible(
"import", bIsGroup && !m_bIsOld && !m_pGlossaryHdl->IsReadOnly() );
438 if (rItemIdent ==
"edit")
444 else if (rItemIdent ==
"replace")
446 m_pGlossaryHdl->NewGlossary(m_xNameED->get_text(),
447 m_xShortNameEdit->get_text());
449 else if (rItemIdent ==
"replacetext")
451 m_pGlossaryHdl->NewGlossary(m_xNameED->get_text(),
452 m_xShortNameEdit->get_text(),
455 else if (rItemIdent ==
"new" || rItemIdent ==
"newtext")
457 bool bNoAttr = rItemIdent ==
"newtext";
459 const OUString
aStr(m_xNameED->get_text());
460 const OUString aShortName(m_xShortNameEdit->get_text());
461 if(m_pGlossaryHdl->HasShortName(aShortName))
464 VclMessageType::Info, VclButtonsType::Ok,
465 SwResId(STR_DOUBLE_SHORTNAME)));
467 m_xShortNameEdit->select_region(0, -1);
468 m_xShortNameEdit->grab_focus();
470 if(m_pGlossaryHdl->NewGlossary(
aStr, aShortName,
false, bNoAttr ))
472 std::unique_ptr<weld::TreeIter> xEntry = m_xCategoryBox->make_iterator();
473 if (!m_xCategoryBox->get_selected(xEntry.get()))
475 else if (m_xCategoryBox->get_iter_depth(*xEntry))
476 m_xCategoryBox->iter_parent(*xEntry);
477 m_xCategoryBox->insert(xEntry.get(), -1, &
aStr, &aShortName,
478 nullptr,
nullptr,
false,
nullptr);
480 m_xNameED->set_text(
aStr);
481 m_xShortNameEdit->set_text(aShortName);
482 NameModify(*m_xNameED);
494 else if (rItemIdent ==
"copy")
496 m_pGlossaryHdl->CopyToClipboard(*
m_pShell, m_xShortNameEdit->get_text());
498 else if (rItemIdent ==
"rename")
500 m_xShortNameEdit->set_text(m_pGlossaryHdl->GetGlossaryShortName(m_xNameED->get_text()));
501 SwNewGlosNameDlg aNewNameDlg(
this, m_xNameED->get_text(), m_xShortNameEdit->get_text());
502 if (aNewNameDlg.run() ==
RET_OK && m_pGlossaryHdl->Rename(m_xShortNameEdit->get_text(),
503 aNewNameDlg.GetNewShort(),
504 aNewNameDlg.GetNewName()))
506 std::unique_ptr<weld::TreeIter> xEntry = m_xCategoryBox->make_iterator();
507 if (m_xCategoryBox->get_selected(xEntry.get()))
509 std::unique_ptr<weld::TreeIter> xOldEntry = m_xCategoryBox->make_iterator(xEntry.get());
510 if (m_xCategoryBox->get_iter_depth(*xEntry))
511 m_xCategoryBox->iter_parent(*xEntry);
513 std::unique_ptr<weld::TreeIter> xNewEntry = m_xCategoryBox->make_iterator();
514 OUString
sId(aNewNameDlg.GetNewShort());
515 OUString
sName(aNewNameDlg.GetNewName());
517 m_xCategoryBox->insert(xEntry.get(), -1, &
sName, &
sId,
518 nullptr,
nullptr,
false, xNewEntry.get());
520 m_xCategoryBox->remove(*xOldEntry);
521 m_xCategoryBox->select(*xNewEntry);
522 m_xCategoryBox->scroll_to_row(*xNewEntry);
525 GrpSelect(*m_xCategoryBox);
527 else if (rItemIdent ==
"delete")
531 else if (rItemIdent ==
"macro")
537 m_pGlossaryHdl->GetMacros(m_xShortNameEdit->get_text(), aStart, aEnd );
540 if( aStart.HasMacro() )
541 aItem.
SetMacro( SvMacroItemId::SwStartInsGlossary, aStart );
543 aItem.
SetMacro( SvMacroItemId::SwEndInsGlossary, aEnd );
551 m_pShell->GetView().GetViewFrame()->GetFrame().GetFrameInterface() ));
552 if ( pMacroDlg && pMacroDlg->Execute() ==
RET_OK &&
556 m_pGlossaryHdl->SetMacros( m_xShortNameEdit->get_text(),
557 rTable.
Get( SvMacroItemId::SwStartInsGlossary ),
558 rTable.
Get( SvMacroItemId::SwEndInsGlossary ) );
561 else if (rItemIdent ==
"import")
564 FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
566 aDlgHelper.SetContext(FileDialogHelper::WriterImportAutotext);
567 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
571 std::shared_ptr<const SfxFilter> pFilter = aIter.
First();
576 xFP->appendFilter( pFilter->GetUIName(),
577 pFilter->GetWildcard().getGlob() );
578 xFP->setCurrentFilter( pFilter->GetUIName() ) ;
582 xFP->appendFilter( pFilter->GetUIName(),
583 pFilter->GetWildcard().getGlob() );
584 xFP->setCurrentFilter( pFilter->GetUIName() ) ;
587 pFilter = aIter.
Next();
592 if( m_pGlossaryHdl->ImportGlossaries( xFP->getSelectedFiles().getConstArray()[0] ))
597 VclMessageType::Info, VclButtonsType::Ok,
616 bool bIsWritable =
false;
617 sal_Int32 nIdx {sGlosPath.isEmpty() ? -1 : 0};
626 uno::Reference< XCommandEnvironment >(),
628 Any aAny = aTestContent.getPropertyValue(
"IsReadOnly" );
631 bIsWritable = !*o3tl::doAccess<bool>(aAny);
648 const OUString sNewGroup = aDlg.GetCreatedGroupName();
650 std::unique_ptr<weld::TreeIter> xEntry = m_xCategoryBox->make_iterator();
651 bool bEntry = m_xCategoryBox->get_iter_first(*xEntry);
653 while (!sNewGroup.isEmpty() && bEntry)
655 if (!m_xCategoryBox->get_iter_depth(*xEntry))
657 GroupUserData* pGroupData = weld::fromId<GroupUserData*>(m_xCategoryBox->get_id(*xEntry));
658 const OUString sGroup = pGroupData->
sGroupName
660 + OUString::number(pGroupData->
nPathIdx);
661 if(sGroup == sNewGroup)
663 m_xCategoryBox->select(*xEntry);
664 m_xCategoryBox->scroll_to_row(*xEntry);
665 GrpSelect(*m_xCategoryBox);
669 bEntry = m_xCategoryBox->iter_next(*xEntry);
677 VclMessageType::Question, VclButtonsType::YesNo,
680 PathHdl(*m_xPathBtn);
695 std::unique_ptr<weld::TreeIter> xSelEntry;
699 static const OUStringLiteral sMyAutoTextEnglish(
u"My AutoText");
700 const OUString sMyAutoTextTranslated(
SwResId(STR_MY_AUTOTEXT));
705 if(sGroupName.isEmpty())
711 if(sTitle == sMyAutoTextEnglish)
712 sTitle = sMyAutoTextTranslated;
714 std::unique_ptr<weld::TreeIter> xEntry =
m_xCategoryBox->make_iterator();
721 pData->
nPathIdx =
static_cast< sal_uInt16
>(nPath);
726 if (sSelStr == pData->
sGroupName && nSelPath == nPath)
733 for(sal_uInt16
i = 0;
i < nCount; ++
i)
738 nullptr,
nullptr,
false,
nullptr);
746 std::unique_ptr<weld::TreeIter> xSearch =
m_xCategoryBox->make_iterator();
756 xSelEntry = std::move(xSearch);
765 xSelEntry = std::move(xSearch);
788 m_xInsertTipCB->set_sensitive(!officecfg::Office::Writer::AutoFunction::Text::ShowToolTip::isReadOnly());
795 OUString
aName(m_xNewName->get_text());
797 if (&rBox == m_xNewName.get())
800 bool bEnable = !
aName.isEmpty() && !m_xNewShort->get_text().isEmpty() &&
801 (!pDlg->DoesBlockExist(
aName, m_xNewShort->get_text())
802 ||
aName == m_xOldName->get_text());
803 m_xOk->set_sensitive(bEnable);
811 && sNew != m_xOldShort->get_text())
814 VclMessageType::Info, VclButtonsType::Ok,
815 SwResId(STR_DOUBLE_SHORTNAME)));
817 m_xNewShort->grab_focus();
826 bool bCheck = rBox.get_active();
827 if (&rBox == m_xInsertTipCB.get())
829 else if (&rBox == m_xFileRelCB.get())
838 if (rKEvt.GetKeyCode().GetCode() ==
KEY_DELETE)
848 std::unique_ptr<weld::TreeIter> xEntry =
m_xCategoryBox->make_iterator();
866 if(
RET_OK == pDlg->Execute())
868 const OUString sTmp(pDlg->
GetPath());
869 if(sTmp != sGlosPath)
890 ResumeShowAutoText();
915 uno::Reference< XTextCursor > & xCursor =
m_xExampleFrame->GetTextCursor();
918 if (!sShortName.isEmpty())
921 uno::Reference< XAutoTextGroup > xGroup;
922 if((aGroup >>= xGroup) && xGroup->hasByName(sShortName))
924 uno::Any aEntry(xGroup->getByName(sShortName));
925 uno::Reference< XAutoTextEntry > xEntry;
927 xEntry->applyTo(xCursor);
939 const OUString aTitle(
m_xNameED->get_text());
942 std::unique_ptr<weld::TreeIter> xParent;
943 std::unique_ptr<weld::TreeIter> xChild =
DoesBlockExist(aTitle, aShortName);
950 const bool bExists =
nullptr != xChild;
951 const bool bIsGroup = bEntry && !xParent;
954 VclMessageType::Question, VclButtonsType::YesNo,
956 if (bExists && !bIsGroup &&
RET_YES == xQuery->run())
960 OSL_ENSURE(xChild,
"entry not found!");
SfxViewFrame * GetViewFrame() const
#define LINK(Instance, Class, Member)
bool GetResumeData(OUString &rGroup, OUString &rShortName)
bool IsGlosPathErr() const
static SvxAutoCorrCfg & Get()
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
std::shared_ptr< const SfxFilter > Next()
std::unique_ptr< weld::Entry > m_xOldShort
virtual const SfxItemSet * GetOutputItemSet() const =0
std::unique_ptr< sal_Int32[]> pData
OUString GetGlossaryShortName(const OUString &rName)
static SvxAbstractDialogFactory * Create()
void ShowAutoText(const OUString &rGroup, const OUString &rShortName)
std::shared_ptr< const SfxFilter > First()
std::unique_ptr< weld::Entry > m_xShortNameEdit
sal_uInt16 GetGlossaryCnt() const
virtual VclPtr< SfxAbstractDialog > CreateEventConfigDialog(weld::Widget *pParent, const SfxItemSet &rAttr, const css::uno::Reference< css::frame::XFrame > &rFrame)=0
virtual ~SwGlossaryDlg() override
bool DelGlossary(const OUString &)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
std::unique_ptr< weld::CheckButton > m_xNetRelCB
void SetSaveRelNet(bool bSet)
std::unique_ptr< SwTextBlocks > GetGroupDoc(const OUString &rName, bool bCreate=false)
static void SetActGroup(const OUString &rNewGroup)
std::unique_ptr< weld::Button > m_xOk
static OUString lcl_GetValidShortCut(const OUString &rName)
virtual void set_text(const OUString &rText)=0
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
size_t GetGroupCnt() const
std::unique_ptr< weld::Button > m_xInsertBtn
TextFilter m_aNoSpaceFilter
IMPL_LINK(SwNewGlosNameDlg, TextFilterHdl, OUString &, rTest, bool)
Used by the UI to modify the document model.
OUString SwResId(TranslateId aId)
constexpr tools::Long Width() const
const SwView & GetView() const
std::unique_ptr< weld::Label > m_xShortNameLbl
constexpr OUStringLiteral FILTER_WW8
WinWord 97 filter.
SwNewGlosNameDlg(SwGlossaryDlg *pParent, const OUString &rOldName, const OUString &rOldShort)
void SetCurGroup(const OUString &aGrp, bool bApi=false, bool bAlwaysCreateNew=false)
static bool HasMacroRecorder(SfxViewFrame const *pFrame)
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
SwGlossaryHdl * m_pGlossaryHdl
static SfxEventNamesItem AddEvents(DlgEventType eType)
static OUString GetCurrGroup()
OUString GetGlossaryName(sal_uInt16)
#define FN_INSERT_GLOSSARY
std::unique_ptr< weld::MenuButton > m_xEditBtn
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
virtual short run() override
std::unique_ptr< weld::TreeIter > DoesBlockExist(std::u16string_view sBlock, std::u16string_view rShort)
SVL_DLLPUBLIC Link< OUString *, bool > const & GetMaybeFileHdl()
std::unique_ptr< weld::Entry > m_xNameED
constexpr TypedWhichId< SvxMacroItem > RES_FRMMACRO(108)
OUString GetNewName() const
SwGlossaryDlg(SfxViewFrame const *pViewFrame, SwGlossaryHdl *pGlosHdl, SwWrtShell *pWrtShell)
bool IsAutoTextTip() const
std::unique_ptr< weld::CustomWeld > m_xExampleFrameWin
std::unique_ptr< weld::CheckButton > m_xFileRelCB
std::unique_ptr< weld::Button > m_xBibBtn
static OUString GetDefName()
DECL_LINK(Modify, weld::Entry &, void)
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
OUString GetCurrGrpName() const
bool IsReadOnly(const OUString *=nullptr) const
OUString GetGroupName(size_t, OUString *pTitle)
virtual VclPtr< AbstractSvxMultiPathDialog > CreateSvxPathSelectDialog(weld::Window *pParent)=0
std::unique_ptr< weld::Entry > m_xNewName
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
bool IsSaveRelFile() const
bool HasReadonlySel() const
void EnableShortName(bool bOn=true)
std::unique_ptr< weld::TreeView > m_xCategoryBox
void UpdateGlosPath(bool bFull)
SwDocShell * GetDocShell()
void SetMacro(SvMacroItemId nEvent, const SvxMacro &)
virtual OUString get_text() const =0
std::unique_ptr< weld::Entry > m_xOldName
virtual OUString GetPath() const =0
void SetAutoTextPath(const OUString &rPath)
void SetSaveRelFile(bool bSet)
SW_DLLPUBLIC const OUString & GetCurrGlosGroup()
void ResumeShowAutoText()
std::vector< std::unique_ptr< GroupUserData > > m_xGroupData
OUString toId(const void *pValue)
bool InsertGlossary(const OUString &rName)
bool HasShortName(const OUString &rShortName) const
css::uno::Reference< css::text::XAutoTextContainer2 > m_xAutoText
const SvxMacro * Get(SvMacroItemId nEvent) const
#define FN_SET_ACT_GLOSSARY
SW_DLLPUBLIC void SetCurrGlosGroup(const OUString &sStr)
IMPL_LINK_NOARG(SwGlossaryDlg, EnableHdl, weld::Toggleable &, void)
std::vector< OUString > const & GetPathArray() const
virtual void SetPath(const OUString &rPath)=0
constexpr tools::Long Height() const
std::unique_ptr< weld::Entry > m_xNewShort
std::unique_ptr< SwOneExampleFrame > m_xExampleFrame
Reference< XExecutableDialog > m_xDialog
Reference< XComponentContext > getProcessComponentContext()
const OUString & GetAutoTextPath() const
sal_Int32 getToken(const Context &rContext, const char *pToken)
void SetAutoTextTip(bool bSet)
std::unique_ptr< weld::CheckButton > m_xInsertTipCB
OUString GetNewShort() const
void SetResumeData(const OUString &rGroup, const OUString &rShortName)
bool IsSaveRelNet() const
void AppendItem(const SfxPoolItem &)
SwGlossaryDlg * m_pParent
constexpr sal_uInt16 KEY_DELETE
constexpr OUStringLiteral FILTER_DOCX
std::unique_ptr< weld::Button > m_xPathBtn
CharClass & GetAppCharClass()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
bool m_bDetectedRangeSegmentation false
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)