static void GetAvailableThemes(std::vector<AvailableTheme> * outThemes) { Guard::ArgumentNotNull(outThemes, GUARD_LINE); outThemes->clear(); NumPredefinedThemes = 0; for (auto predefinedTheme : PredefinedThemes) { AvailableTheme theme {}; theme.Name = predefinedTheme.Theme->Name; outThemes->push_back(std::move(theme)); NumPredefinedThemes++; } auto themesPattern = Path::Combine(GetThemePath(), "*.json"); auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(themesPattern, true)); while (scanner->Next()) { auto fileInfo = scanner->GetFileInfo(); auto name = Path::GetFileNameWithoutExtension(std::string(fileInfo->Name)); AvailableTheme theme {}; theme.Name = name; theme.Path = GetThemeFileName(theme.Name); outThemes->push_back(std::move(theme)); if (Path::Equals(CurrentThemePath, scanner->GetPath())) { ActiveAvailableThemeIndex = outThemes->size() - 1; } } }
CThemeProvider::CThemeProvider() { wxArtProvider::Push(this); m_themePath = GetThemePath(); RegisterOption(OPTION_THEME); }
void CThemeProvider::OnOptionChanged(int option) { wxASSERT(option == OPTION_THEME); m_themePath = GetThemePath(); wxArtProvider::Remove(this); wxArtProvider::Push(this); }
bool EnsureThemeDirectoryExists() { try { auto path = GetThemePath(); Path::CreateDirectory(path); return true; } catch (const std::exception &) { return false; } }
void GetAvailableThemes(List<AvailableTheme> * outThemes) { Guard::ArgumentNotNull(outThemes); outThemes->Clear(); NumPredefinedThemes = 0; for (const UITheme * * predefinedTheme = PredefinedThemes; *predefinedTheme != nullptr; predefinedTheme++) { AvailableTheme theme; String::Set(theme.Path, sizeof(theme.Path), String::Empty); String::Set(theme.Name, sizeof(theme.Name), (*predefinedTheme)->Name); outThemes->Add(theme); NumPredefinedThemes++; } utf8 themesPattern[MAX_PATH]; GetThemePath(themesPattern, sizeof(themesPattern)); Path::Append(themesPattern, sizeof(themesPattern), "*.json"); int handle = platform_enumerate_files_begin(themesPattern); if (handle != INVALID_HANDLE) { file_info fileInfo; while (platform_enumerate_files_next(handle, &fileInfo)) { AvailableTheme theme; Path::GetFileNameWithoutExtension(theme.Name, sizeof(theme.Name), fileInfo.path); GetThemeFileName(theme.Path, sizeof(theme.Path), theme.Name); outThemes->Add(theme); if (Path::Equals(CurrentThemePath, fileInfo.path)) { ActiveAvailableThemeIndex = outThemes->GetCount() - 1; } } platform_enumerate_files_end(handle); } }
bool EnsureThemeDirectoryExists() { utf8 path[MAX_PATH]; GetThemePath(path, sizeof(path)); return platform_ensure_directory_exists(path); }
void GetThemeFileName(utf8 * buffer, size_t bufferSize, const utf8 * name) { GetThemePath(buffer, bufferSize); Path::Append(buffer, bufferSize, name); String::Append(buffer, bufferSize, ".json"); }
std::string GetThemeFileName(const std::string &name) { auto themeDirectory = GetThemePath(); auto themePath = Path::Combine(themeDirectory, name + ".json"); return themePath; }