svx/source/inc/StylesPreviewWindow.hxx | 24 ++++++++++++++++++++++-- svx/source/tbxctrls/StylesPreviewWindow.cxx | 20 +++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-)
New commits: commit de18a4ee448cf393a69592a75201eca05b90cb5f Author: Szymon Kłos <[email protected]> AuthorDate: Tue Dec 14 18:21:39 2021 +0100 Commit: Szymon Kłos <[email protected]> CommitDate: Wed Dec 22 10:28:01 2021 +0100 Update styles previews in Idle This helps with performance when we do series of actions updating styles. In that case we will only request update. When we will reach idle state we will do it only one time. What removes unnecessary updates in the meantime. Change-Id: I9fc59992833a6cf98c42571c1189b3c5d49ba5a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126840 Reviewed-by: Luboš Luňák <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/svx/source/inc/StylesPreviewWindow.hxx b/svx/source/inc/StylesPreviewWindow.hxx index 4c7fdd43dfa5..ec019608d46a 100644 --- a/svx/source/inc/StylesPreviewWindow.hxx +++ b/svx/source/inc/StylesPreviewWindow.hxx @@ -79,8 +79,25 @@ private: const tools::Rectangle& aContentRect, const Color& aColor); }; +class StylesListUpdateTask : public Idle +{ + StylesPreviewWindow_Base& m_rStylesList; + +public: + StylesListUpdateTask(StylesPreviewWindow_Base& rStylesList) + : Idle("StylesListUpdateTask") + , m_rStylesList(rStylesList) + { + SetPriority(TaskPriority::HIGH_IDLE); + } + + virtual void Invoke() override; +}; + class StylesPreviewWindow_Base { + friend class StylesListUpdateTask; + protected: static constexpr unsigned STYLES_COUNT = 6; @@ -88,6 +105,8 @@ protected: std::unique_ptr<weld::IconView> m_xStylesView; + StylesListUpdateTask m_aUpdateTask; + StyleStatusListener* m_pStatusListener; css::uno::Reference<css::lang::XComponent> m_xStatusListener; std::unique_ptr<StylePoolChangeListener> m_pStylePoolChangeListener; @@ -108,10 +127,11 @@ public: ~StylesPreviewWindow_Base(); void Select(const OUString& rStyleName); - void UpdateStylesList(); + void RequestStylesListUpdate(); private: - void Update(); + void UpdateStylesList(); + void UpdateSelection(); bool Command(const CommandEvent& rEvent); }; diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx index b557aade7ce3..a45289e15348 100644 --- a/svx/source/tbxctrls/StylesPreviewWindow.cxx +++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx @@ -102,7 +102,7 @@ StylePoolChangeListener::~StylePoolChangeListener() void StylePoolChangeListener::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& /*rHint*/) { - m_pPreviewControl->UpdateStylesList(); + m_pPreviewControl->RequestStylesListUpdate(); } StyleItemController::StyleItemController(const std::pair<OUString, OUString>& aStyleName) @@ -373,6 +373,7 @@ StylesPreviewWindow_Base::StylesPreviewWindow_Base( const css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) : m_xDispatchProvider(xDispatchProvider) , m_xStylesView(xBuilder.weld_icon_view("stylesview")) + , m_aUpdateTask(*this) , m_aDefaultStyles(aDefaultStyles) { m_xStylesView->connect_selection_changed(LINK(this, StylesPreviewWindow_Base, Selected)); @@ -384,8 +385,7 @@ StylesPreviewWindow_Base::StylesPreviewWindow_Base( m_pStylePoolChangeListener.reset(new StylePoolChangeListener(this)); - UpdateStylesList(); - Update(); + RequestStylesListUpdate(); } IMPL_LINK(StylesPreviewWindow_Base, Selected, weld::IconView&, rIconView, void) @@ -425,6 +425,8 @@ StylesPreviewWindow_Base::~StylesPreviewWindow_Base() { m_pStatusListener->UnBind(); + m_aUpdateTask.Stop(); + try { m_xStatusListener->dispose(); @@ -440,10 +442,10 @@ void StylesPreviewWindow_Base::Select(const OUString& rStyleName) { m_sSelectedStyle = rStyleName; - Update(); + UpdateSelection(); } -void StylesPreviewWindow_Base::Update() +void StylesPreviewWindow_Base::UpdateSelection() { for (unsigned long i = 0; i < m_aAllStyles.size(); ++i) { @@ -455,6 +457,14 @@ void StylesPreviewWindow_Base::Update() } } +void StylesPreviewWindow_Base::RequestStylesListUpdate() { m_aUpdateTask.Start(); } + +void StylesListUpdateTask::Invoke() +{ + m_rStylesList.UpdateStylesList(); + m_rStylesList.UpdateSelection(); +} + void StylesPreviewWindow_Base::UpdateStylesList() { m_aAllStyles = m_aDefaultStyles;
