1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vcl/errinf.hxx>
22 #include <vcl/weld.hxx>
23 #include <svl/macitem.hxx>
24 #include <sfx2/fcontnr.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <sfx2/docfilt.hxx>
27 #include <unotools/transliterationwrapper.hxx>
28 #include <o3tl/string_view.hxx>
32 #include <gloshdl.hxx>
33 #include <glosdoc.hxx>
34 #include <shellio.hxx>
38 #include <gloslst.hxx>
39 #include <swdtflvr.hxx>
41 #include <strings.hrc>
42 #include <vcl/svapp.hxx>
43 #include <osl/diagnose.h>
45 #include <editeng/acorrcfg.hxx>
46 #include <sfx2/event.hxx>
47 #include <swabstdlg.hxx>
51 using namespace ::com::sun::star
;
53 const short RET_EDIT
= 100;
57 struct TextBlockInfo_Impl
62 TextBlockInfo_Impl(OUString aTitle
, OUString aLongName
, OUString aGroupName
)
63 : sTitle(std::move(aTitle
)), sLongName(std::move(aLongName
)), sGroupName(std::move(aGroupName
)) {}
68 // Dialog for edit templates
69 void SwGlossaryHdl::GlossaryDlg()
71 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
72 ScopedVclPtr
<AbstractGlossaryDlg
> pDlg(pFact
->CreateGlossaryDlg(m_rViewFrame
, this, m_pWrtShell
));
76 if( RET_EDIT
== pDlg
->Execute() )
78 sName
= pDlg
->GetCurrGrpName();
79 sShortName
= pDlg
->GetCurrShortName();
82 pDlg
.disposeAndClear();
86 GetGlossaryList()->ClearGroups();
89 if( !sName
.isEmpty() || !sShortName
.isEmpty() )
90 m_rStatGlossaries
.EditGroupDoc( sName
, sShortName
);
93 // set the default group; if called from the dialog
94 // the group is created temporarily for faster access
95 void SwGlossaryHdl::SetCurGroup(const OUString
&rGrp
, bool bApi
, bool bAlwaysCreateNew
)
97 OUString
sGroup(rGrp
);
98 if (sGroup
.indexOf(GLOS_DELIM
)<0 && !FindGroupName(sGroup
))
100 sGroup
+= OUStringChar(GLOS_DELIM
) + "0";
104 bool bPathEqual
= false;
105 if(!bAlwaysCreateNew
)
107 INetURLObject
aTemp( m_pCurGrp
->GetFileName() );
108 const OUString sCurBase
= aTemp
.getBase();
109 aTemp
.removeSegment();
110 const OUString sCurEntryPath
= aTemp
.GetMainURL(INetURLObject::DecodeMechanism::NONE
);
111 const std::vector
<OUString
> & rPathArr
= m_rStatGlossaries
.GetPathArray();
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
);
121 const std::u16string_view sPath
= o3tl::getToken(sGroup
, 1, GLOS_DELIM
);
122 sal_uInt16 nComparePath
= o3tl::narrowing
<sal_uInt16
>(o3tl::toInt32(sPath
));
123 if(nCurrentPath
== nComparePath
&&
124 o3tl::getToken(sGroup
, 0, GLOS_DELIM
) == sCurBase
)
128 // When path changed, the name is not reliable
129 if(!bAlwaysCreateNew
&& bPathEqual
)
135 m_pCurGrp
= m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
, true);
139 size_t SwGlossaryHdl::GetGroupCnt() const
141 return m_rStatGlossaries
.GetGroupCnt();
144 OUString
SwGlossaryHdl::GetGroupName( size_t nId
, OUString
* pTitle
)
146 OUString sRet
= m_rStatGlossaries
.GetGroupName(nId
);
149 std::unique_ptr
<SwTextBlocks
> pGroup
= m_rStatGlossaries
.GetGroupDoc(sRet
);
150 if (pGroup
&& !pGroup
->GetError())
152 *pTitle
= pGroup
->GetName();
153 if (pTitle
->isEmpty())
155 *pTitle
= sRet
.getToken(0, GLOS_DELIM
);
156 pGroup
->SetName(*pTitle
);
167 void SwGlossaryHdl::NewGroup(OUString
&rGrpName
, const OUString
& rTitle
)
169 if (rGrpName
.indexOf(GLOS_DELIM
)<0)
170 FindGroupName(rGrpName
);
171 m_rStatGlossaries
.NewGroupDoc(rGrpName
, rTitle
);
174 void SwGlossaryHdl::RenameGroup(const OUString
& rOld
, OUString
& rNew
, const OUString
& rNewTitle
)
176 OUString
sOldGroup(rOld
);
177 if (rOld
.indexOf(GLOS_DELIM
)<0)
178 FindGroupName(sOldGroup
);
181 std::unique_ptr
<SwTextBlocks
> pGroup
= m_rStatGlossaries
.GetGroupDoc(sOldGroup
);
184 pGroup
->SetName(rNewTitle
);
189 OUString
sNewGroup(rNew
);
190 if (sNewGroup
.indexOf(GLOS_DELIM
)<0)
192 sNewGroup
+= OUStringChar(GLOS_DELIM
) + "0";
194 m_rStatGlossaries
.RenameGroupDoc(sOldGroup
, sNewGroup
, rNewTitle
);
199 bool SwGlossaryHdl::CopyOrMove(const OUString
& rSourceGroupName
, OUString
& rSourceShortName
,
200 const OUString
& rDestGroupName
, const OUString
& rLongName
, bool bMove
)
202 std::unique_ptr
<SwTextBlocks
> pSourceGroup
= m_rStatGlossaries
.GetGroupDoc(rSourceGroupName
);
203 std::unique_ptr
<SwTextBlocks
> pDestGroup
= m_rStatGlossaries
.GetGroupDoc(rDestGroupName
);
204 if (pDestGroup
->IsReadOnly() || (bMove
&& pSourceGroup
->IsReadOnly()) )
209 //The index must be determined here because rSourceShortName maybe changed in CopyBlock
210 sal_uInt16 nDeleteIdx
= pSourceGroup
->GetIndex( rSourceShortName
);
211 OSL_ENSURE(USHRT_MAX
!= nDeleteIdx
, "entry not found");
212 ErrCode nRet
= pSourceGroup
->CopyBlock( *pDestGroup
, rSourceShortName
, rLongName
);
215 // the index must be existing
216 nRet
= pSourceGroup
->Delete( nDeleteIdx
) ? ERRCODE_NONE
: ErrCode(1);
221 // delete an autotext-file-group
222 bool SwGlossaryHdl::DelGroup(const OUString
&rGrpName
)
224 OUString
sGroup(rGrpName
);
225 if (sGroup
.indexOf(GLOS_DELIM
)<0)
226 FindGroupName(sGroup
);
227 if( m_rStatGlossaries
.DelGroupDoc(sGroup
) )
231 if (m_pCurGrp
->GetName() == sGroup
)
239 // ask for number of autotexts
240 sal_uInt16
SwGlossaryHdl::GetGlossaryCnt() const
242 return m_pCurGrp
? m_pCurGrp
->GetCount() : 0;
245 OUString
SwGlossaryHdl::GetGlossaryName( sal_uInt16 nId
)
247 OSL_ENSURE(nId
< GetGlossaryCnt(), "Text building block array over-indexed.");
248 return m_pCurGrp
->GetLongName( nId
);
251 OUString
SwGlossaryHdl::GetGlossaryShortName(sal_uInt16 nId
)
253 OSL_ENSURE(nId
< GetGlossaryCnt(), "Text building block array over-indexed.");
254 return m_pCurGrp
->GetShortName( nId
);
257 // ask for short name
258 OUString
SwGlossaryHdl::GetGlossaryShortName(std::u16string_view aName
)
262 m_pCurGrp
? m_pCurGrp
.get() : m_rStatGlossaries
.GetGroupDoc( m_aCurGrp
).release();
265 sal_uInt16 nIdx
= pTmp
->GetLongIndex( aName
);
266 if( nIdx
!= sal_uInt16(-1) )
267 sReturn
= pTmp
->GetShortName( nIdx
);
274 // short name for autotext already used?
275 bool SwGlossaryHdl::HasShortName(const OUString
& rShortName
) const
277 SwTextBlocks
*pBlock
= m_pCurGrp
? m_pCurGrp
.get()
278 : m_rStatGlossaries
.GetGroupDoc( m_aCurGrp
).release();
279 bool bRet
= pBlock
->GetIndex( rShortName
) != sal_uInt16(-1);
286 bool SwGlossaryHdl::NewGlossary(const OUString
& rName
, const OUString
& rShortName
,
287 bool bCreateGroup
, bool bNoAttr
)
290 m_pCurGrp
? m_pCurGrp
.get() : m_rStatGlossaries
.GetGroupDoc( m_aCurGrp
, bCreateGroup
).release();
291 //pTmp == 0 if the AutoText path setting is wrong
300 OUString
* pOnlyText
= nullptr;
303 m_pWrtShell
->GetSelectedText( sOnlyText
, ParaBreakType::ToOnlyCR
);
304 pOnlyText
= &sOnlyText
;
307 const SvxAutoCorrCfg
& rCfg
= SvxAutoCorrCfg::Get();
309 const sal_uInt16 nSuccess
= m_pWrtShell
->MakeGlossary( *pTmp
, rName
, rShortName
,
310 rCfg
.IsSaveRelFile(), pOnlyText
);
311 if(nSuccess
== sal_uInt16(-1) )
313 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(m_pWrtShell
->GetView().GetFrameWeld(),
314 VclMessageType::Info
, VclButtonsType::Ok
, SwResId(STR_ERR_INSERT_GLOS
)));
319 return nSuccess
!= sal_uInt16(-1);
322 // Delete an autotext
323 bool SwGlossaryHdl::DelGlossary(const OUString
&rShortName
)
325 SwTextBlocks
*pGlossary
= m_pCurGrp
? m_pCurGrp
.get()
326 : m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).release();
327 //pTmp == 0 if the AutoText path setting is wrong
335 sal_uInt16 nIdx
= pGlossary
->GetIndex( rShortName
);
336 if( nIdx
!= sal_uInt16(-1) )
337 pGlossary
->Delete( nIdx
);
344 bool SwGlossaryHdl::ExpandGlossary(weld::Window
* pParent
)
346 OSL_ENSURE(m_pWrtShell
->CanInsert(), "illegal");
347 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
348 ::GlossaryGetCurrGroup fnGetCurrGroup
= pFact
->GetGlossaryCurrGroupFunc();
349 OUString
sGroupName( (*fnGetCurrGroup
)() );
350 if (sGroupName
.indexOf(GLOS_DELIM
)<0)
351 FindGroupName(sGroupName
);
352 std::unique_ptr
<SwTextBlocks
> pGlossary
= m_rStatGlossaries
.GetGroupDoc(sGroupName
);
356 // use this at text selection
357 if(m_pWrtShell
->SwCursorShell::HasSelection() && !m_pWrtShell
->IsBlockMode())
359 aShortName
= m_pWrtShell
->GetSelText();
363 if(m_pWrtShell
->IsAddMode())
364 m_pWrtShell
->LeaveAddMode();
365 else if(m_pWrtShell
->IsBlockMode())
366 m_pWrtShell
->LeaveBlockMode();
367 else if(m_pWrtShell
->IsExtMode())
368 m_pWrtShell
->LeaveExtMode();
369 // select word (tdf#126589: part to the left of cursor)
370 if (m_pWrtShell
->IsInWord() || m_pWrtShell
->IsEndWrd())
371 m_pWrtShell
->PrvWrd(true);
373 if(m_pWrtShell
->IsSelection())
374 aShortName
= m_pWrtShell
->GetSelText();
376 return pGlossary
&& Expand(pParent
, aShortName
, &m_rStatGlossaries
, std::move(pGlossary
));
379 bool SwGlossaryHdl::Expand(weld::Window
* pParent
, const OUString
& rShortName
,
380 SwGlossaries
*pGlossaries
,
381 std::unique_ptr
<SwTextBlocks
> pGlossary
)
383 std::vector
<TextBlockInfo_Impl
> aFoundArr
;
384 OUString
aShortName( rShortName
);
385 bool bCancel
= false;
386 // search for text block
387 // - don't prefer current group depending on configuration setting
388 const SvxAutoCorrCfg
& rCfg
= SvxAutoCorrCfg::Get();
389 sal_uInt16 nFound
= !rCfg
.IsSearchInAllCategories() ? pGlossary
->GetIndex( aShortName
) : -1;
390 // if not found then search in all groups
391 if( nFound
== sal_uInt16(-1) )
393 const ::utl::TransliterationWrapper
& rSCmp
= GetAppCmpStrIgnore();
394 SwGlossaryList
* pGlossaryList
= ::GetGlossaryList();
395 const size_t nGroupCount
= pGlossaryList
->GetGroupCount();
396 for(size_t i
= 0; i
< nGroupCount
; ++i
)
398 // get group name with path-extension
399 const OUString sGroupName
= pGlossaryList
->GetGroupName(i
);
400 if(sGroupName
== pGlossary
->GetName())
402 const sal_uInt16 nBlockCount
= pGlossaryList
->GetBlockCount(i
);
405 const OUString sTitle
= pGlossaryList
->GetGroupTitle(i
);
406 for(sal_uInt16 j
= 0; j
< nBlockCount
; j
++)
408 const OUString
sLongName(pGlossaryList
->GetBlockLongName(i
, j
));
409 const OUString
sShortName(pGlossaryList
->GetBlockShortName(i
, j
));
410 if( rSCmp
.isEqual( rShortName
, sShortName
))
412 aFoundArr
.emplace_back(sTitle
, sLongName
, sGroupName
);
417 if( !aFoundArr
.empty() ) // one was found
420 if (1 == aFoundArr
.size())
422 TextBlockInfo_Impl
& rData
= aFoundArr
.front();
423 pGlossary
= pGlossaries
->GetGroupDoc(rData
.sGroupName
);
424 nFound
= pGlossary
->GetIndex( aShortName
);
428 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
429 ScopedVclPtr
<AbstractSwSelGlossaryDlg
> pDlg(pFact
->CreateSwSelGlossaryDlg(pParent
, 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() :
438 pDlg
.disposeAndClear();
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;
462 if(m_pWrtShell
->IsSelection() && aShortName
.getLength() > nMaxLen
)
464 aShortName
= OUString::Concat(aShortName
.subView(0, nMaxLen
)) + " ...";
466 OUString
aTmp( SwResId(STR_NOGLOS
));
467 aTmp
= aTmp
.replaceFirst("%1", aShortName
);
468 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(m_pWrtShell
->GetView().GetFrameWeld(),
469 VclMessageType::Info
, VclButtonsType::Ok
,
478 SvxMacro
aStartMacro(OUString(), OUString(), STARBASIC
);
479 SvxMacro
aEndMacro(OUString(), OUString(), STARBASIC
);
480 GetMacros( aShortName
, aStartMacro
, aEndMacro
, pGlossary
.get() );
482 // StartAction must not be before HasSelection and DelRight,
483 // otherwise the possible Shell change gets delayed and
484 // API-programs would hang.
485 // Moreover the event macro must also not be called in an action
486 m_pWrtShell
->StartUndo(SwUndoId::INSGLOSSARY
);
487 if( aStartMacro
.HasMacro() )
488 m_pWrtShell
->ExecMacro( aStartMacro
);
489 if(m_pWrtShell
->HasSelection())
490 m_pWrtShell
->DelLeft();
491 m_pWrtShell
->StartAllAction();
493 // cache all InputFields
494 SwInputFieldList
aFieldLst( m_pWrtShell
, true );
496 m_pWrtShell
->InsertGlossary(*pGlossary
, aShortName
);
497 m_pWrtShell
->EndAllAction();
498 if( aEndMacro
.HasMacro() )
500 m_pWrtShell
->ExecMacro( aEndMacro
);
502 m_pWrtShell
->EndUndo(SwUndoId::INSGLOSSARY
);
504 // demand input for all new InputFields
505 if( aFieldLst
.BuildSortLst() )
506 m_pWrtShell
->UpdateInputFields( &aFieldLst
);
512 bool SwGlossaryHdl::InsertGlossary(const OUString
&rName
)
514 OSL_ENSURE(m_pWrtShell
->CanInsert(), "illegal");
516 SwTextBlocks
*pGlos
=
517 m_pCurGrp
? m_pCurGrp
.get() : m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).release();
526 SvxMacro
aStartMacro(OUString(), OUString(), STARBASIC
);
527 SvxMacro
aEndMacro(OUString(), OUString(), STARBASIC
);
528 GetMacros( rName
, aStartMacro
, aEndMacro
, pGlos
);
530 // StartAction must not be before HasSelection and DelRight,
531 // otherwise the possible Shell change gets delayed and
532 // API-programs would hang.
533 // Moreover the event macro must also not be called in an action
534 if( aStartMacro
.HasMacro() )
535 m_pWrtShell
->ExecMacro( aStartMacro
);
536 if( m_pWrtShell
->HasSelection() )
537 m_pWrtShell
->DelRight();
538 m_pWrtShell
->StartAllAction();
540 // cache all InputFields
541 SwInputFieldList
aFieldLst( m_pWrtShell
, true );
543 m_pWrtShell
->InsertGlossary(*pGlos
, rName
);
544 m_pWrtShell
->EndAllAction();
545 if( aEndMacro
.HasMacro() )
547 m_pWrtShell
->ExecMacro( aEndMacro
);
550 // demand input for all new InputFields
551 if( aFieldLst
.BuildSortLst() )
552 m_pWrtShell
->UpdateInputFields( &aFieldLst
);
559 // set / ask for macro
560 void SwGlossaryHdl::SetMacros(const OUString
& rShortName
,
561 const SvxMacro
* pStart
,
562 const SvxMacro
* pEnd
,
563 SwTextBlocks
*pGlossary
)
565 SwTextBlocks
*pGlos
= pGlossary
? pGlossary
:
566 m_pCurGrp
? m_pCurGrp
.get()
567 : m_rStatGlossaries
.GetGroupDoc( m_aCurGrp
).release();
568 SvxMacroTableDtor aMacroTable
;
570 aMacroTable
.Insert( SvMacroItemId::SwStartInsGlossary
, *pStart
);
572 aMacroTable
.Insert( SvMacroItemId::SwEndInsGlossary
, *pEnd
);
573 sal_uInt16 nIdx
= pGlos
->GetIndex( rShortName
);
574 if( !pGlos
->SetMacroTable( nIdx
, aMacroTable
) && pGlos
->GetError() )
575 ErrorHandler::HandleError( pGlos
->GetError() );
577 if(!m_pCurGrp
&& !pGlossary
)
581 void SwGlossaryHdl::GetMacros( const OUString
&rShortName
,
584 SwTextBlocks
*pGlossary
)
586 SwTextBlocks
*pGlos
= pGlossary
? pGlossary
587 : m_pCurGrp
? m_pCurGrp
.get()
588 : m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).release();
589 sal_uInt16 nIndex
= pGlos
->GetIndex( rShortName
);
590 if( nIndex
!= USHRT_MAX
)
592 SvxMacroTableDtor aMacroTable
;
593 if( pGlos
->GetMacroTable( nIndex
, aMacroTable
) )
595 SvxMacro
*pMacro
= aMacroTable
.Get( SvMacroItemId::SwStartInsGlossary
);
599 pMacro
= aMacroTable
.Get( SvMacroItemId::SwEndInsGlossary
);
605 if( !m_pCurGrp
&& !pGlossary
)
610 SwGlossaryHdl::SwGlossaryHdl(SfxViewFrame
& rVwFrame
, SwWrtShell
*pSh
)
611 : m_rStatGlossaries( *::GetGlossaries() ),
612 m_aCurGrp( SwGlossaries::GetDefName() ),
613 m_rViewFrame(rVwFrame
),
618 SwGlossaryHdl::~SwGlossaryHdl()
622 // rename an autotext
623 bool SwGlossaryHdl::Rename(const OUString
& rOldShort
, const OUString
& rNewShortName
,
624 const OUString
& rNewName
)
627 SwTextBlocks
*pGlossary
= m_pCurGrp
? m_pCurGrp
.get()
628 : m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).release();
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
);
640 bRet
= pGlossary
->GetError() == ERRCODE_NONE
;
648 bool SwGlossaryHdl::IsReadOnly( const OUString
* pGrpNm
) const
650 SwTextBlocks
*pGlossary
= nullptr;
653 pGlossary
= m_rStatGlossaries
.GetGroupDoc( *pGrpNm
).release();
655 pGlossary
= m_pCurGrp
.get();
657 pGlossary
= m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).release();
659 const bool bRet
= !pGlossary
|| pGlossary
->IsReadOnly();
660 if( pGrpNm
|| !m_pCurGrp
)
665 bool SwGlossaryHdl::IsOld() const
668 m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).reset();
672 // find group without path index
673 bool SwGlossaryHdl::FindGroupName(OUString
& rGroup
)
675 return m_rStatGlossaries
.FindGroupName(rGroup
);
678 bool SwGlossaryHdl::CopyToClipboard(SwWrtShell
& rSh
, const OUString
& rShortName
)
680 SwTextBlocks
*pGlossary
= m_pCurGrp
? m_pCurGrp
.get()
681 : m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).release();
683 rtl::Reference
<SwTransferable
> pTransfer
= new SwTransferable( rSh
);
685 bool bRet
= pTransfer
->CopyGlossary( *pGlossary
, rShortName
);
691 bool SwGlossaryHdl::ImportGlossaries( const OUString
& rName
)
694 if( !rName
.isEmpty() )
696 std::shared_ptr
<const SfxFilter
> pFilter
;
697 SfxMedium
aMed( rName
, StreamMode::READ
, nullptr, nullptr );
698 SfxFilterMatcher
aMatcher( "swriter" );
699 aMed
.UseInteractionHandler( true );
700 if (aMatcher
.GuessFilter(aMed
, pFilter
, SfxFilterFlags::NONE
) == ERRCODE_NONE
)
702 assert(pFilter
&& "success means pFilter was set");
703 SwTextBlocks
*pGlossary
= nullptr;
704 aMed
.SetFilter( pFilter
);
705 Reader
* pR
= SwReaderWriter::GetReader( pFilter
->GetUserData() );
706 if( pR
&& nullptr != ( pGlossary
= m_pCurGrp
? m_pCurGrp
.get()
707 : m_rStatGlossaries
.GetGroupDoc(m_aCurGrp
).release()) )
709 SwReader
aReader( aMed
, rName
);
710 if( aReader
.HasGlossaries( *pR
) )
712 const SvxAutoCorrCfg
& rCfg
= SvxAutoCorrCfg::Get();
713 bRet
= aReader
.ReadGlossaries( *pR
, *pGlossary
,
714 rCfg
.IsSaveRelFile() );
725 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */