Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / textglos.cxx
blobd229964d2072fd680b5c121478fe6a6b92ac4ca2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/request.hxx>
21 #include <svl/eitem.hxx>
22 #include <svl/stritem.hxx>
23 #include <osl/diagnose.h>
25 #include <view.hxx>
26 #include <cmdid.h>
27 #include <textsh.hxx>
28 #include <initui.hxx>
29 #include <gloshdl.hxx>
30 #include <glosdoc.hxx>
31 #include <gloslst.hxx>
32 #include <swabstdlg.hxx>
34 void SwTextShell::ExecGlossary(SfxRequest &rReq)
36 const sal_uInt16 nSlot = rReq.GetSlot();
37 ::GetGlossaries()->UpdateGlosPath(!rReq.IsAPI() ||
38 FN_GLOSSARY_DLG == nSlot );
39 SwGlossaryHdl* pGlosHdl = GetView().GetGlosHdl();
40 // Update SwGlossaryList?
41 bool bUpdateList = false;
43 const SfxItemSet *pArgs = rReq.GetArgs();
44 const SfxPoolItem* pItem = nullptr;
45 if(pArgs)
46 pArgs->GetItemState(nSlot, false, &pItem );
48 switch( nSlot )
50 case FN_GLOSSARY_DLG:
51 pGlosHdl->GlossaryDlg();
52 bUpdateList = true;
53 rReq.Ignore();
54 break;
55 case FN_EXPAND_GLOSSARY:
57 bool bReturn;
58 bReturn = pGlosHdl->ExpandGlossary(rReq.GetFrameWeld());
59 rReq.SetReturnValue( SfxBoolItem( nSlot, bReturn ) );
60 rReq.Done();
62 break;
63 case FN_NEW_GLOSSARY:
64 if(pItem && pArgs->Count() == 3 )
66 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
67 OUString aName;
68 if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1, false, &pItem ))
69 aName = static_cast<const SfxStringItem *>(pItem)->GetValue();
70 OUString aShortName;
71 if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_2, false, &pItem ))
72 aShortName = static_cast<const SfxStringItem *>(pItem)->GetValue();
74 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
75 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
76 if ( fnSetActGroup )
77 (*fnSetActGroup)( aGroup );
78 pGlosHdl->SetCurGroup(aGroup, true);
79 // Chosen group must be created in NewGlossary if necessary!
80 pGlosHdl->NewGlossary( aName, aShortName, true );
81 rReq.Done();
83 bUpdateList = true;
84 break;
85 case FN_SET_ACT_GLOSSARY:
86 if(pItem)
88 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
89 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
90 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
91 if ( fnSetActGroup )
92 (*fnSetActGroup)( aGroup );
93 rReq.Done();
95 break;
96 case FN_INSERT_GLOSSARY:
98 if(pItem && pArgs->Count() > 1)
100 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
101 OUString aName;
102 if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1, false, &pItem ))
103 aName = static_cast<const SfxStringItem *>(pItem)->GetValue();
104 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
105 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
106 if ( fnSetActGroup )
107 (*fnSetActGroup)( aGroup );
108 pGlosHdl->SetCurGroup(aGroup, true);
109 rReq.SetReturnValue(SfxBoolItem(nSlot, pGlosHdl->InsertGlossary( aName )));
110 rReq.Done();
113 break;
114 default:
115 OSL_FAIL("wrong dispatcher");
116 return;
118 if(bUpdateList)
120 SwGlossaryList* pList = ::GetGlossaryList();
121 if(pList->IsActive())
122 pList->Update();
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */