| 1 |
#include "SourceFormatterBase.hpp" |
| 2 |
|
| 3 |
#include "macros.h" |
| 4 |
#include "wxStringHash.h" |
| 5 |
|
| 6 |
wxDEFINE_EVENT(wxEVT_FORMAT_COMPELTED, clSourceFormatEvent); |
| 7 |
wxDEFINE_EVENT(wxEVT_FORMAT_INPLACE_COMPELTED, clSourceFormatEvent); |
| 8 |
|
| 9 |
SourceFormatterBase::SourceFormatterBase() {} |
| 10 |
|
| 11 |
SourceFormatterBase::~SourceFormatterBase() {} |
| 12 |
|
| 13 |
void SourceFormatterBase::FromJSON(const JSONItem& json) |
| 14 |
{ |
| 15 |
m_languages = json["languages"].toArrayString(); |
| 16 |
m_flags = json["flags"].toSize_t((size_t)FormatterFlags::ENABLED); |
| 17 |
m_configFile = json["config_file"].toString(); |
| 18 |
m_name = json["name"].toString(); |
| 19 |
m_description = json["description"].toString(); |
| 20 |
m_shortDescription = json["short_description"].toString(); |
| 21 |
} |
| 22 |
|
| 23 |
JSONItem SourceFormatterBase::ToJSON() const |
| 24 |
{ |
| 25 |
JSONItem ele = JSONItem::createObject(GetName()); |
| 26 |
ele.addProperty("languages", m_languages); |
| 27 |
ele.addProperty("flags", m_flags); |
| 28 |
ele.addProperty("config_file", m_configFile); |
| 29 |
ele.addProperty("name", m_name); |
| 30 |
ele.addProperty("description", m_description); |
| 31 |
ele.addProperty("short_description", m_shortDescription); |
| 32 |
return ele; |
| 33 |
} |
| 34 |
|
| 35 |
bool SourceFormatterBase::CanHandle(FileExtManager::FileType file_type) const |
| 36 |
{ |
| 37 |
wxString lang = FileExtManager::GetLanguageFromType(file_type); |
| 38 |
return !lang.empty() && m_languages.Index(lang) != wxNOT_FOUND; |
| 39 |
} |
| 40 |
|
| 41 |
void SourceFormatterBase::SetFileTypes(const std::vector<FileExtManager::FileType>& types) |
| 42 |
{ |
| 43 |
wxStringSet_t langs; |
| 44 |
for(auto type : types) { |
| 45 |
wxString lang = FileExtManager::GetLanguageFromType(type); |
| 46 |
if(lang.empty()) { |
| 47 |
continue; |
| 48 |
} |
| 49 |
langs.insert(lang); |
| 50 |
} |
| 51 |
|
| 52 |
m_languages.clear(); |
| 53 |
m_languages.reserve(langs.size()); |
| 54 |
for(const auto& lang : langs) { |
| 55 |
m_languages.Add(lang); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
void SourceFormatterBase::SetConfigFilepath(const wxString& filepath) |
| 60 |
{ |
| 61 |
m_configFile = filepath; |
| 62 |
SetFlag(FormatterFlags::HAS_FILE_CONFIG, !m_configFile.empty()); |
| 63 |
} |