| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2009 by Eran Ifrah |
| 5 |
// file name : fileextmanager.h |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
#ifndef __FILEEXTMANAGER__ |
| 27 |
#define __FILEEXTMANAGER__ |
| 28 |
|
| 29 |
#include "codelite_exports.h" |
| 30 |
#include "smart_ptr.h" |
| 31 |
#include "wxStringHash.h" |
| 32 |
|
| 33 |
#include <map> |
| 34 |
#include <vector> |
| 35 |
#include <wx/filename.h> |
| 36 |
#include <wx/regex.h> |
| 37 |
#include <wx/string.h> |
| 38 |
|
| 39 |
class WXDLLIMPEXP_CL FileExtManager |
| 40 |
{ |
| 41 |
public: |
| 42 |
enum FileType { |
| 43 |
TypeOther = wxNOT_FOUND, |
| 44 |
TypeSourceC, // 0 |
| 45 |
TypeSourceCpp, |
| 46 |
TypeHeader, |
| 47 |
TypeResource, |
| 48 |
TypeYacc, |
| 49 |
TypeLex, |
| 50 |
TypeQtForm, |
| 51 |
TypeQtResource, |
| 52 |
TypeWorkspace, |
| 53 |
TypeProject, |
| 54 |
TypeFormbuilder, |
| 55 |
TypeCodedesigner, |
| 56 |
TypeErd, |
| 57 |
TypePhp, |
| 58 |
TypeXml, |
| 59 |
TypeCSS, |
| 60 |
TypeJS, |
| 61 |
TypePython, |
| 62 |
TypeExe, |
| 63 |
TypeHtml, |
| 64 |
TypeArchive, |
| 65 |
TypeDll, |
| 66 |
TypeBmp, |
| 67 |
TypeSvg, |
| 68 |
TypeMakefile, |
| 69 |
TypeText, |
| 70 |
TypeShellScript, |
| 71 |
TypeWxCrafter, |
| 72 |
TypeXRC, |
| 73 |
TypeSQL, |
| 74 |
TypeFolder, |
| 75 |
TypeFolderExpanded, // For UI purposes only |
| 76 |
TypeProjectActive, // For UI purposes only |
| 77 |
TypeProjectExpanded, // For UI purposes only |
| 78 |
TypeWorkspaceFolder, // For UI purposes only |
| 79 |
TypeWorkspaceFolderExpanded, // For UI purposes only |
| 80 |
TypeWorkspacePHP, |
| 81 |
TypeWorkspaceFileSystem, |
| 82 |
TypeWorkspaceDocker, |
| 83 |
TypeWorkspaceNodeJS, |
| 84 |
TypeWorkspacePHPTags, |
| 85 |
TypeWorkspaceDatabase, |
| 86 |
TypeAsm, |
| 87 |
TypeJava, |
| 88 |
TypeQMake, |
| 89 |
TypeCMake, |
| 90 |
TypeDockerfile, |
| 91 |
TypeYAML, |
| 92 |
TypeDatabase, |
| 93 |
TypeFileSymlink, |
| 94 |
TypeFolderSymlink, |
| 95 |
TypeFolderSymlinkExpanded, // For UI purposes only |
| 96 |
TypeLua, |
| 97 |
TypeRust, |
| 98 |
TypeRuby, |
| 99 |
TypeDiff, |
| 100 |
TypePatch, |
| 101 |
TypeJSON, |
| 102 |
TypeMarkdown, |
| 103 |
TypeDart, |
| 104 |
TypeLast, |
| 105 |
}; |
| 106 |
|
| 107 |
public: |
| 108 |
static FileType GetType(const wxString& filename, FileExtManager::FileType defaultType = FileExtManager::TypeOther); |
| 109 |
static void Init(); |
| 110 |
|
| 111 |
static bool IsSymlinkFolder(const wxString& filename); |
| 112 |
static bool IsSymlinkFolder(const wxFileName& filename) { return IsSymlinkFolder(filename.GetFullPath()); } |
| 113 |
|
| 114 |
static bool IsSymlinkFile(const wxString& filename); |
| 115 |
static bool IsSymlinkFile(const wxFileName& filename) { return IsSymlinkFile(filename.GetFullPath()); } |
| 116 |
|
| 117 |
static bool IsSymlink(const wxString& filename) { return IsSymlinkFolder(filename) || IsSymlinkFile(filename); } |
| 118 |
static bool IsSymlink(const wxFileName& filename) { return IsSymlinkFolder(filename) || IsSymlinkFile(filename); } |
| 119 |
|
| 120 |
/** |
| 121 |
* @brief return true if the file is a C/C++ file |
| 122 |
*/ |
| 123 |
static bool IsCxxFile(const wxString& filename); |
| 124 |
static bool IsCxxFile(const wxFileName& filename) { return IsCxxFile(filename.GetFullPath()); } |
| 125 |
|
| 126 |
/** |
| 127 |
* @brief return true if a file is a JavaScript file |
| 128 |
*/ |
| 129 |
static bool IsJavascriptFile(const wxString& filename); |
| 130 |
static bool IsJavascriptFile(const wxFileName& filename) { return IsJavascriptFile(filename.GetFullPath()); } |
| 131 |
|
| 132 |
/** |
| 133 |
* @param return true if a file is a PHP file |
| 134 |
*/ |
| 135 |
static bool IsPHPFile(const wxString& filename); |
| 136 |
static bool IsPHPFile(const wxFileName& filename) { return IsPHPFile(filename.GetFullPath()); } |
| 137 |
|
| 138 |
/** |
| 139 |
* @param return true if a file is a Java file |
| 140 |
*/ |
| 141 |
static bool IsJavaFile(const wxString& filename); |
| 142 |
static bool IsJavaFile(const wxFileName& filename) { return IsJavaFile(filename.GetFullPath()); } |
| 143 |
|
| 144 |
/** |
| 145 |
* @param return true if the file is of type 'type' |
| 146 |
*/ |
| 147 |
static bool IsFileType(const wxString& filename, FileExtManager::FileType type); |
| 148 |
static bool IsFileType(const wxFileName& filename, FileExtManager::FileType type) |
| 149 |
{ |
| 150 |
return IsFileType(filename.GetFullPath(), type); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* @brief attempt to autodetect the file type by examining its content |
| 155 |
*/ |
| 156 |
static bool AutoDetectByContent(const wxString& filename, FileExtManager::FileType& fileType); |
| 157 |
/** |
| 158 |
* @brief given input string, return the content type |
| 159 |
*/ |
| 160 |
static bool GetContentType(const wxString& string_content, FileExtManager::FileType& fileType); |
| 161 |
|
| 162 |
/** |
| 163 |
* @brief return the file type only by checking its extension |
| 164 |
*/ |
| 165 |
static FileExtManager::FileType GetTypeFromExtension(const wxString& filename) |
| 166 |
{ |
| 167 |
return GetTypeFromExtension(wxFileName(filename)); |
| 168 |
} |
| 169 |
static FileExtManager::FileType GetTypeFromExtension(const wxFileName& filename); |
| 170 |
|
| 171 |
/** |
| 172 |
* @brief return map of all supported file types |
| 173 |
* the returned map contains pairs of file extension -> FileType enumerator |
| 174 |
*/ |
| 175 |
static std::unordered_map<wxString, FileExtManager::FileType> GetAllSupportedFileTypes(); |
| 176 |
/** |
| 177 |
* @brief return map of file types grouped by languages |
| 178 |
*/ |
| 179 |
static std::unordered_map<wxString, std::vector<FileExtManager::FileType>> GetLanguageBundles(); |
| 180 |
|
| 181 |
static wxString GetLanguageFromType(FileExtManager::FileType file_type); |
| 182 |
}; |
| 183 |
|
| 184 |
#endif // __fileextmanager__ |