2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 // PlugInManager.cpp: implementation of the CPlugInManager class.
24 //////////////////////////////////////////////////////////////////////
26 #include "pluginmanager.h"
28 #include "modulesystem.h"
29 #include "qerplugin.h"
32 #include "math/vector.h"
33 #include "string/string.h"
39 #include "modulesystem.h"
43 /* plugin manager --------------------------------------- */
44 class CPluginSlot : public IPlugIn
46 CopiedString m_menu_name;
47 const _QERPluginTable *mpTable;
48 std::list<CopiedString> m_CommandStrings;
49 std::list<CopiedString> m_CommandTitleStrings;
50 std::list<std::size_t> m_CommandIDs;
54 build directly from a SYN_PROVIDE interface
56 CPluginSlot(GtkWidget* main_window, const char* name, const _QERPluginTable& table);
58 dispatching a command by name to the plugin
60 void Dispatch(const char *p);
62 // IPlugIn ------------------------------------------------------------
63 const char* getMenuName();
64 std::size_t getCommandCount();
65 const char* getCommand(std::size_t n);
66 const char* getCommandTitle(std::size_t n);
67 void addMenuID(std::size_t n);
68 bool ownsCommandID(std::size_t n);
72 CPluginSlot::CPluginSlot(GtkWidget* main_window, const char* name, const _QERPluginTable& table)
77 const char* commands = mpTable->m_pfnQERPlug_GetCommandList();
78 const char* titles = mpTable->m_pfnQERPlug_GetCommandTitleList();
80 StringTokeniser commandTokeniser(commands, ",;");
81 StringTokeniser titleTokeniser(titles, ",;");
83 const char* cmdToken = commandTokeniser.getToken();
84 const char *titleToken = titleTokeniser.getToken();
85 while (!string_empty(cmdToken))
87 if(string_empty(titleToken))
89 m_CommandStrings.push_back(cmdToken);
90 m_CommandTitleStrings.push_back(cmdToken);
91 cmdToken = commandTokeniser.getToken();
96 m_CommandStrings.push_back(cmdToken);
97 m_CommandTitleStrings.push_back(titleToken);
98 cmdToken = commandTokeniser.getToken();
99 titleToken = titleTokeniser.getToken();
102 mpTable->m_pfnQERPlug_Init(0, (void*)main_window);
105 const char* CPluginSlot::getMenuName()
107 return m_menu_name.c_str();
110 std::size_t CPluginSlot::getCommandCount()
112 return m_CommandStrings.size();
115 const char* CPluginSlot::getCommand(std::size_t n)
117 std::list<CopiedString>::iterator i = m_CommandStrings.begin();
123 const char* CPluginSlot::getCommandTitle(std::size_t n)
125 std::list<CopiedString>::iterator i = m_CommandTitleStrings.begin();
131 void CPluginSlot::addMenuID(std::size_t n)
133 m_CommandIDs.push_back(n);
136 bool CPluginSlot::ownsCommandID(std::size_t n)
138 for(std::list<std::size_t>::iterator i = m_CommandIDs.begin(); i != m_CommandIDs.end(); ++i)
146 void CPluginSlot::Dispatch(const char *p)
149 Select_GetBounds (vMin, vMax);
150 mpTable->m_pfnQERPlug_Dispatch(p, reinterpret_cast<float*>(&vMin), reinterpret_cast<float*>(&vMax), true);//QE_SingleBrush(true));
156 std::list<CPluginSlot *> mSlots;
158 virtual ~CPluginSlots();
160 void AddPluginSlot(GtkWidget* main_window, const char* name, const _QERPluginTable& table)
162 mSlots.push_back(new CPluginSlot(main_window, name, table));
165 void PopulateMenu(PluginsVisitor& menu);
166 bool Dispatch(std::size_t n, const char* p);
169 CPluginSlots::~CPluginSlots()
171 std::list<CPluginSlot *>::iterator iSlot;
172 for(iSlot=mSlots.begin(); iSlot!=mSlots.end(); ++iSlot)
179 void CPluginSlots::PopulateMenu(PluginsVisitor& menu)
181 std::list<CPluginSlot *>::iterator iPlug;
182 for(iPlug=mSlots.begin(); iPlug != mSlots.end(); ++iPlug)
184 menu.visit(*(*iPlug));
188 bool CPluginSlots::Dispatch(std::size_t n, const char* p)
190 std::list<CPluginSlot *>::iterator iPlug;
191 for(iPlug=mSlots.begin(); iPlug!=mSlots.end(); ++iPlug)
193 CPluginSlot *pPlug = *iPlug;
194 if (pPlug->ownsCommandID(n))
203 CPluginSlots g_plugin_slots;
206 void FillPluginSlots(CPluginSlots& slots, GtkWidget* main_window)
208 class AddPluginVisitor : public PluginModules::Visitor
210 CPluginSlots& m_slots;
211 GtkWidget* m_main_window;
213 AddPluginVisitor(CPluginSlots& slots, GtkWidget* main_window)
214 : m_slots(slots), m_main_window(main_window)
217 void visit(const char* name, const _QERPluginTable& table) const
219 m_slots.AddPluginSlot(m_main_window, name, table);
221 } visitor(slots, main_window);
223 Radiant_getPluginModules().foreachModule(visitor);
227 #include "pluginmanager.h"
229 CPlugInManager g_PlugInMgr;
231 CPlugInManager& GetPlugInMgr()
236 void CPlugInManager::Dispatch(std::size_t n, const char * p)
238 g_plugin_slots.Dispatch(n, p);
241 void CPlugInManager::Init(GtkWidget* main_window)
243 FillPluginSlots(g_plugin_slots, main_window);
246 void CPlugInManager::constructMenu(PluginsVisitor& menu)
248 g_plugin_slots.PopulateMenu(menu);
251 void CPlugInManager::Shutdown()