Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / sw / source / uibase / shells / textglos.cxx
blob6d9bb08028a6427369961a291825ebfa7b4d5f8d
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(); // async dialog
52 rReq.Ignore();
53 break;
54 case FN_EXPAND_GLOSSARY:
56 bool bReturn = pGlosHdl->ExpandGlossary(rReq.GetFrameWeld());
57 rReq.SetReturnValue( SfxBoolItem( nSlot, bReturn ) );
58 rReq.Done();
60 break;
61 case FN_NEW_GLOSSARY:
62 if(pItem && pArgs->Count() == 3 )
64 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
65 OUString aName;
66 if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1, false, &pItem ))
67 aName = static_cast<const SfxStringItem *>(pItem)->GetValue();
68 OUString aShortName;
69 if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_2, false, &pItem ))
70 aShortName = static_cast<const SfxStringItem *>(pItem)->GetValue();
72 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
73 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
74 if ( fnSetActGroup )
75 (*fnSetActGroup)( aGroup );
76 pGlosHdl->SetCurGroup(aGroup, true);
77 // Chosen group must be created in NewGlossary if necessary!
78 pGlosHdl->NewGlossary( aName, aShortName, true );
79 rReq.Done();
81 bUpdateList = true;
82 break;
83 case FN_SET_ACT_GLOSSARY:
84 if(pItem)
86 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
87 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
88 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
89 if ( fnSetActGroup )
90 (*fnSetActGroup)( aGroup );
91 rReq.Done();
93 break;
94 case FN_INSERT_GLOSSARY:
96 if(pItem && pArgs->Count() > 1)
98 OUString aGroup = static_cast<const SfxStringItem *>(pItem)->GetValue();
99 OUString aName;
100 if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1, false, &pItem ))
101 aName = static_cast<const SfxStringItem *>(pItem)->GetValue();
102 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
103 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
104 if ( fnSetActGroup )
105 (*fnSetActGroup)( aGroup );
106 pGlosHdl->SetCurGroup(aGroup, true);
107 rReq.SetReturnValue(SfxBoolItem(nSlot, pGlosHdl->InsertGlossary( aName )));
108 rReq.Done();
111 break;
112 default:
113 OSL_FAIL("wrong dispatcher");
114 return;
116 if(bUpdateList)
118 SwGlossaryList* pList = ::GetGlossaryList();
119 if(pList->IsActive())
120 pList->Update();
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */