43#include <osl/diagnose.h>
57struct TextBlockInfo_Impl
62 TextBlockInfo_Impl(OUString aTitle, OUString aLongName, OUString aGroupName)
63 : sTitle(std::move(aTitle)), sLongName(std::move(aLongName)), sGroupName(std::move(aGroupName)) {}
78 sName = pDlg->GetCurrGrpName();
79 sShortName = pDlg->GetCurrShortName();
89 if( !
sName.isEmpty() || !sShortName.isEmpty() )
97 OUString sGroup(rGrp);
104 bool bPathEqual =
false;
105 if(!bAlwaysCreateNew)
108 const OUString sCurBase = aTemp.
getBase();
112 sal_uInt16 nCurrentPath = USHRT_MAX;
113 for (
size_t nPath = 0; nPath < rPathArr.size(); ++nPath)
115 if (sCurEntryPath == rPathArr[nPath])
117 nCurrentPath = o3tl::narrowing<sal_uInt16>(nPath);
122 sal_uInt16 nComparePath = o3tl::narrowing<sal_uInt16>(
o3tl::toInt32(sPath));
123 if(nCurrentPath == nComparePath &&
129 if(!bAlwaysCreateNew && bPathEqual)
150 if (pGroup && !pGroup->GetError())
152 *pTitle = pGroup->GetName();
153 if (pTitle->isEmpty())
156 pGroup->SetName(*pTitle);
176 OUString sOldGroup(rOld);
184 pGroup->SetName(rNewTitle);
189 OUString sNewGroup(rNew);
200 const OUString& rDestGroupName,
const OUString& rLongName,
bool bMove)
204 if (pDestGroup->IsReadOnly() || (bMove && pSourceGroup->IsReadOnly()) )
210 sal_uInt16 nDeleteIdx = pSourceGroup->GetIndex( rSourceShortName );
211 OSL_ENSURE(USHRT_MAX != nDeleteIdx,
"entry not found");
212 ErrCode nRet = pSourceGroup->CopyBlock( *pDestGroup, rSourceShortName, rLongName );
224 OUString sGroup(rGrpName);
266 if( nIdx != sal_uInt16(-1) )
279 bool bRet = pBlock->
GetIndex( rShortName ) != sal_uInt16(-1);
287 bool bCreateGroup,
bool bNoAttr)
300 OUString* pOnlyText =
nullptr;
304 pOnlyText = &sOnlyText;
311 if(nSuccess == sal_uInt16(-1) )
314 VclMessageType::Info, VclButtonsType::Ok,
SwResId(STR_ERR_INSERT_GLOS)));
319 return nSuccess != sal_uInt16(-1);
335 sal_uInt16 nIdx = pGlossary->
GetIndex( rShortName );
336 if( nIdx != sal_uInt16(-1) )
337 pGlossary->
Delete( nIdx );
349 OUString sGroupName( (*fnGetCurrGroup)() );
381 std::unique_ptr<SwTextBlocks> pGlossary)
383 std::vector<TextBlockInfo_Impl> aFoundArr;
384 OUString aShortName( rShortName );
385 bool bCancel =
false;
391 if( nFound == sal_uInt16(-1) )
396 for(
size_t i = 0;
i < nGroupCount; ++
i)
400 if(sGroupName == pGlossary->GetName())
406 for(sal_uInt16 j = 0; j < nBlockCount; j++)
410 if( rSCmp.isEqual( rShortName, sShortName ))
412 aFoundArr.emplace_back(sTitle, sLongName, sGroupName);
417 if( !aFoundArr.empty() )
420 if (1 == aFoundArr.size())
422 TextBlockInfo_Impl& rData = aFoundArr.front();
423 pGlossary =
pGlossaries->GetGroupDoc(rData.sGroupName);
424 nFound = pGlossary->GetIndex( aShortName );
430 for(
const TextBlockInfo_Impl &
i : aFoundArr)
432 pDlg->InsertGlos(
i.sTitle,
i.sLongName);
434 pDlg->SelectEntryPos(0);
435 const sal_Int32 nRet =
RET_OK == pDlg->Execute() ?
436 pDlg->GetSelectedIdx() :
441 TextBlockInfo_Impl& rData = aFoundArr[nRet];
442 pGlossary =
pGlossaries->GetGroupDoc(rData.sGroupName);
443 nFound = pGlossary->GetIndex( aShortName );
447 nFound = sal_uInt16(-1);
455 if( nFound == sal_uInt16(-1) )
461 const sal_Int32 nMaxLen = 50;
464 aShortName = OUString::Concat(aShortName.subView(0, nMaxLen)) +
" ...";
466 OUString aTmp(
SwResId(STR_NOGLOS));
467 aTmp = aTmp.replaceFirst(
"%1", aShortName);
469 VclMessageType::Info, VclButtonsType::Ok,
480 GetMacros( aShortName, aStartMacro, aEndMacro, pGlossary.get() );
528 GetMacros( rName, aStartMacro, aEndMacro, pGlos );
570 aMacroTable.
Insert( SvMacroItemId::SwStartInsGlossary, *pStart);
572 aMacroTable.
Insert( SvMacroItemId::SwEndInsGlossary, *pEnd);
573 sal_uInt16 nIdx = pGlos->
GetIndex( rShortName );
595 SvxMacro *pMacro = aMacroTable.
Get( SvMacroItemId::SwStartInsGlossary );
599 pMacro = aMacroTable.
Get( SvMacroItemId::SwEndInsGlossary );
613 m_rViewFrame(rVwFrame),
624 const OUString& rNewName )
631 sal_uInt16 nIdx = pGlossary->
GetIndex( rOldShort );
632 sal_uInt16 nOldLongIdx = pGlossary->
GetLongIndex( rNewName );
633 sal_uInt16 nOldIdx = pGlossary->
GetIndex( rNewShortName );
635 if( nIdx != USHRT_MAX &&
636 (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&&
637 (nOldIdx == USHRT_MAX || nOldIdx == nIdx ))
639 pGlossary->
Rename( nIdx, &rNewShortName, &rNewName );
659 const bool bRet = !pGlossary || pGlossary->
IsReadOnly();
685 bool bRet = pTransfer->CopyGlossary( *pGlossary, rShortName );
694 if( !rName.isEmpty() )
696 std::shared_ptr<const SfxFilter> pFilter;
697 SfxMedium aMed( rName, StreamMode::READ,
nullptr,
nullptr );
702 assert(pFilter &&
"success means pFilter was set");
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
OUString getBase(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
ErrCode GuessFilter(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
void UseInteractionHandler(bool)
void SetFilter(const std::shared_ptr< const SfxFilter > &pFilter)
weld::Window * GetFrameWeld() const
bool IsSearchInAllCategories() const
static SvxAutoCorrCfg & Get()
bool IsSaveRelFile() const
SvxMacro & Insert(SvMacroItemId nEvent, const SvxMacro &rMacro)
const SvxMacro * Get(SvMacroItemId nEvent) const
virtual VclPtr< AbstractGlossaryDlg > CreateGlossaryDlg(SfxViewFrame &rViewFrame, SwGlossaryHdl *pGlosHdl, SwWrtShell *pWrtShell)=0
virtual GlossaryGetCurrGroup GetGlossaryCurrGroupFunc()=0
static SwAbstractDialogFactory * Create()
virtual VclPtr< AbstractSwSelGlossaryDlg > CreateSwSelGlossaryDlg(weld::Window *pParent, const OUString &rShortName)=0
bool IsInWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
OUString GetSelText() const
get selected text of a node at current cursor
void StartAllAction()
For all views of this document.
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
sal_uInt16 MakeGlossary(SwTextBlocks &rToFill, const OUString &rName, const OUString &rShortName, bool bSaveRelFile, const OUString *pOnlyText)
Make current selection glossary and insert into glossary document including styles.
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
void GetSelectedText(OUString &rBuf, ParaBreakType nHndlParaBreak=ParaBreakType::ToBlank)
Query text within selection.
void InsertGlossary(SwTextBlocks &rGlossary, const OUString &)
Glossary from glossary document in current document.
bool NewGroupDoc(OUString &rGroupName, const OUString &rTitle)
std::vector< OUString > const & GetPathArray() const
std::unique_ptr< SwTextBlocks > GetGroupDoc(const OUString &rName, bool bCreate=false)
SwDocShellRef EditGroupDoc(const OUString &rGrpName, const OUString &rShortName, bool bShow=true)
OUString const & GetGroupName(size_t)
bool DelGroupDoc(std::u16string_view)
bool FindGroupName(OUString &rGroup)
bool RenameGroupDoc(const OUString &sOldGroup, OUString &sNewGroup, const OUString &rNewTitle)
bool ExpandGlossary(weld::Window *pParent)
bool DelGroup(const OUString &)
bool DelGlossary(const OUString &)
bool Rename(const OUString &rOldShortName, const OUString &rNewShortName, const OUString &rNewName)
bool ImportGlossaries(const OUString &rName)
bool HasShortName(const OUString &rShortName) const
SwGlossaries & m_rStatGlossaries
sal_uInt16 GetGlossaryCnt() const
bool InsertGlossary(const OUString &rName)
bool IsReadOnly(const OUString *=nullptr) const
void SetCurGroup(const OUString &aGrp, bool bApi=false, bool bAlwaysCreateNew=false)
OUString GetGlossaryShortName(std::u16string_view aName)
bool NewGlossary(const OUString &rName, const OUString &rShortName, bool bApiCall=false, bool bNoAttr=false)
void SetMacros(const OUString &rName, const SvxMacro *pStart, const SvxMacro *pEnd, SwTextBlocks *pGlossary=nullptr)
OUString GetGroupName(size_t, OUString *pTitle)
bool CopyOrMove(const OUString &rSourceGroupName, OUString &rSourceShortName, const OUString &rDestGroupName, const OUString &rLongName, bool bMove)
std::unique_ptr< SwTextBlocks > m_pCurGrp
bool CopyToClipboard(SwWrtShell &rSh, const OUString &rShortName)
void GetMacros(const OUString &rShortName, SvxMacro &rStart, SvxMacro &rEnd, SwTextBlocks *pGlossary=nullptr)
SAL_DLLPRIVATE bool Expand(weld::Window *pParent, const OUString &rShortName, SwGlossaries *pGlossaries, std::unique_ptr< SwTextBlocks > pGlossary)
size_t GetGroupCnt() const
OUString GetGlossaryName(sal_uInt16)
SfxViewFrame & m_rViewFrame
void RenameGroup(const OUString &rOld, OUString &rNew, const OUString &rNewTitle)
SwGlossaryHdl(SfxViewFrame &rViewFrame, SwWrtShell *)
bool FindGroupName(OUString &rGroup)
void NewGroup(OUString &rGroupName, const OUString &rTitle)
OUString GetBlockShortName(size_t nGroup, sal_uInt16 nBlock)
OUString GetGroupName(size_t nPos)
OUString GetBlockLongName(size_t nGroup, sal_uInt16 nBlock)
OUString GetGroupTitle(size_t nPos)
sal_uInt16 GetBlockCount(size_t nGroup)
bool ReadGlossaries(const Reader &, SwTextBlocks &, bool bSaveRelFiles)
bool HasGlossaries(const Reader &)
void Rename(sal_uInt16, const OUString *, const OUString *)
bool SetMacroTable(sal_uInt16 nIdx, const SvxMacroTableDtor &rMacroTable)
bool GetMacroTable(sal_uInt16 nIdx, SvxMacroTableDtor &rMacroTable)
sal_uInt16 GetIndex(const OUString &) const
sal_uInt16 GetLongIndex(std::u16string_view) const
OUString GetShortName(sal_uInt16) const
ErrCode const & GetError() const
Used by the UI to modify the document model.
bool PrvWrd(bool bSelect=false)
void UpdateInputFields(SwInputFieldList *pLst=nullptr)
void ExecMacro(const SvxMacro &rMacro, OUString *pRet=nullptr, SbxArray *pArgs=nullptr)
bool DelRight(bool isReplaceHeuristic=false)
bool HasSelection() const
const SwView & GetView() const
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
static std::unique_ptr< SwGlossaries > pGlossaries
static SwGlossaryList * pGlossaryList
SwGlossaryList * GetGlossaryList()
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
Reader * GetReader(const OUString &rFltName)
Return reader based on the name.
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OUString(* GlossaryGetCurrGroup)()
OUString SwResId(TranslateId aId)