2 Copyright (C) 2001-2006, William Joseph.
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 #include "filetypes.h"
24 #include "debugging/debugging.h"
26 #include "ifiletypes.h"
28 #include "string/string.h"
33 class RadiantFileTypeRegistry : public IFileTypeRegistry {
34 struct filetype_copy_t {
35 filetype_copy_t(const char *moduleName, const filetype_t other)
36 : m_can_load(other.can_load), m_can_import(other.can_import), m_can_save(other.can_save),
37 m_moduleName(moduleName), m_name(other.name), m_pattern(other.pattern)
41 const char *getModuleName() const
43 return m_moduleName.c_str();
46 filetype_t getType() const
48 return filetype_t(m_name.c_str(), m_pattern.c_str(), m_can_load, m_can_save, m_can_import);
55 CopiedString m_moduleName;
57 CopiedString m_pattern;
60 typedef std::vector<filetype_copy_t> filetype_list_t;
61 std::map<CopiedString, filetype_list_t> m_typelists;
63 RadiantFileTypeRegistry()
65 addType("*", "*", filetype_t("All Files", "*.*"));
68 void addType(const char *moduleType, const char *moduleName, filetype_t type)
70 m_typelists[moduleType].push_back(filetype_copy_t(moduleName, type));
73 void getTypeList(const char *moduleType, IFileTypeList *typelist, bool want_load, bool want_import, bool want_save)
75 filetype_list_t &list_ref = m_typelists[moduleType];
76 for (filetype_list_t::iterator i = list_ref.begin(); i != list_ref.end(); ++i) {
77 if (want_load && !(*i).m_can_load) {
80 if (want_import && !(*i).m_can_import) {
83 if (want_save && !(*i).m_can_save) {
86 typelist->addType((*i).getModuleName(), (*i).getType());
91 static RadiantFileTypeRegistry g_patterns;
93 IFileTypeRegistry *GetFileTypeRegistry()
98 const char *findModuleName(IFileTypeRegistry *registry, const char *moduleType, const char *extension)
100 class SearchFileTypeList : public IFileTypeList {
102 const char *m_moduleName;
104 SearchFileTypeList(const char *ext)
109 strncpy(m_pattern + 2, ext, 125);
110 m_pattern[127] = '\0';
113 void addType(const char *moduleName, filetype_t type)
115 if (extension_equal(m_pattern, type.pattern)) {
116 m_moduleName = moduleName;
120 const char *getModuleName()
125 registry->getTypeList(moduleType, &search);
126 return search.getModuleName();
130 #include "modulesystem/singletonmodule.h"
131 #include "modulesystem/moduleregistry.h"
134 IFileTypeRegistry *m_filetypes;
136 typedef IFileTypeRegistry Type;
138 STRING_CONSTANT(Name, "*");
142 m_filetypes = GetFileTypeRegistry();
145 IFileTypeRegistry *getTable()
151 typedef SingletonModule<FiletypesAPI> FiletypesModule;
152 typedef Static<FiletypesModule> StaticFiletypesModule;
153 StaticRegisterModule staticRegisterFiletypes(StaticFiletypesModule::instance());