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