LibreOffice Module sw (master) 1
gloshdl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
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>
40
41#include <strings.hrc>
42#include <vcl/svapp.hxx>
43#include <osl/diagnose.h>
44
45#include <editeng/acorrcfg.hxx>
46#include <sfx2/event.hxx>
47#include <swabstdlg.hxx>
48
49#include <memory>
50
51using namespace ::com::sun::star;
52
53const short RET_EDIT = 100;
54
55namespace {
56
57struct TextBlockInfo_Impl
58{
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)) {}
64};
65
66}
67
68// Dialog for edit templates
70{
73 OUString sName;
74 OUString sShortName;
75
76 if( RET_EDIT == pDlg->Execute() )
77 {
78 sName = pDlg->GetCurrGrpName();
79 sShortName = pDlg->GetCurrShortName();
80 }
81
82 pDlg.disposeAndClear();
83 m_pCurGrp.reset();
84 if(HasGlossaryList())
85 {
87 }
88
89 if( !sName.isEmpty() || !sShortName.isEmpty() )
91}
92
93// set the default group; if called from the dialog
94// the group is created temporarily for faster access
95void SwGlossaryHdl::SetCurGroup(const OUString &rGrp, bool bApi, bool bAlwaysCreateNew )
96{
97 OUString sGroup(rGrp);
98 if (sGroup.indexOf(GLOS_DELIM)<0 && !FindGroupName(sGroup))
99 {
100 sGroup += OUStringChar(GLOS_DELIM) + "0";
101 }
102 if(m_pCurGrp)
103 {
104 bool bPathEqual = false;
105 if(!bAlwaysCreateNew)
106 {
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)
114 {
115 if (sCurEntryPath == rPathArr[nPath])
116 {
117 nCurrentPath = o3tl::narrowing<sal_uInt16>(nPath);
118 break;
119 }
120 }
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;
126 }
127
128 // When path changed, the name is not reliable
129 if(!bAlwaysCreateNew && bPathEqual)
130 return;
131 }
132 m_aCurGrp = sGroup;
133 if(!bApi)
134 {
136 }
137}
138
140{
142}
143
144OUString SwGlossaryHdl::GetGroupName( size_t nId, OUString* pTitle )
145{
146 OUString sRet = m_rStatGlossaries.GetGroupName(nId);
147 if(pTitle)
148 {
149 std::unique_ptr<SwTextBlocks> pGroup = m_rStatGlossaries.GetGroupDoc(sRet);
150 if (pGroup && !pGroup->GetError())
151 {
152 *pTitle = pGroup->GetName();
153 if (pTitle->isEmpty())
154 {
155 *pTitle = sRet.getToken(0, GLOS_DELIM);
156 pGroup->SetName(*pTitle);
157 }
158 }
159 else
160 {
161 sRet.clear();
162 }
163 }
164 return sRet;
165}
166
167void SwGlossaryHdl::NewGroup(OUString &rGrpName, const OUString& rTitle)
168{
169 if (rGrpName.indexOf(GLOS_DELIM)<0)
170 FindGroupName(rGrpName);
171 m_rStatGlossaries.NewGroupDoc(rGrpName, rTitle);
172}
173
174void SwGlossaryHdl::RenameGroup(const OUString& rOld, OUString& rNew, const OUString& rNewTitle)
175{
176 OUString sOldGroup(rOld);
177 if (rOld.indexOf(GLOS_DELIM)<0)
178 FindGroupName(sOldGroup);
179 if(rOld == rNew)
180 {
181 std::unique_ptr<SwTextBlocks> pGroup = m_rStatGlossaries.GetGroupDoc(sOldGroup);
182 if(pGroup)
183 {
184 pGroup->SetName(rNewTitle);
185 }
186 }
187 else
188 {
189 OUString sNewGroup(rNew);
190 if (sNewGroup.indexOf(GLOS_DELIM)<0)
191 {
192 sNewGroup += OUStringChar(GLOS_DELIM) + "0";
193 }
194 m_rStatGlossaries.RenameGroupDoc(sOldGroup, sNewGroup, rNewTitle);
195 rNew = sNewGroup;
196 }
197}
198
199bool SwGlossaryHdl::CopyOrMove(const OUString& rSourceGroupName, OUString& rSourceShortName,
200 const OUString& rDestGroupName, const OUString& rLongName, bool bMove)
201{
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()) )
205 {
206 return false;
207 }
208
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)
214 {
215 // the index must be existing
216 nRet = pSourceGroup->Delete( nDeleteIdx ) ? ERRCODE_NONE : ErrCode(1);
217 }
218 return !nRet;
219}
220
221// delete an autotext-file-group
222bool SwGlossaryHdl::DelGroup(const OUString &rGrpName)
223{
224 OUString sGroup(rGrpName);
225 if (sGroup.indexOf(GLOS_DELIM)<0)
226 FindGroupName(sGroup);
227 if( m_rStatGlossaries.DelGroupDoc(sGroup) )
228 {
229 if(m_pCurGrp)
230 {
231 if (m_pCurGrp->GetName() == sGroup)
232 m_pCurGrp.reset();
233 }
234 return true;
235 }
236 return false;
237}
238
239// ask for number of autotexts
241{
242 return m_pCurGrp ? m_pCurGrp->GetCount() : 0;
243}
244
245OUString SwGlossaryHdl::GetGlossaryName( sal_uInt16 nId )
246{
247 OSL_ENSURE(nId < GetGlossaryCnt(), "Text building block array over-indexed.");
248 return m_pCurGrp->GetLongName( nId );
249}
250
252{
253 OSL_ENSURE(nId < GetGlossaryCnt(), "Text building block array over-indexed.");
254 return m_pCurGrp->GetShortName( nId );
255}
256
257// ask for short name
258OUString SwGlossaryHdl::GetGlossaryShortName(std::u16string_view aName)
259{
260 OUString sReturn;
261 SwTextBlocks *pTmp =
263 if(pTmp)
264 {
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;
270 }
271 return sReturn;
272}
273
274// short name for autotext already used?
275bool SwGlossaryHdl::HasShortName(const OUString& rShortName) const
276{
277 SwTextBlocks *pBlock = m_pCurGrp ? m_pCurGrp.get()
279 bool bRet = pBlock->GetIndex( rShortName ) != sal_uInt16(-1);
280 if( !m_pCurGrp )
281 delete pBlock;
282 return bRet;
283}
284
285// Create autotext
286bool SwGlossaryHdl::NewGlossary(const OUString& rName, const OUString& rShortName,
287 bool bCreateGroup, bool bNoAttr)
288{
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)
293 {
294 if (!m_pCurGrp)
295 delete pTmp;
296 return false;
297 }
298
299 OUString sOnlyText;
300 OUString* pOnlyText = nullptr;
301 if( bNoAttr )
302 {
304 pOnlyText = &sOnlyText;
305 }
306
307 const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
308
309 const sal_uInt16 nSuccess = m_pWrtShell->MakeGlossary( *pTmp, rName, rShortName,
310 rCfg.IsSaveRelFile(), pOnlyText );
311 if(nSuccess == sal_uInt16(-1) )
312 {
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();
316 }
317 if( !m_pCurGrp )
318 delete pTmp;
319 return nSuccess != sal_uInt16(-1);
320}
321
322// Delete an autotext
323bool SwGlossaryHdl::DelGlossary(const OUString &rShortName)
324{
325 SwTextBlocks *pGlossary = m_pCurGrp ? m_pCurGrp.get()
327 //pTmp == 0 if the AutoText path setting is wrong
328 if(!pGlossary)
329 {
330 if( !m_pCurGrp )
331 delete pGlossary;
332 return false;
333 }
334
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;
341}
342
343// expand short name
345{
346 OSL_ENSURE(m_pWrtShell->CanInsert(), "illegal");
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);
353
354 OUString aShortName;
355
356 // use this at text selection
357 if(m_pWrtShell->SwCursorShell::HasSelection() && !m_pWrtShell->IsBlockMode())
358 {
359 aShortName = m_pWrtShell->GetSelText();
360 }
361 else
362 {
365 else if(m_pWrtShell->IsBlockMode())
367 else if(m_pWrtShell->IsExtMode())
369 // select word (tdf#126589: part to the left of cursor)
371 m_pWrtShell->PrvWrd(true);
372 // ask for word
374 aShortName = m_pWrtShell->GetSelText();
375 }
376 return pGlossary && Expand(pParent, aShortName, &m_rStatGlossaries, std::move(pGlossary));
377}
378
379bool SwGlossaryHdl::Expand(weld::Window* pParent, const OUString& rShortName,
381 std::unique_ptr<SwTextBlocks> pGlossary)
382{
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) )
392 {
393 const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
395 const size_t nGroupCount = pGlossaryList->GetGroupCount();
396 for(size_t i = 0; i < nGroupCount; ++i)
397 {
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)
404 {
405 const OUString sTitle = pGlossaryList->GetGroupTitle(i);
406 for(sal_uInt16 j = 0; j < nBlockCount; j++)
407 {
408 const OUString sLongName(pGlossaryList->GetBlockLongName(i, j));
409 const OUString sShortName(pGlossaryList->GetBlockShortName(i, j));
410 if( rSCmp.isEqual( rShortName, sShortName ))
411 {
412 aFoundArr.emplace_back(sTitle, sLongName, sGroupName);
413 }
414 }
415 }
416 }
417 if( !aFoundArr.empty() ) // one was found
418 {
419 pGlossary.reset();
420 if (1 == aFoundArr.size())
421 {
422 TextBlockInfo_Impl& rData = aFoundArr.front();
423 pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
424 nFound = pGlossary->GetIndex( aShortName );
425 }
426 else
427 {
429 ScopedVclPtr<AbstractSwSelGlossaryDlg> pDlg(pFact->CreateSwSelGlossaryDlg(pParent, aShortName));
430 for(const TextBlockInfo_Impl & i : aFoundArr)
431 {
432 pDlg->InsertGlos(i.sTitle, i.sLongName);
433 }
434 pDlg->SelectEntryPos(0);
435 const sal_Int32 nRet = RET_OK == pDlg->Execute() ?
436 pDlg->GetSelectedIdx() :
437 -1;
438 pDlg.disposeAndClear();
439 if (nRet != -1)
440 {
441 TextBlockInfo_Impl& rData = aFoundArr[nRet];
442 pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
443 nFound = pGlossary->GetIndex( aShortName );
444 }
445 else
446 {
447 nFound = sal_uInt16(-1);
448 bCancel = true;
449 }
450 }
451 }
452 }
453
454 // not found
455 if( nFound == sal_uInt16(-1) )
456 {
457 if( !bCancel )
458 {
459 pGlossary.reset();
460
461 const sal_Int32 nMaxLen = 50;
462 if(m_pWrtShell->IsSelection() && aShortName.getLength() > nMaxLen)
463 {
464 aShortName = OUString::Concat(aShortName.subView(0, nMaxLen)) + " ...";
465 }
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();
472 }
473
474 return false;
475 }
476 else
477 {
478 SvxMacro aStartMacro(OUString(), OUString(), STARBASIC);
479 SvxMacro aEndMacro(OUString(), OUString(), STARBASIC);
480 GetMacros( aShortName, aStartMacro, aEndMacro, pGlossary.get() );
481
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
487 if( aStartMacro.HasMacro() )
488 m_pWrtShell->ExecMacro( aStartMacro );
492
493 // cache all InputFields
494 SwInputFieldList aFieldLst( m_pWrtShell, true );
495
496 m_pWrtShell->InsertGlossary(*pGlossary, aShortName);
498 if( aEndMacro.HasMacro() )
499 {
500 m_pWrtShell->ExecMacro( aEndMacro );
501 }
503
504 // demand input for all new InputFields
505 if( aFieldLst.BuildSortLst() )
506 m_pWrtShell->UpdateInputFields( &aFieldLst );
507 }
508 return true;
509}
510
511// add autotext
512bool SwGlossaryHdl::InsertGlossary(const OUString &rName)
513{
514 OSL_ENSURE(m_pWrtShell->CanInsert(), "illegal");
515
516 SwTextBlocks *pGlos =
518
519 if (!pGlos)
520 {
521 if (!m_pCurGrp)
522 delete pGlos;
523 return false;
524 }
525
526 SvxMacro aStartMacro(OUString(), OUString(), STARBASIC);
527 SvxMacro aEndMacro(OUString(), OUString(), STARBASIC);
528 GetMacros( rName, aStartMacro, aEndMacro, pGlos );
529
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 );
539
540 // cache all InputFields
541 SwInputFieldList aFieldLst( m_pWrtShell, true );
542
543 m_pWrtShell->InsertGlossary(*pGlos, rName);
545 if( aEndMacro.HasMacro() )
546 {
547 m_pWrtShell->ExecMacro( aEndMacro );
548 }
549
550 // demand input for all new InputFields
551 if( aFieldLst.BuildSortLst() )
552 m_pWrtShell->UpdateInputFields( &aFieldLst );
553
554 if(!m_pCurGrp)
555 delete pGlos;
556 return true;
557}
558
559// set / ask for macro
560void SwGlossaryHdl::SetMacros(const OUString& rShortName,
561 const SvxMacro* pStart,
562 const SvxMacro* pEnd,
563 SwTextBlocks *pGlossary )
564{
565 SwTextBlocks *pGlos = pGlossary ? pGlossary :
566 m_pCurGrp ? m_pCurGrp.get()
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() )
576
577 if(!m_pCurGrp && !pGlossary)
578 delete pGlos;
579}
580
581void SwGlossaryHdl::GetMacros( const OUString &rShortName,
582 SvxMacro& rStart,
583 SvxMacro& rEnd,
584 SwTextBlocks *pGlossary )
585{
586 SwTextBlocks *pGlos = pGlossary ? pGlossary
587 : m_pCurGrp ? m_pCurGrp.get()
589 sal_uInt16 nIndex = pGlos->GetIndex( rShortName );
590 if( nIndex != USHRT_MAX )
591 {
592 SvxMacroTableDtor aMacroTable;
593 if( pGlos->GetMacroTable( nIndex, aMacroTable ) )
594 {
595 SvxMacro *pMacro = aMacroTable.Get( SvMacroItemId::SwStartInsGlossary );
596 if( pMacro )
597 rStart = *pMacro;
598
599 pMacro = aMacroTable.Get( SvMacroItemId::SwEndInsGlossary );
600 if( pMacro )
601 rEnd = *pMacro;
602 }
603 }
604
605 if( !m_pCurGrp && !pGlossary )
606 delete pGlos;
607}
608
609// ctor, dtor
611 : m_rStatGlossaries( *::GetGlossaries() ),
612 m_aCurGrp( SwGlossaries::GetDefName() ),
613 m_rViewFrame(rVwFrame),
614 m_pWrtShell( pSh )
615{
616}
617
619{
620}
621
622// rename an autotext
623bool SwGlossaryHdl::Rename(const OUString& rOldShort, const OUString& rNewShortName,
624 const OUString& rNewName )
625{
626 bool bRet = false;
627 SwTextBlocks *pGlossary = m_pCurGrp ? m_pCurGrp.get()
629 if(pGlossary)
630 {
631 sal_uInt16 nIdx = pGlossary->GetIndex( rOldShort );
632 sal_uInt16 nOldLongIdx = pGlossary->GetLongIndex( rNewName );
633 sal_uInt16 nOldIdx = pGlossary->GetIndex( rNewShortName );
634
635 if( nIdx != USHRT_MAX &&
636 (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&&
637 (nOldIdx == USHRT_MAX || nOldIdx == nIdx ))
638 {
639 pGlossary->Rename( nIdx, &rNewShortName, &rNewName );
640 bRet = pGlossary->GetError() == ERRCODE_NONE;
641 }
642 if( !m_pCurGrp )
643 delete pGlossary;
644 }
645 return bRet;
646}
647
648bool SwGlossaryHdl::IsReadOnly( const OUString* pGrpNm ) const
649{
650 SwTextBlocks *pGlossary = nullptr;
651
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();
658
659 const bool bRet = !pGlossary || pGlossary->IsReadOnly();
660 if( pGrpNm || !m_pCurGrp )
661 delete pGlossary;
662 return bRet;
663}
664
666{
667 if( !m_pCurGrp )
669 return false;
670}
671
672// find group without path index
673bool SwGlossaryHdl::FindGroupName(OUString& rGroup)
674{
675 return m_rStatGlossaries.FindGroupName(rGroup);
676}
677
678bool SwGlossaryHdl::CopyToClipboard(SwWrtShell& rSh, const OUString& rShortName)
679{
680 SwTextBlocks *pGlossary = m_pCurGrp ? m_pCurGrp.get()
682
683 rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
684
685 bool bRet = pTransfer->CopyGlossary( *pGlossary, rShortName );
686 if( !m_pCurGrp )
687 delete pGlossary;
688 return bRet;
689}
690
691bool SwGlossaryHdl::ImportGlossaries( const OUString& rName )
692{
693 bool bRet = false;
694 if( !rName.isEmpty() )
695 {
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)
701 {
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()
708 {
709 SwReader aReader( aMed, rName );
710 if( aReader.HasGlossaries( *pR ) )
711 {
712 const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
713 bRet = aReader.ReadGlossaries( *pR, *pGlossary,
714 rCfg.IsSaveRelFile() );
715 }
716
717 if (!m_pCurGrp)
718 delete pGlossary;
719 }
720 }
721 }
722 return bRet;
723}
724
725/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
bool HasMacro() const
virtual VclPtr< AbstractGlossaryDlg > CreateGlossaryDlg(SfxViewFrame &rViewFrame, SwGlossaryHdl *pGlosHdl, SwWrtShell *pWrtShell)=0
virtual GlossaryGetCurrGroup GetGlossaryCurrGroupFunc()=0
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
virtual VclPtr< AbstractSwSelGlossaryDlg > CreateSwSelGlossaryDlg(weld::Window *pParent, const OUString &rShortName)=0
bool IsInWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:36
OUString GetSelText() const
get selected text of a node at current cursor
Definition: crsrsh.cxx:2862
bool IsSelection() const
Definition: crsrsh.hxx:910
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
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.
Definition: edglss.cxx:47
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
void GetSelectedText(OUString &rBuf, ParaBreakType nHndlParaBreak=ParaBreakType::ToBlank)
Query text within selection.
Definition: edglss.cxx:249
void EndAllAction()
Definition: edws.cxx:97
void InsertGlossary(SwTextBlocks &rGlossary, const OUString &)
Glossary from glossary document in current document.
Definition: edglss.cxx:39
bool NewGroupDoc(OUString &rGroupName, const OUString &rTitle)
Definition: glosdoc.cxx:175
size_t GetGroupCnt()
Definition: glosdoc.cxx:98
std::vector< OUString > const & GetPathArray() const
Definition: glosdoc.hxx:124
std::unique_ptr< SwTextBlocks > GetGroupDoc(const OUString &rName, bool bCreate=false)
Definition: glosdoc.cxx:158
SwDocShellRef EditGroupDoc(const OUString &rGrpName, const OUString &rShortName, bool bShow=true)
Definition: glshell.cxx:196
OUString const & GetGroupName(size_t)
Definition: glosdoc.cxx:136
bool DelGroupDoc(std::u16string_view)
Definition: glosdoc.cxx:247
bool FindGroupName(OUString &rGroup)
Definition: glosdoc.cxx:104
bool RenameGroupDoc(const OUString &sOldGroup, OUString &sNewGroup, const OUString &rNewTitle)
Definition: glosdoc.cxx:195
bool ExpandGlossary(weld::Window *pParent)
Definition: gloshdl.cxx:344
bool DelGroup(const OUString &)
Definition: gloshdl.cxx:222
bool DelGlossary(const OUString &)
Definition: gloshdl.cxx:323
SwWrtShell * m_pWrtShell
Definition: gloshdl.hxx:40
bool Rename(const OUString &rOldShortName, const OUString &rNewShortName, const OUString &rNewName)
Definition: gloshdl.cxx:623
bool ImportGlossaries(const OUString &rName)
Definition: gloshdl.cxx:691
bool HasShortName(const OUString &rShortName) const
Definition: gloshdl.cxx:275
SwGlossaries & m_rStatGlossaries
Definition: gloshdl.hxx:37
sal_uInt16 GetGlossaryCnt() const
Definition: gloshdl.cxx:240
void GlossaryDlg()
Definition: gloshdl.cxx:69
bool InsertGlossary(const OUString &rName)
Definition: gloshdl.cxx:512
bool IsReadOnly(const OUString *=nullptr) const
Definition: gloshdl.cxx:648
void SetCurGroup(const OUString &aGrp, bool bApi=false, bool bAlwaysCreateNew=false)
Definition: gloshdl.cxx:95
OUString GetGlossaryShortName(std::u16string_view aName)
Definition: gloshdl.cxx:258
bool NewGlossary(const OUString &rName, const OUString &rShortName, bool bApiCall=false, bool bNoAttr=false)
Definition: gloshdl.cxx:286
void SetMacros(const OUString &rName, const SvxMacro *pStart, const SvxMacro *pEnd, SwTextBlocks *pGlossary=nullptr)
Definition: gloshdl.cxx:560
OUString GetGroupName(size_t, OUString *pTitle)
Definition: gloshdl.cxx:144
bool CopyOrMove(const OUString &rSourceGroupName, OUString &rSourceShortName, const OUString &rDestGroupName, const OUString &rLongName, bool bMove)
Definition: gloshdl.cxx:199
std::unique_ptr< SwTextBlocks > m_pCurGrp
Definition: gloshdl.hxx:42
bool IsOld() const
Definition: gloshdl.cxx:665
bool CopyToClipboard(SwWrtShell &rSh, const OUString &rShortName)
Definition: gloshdl.cxx:678
void GetMacros(const OUString &rShortName, SvxMacro &rStart, SvxMacro &rEnd, SwTextBlocks *pGlossary=nullptr)
Definition: gloshdl.cxx:581
SAL_DLLPRIVATE bool Expand(weld::Window *pParent, const OUString &rShortName, SwGlossaries *pGlossaries, std::unique_ptr< SwTextBlocks > pGlossary)
Definition: gloshdl.cxx:379
size_t GetGroupCnt() const
Definition: gloshdl.cxx:139
OUString m_aCurGrp
Definition: gloshdl.hxx:38
OUString GetGlossaryName(sal_uInt16)
Definition: gloshdl.cxx:245
SfxViewFrame & m_rViewFrame
Definition: gloshdl.hxx:39
void RenameGroup(const OUString &rOld, OUString &rNew, const OUString &rNewTitle)
Definition: gloshdl.cxx:174
SwGlossaryHdl(SfxViewFrame &rViewFrame, SwWrtShell *)
Definition: gloshdl.cxx:610
bool FindGroupName(OUString &rGroup)
Definition: gloshdl.cxx:673
void NewGroup(OUString &rGroupName, const OUString &rTitle)
Definition: gloshdl.cxx:167
OUString GetBlockShortName(size_t nGroup, sal_uInt16 nBlock)
Definition: gloslst.cxx:223
OUString GetGroupName(size_t nPos)
Definition: gloslst.cxx:178
size_t GetGroupCount()
Definition: gloslst.cxx:171
void ClearGroups()
Definition: gloslst.cxx:439
OUString GetBlockLongName(size_t nGroup, sal_uInt16 nBlock)
Definition: gloslst.cxx:212
OUString GetGroupTitle(size_t nPos)
Definition: gloslst.cxx:190
sal_uInt16 GetBlockCount(size_t nGroup)
Definition: gloslst.cxx:201
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:113
bool ReadGlossaries(const Reader &, SwTextBlocks &, bool bSaveRelFiles)
Definition: shellio.cxx:665
bool HasGlossaries(const Reader &)
Definition: shellio.cxx:650
void Rename(sal_uInt16, const OUString *, const OUString *)
Definition: swblocks.cxx:311
bool IsReadOnly() const
Definition: swblocks.cxx:502
bool Delete(sal_uInt16)
Definition: swblocks.cxx:285
bool SetMacroTable(sal_uInt16 nIdx, const SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:547
bool GetMacroTable(sal_uInt16 nIdx, SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:539
sal_uInt16 GetIndex(const OUString &) const
Definition: swblocks.cxx:261
sal_uInt16 GetLongIndex(std::u16string_view) const
Definition: swblocks.cxx:266
OUString GetShortName(sal_uInt16) const
Definition: swblocks.cxx:271
ErrCode const & GetError() const
Definition: shellio.hxx:321
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
bool DelLeft()
Definition: delete.cxx:136
void LeaveAddMode()
Definition: select.cxx:650
bool PrvWrd(bool bSelect=false)
Definition: wrtsh.hxx:218
void UpdateInputFields(SwInputFieldList *pLst=nullptr)
Definition: wrtsh2.cxx:146
void LeaveBlockMode()
Definition: select.cxx:669
void ExecMacro(const SvxMacro &rMacro, OUString *pRet=nullptr, SbxArray *pArgs=nullptr)
Definition: wrtsh3.cxx:319
bool IsBlockMode() const
Definition: wrtsh.hxx:168
bool DelRight(bool isReplaceHeuristic=false)
Definition: delete.cxx:285
void LeaveExtMode()
Definition: select.cxx:607
bool HasSelection() const
Definition: wrtsh.hxx:147
bool IsAddMode() const
Definition: wrtsh.hxx:163
bool IsEndWrd()
Definition: wrtsh1.cxx:196
bool CanInsert()
Definition: wrtsh1.cxx:2058
bool IsExtMode() const
Definition: wrtsh.hxx:158
const SwView & GetView() const
Definition: wrtsh.hxx:443
void disposeAndClear()
#define ERRCODE_NONE
OUString sName
#define GLOS_DELIM
Definition: glosdoc.hxx:45
const short RET_EDIT
Definition: gloshdl.cxx:53
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
Definition: init.cxx:802
static std::unique_ptr< SwGlossaries > pGlossaries
Definition: initui.cxx:38
static SwGlossaryList * pGlossaryList
Definition: initui.cxx:41
SwGlossaryList * GetGlossaryList()
Definition: initui.cxx:174
bool HasGlossaryList()
Definition: initui.cxx:169
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
Definition: initui.cxx:162
sal_Int32 nIndex
OUString aName
STARBASIC
Reader * GetReader(const OUString &rFltName)
Return reader based on the name.
Definition: fltini.cxx:169
int i
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)
sal_Int16 nId
OUString(* GlossaryGetCurrGroup)()
Definition: swabstdlg.hxx:88
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
RET_OK