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 <vcl/errinf.hxx>
21 #include <vcl/weld.hxx>
22 #include <svl/macitem.hxx>
23 #include <sfx2/fcontnr.hxx>
24 #include <sfx2/docfile.hxx>
25 #include <sfx2/docfilt.hxx>
27 #include <docsh.hxx>
28 #include <wrtsh.hxx>
29 #include <view.hxx>
30 #include <gloshdl.hxx>
31 #include <glosdoc.hxx>
32 #include <shellio.hxx>
33 #include <swundo.hxx>
34 #include <expfld.hxx>
35 #include <initui.hxx>
36 #include <gloslst.hxx>
37 #include <swdtflvr.hxx>
38 
39 #include <strings.hrc>
40 #include <vcl/svapp.hxx>
41 #include <osl/diagnose.h>
42 
43 #include <editeng/acorrcfg.hxx>
44 #include <sfx2/event.hxx>
45 #include <swabstdlg.hxx>
46 
47 #include <memory>
48 
49 using namespace ::com::sun::star;
50 
51 const short RET_EDIT = 100;
52 
53 namespace {
54 
55 struct TextBlockInfo_Impl
56 {
57  OUString sTitle;
58  OUString sLongName;
59  OUString sGroupName;
60  TextBlockInfo_Impl(OUString const& rTitle, OUString const& rLongName, OUString const& rGroupName)
61  : sTitle(rTitle), sLongName(rLongName), sGroupName(rGroupName) {}
62 };
63 
64 }
65 
66 // Dialog for edit templates
68 {
71  OUString sName;
72  OUString sShortName;
73 
74  if( RET_EDIT == pDlg->Execute() )
75  {
76  sName = pDlg->GetCurrGrpName();
77  sShortName = pDlg->GetCurrShortName();
78  }
79 
80  pDlg.disposeAndClear();
81  pCurGrp.reset();
82  if(HasGlossaryList())
83  {
85  }
86 
87  if( !sName.isEmpty() || !sShortName.isEmpty() )
88  rStatGlossaries.EditGroupDoc( sName, sShortName );
89 }
90 
91 // set the default group; if called from the dialog
92 // the group is created temporarily for faster access
93 void SwGlossaryHdl::SetCurGroup(const OUString &rGrp, bool bApi, bool bAlwaysCreateNew )
94 {
95  OUString sGroup(rGrp);
96  if (sGroup.indexOf(GLOS_DELIM)<0 && !FindGroupName(sGroup))
97  {
98  sGroup += OUStringChar(GLOS_DELIM) + "0";
99  }
100  if(pCurGrp)
101  {
102  bool bPathEqual = false;
103  if(!bAlwaysCreateNew)
104  {
105  INetURLObject aTemp( pCurGrp->GetFileName() );
106  const OUString sCurBase = aTemp.getBase();
107  aTemp.removeSegment();
108  const OUString sCurEntryPath = aTemp.GetMainURL(INetURLObject::DecodeMechanism::NONE);
109  const std::vector<OUString> & rPathArr = rStatGlossaries.GetPathArray();
110  sal_uInt16 nCurrentPath = USHRT_MAX;
111  for (size_t nPath = 0; nPath < rPathArr.size(); ++nPath)
112  {
113  if (sCurEntryPath == rPathArr[nPath])
114  {
115  nCurrentPath = static_cast<sal_uInt16>(nPath);
116  break;
117  }
118  }
119  const OUString sPath = sGroup.getToken(1, GLOS_DELIM);
120  sal_uInt16 nComparePath = static_cast<sal_uInt16>(sPath.toInt32());
121  if(nCurrentPath == nComparePath &&
122  sGroup.getToken(0, GLOS_DELIM) == sCurBase)
123  bPathEqual = true;
124  }
125 
126  // When path changed, the name is not reliable
127  if(!bAlwaysCreateNew && bPathEqual)
128  return;
129  }
130  aCurGrp = sGroup;
131  if(!bApi)
132  {
134  }
135 }
136 
138 {
139  return rStatGlossaries.GetGroupCnt();
140 }
141 
142 OUString SwGlossaryHdl::GetGroupName( size_t nId, OUString* pTitle )
143 {
144  OUString sRet = rStatGlossaries.GetGroupName(nId);
145  if(pTitle)
146  {
147  std::unique_ptr<SwTextBlocks> pGroup = rStatGlossaries.GetGroupDoc(sRet);
148  if (pGroup && !pGroup->GetError())
149  {
150  *pTitle = pGroup->GetName();
151  if (pTitle->isEmpty())
152  {
153  *pTitle = sRet.getToken(0, GLOS_DELIM);
154  pGroup->SetName(*pTitle);
155  }
156  }
157  else
158  {
159  sRet.clear();
160  }
161  }
162  return sRet;
163 }
164 
165 void SwGlossaryHdl::NewGroup(OUString &rGrpName, const OUString& rTitle)
166 {
167  if (rGrpName.indexOf(GLOS_DELIM)<0)
168  FindGroupName(rGrpName);
169  rStatGlossaries.NewGroupDoc(rGrpName, rTitle);
170 }
171 
172 void SwGlossaryHdl::RenameGroup(const OUString& rOld, OUString& rNew, const OUString& rNewTitle)
173 {
174  OUString sOldGroup(rOld);
175  if (rOld.indexOf(GLOS_DELIM)<0)
176  FindGroupName(sOldGroup);
177  if(rOld == rNew)
178  {
179  std::unique_ptr<SwTextBlocks> pGroup = rStatGlossaries.GetGroupDoc(sOldGroup);
180  if(pGroup)
181  {
182  pGroup->SetName(rNewTitle);
183  }
184  }
185  else
186  {
187  OUString sNewGroup(rNew);
188  if (sNewGroup.indexOf(GLOS_DELIM)<0)
189  {
190  sNewGroup += OUStringChar(GLOS_DELIM) + "0";
191  }
192  rStatGlossaries.RenameGroupDoc(sOldGroup, sNewGroup, rNewTitle);
193  rNew = sNewGroup;
194  }
195 }
196 
197 // delete an autotext-file-group
198 bool SwGlossaryHdl::DelGroup(const OUString &rGrpName)
199 {
200  OUString sGroup(rGrpName);
201  if (sGroup.indexOf(GLOS_DELIM)<0)
202  FindGroupName(sGroup);
203  if( rStatGlossaries.DelGroupDoc(sGroup) )
204  {
205  if(pCurGrp)
206  {
207  if (pCurGrp->GetName() == sGroup)
208  pCurGrp.reset();
209  }
210  return true;
211  }
212  return false;
213 }
214 
215 // ask for number of autotexts
217 {
218  return pCurGrp ? pCurGrp->GetCount() : 0;
219 }
220 
221 OUString SwGlossaryHdl::GetGlossaryName( sal_uInt16 nId )
222 {
223  OSL_ENSURE(nId < GetGlossaryCnt(), "Text building block array over-indexed.");
224  return pCurGrp->GetLongName( nId );
225 }
226 
227 OUString SwGlossaryHdl::GetGlossaryShortName(sal_uInt16 nId)
228 {
229  OSL_ENSURE(nId < GetGlossaryCnt(), "Text building block array over-indexed.");
230  return pCurGrp->GetShortName( nId );
231 }
232 
233 // ask for short name
234 OUString SwGlossaryHdl::GetGlossaryShortName(const OUString &rName)
235 {
236  OUString sReturn;
237  SwTextBlocks *pTmp =
238  pCurGrp ? pCurGrp.get() : rStatGlossaries.GetGroupDoc( aCurGrp ).release();
239  if(pTmp)
240  {
241  sal_uInt16 nIdx = pTmp->GetLongIndex( rName );
242  if( nIdx != sal_uInt16(-1) )
243  sReturn = pTmp->GetShortName( nIdx );
244  if( !pCurGrp )
245  delete pTmp;
246  }
247  return sReturn;
248 }
249 
250 // short name for autotext already used?
251 bool SwGlossaryHdl::HasShortName(const OUString& rShortName) const
252 {
253  SwTextBlocks *pBlock = pCurGrp ? pCurGrp.get()
254  : rStatGlossaries.GetGroupDoc( aCurGrp ).release();
255  bool bRet = pBlock->GetIndex( rShortName ) != sal_uInt16(-1);
256  if( !pCurGrp )
257  delete pBlock;
258  return bRet;
259 }
260 
261 // Create autotext
262 bool SwGlossaryHdl::NewGlossary(const OUString& rName, const OUString& rShortName,
263  bool bCreateGroup, bool bNoAttr)
264 {
265  SwTextBlocks *pTmp =
266  pCurGrp ? pCurGrp.get() : rStatGlossaries.GetGroupDoc( aCurGrp, bCreateGroup ).release();
267  //pTmp == 0 if the AutoText path setting is wrong
268  if(!pTmp)
269  {
270  if (!pCurGrp)
271  delete pTmp;
272  return false;
273  }
274 
275  OUString sOnlyText;
276  OUString* pOnlyText = nullptr;
277  if( bNoAttr )
278  {
280  pOnlyText = &sOnlyText;
281  }
282 
283  const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
284 
285  const sal_uInt16 nSuccess = pWrtShell->MakeGlossary( *pTmp, rName, rShortName,
286  rCfg.IsSaveRelFile(), pOnlyText );
287  if(nSuccess == sal_uInt16(-1) )
288  {
289  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pWrtShell->GetView().GetFrameWeld(),
290  VclMessageType::Info, VclButtonsType::Ok, SwResId(STR_ERR_INSERT_GLOS)));
291  xBox->run();
292  }
293  if( !pCurGrp )
294  delete pTmp;
295  return nSuccess != sal_uInt16(-1);
296 }
297 
298 // Delete an autotext
299 bool SwGlossaryHdl::DelGlossary(const OUString &rShortName)
300 {
301  SwTextBlocks *pGlossary = pCurGrp ? pCurGrp.get()
302  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
303  //pTmp == 0 if the AutoText path setting is wrong
304  if(!pGlossary)
305  {
306  if( !pCurGrp )
307  delete pGlossary;
308  return false;
309  }
310 
311  sal_uInt16 nIdx = pGlossary->GetIndex( rShortName );
312  if( nIdx != sal_uInt16(-1) )
313  pGlossary->Delete( nIdx );
314  if( !pCurGrp )
315  delete pGlossary;
316  return true;
317 }
318 
319 // expand short name
321 {
322  OSL_ENSURE(pWrtShell->CanInsert(), "illegal");
324  ::GlossaryGetCurrGroup fnGetCurrGroup = pFact->GetGlossaryCurrGroupFunc();
325  OUString sGroupName( (*fnGetCurrGroup)() );
326  if (sGroupName.indexOf(GLOS_DELIM)<0)
327  FindGroupName(sGroupName);
328  std::unique_ptr<SwTextBlocks> pGlossary = rStatGlossaries.GetGroupDoc(sGroupName);
329 
330  OUString aShortName;
331 
332  // use this at text selection
333  if(pWrtShell->SwCursorShell::HasSelection() && !pWrtShell->IsBlockMode())
334  {
335  aShortName = pWrtShell->GetSelText();
336  }
337  else
338  {
339  if(pWrtShell->IsAddMode())
341  else if(pWrtShell->IsBlockMode())
343  else if(pWrtShell->IsExtMode())
345  // select word (tdf#126589: part to the left of cursor)
346  if (pWrtShell->IsInWord() || pWrtShell->IsEndWrd())
347  pWrtShell->PrvWrd(true);
348  // ask for word
349  if(pWrtShell->IsSelection())
350  aShortName = pWrtShell->GetSelText();
351  }
352  return pGlossary && Expand(pParent, aShortName, &rStatGlossaries, std::move(pGlossary));
353 }
354 
355 bool SwGlossaryHdl::Expand(weld::Window* pParent, const OUString& rShortName,
357  std::unique_ptr<SwTextBlocks> pGlossary)
358 {
359  std::vector<TextBlockInfo_Impl> aFoundArr;
360  OUString aShortName( rShortName );
361  bool bCancel = false;
362  // search for text block
363  // - don't prefer current group depending on configuration setting
364  const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
365  sal_uInt16 nFound = !rCfg.IsSearchInAllCategories() ? pGlossary->GetIndex( aShortName ) : -1;
366  // if not found then search in all groups
367  if( nFound == sal_uInt16(-1) )
368  {
369  const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
371  const size_t nGroupCount = pGlossaryList->GetGroupCount();
372  for(size_t i = 0; i < nGroupCount; ++i)
373  {
374  // get group name with path-extension
375  const OUString sGroupName = pGlossaryList->GetGroupName(i);
376  if(sGroupName == pGlossary->GetName())
377  continue;
378  const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i);
379  if(nBlockCount)
380  {
381  const OUString sTitle = pGlossaryList->GetGroupTitle(i);
382  for(sal_uInt16 j = 0; j < nBlockCount; j++)
383  {
384  const OUString sLongName(pGlossaryList->GetBlockLongName(i, j));
385  const OUString sShortName(pGlossaryList->GetBlockShortName(i, j));
386  if( rSCmp.isEqual( rShortName, sShortName ))
387  {
388  aFoundArr.emplace_back(sTitle, sLongName, sGroupName);
389  }
390  }
391  }
392  }
393  if( !aFoundArr.empty() ) // one was found
394  {
395  pGlossary.reset();
396  if (1 == aFoundArr.size())
397  {
398  TextBlockInfo_Impl& rData = aFoundArr.front();
399  pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
400  nFound = pGlossary->GetIndex( aShortName );
401  }
402  else
403  {
405  ScopedVclPtr<AbstractSwSelGlossaryDlg> pDlg(pFact->CreateSwSelGlossaryDlg(pParent, aShortName));
406  for(const TextBlockInfo_Impl & i : aFoundArr)
407  {
408  pDlg->InsertGlos(i.sTitle, i.sLongName);
409  }
410  pDlg->SelectEntryPos(0);
411  const sal_Int32 nRet = RET_OK == pDlg->Execute() ?
412  pDlg->GetSelectedIdx() :
413  -1;
414  pDlg.disposeAndClear();
415  if (nRet != -1)
416  {
417  TextBlockInfo_Impl& rData = aFoundArr[nRet];
418  pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
419  nFound = pGlossary->GetIndex( aShortName );
420  }
421  else
422  {
423  nFound = sal_uInt16(-1);
424  bCancel = true;
425  }
426  }
427  }
428  }
429 
430  // not found
431  if( nFound == sal_uInt16(-1) )
432  {
433  if( !bCancel )
434  {
435  pGlossary.reset();
436 
437  const sal_Int32 nMaxLen = 50;
438  if(pWrtShell->IsSelection() && aShortName.getLength() > nMaxLen)
439  {
440  aShortName = OUString::Concat(aShortName.subView(0, nMaxLen)) + " ...";
441  }
442  OUString aTmp( SwResId(STR_NOGLOS));
443  aTmp = aTmp.replaceFirst("%1", aShortName);
444  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWrtShell->GetView().GetFrameWeld(),
445  VclMessageType::Info, VclButtonsType::Ok,
446  aTmp));
447  xInfoBox->run();
448  }
449 
450  return false;
451  }
452  else
453  {
454  SvxMacro aStartMacro(OUString(), OUString(), STARBASIC);
455  SvxMacro aEndMacro(OUString(), OUString(), STARBASIC);
456  GetMacros( aShortName, aStartMacro, aEndMacro, pGlossary.get() );
457 
458  // StartAction must not be before HasSelection and DelRight,
459  // otherwise the possible Shell change gets delayed and
460  // API-programs would hang.
461  // Moreover the event macro must also not be called in an action
463  if( aStartMacro.HasMacro() )
464  pWrtShell->ExecMacro( aStartMacro );
465  if(pWrtShell->HasSelection())
466  pWrtShell->DelLeft();
468 
469  // cache all InputFields
470  SwInputFieldList aFieldLst( pWrtShell, true );
471 
472  pWrtShell->InsertGlossary(*pGlossary, aShortName);
474  if( aEndMacro.HasMacro() )
475  {
476  pWrtShell->ExecMacro( aEndMacro );
477  }
479 
480  // demand input for all new InputFields
481  if( aFieldLst.BuildSortLst() )
482  pWrtShell->UpdateInputFields( &aFieldLst );
483  }
484  return true;
485 }
486 
487 // add autotext
488 bool SwGlossaryHdl::InsertGlossary(const OUString &rName)
489 {
490  OSL_ENSURE(pWrtShell->CanInsert(), "illegal");
491 
492  SwTextBlocks *pGlos =
493  pCurGrp ? pCurGrp.get() : rStatGlossaries.GetGroupDoc(aCurGrp).release();
494 
495  if (!pGlos)
496  {
497  if (!pCurGrp)
498  delete pGlos;
499  return false;
500  }
501 
502  SvxMacro aStartMacro(OUString(), OUString(), STARBASIC);
503  SvxMacro aEndMacro(OUString(), OUString(), STARBASIC);
504  GetMacros( rName, aStartMacro, aEndMacro, pGlos );
505 
506  // StartAction must not be before HasSelection and DelRight,
507  // otherwise the possible Shell change gets delayed and
508  // API-programs would hang.
509  // Moreover the event macro must also not be called in an action
510  if( aStartMacro.HasMacro() )
511  pWrtShell->ExecMacro( aStartMacro );
512  if( pWrtShell->HasSelection() )
513  pWrtShell->DelRight();
515 
516  // cache all InputFields
517  SwInputFieldList aFieldLst( pWrtShell, true );
518 
519  pWrtShell->InsertGlossary(*pGlos, rName);
521  if( aEndMacro.HasMacro() )
522  {
523  pWrtShell->ExecMacro( aEndMacro );
524  }
525 
526  // demand input for all new InputFields
527  if( aFieldLst.BuildSortLst() )
528  pWrtShell->UpdateInputFields( &aFieldLst );
529 
530  if(!pCurGrp)
531  delete pGlos;
532  return true;
533 }
534 
535 // set / ask for macro
536 void SwGlossaryHdl::SetMacros(const OUString& rShortName,
537  const SvxMacro* pStart,
538  const SvxMacro* pEnd,
539  SwTextBlocks *pGlossary )
540 {
541  SwTextBlocks *pGlos = pGlossary ? pGlossary :
542  pCurGrp ? pCurGrp.get()
543  : rStatGlossaries.GetGroupDoc( aCurGrp ).release();
544  SvxMacroTableDtor aMacroTable;
545  if( pStart )
546  aMacroTable.Insert( SvMacroItemId::SwStartInsGlossary, *pStart);
547  if( pEnd )
548  aMacroTable.Insert( SvMacroItemId::SwEndInsGlossary, *pEnd);
549  sal_uInt16 nIdx = pGlos->GetIndex( rShortName );
550  if( !pGlos->SetMacroTable( nIdx, aMacroTable ) && pGlos->GetError() )
552 
553  if(!pCurGrp && !pGlossary)
554  delete pGlos;
555 }
556 
557 void SwGlossaryHdl::GetMacros( const OUString &rShortName,
558  SvxMacro& rStart,
559  SvxMacro& rEnd,
560  SwTextBlocks *pGlossary )
561 {
562  SwTextBlocks *pGlos = pGlossary ? pGlossary
563  : pCurGrp ? pCurGrp.get()
564  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
565  sal_uInt16 nIndex = pGlos->GetIndex( rShortName );
566  if( nIndex != USHRT_MAX )
567  {
568  SvxMacroTableDtor aMacroTable;
569  if( pGlos->GetMacroTable( nIndex, aMacroTable ) )
570  {
571  SvxMacro *pMacro = aMacroTable.Get( SvMacroItemId::SwStartInsGlossary );
572  if( pMacro )
573  rStart = *pMacro;
574 
575  pMacro = aMacroTable.Get( SvMacroItemId::SwEndInsGlossary );
576  if( pMacro )
577  rEnd = *pMacro;
578  }
579  }
580 
581  if( !pCurGrp && !pGlossary )
582  delete pGlos;
583 }
584 
585 // ctor, dtor
587  : rStatGlossaries( *::GetGlossaries() ),
588  aCurGrp( SwGlossaries::GetDefName() ),
589  pViewFrame( pVwFrame ),
590  pWrtShell( pSh )
591 {
592 }
593 
595 {
596 }
597 
598 // rename an autotext
599 bool SwGlossaryHdl::Rename(const OUString& rOldShort, const OUString& rNewShortName,
600  const OUString& rNewName )
601 {
602  bool bRet = false;
603  SwTextBlocks *pGlossary = pCurGrp ? pCurGrp.get()
604  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
605  if(pGlossary)
606  {
607  sal_uInt16 nIdx = pGlossary->GetIndex( rOldShort );
608  sal_uInt16 nOldLongIdx = pGlossary->GetLongIndex( rNewName );
609  sal_uInt16 nOldIdx = pGlossary->GetIndex( rNewShortName );
610 
611  if( nIdx != USHRT_MAX &&
612  (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&&
613  (nOldIdx == USHRT_MAX || nOldIdx == nIdx ))
614  {
615  pGlossary->Rename( nIdx, &rNewShortName, &rNewName );
616  bRet = pGlossary->GetError() == ERRCODE_NONE;
617  }
618  if( !pCurGrp )
619  delete pGlossary;
620  }
621  return bRet;
622 }
623 
624 bool SwGlossaryHdl::IsReadOnly( const OUString* pGrpNm ) const
625 {
626  SwTextBlocks *pGlossary = nullptr;
627 
628  if (pGrpNm)
629  pGlossary = rStatGlossaries.GetGroupDoc( *pGrpNm ).release();
630  else if (pCurGrp)
631  pGlossary = pCurGrp.get();
632  else
633  pGlossary = rStatGlossaries.GetGroupDoc(aCurGrp).release();
634 
635  const bool bRet = !pGlossary || pGlossary->IsReadOnly();
636  if( pGrpNm || !pCurGrp )
637  delete pGlossary;
638  return bRet;
639 }
640 
642 {
643  if( !pCurGrp )
645  return false;
646 }
647 
648 // find group without path index
649 bool SwGlossaryHdl::FindGroupName(OUString& rGroup)
650 {
651  return rStatGlossaries.FindGroupName(rGroup);
652 }
653 
654 bool SwGlossaryHdl::CopyToClipboard(SwWrtShell& rSh, const OUString& rShortName)
655 {
656  SwTextBlocks *pGlossary = pCurGrp ? pCurGrp.get()
657  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
658 
659  rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
660 
661  bool bRet = pTransfer->CopyGlossary( *pGlossary, rShortName );
662  if( !pCurGrp )
663  delete pGlossary;
664  return bRet;
665 }
666 
667 bool SwGlossaryHdl::ImportGlossaries( const OUString& rName )
668 {
669  bool bRet = false;
670  if( !rName.isEmpty() )
671  {
672  std::shared_ptr<const SfxFilter> pFilter;
673  std::unique_ptr<SfxMedium> pMed(new SfxMedium( rName, StreamMode::READ, nullptr, nullptr ));
674  SfxFilterMatcher aMatcher( "swriter" );
675  pMed->UseInteractionHandler( true );
676  if (!aMatcher.GuessFilter(*pMed, pFilter, SfxFilterFlags::NONE))
677  {
678  SwTextBlocks *pGlossary = nullptr;
679  pMed->SetFilter( pFilter );
680  Reader* pR = SwReaderWriter::GetReader( pFilter->GetUserData() );
681  if( pR && nullptr != ( pGlossary = pCurGrp ? pCurGrp.get()
682  : rStatGlossaries.GetGroupDoc(aCurGrp).release()) )
683  {
684  SwReader aReader( *pMed, rName );
685  if( aReader.HasGlossaries( *pR ) )
686  {
687  const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
688  bRet = aReader.ReadGlossaries( *pR, *pGlossary,
689  rCfg.IsSaveRelFile() );
690  }
691 
692  if (!pCurGrp)
693  delete pGlossary;
694  }
695  }
696  }
697  return bRet;
698 }
699 
700 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const short RET_EDIT
Definition: gloshdl.cxx:51
SwWrtShell * pWrtShell
Definition: gloshdl.hxx:40
void InsertGlossary(SwTextBlocks &rGlossary, const OUString &)
Glossary from glossary document in current document.
Definition: edglss.cxx:39
OUString(* GlossaryGetCurrGroup)()
Definition: swabstdlg.hxx:86
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
Definition: init.cxx:795
SvxMacro & Insert(SvMacroItemId nEvent, const SvxMacro &rMacro)
sal_uInt16 GetBlockCount(size_t nGroup)
Definition: gloslst.cxx:198
sal_Int32 nIndex
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:115
static SvxAutoCorrCfg & Get()
bool Rename(const OUString &rOldShortName, const OUString &rNewShortName, const OUString &rNewName)
Definition: gloshdl.cxx:599
bool HasGlossaryList()
Definition: initui.cxx:167
bool ReadGlossaries(const Reader &, SwTextBlocks &, bool bSaveRelFiles)
Definition: shellio.cxx:657
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
void LeaveBlockMode()
Definition: select.cxx:660
OUString getBase(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetGlossaryShortName(const OUString &rName)
Definition: gloshdl.cxx:234
void GetSelectedText(OUString &rBuf, ParaBreakType nHndlParaBreak=ParaBreakType::ToBlank)
Query text within selection.
Definition: edglss.cxx:261
std::unique_ptr< SwTextBlocks > pCurGrp
Definition: gloshdl.hxx:42
sal_uInt16 GetGlossaryCnt() const
Definition: gloshdl.cxx:216
SwDocShellRef EditGroupDoc(const OUString &rGrpName, const OUString &rShortName, bool bShow=true)
Definition: glshell.cxx:197
bool DelGlossary(const OUString &)
Definition: gloshdl.cxx:299
const ContentProperties & rData
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
ErrCode GuessFilter(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
size_t GetGroupCnt()
Definition: glosdoc.cxx:98
void UpdateInputFields(SwInputFieldList *pLst=nullptr)
Definition: wrtsh2.cxx:143
size_t GetGroupCount()
Definition: gloslst.cxx:168
std::unique_ptr< SwTextBlocks > GetGroupDoc(const OUString &rName, bool bCreate=false)
Definition: glosdoc.cxx:158
void Rename(sal_uInt16, const OUString *, const OUString *)
Definition: swblocks.cxx:310
void EndAllAction()
Definition: edws.cxx:97
bool FindGroupName(OUString &rGroup)
Definition: glosdoc.cxx:104
ErrCode const & GetError() const
Definition: shellio.hxx:319
bool IsOld() const
Definition: gloshdl.cxx:641
bool DelRight()
Definition: delete.cxx:292
SwGlossaries & rStatGlossaries
Definition: gloshdl.hxx:37
size_t GetGroupCnt() const
Definition: gloshdl.cxx:137
Used by the UI to modify the document model.
Definition: wrtsh.hxx:91
bool HasMacro() const
const SwView & GetView() const
Definition: wrtsh.hxx:429
virtual VclPtr< AbstractGlossaryDlg > CreateGlossaryDlg(SfxViewFrame *pViewFrame, SwGlossaryHdl *pGlosHdl, SwWrtShell *pWrtShell)=0
void LeaveAddMode()
Definition: select.cxx:641
Reader * GetReader(const OUString &rFltName)
Return reader based on the name.
Definition: fltini.cxx:169
void SetMacros(const OUString &rName, const SvxMacro *pStart, const SvxMacro *pEnd, SwTextBlocks *pGlossary=nullptr)
Definition: gloshdl.cxx:536
bool PrvWrd(bool bSelect=false)
Definition: wrtsh.hxx:212
void SetCurGroup(const OUString &aGrp, bool bApi=false, bool bAlwaysCreateNew=false)
Definition: gloshdl.cxx:93
OUString GetBlockLongName(size_t nGroup, sal_uInt16 nBlock)
Definition: gloslst.cxx:209
OUString GetGroupName(size_t nPos)
Definition: gloslst.cxx:175
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
Definition: initui.cxx:160
OUString GetBlockShortName(size_t nGroup, sal_uInt16 nBlock)
Definition: gloslst.cxx:220
bool IsBlockMode() const
Definition: wrtsh.hxx:162
bool DelGroupDoc(const OUString &)
Definition: glosdoc.cxx:247
const char * sName
void ExecMacro(const SvxMacro &rMacro, OUString *pRet=nullptr, SbxArray *pArgs=nullptr)
Definition: wrtsh3.cxx:181
SAL_DLLPRIVATE bool Expand(weld::Window *pParent, const OUString &rShortName, SwGlossaries *pGlossaries, std::unique_ptr< SwTextBlocks > pGlossary)
Definition: gloshdl.cxx:355
OUString GetGlossaryName(sal_uInt16)
Definition: gloshdl.cxx:221
bool DelGroup(const OUString &)
Definition: gloshdl.cxx:198
bool IsSelection() const
Definition: crsrsh.hxx:879
SwGlossaryHdl(SfxViewFrame *pViewFrame, SwWrtShell *)
Definition: gloshdl.cxx:586
void GlossaryDlg()
Definition: gloshdl.cxx:67
bool HasSelection() const
Definition: wrtsh.hxx:142
int i
OUString GetGroupTitle(size_t nPos)
Definition: gloslst.cxx:187
static SwGlossaryList * pGlossaryList
Definition: initui.cxx:39
bool CopyToClipboard(SwWrtShell &rSh, const OUString &rShortName)
Definition: gloshdl.cxx:654
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
static std::unique_ptr< SwGlossaries > pGlossaries
Definition: initui.cxx:36
bool ExpandGlossary(weld::Window *pParent)
Definition: gloshdl.cxx:320
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 GetLongIndex(const OUString &) const
Definition: swblocks.cxx:265
bool IsInWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:36
bool IsReadOnly(const OUString *=nullptr) const
Definition: gloshdl.cxx:624
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
OUString GetGroupName(size_t, OUString *pTitle)
Definition: gloshdl.cxx:142
OUString SwResId(const char *pId)
Definition: swmodule.cxx:166
bool IsSaveRelFile() const
bool DelLeft()
Definition: delete.cxx:132
virtual OUString GetCurrGrpName() const =0
void NewGroup(OUString &rGroupName, const OUString &rTitle)
Definition: gloshdl.cxx:165
bool IsReadOnly() const
Definition: swblocks.cxx:491
bool IsSearchInAllCategories() const
void LeaveExtMode()
Definition: select.cxx:598
OUString aCurGrp
Definition: gloshdl.hxx:38
bool Delete(sal_uInt16)
Definition: swblocks.cxx:284
bool InsertGlossary(const OUString &rName)
Definition: gloshdl.cxx:488
bool GetMacroTable(sal_uInt16 nIdx, SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:528
bool HasShortName(const OUString &rShortName) const
Definition: gloshdl.cxx:251
const SvxMacro * Get(SvMacroItemId nEvent) const
OUString const & GetGroupName(size_t)
Definition: glosdoc.cxx:136
weld::Window * GetFrameWeld() const
SfxViewFrame * pViewFrame
Definition: gloshdl.hxx:39
std::vector< OUString > const & GetPathArray() const
Definition: glosdoc.hxx:120
#define ERRCODE_NONE
bool RenameGroupDoc(const OUString &sOldGroup, OUString &sNewGroup, const OUString &rNewTitle)
Definition: glosdoc.cxx:195
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
void ClearGroups()
Definition: gloslst.cxx:436
OUString GetSelText() const
get selected text of a node at current cursor
Definition: crsrsh.cxx:2539
sal_uInt16 GetIndex(const OUString &) const
Definition: swblocks.cxx:260
RET_OK
bool CanInsert()
Definition: wrtsh1.cxx:1729
bool IsExtMode() const
Definition: wrtsh.hxx:152
#define GLOS_DELIM
Definition: glosdoc.hxx:41
void GetMacros(const OUString &rShortName, SvxMacro &rStart, SvxMacro &rEnd, SwTextBlocks *pGlossary=nullptr)
Definition: gloshdl.cxx:557
bool IsEndWrd()
Definition: wrtsh1.cxx:161
OUString GetShortName(sal_uInt16) const
Definition: swblocks.cxx:270
void RenameGroup(const OUString &rOld, OUString &rNew, const OUString &rNewTitle)
Definition: gloshdl.cxx:172
bool SetMacroTable(sal_uInt16 nIdx, const SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:536
bool IsAddMode() const
Definition: wrtsh.hxx:157
virtual VclPtr< AbstractSwSelGlossaryDlg > CreateSwSelGlossaryDlg(weld::Window *pParent, const OUString &rShortName)=0
bool FindGroupName(OUString &rGroup)
Definition: gloshdl.cxx:649
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
bool NewGlossary(const OUString &rName, const OUString &rShortName, bool bApiCall=false, bool bNoAttr=false)
Definition: gloshdl.cxx:262
STARBASIC
bool NewGroupDoc(OUString &rGroupName, const OUString &rTitle)
Definition: glosdoc.cxx:175
bool HasGlossaries(const Reader &)
Definition: shellio.cxx:642
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
bool ImportGlossaries(const OUString &rName)
Definition: gloshdl.cxx:667
SwGlossaryList * GetGlossaryList()
Definition: initui.cxx:172