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 += OUStringLiteral1(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 += OUStringLiteral1(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
356  // ask for word
357  if(pWrtShell->IsSelection())
358  aShortName = pWrtShell->GetSelText();
359  }
360  return pGlossary && Expand(pParent, aShortName, &rStatGlossaries, std::move(pGlossary));
361 }
362 
363 bool SwGlossaryHdl::Expand(weld::Window* pParent, const OUString& rShortName,
365  std::unique_ptr<SwTextBlocks> pGlossary)
366 {
367  std::vector<TextBlockInfo_Impl> aFoundArr;
368  OUString aShortName( rShortName );
369  bool bCancel = false;
370  // search for text block
371  // - don't prefer current group depending on configuration setting
372  const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
373  sal_uInt16 nFound = !rCfg.IsSearchInAllCategories() ? pGlossary->GetIndex( aShortName ) : -1;
374  // if not found then search in all groups
375  if( nFound == sal_uInt16(-1) )
376  {
377  const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
379  const size_t nGroupCount = pGlossaryList->GetGroupCount();
380  for(size_t i = 0; i < nGroupCount; ++i)
381  {
382  // get group name with path-extension
383  const OUString sGroupName = pGlossaryList->GetGroupName(i);
384  if(sGroupName == pGlossary->GetName())
385  continue;
386  const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i);
387  if(nBlockCount)
388  {
389  const OUString sTitle = pGlossaryList->GetGroupTitle(i);
390  for(sal_uInt16 j = 0; j < nBlockCount; j++)
391  {
392  const OUString sLongName(pGlossaryList->GetBlockLongName(i, j));
393  const OUString sShortName(pGlossaryList->GetBlockShortName(i, j));
394  if( rSCmp.isEqual( rShortName, sShortName ))
395  {
396  aFoundArr.emplace_back(sTitle, sLongName, sGroupName);
397  }
398  }
399  }
400  }
401  if( !aFoundArr.empty() ) // one was found
402  {
403  pGlossary.reset();
404  if (1 == aFoundArr.size())
405  {
406  TextBlockInfo_Impl& rData = aFoundArr.front();
407  pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
408  nFound = pGlossary->GetIndex( aShortName );
409  }
410  else
411  {
413  ScopedVclPtr<AbstractSwSelGlossaryDlg> pDlg(pFact->CreateSwSelGlossaryDlg(pParent, aShortName));
414  for(const TextBlockInfo_Impl & i : aFoundArr)
415  {
416  pDlg->InsertGlos(i.sTitle, i.sLongName);
417  }
418  pDlg->SelectEntryPos(0);
419  const sal_Int32 nRet = RET_OK == pDlg->Execute()?
420  pDlg->GetSelectedIdx():
422  pDlg.disposeAndClear();
423  if (LISTBOX_ENTRY_NOTFOUND != nRet)
424  {
425  TextBlockInfo_Impl& rData = aFoundArr[nRet];
426  pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
427  nFound = pGlossary->GetIndex( aShortName );
428  }
429  else
430  {
431  nFound = sal_uInt16(-1);
432  bCancel = true;
433  }
434  }
435  }
436  }
437 
438  // not found
439  if( nFound == sal_uInt16(-1) )
440  {
441  if( !bCancel )
442  {
443  pGlossary.reset();
444 
445  const sal_Int32 nMaxLen = 50;
446  if(pWrtShell->IsSelection() && aShortName.getLength() > nMaxLen)
447  {
448  aShortName = aShortName.copy(0, nMaxLen) + " ...";
449  }
450  OUString aTmp( SwResId(STR_NOGLOS));
451  aTmp = aTmp.replaceFirst("%1", aShortName);
452  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWrtShell->GetView().GetFrameWeld(),
453  VclMessageType::Info, VclButtonsType::Ok,
454  aTmp));
455  xInfoBox->run();
456  }
457 
458  return false;
459  }
460  else
461  {
462  SvxMacro aStartMacro(OUString(), OUString(), STARBASIC);
463  SvxMacro aEndMacro(OUString(), OUString(), STARBASIC);
464  GetMacros( aShortName, aStartMacro, aEndMacro, pGlossary.get() );
465 
466  // StartAction must not be before HasSelection and DelRight,
467  // otherwise the possible Shell change gets delayed and
468  // API-programs would hang.
469  // Moreover the event macro must also not be called in an action
471  if( aStartMacro.HasMacro() )
472  pWrtShell->ExecMacro( aStartMacro );
473  if(pWrtShell->HasSelection())
474  pWrtShell->DelLeft();
476 
477  // cache all InputFields
478  SwInputFieldList aFieldLst( pWrtShell, true );
479 
480  pWrtShell->InsertGlossary(*pGlossary, aShortName);
482  if( aEndMacro.HasMacro() )
483  {
484  pWrtShell->ExecMacro( aEndMacro );
485  }
487 
488  // demand input for all new InputFields
489  if( aFieldLst.BuildSortLst() )
490  pWrtShell->UpdateInputFields( &aFieldLst );
491  }
492  return true;
493 }
494 
495 // add autotext
496 bool SwGlossaryHdl::InsertGlossary(const OUString &rName)
497 {
498  OSL_ENSURE(pWrtShell->CanInsert(), "illegal");
499 
500  SwTextBlocks *pGlos =
501  pCurGrp ? pCurGrp.get() : rStatGlossaries.GetGroupDoc(aCurGrp).release();
502 
503  if (!pGlos)
504  {
505  if (!pCurGrp)
506  delete pGlos;
507  return false;
508  }
509 
510  SvxMacro aStartMacro(OUString(), OUString(), STARBASIC);
511  SvxMacro aEndMacro(OUString(), OUString(), STARBASIC);
512  GetMacros( rName, aStartMacro, aEndMacro, pGlos );
513 
514  // StartAction must not be before HasSelection and DelRight,
515  // otherwise the possible Shell change gets delayed and
516  // API-programs would hang.
517  // Moreover the event macro must also not be called in an action
518  if( aStartMacro.HasMacro() )
519  pWrtShell->ExecMacro( aStartMacro );
520  if( pWrtShell->HasSelection() )
521  pWrtShell->DelRight();
523 
524  // cache all InputFields
525  SwInputFieldList aFieldLst( pWrtShell, true );
526 
527  pWrtShell->InsertGlossary(*pGlos, rName);
529  if( aEndMacro.HasMacro() )
530  {
531  pWrtShell->ExecMacro( aEndMacro );
532  }
533 
534  // demand input for all new InputFields
535  if( aFieldLst.BuildSortLst() )
536  pWrtShell->UpdateInputFields( &aFieldLst );
537 
538  if(!pCurGrp)
539  delete pGlos;
540  return true;
541 }
542 
543 // set / ask for macro
544 void SwGlossaryHdl::SetMacros(const OUString& rShortName,
545  const SvxMacro* pStart,
546  const SvxMacro* pEnd,
547  SwTextBlocks *pGlossary )
548 {
549  SwTextBlocks *pGlos = pGlossary ? pGlossary :
550  pCurGrp ? pCurGrp.get()
551  : rStatGlossaries.GetGroupDoc( aCurGrp ).release();
552  SvxMacroTableDtor aMacroTable;
553  if( pStart )
554  aMacroTable.Insert( SvMacroItemId::SwStartInsGlossary, *pStart);
555  if( pEnd )
556  aMacroTable.Insert( SvMacroItemId::SwEndInsGlossary, *pEnd);
557  sal_uInt16 nIdx = pGlos->GetIndex( rShortName );
558  if( !pGlos->SetMacroTable( nIdx, aMacroTable ) && pGlos->GetError() )
560 
561  if(!pCurGrp && !pGlossary)
562  delete pGlos;
563 }
564 
565 void SwGlossaryHdl::GetMacros( const OUString &rShortName,
566  SvxMacro& rStart,
567  SvxMacro& rEnd,
568  SwTextBlocks *pGlossary )
569 {
570  SwTextBlocks *pGlos = pGlossary ? pGlossary
571  : pCurGrp ? pCurGrp.get()
572  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
573  sal_uInt16 nIndex = pGlos->GetIndex( rShortName );
574  if( nIndex != USHRT_MAX )
575  {
576  SvxMacroTableDtor aMacroTable;
577  if( pGlos->GetMacroTable( nIndex, aMacroTable ) )
578  {
579  SvxMacro *pMacro = aMacroTable.Get( SvMacroItemId::SwStartInsGlossary );
580  if( pMacro )
581  rStart = *pMacro;
582 
583  pMacro = aMacroTable.Get( SvMacroItemId::SwEndInsGlossary );
584  if( pMacro )
585  rEnd = *pMacro;
586  }
587  }
588 
589  if( !pCurGrp && !pGlossary )
590  delete pGlos;
591 }
592 
593 // ctor, dtor
595  : rStatGlossaries( *::GetGlossaries() ),
596  aCurGrp( SwGlossaries::GetDefName() ),
597  pViewFrame( pVwFrame ),
598  pWrtShell( pSh )
599 {
600 }
601 
603 {
604 }
605 
606 // rename an autotext
607 bool SwGlossaryHdl::Rename(const OUString& rOldShort, const OUString& rNewShortName,
608  const OUString& rNewName )
609 {
610  bool bRet = false;
611  SwTextBlocks *pGlossary = pCurGrp ? pCurGrp.get()
612  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
613  if(pGlossary)
614  {
615  sal_uInt16 nIdx = pGlossary->GetIndex( rOldShort );
616  sal_uInt16 nOldLongIdx = pGlossary->GetLongIndex( rNewName );
617  sal_uInt16 nOldIdx = pGlossary->GetIndex( rNewShortName );
618 
619  if( nIdx != USHRT_MAX &&
620  (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&&
621  (nOldIdx == USHRT_MAX || nOldIdx == nIdx ))
622  {
623  pGlossary->Rename( nIdx, &rNewShortName, &rNewName );
624  bRet = pGlossary->GetError() == ERRCODE_NONE;
625  }
626  if( !pCurGrp )
627  delete pGlossary;
628  }
629  return bRet;
630 }
631 
632 bool SwGlossaryHdl::IsReadOnly( const OUString* pGrpNm ) const
633 {
634  SwTextBlocks *pGlossary = nullptr;
635 
636  if (pGrpNm)
637  pGlossary = rStatGlossaries.GetGroupDoc( *pGrpNm ).release();
638  else if (pCurGrp)
639  pGlossary = pCurGrp.get();
640  else
641  pGlossary = rStatGlossaries.GetGroupDoc(aCurGrp).release();
642 
643  const bool bRet = !pGlossary || pGlossary->IsReadOnly();
644  if( pGrpNm || !pCurGrp )
645  delete pGlossary;
646  return bRet;
647 }
648 
650 {
651  SwTextBlocks *pGlossary = pCurGrp ? pCurGrp.get()
652  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
653  bool bRet = pGlossary && pGlossary->IsOld();
654  if( !pCurGrp )
655  delete pGlossary;
656  return bRet;
657 }
658 
659 // find group without path index
660 bool SwGlossaryHdl::FindGroupName(OUString& rGroup)
661 {
662  return rStatGlossaries.FindGroupName(rGroup);
663 }
664 
665 bool SwGlossaryHdl::CopyToClipboard(SwWrtShell& rSh, const OUString& rShortName)
666 {
667  SwTextBlocks *pGlossary = pCurGrp ? pCurGrp.get()
668  : rStatGlossaries.GetGroupDoc(aCurGrp).release();
669 
670  rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
671 
672  bool bRet = pTransfer->CopyGlossary( *pGlossary, rShortName );
673  if( !pCurGrp )
674  delete pGlossary;
675  return bRet;
676 }
677 
678 bool SwGlossaryHdl::ImportGlossaries( const OUString& rName )
679 {
680  bool bRet = false;
681  if( !rName.isEmpty() )
682  {
683  std::shared_ptr<const SfxFilter> pFilter;
684  std::unique_ptr<SfxMedium> pMed(new SfxMedium( rName, StreamMode::READ, nullptr, nullptr ));
685  SfxFilterMatcher aMatcher( "swriter" );
686  pMed->UseInteractionHandler( true );
687  if (!aMatcher.GuessFilter(*pMed, pFilter, SfxFilterFlags::NONE))
688  {
689  SwTextBlocks *pGlossary = nullptr;
690  pMed->SetFilter( pFilter );
691  Reader* pR = SwReaderWriter::GetReader( pFilter->GetUserData() );
692  if( pR && nullptr != ( pGlossary = pCurGrp ? pCurGrp.get()
693  : rStatGlossaries.GetGroupDoc(aCurGrp).release()) )
694  {
695  SwReader aReader( *pMed, rName );
696  if( aReader.HasGlossaries( *pR ) )
697  {
698  const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
699  bRet = aReader.ReadGlossaries( *pR, *pGlossary,
700  rCfg.IsSaveRelFile() );
701  }
702 
703  if (!pCurGrp)
704  delete pGlossary;
705  }
706  }
707  }
708  return bRet;
709 }
710 
711 /* 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:828
bool SelNearestWrd()
Definition: select.cxx:67
SvxMacro & Insert(SvMacroItemId nEvent, const SvxMacro &rMacro)
sal_uInt16 GetBlockCount(size_t nGroup)
Definition: gloslst.cxx:193
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:607
bool HasGlossaryList()
Definition: initui.cxx:172
sal_uInt16 GetGlossaryCnt()
Definition: gloshdl.cxx:225
bool ReadGlossaries(const Reader &, SwTextBlocks &, bool bSaveRelFiles)
Definition: shellio.cxx:653
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:661
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
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:98
void UpdateInputFields(SwInputFieldList *pLst=nullptr)
Definition: wrtsh2.cxx:152
size_t GetGroupCount()
Definition: gloslst.cxx:163
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:329
void EndAllAction()
Definition: edws.cxx:96
bool FindGroupName(OUString &rGroup)
Definition: glosdoc.cxx:104
ErrCode const & GetError() const
Definition: shellio.hxx:317
#define LISTBOX_ENTRY_NOTFOUND
bool IsOld() const
Definition: gloshdl.cxx:649
bool DelRight()
Definition: delete.cxx:282
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:88
bool HasMacro() const
const SwView & GetView() const
Definition: wrtsh.hxx:426
virtual VclPtr< AbstractGlossaryDlg > CreateGlossaryDlg(SfxViewFrame *pViewFrame, SwGlossaryHdl *pGlosHdl, SwWrtShell *pWrtShell)=0
void LeaveAddMode()
Definition: select.cxx:642
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:544
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:204
OUString GetGroupName(size_t nPos)
Definition: gloslst.cxx:170
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
Definition: initui.cxx:165
OUString GetBlockShortName(size_t nGroup, sal_uInt16 nBlock)
Definition: gloslst.cxx:215
bool IsBlockMode() const
Definition: wrtsh.hxx:159
OUString const sTitle
Definition: gloshdl.cxx:68
bool DelGroupDoc(const OUString &)
Definition: glosdoc.cxx:247
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:363
OUString GetGlossaryName(sal_uInt16)
Definition: gloshdl.cxx:230
bool DelGroup(const OUString &)
Definition: gloshdl.cxx:207
bool IsSelection() const
Definition: crsrsh.hxx:878
SwGlossaryHdl(SfxViewFrame *pViewFrame, SwWrtShell *)
Definition: gloshdl.cxx:594
void GlossaryDlg()
Definition: gloshdl.cxx:76
bool HasSelection() const
Definition: wrtsh.hxx:139
OUString GetGroupTitle(size_t nPos)
Definition: gloslst.cxx:182
OUString const sLongName
Definition: gloshdl.cxx:69
static SwGlossaryList * pGlossaryList
Definition: initui.cxx:44
bool CopyToClipboard(SwWrtShell &rSh, const OUString &rShortName)
Definition: gloshdl.cxx:665
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:284
bool IsReadOnly(const OUString *=nullptr) const
Definition: gloshdl.cxx:632
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:191
bool IsSaveRelFile() const
bool DelLeft()
Definition: delete.cxx:129
virtual OUString GetCurrGrpName() const =0
OUString const sGroupName
Definition: gloshdl.cxx:70
bool IsOld() const
Definition: swblocks.cxx:263
void NewGroup(OUString &rGroupName, const OUString &rTitle)
Definition: gloshdl.cxx:174
bool IsReadOnly() const
Definition: swblocks.cxx:510
bool IsSearchInAllCategories() const
void LeaveExtMode()
Definition: select.cxx:599
OUString aCurGrp
Definition: gloshdl.hxx:38
bool Delete(sal_uInt16)
Definition: swblocks.cxx:303
bool InsertGlossary(const OUString &rName)
Definition: gloshdl.cxx:496
bool GetMacroTable(sal_uInt16 nIdx, SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:547
bool HasShortName(const OUString &rShortName) const
Definition: gloshdl.cxx:260
const SvxMacro * Get(SvMacroItemId nEvent) const
OUString const & GetGroupName(size_t)
Definition: glosdoc.cxx:136
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:195
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
void ClearGroups()
Definition: gloslst.cxx:394
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:279
RET_OK
bool CanInsert()
Definition: wrtsh1.cxx:1732
bool IsExtMode() const
Definition: wrtsh.hxx:149
#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:565
TextBlockInfo_Impl(OUString const &rTitle, OUString const &rLongName, OUString const &rGroupName)
Definition: gloshdl.cxx:71
OUString GetShortName(sal_uInt16) const
Definition: swblocks.cxx:289
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:555
bool IsAddMode() const
Definition: wrtsh.hxx:154
virtual VclPtr< AbstractSwSelGlossaryDlg > CreateSwSelGlossaryDlg(weld::Window *pParent, const OUString &rShortName)=0
bool FindGroupName(OUString &rGroup)
Definition: gloshdl.cxx:660
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:175
bool HasGlossaries(const Reader &)
Definition: shellio.cxx:638
bool ImportGlossaries(const OUString &rName)
Definition: gloshdl.cxx:678
SwGlossaryList * GetGlossaryList()
Definition: initui.cxx:177