diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 26a3c7f2a..42e8477e0 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -483,6 +483,10 @@ SendMediaReady PrepareWallPaper(const QImage &image) { 0); } +void ClearEditingPalette() { + QFile(EditingPalettePath()).remove(); +} + } // namespace ChatBackground::AdjustableColor::AdjustableColor(style::color data) @@ -739,13 +743,20 @@ std::optional ChatBackground::editingTheme() const { return _editingTheme; } -void ChatBackground::setEditingTheme( - std::optional editing) { - if (!_editingTheme && !editing) { +void ChatBackground::setEditingTheme(const Data::CloudTheme &editing) { + _editingTheme = editing; +} + +void ChatBackground::clearEditingTheme(ClearEditing clear) { + if (!_editingTheme) { return; } - _editingTheme = editing; - if (!_editingTheme) { + _editingTheme = std::nullopt; + if (clear == ClearEditing::Temporary) { + return; + } + ClearEditingPalette(); + if (clear == ClearEditing::RevertChanges) { reapplyWithNightMode(std::nullopt, _nightMode); KeepApplied(); } @@ -1235,10 +1246,6 @@ QString EditingPalettePath() { return cWorkingDir() + "tdata/editing-theme.tdesktop-palette"; } -void ClearEditingPalette() { - QFile(EditingPalettePath()).remove(); -} - QColor CountAverageColor(const QImage &image) { Expects(image.format() == QImage::Format_ARGB32_Premultiplied); diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index fbbe85226..e139a1ed4 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -70,7 +70,6 @@ void ToggleNightMode(const QString &themePath); void Revert(); [[nodiscard]] QString EditingPalettePath(); -void ClearEditingPalette(); bool LoadFromFile( const QString &file, @@ -103,6 +102,12 @@ struct BackgroundUpdate { bool tiled; }; +enum class ClearEditing { + Temporary, + RevertChanges, + KeepChanges, +}; + class ChatBackground : public base::Observable , private base::Subscriber { @@ -121,7 +126,8 @@ public: void setThemeObject(const Object &object); [[nodiscard]] const Object &themeObject() const; [[nodiscard]] std::optional editingTheme() const; - void setEditingTheme(std::optional editing); + void setEditingTheme(const Data::CloudTheme &editing); + void clearEditingTheme(ClearEditing clear = ClearEditing::Temporary); void reset(); void setTestingTheme(Instance &&theme); diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index 2e4ecdaae..23eabc3a0 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -664,7 +664,7 @@ Editor::Editor( _close->setClickedCallback([=] { const auto box = std::make_shared>(); const auto close = crl::guard(this, [=] { - ClearEditingPalette(); + Background()->clearEditingTheme(ClearEditing::RevertChanges); closeEditor(); if (*box) { (*box)->closeBox(); @@ -791,7 +791,7 @@ void Editor::paintEvent(QPaintEvent *e) { void Editor::closeEditor() { if (const auto window = App::wnd()) { window->showRightColumn(nullptr); - Background()->setEditingTheme(std::nullopt); + Background()->clearEditingTheme(); } } diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index 388d97ecb..bc937ee5f 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -482,6 +482,7 @@ Fn SavePreparedTheme( const auto finish = [=](const MTPTheme &result) { done(); + Background()->clearEditingTheme(ClearEditing::KeepChanges); const auto cloud = result.match([&](const MTPDtheme &data) { const auto result = Data::CloudTheme::Parse(session, data); @@ -503,7 +504,6 @@ Fn SavePreparedTheme( Apply(std::move(preview)); KeepApplied(); } - Background()->setEditingTheme(std::nullopt); }; const auto createTheme = [=](const MTPDocument &data) {