android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / uibase / dochdl / gloshdl.cxx
blobe70ed7ffc4b20e6fe1e1f89bf9342052b34474c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <utility>
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>
29 #include <docsh.hxx>
30 #include <wrtsh.hxx>
31 #include <view.hxx>
32 #include <gloshdl.hxx>
33 #include <glosdoc.hxx>
34 #include <shellio.hxx>
35 #include <swundo.hxx>
36 #include <expfld.hxx>
37 #include <initui.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>
49 #include <memory>
51 using namespace ::com::sun::star;
53 const short RET_EDIT = 100;
55 namespace {
57 struct TextBlockInfo_Impl
59 OUString sTitle;
60 OUString sLongName;
61 OUString sGroupName;
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));
73 OUString sName;
74 OUString sShortName;
76 if( RET_EDIT == pDlg->Execute() )
78 sName = pDlg->GetCurrGrpName();
79 sShortName = pDlg->GetCurrShortName();
82 pDlg.disposeAndClear();
83 m_pCurGrp.reset();
84 if(HasGlossaryList())
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";
102 if(m_pCurGrp)
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);
118 break;
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)
125 bPathEqual = true;
128 // When path changed, the name is not reliable
129 if(!bAlwaysCreateNew && bPathEqual)
130 return;
132 m_aCurGrp = sGroup;
133 if(!bApi)
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);
147 if(pTitle)
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);
159 else
161 sRet.clear();
164 return sRet;
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);
179 if(rOld == rNew)
181 std::unique_ptr<SwTextBlocks> pGroup = m_rStatGlossaries.GetGroupDoc(sOldGroup);
182 if(pGroup)
184 pGroup->SetName(rNewTitle);
187 else
189 OUString sNewGroup(rNew);
190 if (sNewGroup.indexOf(GLOS_DELIM)<0)
192 sNewGroup += OUStringChar(GLOS_DELIM) + "0";
194 m_rStatGlossaries.RenameGroupDoc(sOldGroup, sNewGroup, rNewTitle);
195 rNew = sNewGroup;
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()) )
206 return false;
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 );
213 if(!nRet && bMove)
215 // the index must be existing
216 nRet = pSourceGroup->Delete( nDeleteIdx ) ? ERRCODE_NONE : ErrCode(1);
218 return !nRet;
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) )
229 if(m_pCurGrp)
231 if (m_pCurGrp->GetName() == sGroup)
232 m_pCurGrp.reset();
234 return true;
236 return false;
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)
260 OUString sReturn;
261 SwTextBlocks *pTmp =
262 m_pCurGrp ? m_pCurGrp.get() : m_rStatGlossaries.GetGroupDoc( m_aCurGrp ).release();
263 if(pTmp)
265 sal_uInt16 nIdx = pTmp->GetLongIndex( aName );
266 if( nIdx != sal_uInt16(-1) )
267 sReturn = pTmp->GetShortName( nIdx );
268 if( !m_pCurGrp )
269 delete pTmp;
271 return sReturn;
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);
280 if( !m_pCurGrp )
281 delete pBlock;
282 return bRet;
285 // Create autotext
286 bool SwGlossaryHdl::NewGlossary(const OUString& rName, const OUString& rShortName,
287 bool bCreateGroup, bool bNoAttr)
289 SwTextBlocks *pTmp =
290 m_pCurGrp ? m_pCurGrp.get() : m_rStatGlossaries.GetGroupDoc( m_aCurGrp, bCreateGroup ).release();
291 //pTmp == 0 if the AutoText path setting is wrong
292 if(!pTmp)
294 if (!m_pCurGrp)
295 delete pTmp;
296 return false;
299 OUString sOnlyText;
300 OUString* pOnlyText = nullptr;
301 if( bNoAttr )
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)));
315 xBox->run();
317 if( !m_pCurGrp )
318 delete pTmp;
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
328 if(!pGlossary)
330 if( !m_pCurGrp )
331 delete pGlossary;
332 return false;
335 sal_uInt16 nIdx = pGlossary->GetIndex( rShortName );
336 if( nIdx != sal_uInt16(-1) )
337 pGlossary->Delete( nIdx );
338 if( !m_pCurGrp )
339 delete pGlossary;
340 return true;
343 // expand short name
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);
354 OUString aShortName;
356 // use this at text selection
357 if(m_pWrtShell->SwCursorShell::HasSelection() && !m_pWrtShell->IsBlockMode())
359 aShortName = m_pWrtShell->GetSelText();
361 else
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);
372 // ask for word
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())
401 continue;
402 const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i);
403 if(nBlockCount)
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
419 pGlossary.reset();
420 if (1 == aFoundArr.size())
422 TextBlockInfo_Impl& rData = aFoundArr.front();
423 pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
424 nFound = pGlossary->GetIndex( aShortName );
426 else
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();
439 if (nRet != -1)
441 TextBlockInfo_Impl& rData = aFoundArr[nRet];
442 pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
443 nFound = pGlossary->GetIndex( aShortName );
445 else
447 nFound = sal_uInt16(-1);
448 bCancel = true;
454 // not found
455 if( nFound == sal_uInt16(-1) )
457 if( !bCancel )
459 pGlossary.reset();
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,
470 aTmp));
471 xInfoBox->run();
474 return false;
476 else
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 );
508 return true;
511 // add autotext
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();
519 if (!pGlos)
521 if (!m_pCurGrp)
522 delete pGlos;
523 return false;
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 );
554 if(!m_pCurGrp)
555 delete pGlos;
556 return true;
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;
569 if( pStart )
570 aMacroTable.Insert( SvMacroItemId::SwStartInsGlossary, *pStart);
571 if( pEnd )
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)
578 delete pGlos;
581 void SwGlossaryHdl::GetMacros( const OUString &rShortName,
582 SvxMacro& rStart,
583 SvxMacro& rEnd,
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 );
596 if( pMacro )
597 rStart = *pMacro;
599 pMacro = aMacroTable.Get( SvMacroItemId::SwEndInsGlossary );
600 if( pMacro )
601 rEnd = *pMacro;
605 if( !m_pCurGrp && !pGlossary )
606 delete pGlos;
609 // ctor, dtor
610 SwGlossaryHdl::SwGlossaryHdl(SfxViewFrame& rVwFrame, SwWrtShell *pSh)
611 : m_rStatGlossaries( *::GetGlossaries() ),
612 m_aCurGrp( SwGlossaries::GetDefName() ),
613 m_rViewFrame(rVwFrame),
614 m_pWrtShell( pSh )
618 SwGlossaryHdl::~SwGlossaryHdl()
622 // rename an autotext
623 bool SwGlossaryHdl::Rename(const OUString& rOldShort, const OUString& rNewShortName,
624 const OUString& rNewName )
626 bool bRet = false;
627 SwTextBlocks *pGlossary = m_pCurGrp ? m_pCurGrp.get()
628 : m_rStatGlossaries.GetGroupDoc(m_aCurGrp).release();
629 if(pGlossary)
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;
642 if( !m_pCurGrp )
643 delete pGlossary;
645 return bRet;
648 bool SwGlossaryHdl::IsReadOnly( const OUString* pGrpNm ) const
650 SwTextBlocks *pGlossary = nullptr;
652 if (pGrpNm)
653 pGlossary = m_rStatGlossaries.GetGroupDoc( *pGrpNm ).release();
654 else if (m_pCurGrp)
655 pGlossary = m_pCurGrp.get();
656 else
657 pGlossary = m_rStatGlossaries.GetGroupDoc(m_aCurGrp).release();
659 const bool bRet = !pGlossary || pGlossary->IsReadOnly();
660 if( pGrpNm || !m_pCurGrp )
661 delete pGlossary;
662 return bRet;
665 bool SwGlossaryHdl::IsOld() const
667 if( !m_pCurGrp )
668 m_rStatGlossaries.GetGroupDoc(m_aCurGrp).reset();
669 return false;
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 );
686 if( !m_pCurGrp )
687 delete pGlossary;
688 return bRet;
691 bool SwGlossaryHdl::ImportGlossaries( const OUString& rName )
693 bool bRet = false;
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() );
717 if (!m_pCurGrp)
718 delete pGlossary;
722 return bRet;
725 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */