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 <sfx2/request.hxx>
21 #include <svl/eitem.hxx>
22 #include <svl/stritem.hxx>
23 
24 #include <view.hxx>
25 #include <cmdid.h>
26 #include <textsh.hxx>
27 #include <initui.hxx>
28 #include <gloshdl.hxx>
29 #include <glosdoc.hxx>
30 #include <gloslst.hxx>
31 #include <swabstdlg.hxx>
32 
ExecGlossary(SfxRequest & rReq)33 void SwTextShell::ExecGlossary(SfxRequest &rReq)
34 {
35     const sal_uInt16 nSlot = rReq.GetSlot();
36     ::GetGlossaries()->UpdateGlosPath(!rReq.IsAPI() ||
37                                         FN_GLOSSARY_DLG == nSlot );
38     SwGlossaryHdl* pGlosHdl = GetView().GetGlosHdl();
39     // Update SwGlossaryList?
40     bool bUpdateList = false;
41 
42     const SfxItemSet *pArgs = rReq.GetArgs();
43     const SfxPoolItem* pItem = nullptr;
44     if(pArgs)
45        pArgs->GetItemState(nSlot, false, &pItem );
46 
47     switch( nSlot )
48     {
49         case FN_GLOSSARY_DLG:
50             pGlosHdl->GlossaryDlg();
51             bUpdateList = true;
52             rReq.Ignore();
53             break;
54         case FN_EXPAND_GLOSSARY:
55         {
56             bool bReturn;
57             bReturn = pGlosHdl->ExpandGlossary(rReq.GetFrameWeld());
58             rReq.SetReturnValue( SfxBoolItem( nSlot, bReturn ) );
59             rReq.Done();
60         }
61         break;
62         case FN_NEW_GLOSSARY:
63             if(pItem && pArgs->Count() == 3 )
64             {
65                 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
66                 OUString aName;
67                 if(SfxItemState::SET ==  pArgs->GetItemState(FN_PARAM_1, false, &pItem ))
68                     aName = static_cast<const SfxStringItem *>(pItem)->GetValue();
69                 OUString aShortName;
70                 if(SfxItemState::SET ==  pArgs->GetItemState(FN_PARAM_2, false, &pItem ))
71                     aShortName = static_cast<const SfxStringItem *>(pItem)->GetValue();
72 
73                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
74                 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
75                 if ( fnSetActGroup )
76                     (*fnSetActGroup)( aGroup );
77                 pGlosHdl->SetCurGroup(aGroup, true);
78                 // Chosen group must be created in NewGlossary if necessary!
79                 pGlosHdl->NewGlossary( aName, aShortName, true );
80                 rReq.Done();
81             }
82             bUpdateList = true;
83         break;
84         case FN_SET_ACT_GLOSSARY:
85             if(pItem)
86             {
87                 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
88                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
89                 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
90                 if ( fnSetActGroup )
91                     (*fnSetActGroup)( aGroup );
92                 rReq.Done();
93             }
94         break;
95         case FN_INSERT_GLOSSARY:
96         {
97             if(pItem && pArgs->Count() > 1)
98             {
99                 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
100                 OUString aName;
101                 if(SfxItemState::SET ==  pArgs->GetItemState(FN_PARAM_1, false, &pItem ))
102                     aName = static_cast<const SfxStringItem *>(pItem)->GetValue();
103                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
104                 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
105                 if ( fnSetActGroup )
106                     (*fnSetActGroup)( aGroup );
107                 pGlosHdl->SetCurGroup(aGroup, true);
108                 rReq.SetReturnValue(SfxBoolItem(nSlot, pGlosHdl->InsertGlossary( aName )));
109                 rReq.Done();
110             }
111         }
112         break;
113         default:
114             OSL_FAIL("wrong dispatcher");
115             return;
116     }
117     if(bUpdateList)
118     {
119         SwGlossaryList* pList = ::GetGlossaryList();
120         if(pList->IsActive())
121             pList->Update();
122     }
123 }
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
126