| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <list> |
| 4 |
#include <string> |
| 5 |
#include "imodule.h" |
| 6 |
|
| 7 |
/** |
| 8 |
* Simple structure to store a file pattern (e.g. "*.map") |
| 9 |
* along with its name (e.g. "Map files") and extension. |
| 10 |
*/ |
| 11 |
struct FileTypePattern |
| 12 |
{ |
| 13 |
// The user-friendly name ("Doom 3 Map") |
| 14 |
std::string name; |
| 15 |
|
| 16 |
// The extension in lowercase ("map") |
| 17 |
std::string extension; |
| 18 |
|
| 19 |
// The mask pattern ("*.map") |
| 20 |
std::string pattern; |
| 21 |
|
| 22 |
// Optional icon string, referring to an image in the bitmaps folder |
| 23 |
std::string icon; |
| 24 |
|
| 25 |
// Constructor with optional initialisation parameters |
| 26 |
FileTypePattern(const std::string& name_ = "", |
| 27 |
const std::string& extension_ = "", |
| 28 |
const std::string& pattern_ = "", |
| 29 |
const std::string& icon_ = "") : |
| 30 |
name(name_), |
| 31 |
extension(extension_), |
| 32 |
pattern(pattern_), |
| 33 |
icon(icon_) |
| 34 |
{} |
| 35 |
}; |
| 36 |
typedef std::list<FileTypePattern> FileTypePatterns; |
| 37 |
|
| 38 |
const char* const MODULE_FILETYPES = "FileTypes"; |
| 39 |
|
| 40 |
/** |
| 41 |
* Interface for the FileType registry module. This module retains a list of |
| 42 |
* FileTypePattern objects along with their associated module names. |
| 43 |
*/ |
| 44 |
class IFileTypeRegistry : |
| 45 |
public RegisterableModule |
| 46 |
{ |
| 47 |
public: |
| 48 |
/** |
| 49 |
* greebo: Registers an extension (e.g. "map") for a certain file type ("prefab"). |
| 50 |
* Common file types are "map", "prefab" and "model", each of them can have one |
| 51 |
* or more extensions associated in a certain order ("prefab" => "pfb", "map", "reg", |
| 52 |
* or "map" => "map", "reg", "pfb"). The order is important e.g. for the file |
| 53 |
* filters in the Map Open dialog. |
| 54 |
* |
| 55 |
* The pattern argument is a structure containing the lowercase extensions as well |
| 56 |
* as the display name and the filter pattern used in the file chooser dialogs. |
| 57 |
* |
| 58 |
* If an extension is already associated with the given filetype, it is ignored. |
| 59 |
* New extensions are added to the end of the list. |
| 60 |
* |
| 61 |
* @param fileType: the file type which an extension should be associated to. |
| 62 |
* @param pattern: the extension as well as the display name and a pattern ("*.map") |
| 63 |
*/ |
| 64 |
virtual void registerPattern(const std::string& fileType, |
| 65 |
const FileTypePattern& pattern) = 0; |
| 66 |
|
| 67 |
/** |
| 68 |
* Retrieve a list of patterns for the given file type (e.g. "prefab" or "map"). |
| 69 |
* |
| 70 |
* @returns: a list of FileTypePatterns containing extension, display name, etc. |
| 71 |
*/ |
| 72 |
virtual FileTypePatterns getPatternsForType(const std::string& fileType) = 0; |
| 73 |
|
| 74 |
/** |
| 75 |
* Tries to find an icon file for the given extension. If not empty, |
| 76 |
* the returned string refers to a filename in the bitmaps/ folder. |
| 77 |
*/ |
| 78 |
virtual std::string getIconForExtension(const std::string& extension) = 0; |
| 79 |
}; |
| 80 |
|
| 81 |
namespace filetype |
| 82 |
{ |
| 83 |
|
| 84 |
// Some well-known file type constants |
| 85 |
const char* const TYPE_MAP = "map"; |
| 86 |
const char* const TYPE_MAP_EXPORT = "mapexport"; |
| 87 |
const char* const TYPE_PREFAB = "prefab"; |
| 88 |
const char* const TYPE_REGION = "region"; |
| 89 |
const char* const TYPE_MODEL_EXPORT = "modelexport"; |
| 90 |
const char* const TYPE_PAK = "pak"; |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
inline IFileTypeRegistry& GlobalFiletypes() |
| 95 |
{ |
| 96 |
static module::InstanceReference<IFileTypeRegistry> _reference(MODULE_FILETYPES); |
| 97 |
return _reference; |
| 98 |
} |