summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2021-03-02 12:18:21 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2021-03-04 12:32:45 +0100
commit145fba733121fe36d29d10fa62ce8ab90e00b891 (patch)
tree4f541bd31a837e93f87ef643669e5c22f406d2a4
parent9ebab440094b04917497327878277593b3103d00 (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r--svx/source/inc/StylesPreviewWindow.hxx16
-rw-r--r--svx/source/tbxctrls/StylesPreviewWindow.cxx32
-rw-r--r--sw/source/uibase/app/docst.cxx4
3 files changed, 48 insertions, 4 deletions
diff --git a/svx/source/inc/StylesPreviewWindow.hxx b/svx/source/inc/StylesPreviewWindow.hxx
index 99e59037b617..ce4f6eb6d4a8 100644
--- a/svx/source/inc/StylesPreviewWindow.hxx
+++ b/svx/source/inc/StylesPreviewWindow.hxx
@@ -40,6 +40,19 @@ public:
void StateChanged(SfxItemState eState, const SfxPoolItem* pState) override;
};
+
+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;
@@ -75,6 +88,7 @@ protected:
std::unique_ptr<weld::IconView> m_xStylesView;
StyleStatusListener* m_pStatusListener;
+ std::unique_ptr<StylePoolChangeListener> m_pStylePoolChangeListener;
css::uno::Reference<css::lang::XComponent> m_xStatusListener;
std::vector<std::pair<OUString, OUString>> m_aDefaultStyles;
@@ -93,10 +107,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 5413056e2177..0520f5c99a24 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)
@@ -349,6 +375,9 @@ StylesPreviewWindow_Base::StylesPreviewWindow_Base(
m_pStatusListener = new StyleStatusListener(this, xDispatchProvider);
m_xStatusListener.set(static_cast<cppu::OWeakObject*>(m_pStatusListener), css::uno::UNO_QUERY);
+ m_pStylePoolChangeListener.reset(new StylePoolChangeListener(this));
+
+ UpdateStylesList();
Update();
}
@@ -404,14 +433,11 @@ void StylesPreviewWindow_Base::Select(const OUString& rStyleName)
{
m_sSelectedStyle = rStyleName;
- UpdateStylesList();
Update();
}
void StylesPreviewWindow_Base::Update()
{
- UpdateStylesList();
-
for (unsigned long 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 b2656c925620..2e25b89ea9e6 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -1314,6 +1314,8 @@ void SwDocShell::UpdateStyle(const OUString &rName, SfxStyleFamily nFamily, SwWr
break;
default: break;
}
+
+ m_xDoc->BroadcastStyleOperation(rName, nFamily, SfxHintId::StyleSheetModified);
}
// NewByExample
@@ -1507,6 +1509,8 @@ void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily,
default: break;
}
+
+ m_xDoc->BroadcastStyleOperation(rName, nFamily, SfxHintId::StyleSheetCreated);
}
std::set<Color> SwDocShell::GetDocColors()