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