svx/source/inc/StylesPreviewWindow.hxx | 17 ++++++++++++++ svx/source/tbxctrls/StylesPreviewWindow.cxx | 32 +++++++++++++++++++++++++--- sw/source/uibase/app/docst.cxx | 4 +++ 3 files changed, 49 insertions(+), 4 deletions(-)
New commits: commit 01d99c0005f67d6ecb139bae7463dc25d45884ef Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Tue Mar 2 12:18:21 2021 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Sat Mar 6 16:09:28 2021 +0100 Styles preview: use listener to trigger update Do not render all styles on every selection change. Use listener to detect styles modification. Change-Id: I6d41acd7acad160d1477281d2b3d473233def4d7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111833 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112013 Tested-by: Jenkins diff --git a/svx/source/inc/StylesPreviewWindow.hxx b/svx/source/inc/StylesPreviewWindow.hxx index 7c2c572708ef..533ff40601b4 100644 --- a/svx/source/inc/StylesPreviewWindow.hxx +++ b/svx/source/inc/StylesPreviewWindow.hxx @@ -28,6 +28,7 @@ class StylesPreviewWindow_Base; +/// Listener for style selection class StyleStatusListener : public SfxStatusListener { StylesPreviewWindow_Base* m_pPreviewControl; @@ -40,6 +41,19 @@ public: void StateChanged(SfxItemState eState, const SfxPoolItem* pState) override; }; +/// Listener for styles creation or modification +class StylePoolChangeListener : public SfxListener +{ + StylesPreviewWindow_Base* m_pPreviewControl; + SfxStyleSheetBasePool* m_pStyleSheetPool; + +public: + StylePoolChangeListener(StylesPreviewWindow_Base* pPreviewControl); + ~StylePoolChangeListener(); + + virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override; +}; + class StyleItemController { static constexpr unsigned LEFT_MARGIN = 8; @@ -70,6 +84,7 @@ protected: std::unique_ptr<weld::IconView> m_xStylesView; rtl::Reference<StyleStatusListener> m_xStatusListener; + std::unique_ptr<StylePoolChangeListener> m_pStylePoolChangeListener; std::vector<std::pair<OUString, OUString>> m_aDefaultStyles; std::vector<std::pair<OUString, OUString>> m_aAllStyles; @@ -87,10 +102,10 @@ public: ~StylesPreviewWindow_Base(); void Select(const OUString& rStyleName); + void UpdateStylesList(); private: void Update(); - void UpdateStylesList(); bool Command(const CommandEvent& rEvent); }; diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx index f392c2fc90de..59e86b7d2bd6 100644 --- a/svx/source/tbxctrls/StylesPreviewWindow.cxx +++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx @@ -72,6 +72,32 @@ void StyleStatusListener::StateChanged(SfxItemState /*eState*/, const SfxPoolIte m_pPreviewControl->Select(pStateItem->GetStyleName()); } +StylePoolChangeListener::StylePoolChangeListener(StylesPreviewWindow_Base* pPreviewControl) + : SfxListener() + , m_pPreviewControl(pPreviewControl) +{ + SfxObjectShell* pDocShell = SfxObjectShell::Current(); + + if (pDocShell) + m_pStyleSheetPool = pDocShell->GetStyleSheetPool(); + + if (m_pStyleSheetPool) + { + StartListening(*m_pStyleSheetPool); + } +} + +StylePoolChangeListener::~StylePoolChangeListener() +{ + if (m_pStyleSheetPool) + EndListening(*m_pStyleSheetPool); +} + +void StylePoolChangeListener::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& /*rHint*/) +{ + m_pPreviewControl->UpdateStylesList(); +} + StyleItemController::StyleItemController(const std::pair<OUString, OUString>& aStyleName) : m_eStyleFamily(SfxStyleFamily::Para) , m_aStyleName(aStyleName) @@ -335,6 +361,9 @@ StylesPreviewWindow_Base::StylesPreviewWindow_Base( m_xStatusListener = new StyleStatusListener(this, xDispatchProvider); + m_pStylePoolChangeListener.reset(new StylePoolChangeListener(this)); + + UpdateStylesList(); Update(); } @@ -390,14 +419,11 @@ void StylesPreviewWindow_Base::Select(const OUString& rStyleName) { m_sSelectedStyle = rStyleName; - UpdateStylesList(); Update(); } void StylesPreviewWindow_Base::Update() { - UpdateStylesList(); - for (std::vector<std::pair<OUString, OUString>>::size_type i = 0; i < m_aAllStyles.size(); ++i) { if (m_aAllStyles[i].first == m_sSelectedStyle || m_aAllStyles[i].second == m_sSelectedStyle) diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index ff9ea4af3585..f2a414a88955 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -1317,6 +1317,8 @@ void SwDocShell::UpdateStyle(const OUString &rName, SfxStyleFamily nFamily, SwWr break; default: break; } + + m_xDoc->BroadcastStyleOperation(rName, nFamily, SfxHintId::StyleSheetModified); } // NewByExample @@ -1510,6 +1512,8 @@ void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily, default: break; } + + m_xDoc->BroadcastStyleOperation(rName, nFamily, SfxHintId::StyleSheetCreated); } sfx::AccessibilityIssueCollection SwDocShell::runAccessibilityCheck() _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits