diff options
-rw-r--r-- | svx/source/tbxctrls/StylesPreviewWindow.cxx | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx index 53a8f14511a9..c5215cba4a6d 100644 --- a/svx/source/tbxctrls/StylesPreviewWindow.cxx +++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx @@ -68,35 +68,66 @@ namespace { class StylePreviewCache { +private: + class JsonStylePreviewCacheClear final : public Timer + { + public: + JsonStylePreviewCacheClear() + : Timer("Json Style Preview Cache clear callback") + { + // a generous 30 secs + SetTimeout(30000); + SetStatic(); + } + virtual void Invoke() override { StylePreviewCache::gJsonStylePreviewCache.clear(); } + }; + static std::map<OUString, VclPtr<VirtualDevice>> gStylePreviewCache; static std::map<OUString, OString> gJsonStylePreviewCache; static int gStylePreviewCacheClients; + static JsonStylePreviewCacheClear gJsonIdleClear; public: static std::map<OUString, VclPtr<VirtualDevice>>& Get() { return gStylePreviewCache; } static std::map<OUString, OString>& GetJson() { return gJsonStylePreviewCache; } - static void ClearCache() + static void ClearCache(bool bHard) { for (auto& aPreview : gStylePreviewCache) aPreview.second.disposeAndClear(); gStylePreviewCache.clear(); - gJsonStylePreviewCache.clear(); + if (bHard) + { + StylePreviewCache::gJsonStylePreviewCache.clear(); + gJsonIdleClear.Stop(); + } + else + { + // tdf#155720 don't immediately clear the json representation + gJsonIdleClear.Start(); + } + } + + static void RegisterClient() + { + if (!gStylePreviewCacheClients) + gJsonIdleClear.Stop(); + gStylePreviewCacheClients++; } - static void RegisterClient() { gStylePreviewCacheClients++; } static void UnregisterClient() { gStylePreviewCacheClients--; if (!gStylePreviewCacheClients) - ClearCache(); + ClearCache(false); } }; std::map<OUString, VclPtr<VirtualDevice>> StylePreviewCache::gStylePreviewCache; std::map<OUString, OString> StylePreviewCache::gJsonStylePreviewCache; int StylePreviewCache::gStylePreviewCacheClients; +StylePreviewCache::JsonStylePreviewCacheClear StylePreviewCache::gJsonIdleClear; } StyleStatusListener::StyleStatusListener( @@ -143,7 +174,7 @@ StylePoolChangeListener::~StylePoolChangeListener() void StylePoolChangeListener::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) { if (rHint.GetId() == SfxHintId::StyleSheetModified) - StylePreviewCache::ClearCache(); + StylePreviewCache::ClearCache(true); m_pPreviewControl->RequestStylesListUpdate(); } |