mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-23 18:39:55 +00:00
Update themes list when extensions are enabled/disabled
This commit is contained in:
parent
511cf43484
commit
c4d0273e4e
@ -56,8 +56,7 @@ class OptionsWindow : public app::gen::Options {
|
||||
const std::string& themeName() const { return m_name; }
|
||||
|
||||
void openFolder() const {
|
||||
app::launcher::open_folder(
|
||||
m_name.empty() ? m_path: base::join_path(m_path, m_name));
|
||||
app::launcher::open_folder(m_path);
|
||||
}
|
||||
|
||||
bool canSelect() const {
|
||||
@ -322,6 +321,11 @@ public:
|
||||
onChangeBgScope();
|
||||
onChangeGridScope();
|
||||
sectionListbox()->selectIndex(m_curSection);
|
||||
|
||||
// Reload themes when extensions are enabled/disabled
|
||||
m_extThemesChanges =
|
||||
App::instance()->extensions().ThemesChange.connect(
|
||||
base::Bind<void>(&OptionsWindow::reloadThemes, this));
|
||||
}
|
||||
|
||||
bool ok() {
|
||||
@ -579,15 +583,25 @@ private:
|
||||
app::launcher::open_folder(app::main_config_filename());
|
||||
}
|
||||
|
||||
void reloadThemes() {
|
||||
while (themeList()->firstChild())
|
||||
delete themeList()->lastChild();
|
||||
|
||||
loadThemes();
|
||||
}
|
||||
|
||||
void loadThemes() {
|
||||
// Themes already loaded
|
||||
if (themeList()->getItemsCount() > 0)
|
||||
return;
|
||||
|
||||
auto theme = skin::SkinTheme::instance();
|
||||
auto userFolder = userThemeFolder();
|
||||
auto folders = themeFolders();
|
||||
std::sort(folders.begin(), folders.end());
|
||||
const auto& selectedPath = theme->path();
|
||||
|
||||
bool first = true;
|
||||
for (const auto& path : folders) {
|
||||
auto files = base::list_files(path);
|
||||
|
||||
@ -595,17 +609,52 @@ private:
|
||||
if (files.empty() && path != userFolder)
|
||||
continue;
|
||||
|
||||
themeList()->addChild(new ThemeItem(path, std::string()));
|
||||
std::sort(files.begin(), files.end());
|
||||
for (auto& fn : files) {
|
||||
if (!base::is_directory(base::join_path(path, fn)))
|
||||
std::string fullPath =
|
||||
base::normalize_path(
|
||||
base::join_path(path, fn));
|
||||
if (!base::is_directory(fullPath))
|
||||
continue;
|
||||
|
||||
ThemeItem* item = new ThemeItem(path, fn);
|
||||
if (first) {
|
||||
first = false;
|
||||
auto sep = new Separator(base::normalize_path(path), HORIZONTAL);
|
||||
sep->setStyle(theme->styles.separatorInView());
|
||||
themeList()->addChild(sep);
|
||||
}
|
||||
|
||||
ThemeItem* item = new ThemeItem(fullPath, fn);
|
||||
themeList()->addChild(item);
|
||||
|
||||
// Selected theme
|
||||
if (fn == m_pref.theme.selected())
|
||||
if (fullPath == selectedPath)
|
||||
themeList()->selectChild(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Themes from extensions
|
||||
first = true;
|
||||
for (auto ext : App::instance()->extensions()) {
|
||||
if (!ext->isEnabled())
|
||||
continue;
|
||||
|
||||
if (ext->themes().empty())
|
||||
continue;
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
auto sep = new Separator("Extension Themes", HORIZONTAL);
|
||||
sep->setStyle(theme->styles.separatorInView());
|
||||
themeList()->addChild(sep);
|
||||
}
|
||||
|
||||
for (auto it : ext->themes()) {
|
||||
ThemeItem* item = new ThemeItem(it.second, it.first);
|
||||
themeList()->addChild(item);
|
||||
|
||||
// Selected theme
|
||||
if (it.second == selectedPath)
|
||||
themeList()->selectChild(item);
|
||||
}
|
||||
}
|
||||
@ -630,6 +679,7 @@ private:
|
||||
void onThemeChange() {
|
||||
ThemeItem* item = dynamic_cast<ThemeItem*>(themeList()->getSelectedChild());
|
||||
selectTheme()->setEnabled(item && item->canSelect());
|
||||
openThemeFolder()->setEnabled(item != nullptr);
|
||||
}
|
||||
|
||||
void onSelectTheme() {
|
||||
@ -779,6 +829,7 @@ private:
|
||||
DocumentPreferences& m_docPref;
|
||||
DocumentPreferences* m_curPref;
|
||||
int& m_curSection;
|
||||
obs::scoped_connection m_extThemesChanges;
|
||||
};
|
||||
|
||||
class OptionsCommand : public Command {
|
||||
|
@ -29,6 +29,7 @@ namespace app {
|
||||
namespace {
|
||||
|
||||
const char* kPackageJson = "package.json";
|
||||
const char* kAsepriteDefaultThemeExtensionName = "aseprite-theme";
|
||||
|
||||
class ReadArchive {
|
||||
public:
|
||||
@ -171,12 +172,16 @@ void Extension::addPalette(const std::string& id, const std::string& path)
|
||||
|
||||
bool Extension::canBeDisabled() const
|
||||
{
|
||||
return (m_isEnabled && !isCurrentTheme());
|
||||
return (m_isEnabled &&
|
||||
!isCurrentTheme() &&
|
||||
!isDefaultTheme()); // Default theme cannot be disabled or uninstalled
|
||||
}
|
||||
|
||||
bool Extension::canBeUninstalled() const
|
||||
{
|
||||
return (!m_isBuiltinExtension && !isCurrentTheme());
|
||||
return (!m_isBuiltinExtension &&
|
||||
!isCurrentTheme() &&
|
||||
!isDefaultTheme());
|
||||
}
|
||||
|
||||
void Extension::enable(const bool state)
|
||||
@ -230,10 +235,15 @@ void Extension::uninstallFiles(const std::string& path)
|
||||
|
||||
bool Extension::isCurrentTheme() const
|
||||
{
|
||||
auto it = m_themes.find(Preferences::instance().theme.selected.defaultValue());
|
||||
auto it = m_themes.find(Preferences::instance().theme.selected());
|
||||
return (it != m_themes.end());
|
||||
}
|
||||
|
||||
bool Extension::isDefaultTheme() const
|
||||
{
|
||||
return (name() == kAsepriteDefaultThemeExtensionName);
|
||||
}
|
||||
|
||||
Extensions::Extensions()
|
||||
{
|
||||
// Create and get the user extensions directory
|
||||
|
@ -51,6 +51,7 @@ namespace app {
|
||||
void uninstall();
|
||||
void uninstallFiles(const std::string& path);
|
||||
bool isCurrentTheme() const;
|
||||
bool isDefaultTheme() const;
|
||||
|
||||
ExtensionItems m_themes;
|
||||
ExtensionItems m_palettes;
|
||||
|
@ -259,7 +259,7 @@ void SkinTheme::loadAll(const std::string& themeId)
|
||||
if (m_fonts.empty())
|
||||
loadFontData();
|
||||
|
||||
m_path = themePath(themeId);
|
||||
m_path = findThemePath(themeId);
|
||||
if (m_path.empty())
|
||||
throw base::Exception("Theme %s not found", themeId.c_str());
|
||||
|
||||
@ -1578,7 +1578,7 @@ void SkinTheme::paintProgressBar(ui::Graphics* g, const gfx::Rect& rc0, double p
|
||||
g->fillRect(colors.background(), gfx::Rect(rc.x+u, rc.y, rc.w-u, rc.h));
|
||||
}
|
||||
|
||||
std::string SkinTheme::themePath(const std::string& themeId) const
|
||||
std::string SkinTheme::findThemePath(const std::string& themeId) const
|
||||
{
|
||||
// First we try to find the theme on an extensions
|
||||
std::string path = App::instance()->extensions().themePath(themeId);
|
||||
@ -1594,7 +1594,7 @@ std::string SkinTheme::themePath(const std::string& themeId) const
|
||||
|
||||
path = base::get_file_path(rf.filename());
|
||||
}
|
||||
return path;
|
||||
return base::normalize_path(path);
|
||||
}
|
||||
|
||||
} // namespace skin
|
||||
|
@ -47,6 +47,8 @@ namespace app {
|
||||
SkinTheme();
|
||||
~SkinTheme();
|
||||
|
||||
const std::string& path() { return m_path; }
|
||||
|
||||
she::Font* getDefaultFont() const override { return m_defaultFont; }
|
||||
she::Font* getWidgetFont(const ui::Widget* widget) const override;
|
||||
she::Font* getMiniFont() const { return m_miniFont; }
|
||||
@ -139,7 +141,7 @@ namespace app {
|
||||
int selected_offset, int mnemonic);
|
||||
void drawEntryText(ui::Graphics* g, ui::Entry* widget);
|
||||
|
||||
std::string themePath(const std::string& themeId) const;
|
||||
std::string findThemePath(const std::string& themeId) const;
|
||||
|
||||
std::string m_path;
|
||||
she::Surface* m_sheet;
|
||||
|
Loading…
x
Reference in New Issue
Block a user