chart2/source/controller/inc/CommandDispatchContainer.hxx   |    2 
 chart2/source/controller/inc/ControllerCommandDispatch.hxx  |    1 
 chart2/source/controller/main/ChartController.cxx           |   65 ------------
 chart2/source/controller/main/CommandDispatchContainer.cxx  |    8 -
 chart2/source/controller/main/ControllerCommandDispatch.cxx |    5 
 5 files changed, 14 insertions(+), 67 deletions(-)

New commits:
commit 40df99b1111b492f81157b101e084f5c2028c8e2
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Jul 6 20:51:12 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Jul 6 20:00:36 2025 +0200

    Avoid duplicating command lists
    
    ChartController::impl_getAvailableCommands had almost the same list as
    what was stored in ControllerCommandDispatch::m_aCommandAvailability.
    That required to keep these lists in sync, prone to overlooks.
    
    This change makes ChartController::impl_getAvailableCommands only hold
    those commands that should not appear in ControllerCommandDispatch. At
    the moment, those are only forwarded commands and ChartElementSelector,
    that may need to be handled in ControllerCommandDispatch. LOK-specific
    commands may be added here later.
    
    Change-Id: I82bbfbd6a69bbaaebcc91d8f29b6c22ddf2f8ae6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187448
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/chart2/source/controller/inc/CommandDispatchContainer.hxx 
b/chart2/source/controller/inc/CommandDispatchContainer.hxx
index 22cff84fe7fe..e9f8ed072073 100644
--- a/chart2/source/controller/inc/CommandDispatchContainer.hxx
+++ b/chart2/source/controller/inc/CommandDispatchContainer.hxx
@@ -127,7 +127,7 @@ private:
     unotools::WeakReference< ::chart::ChartModel >         m_xModel;
 
     rtl::Reference<ControllerCommandDispatch> m_xChartDispatcher;
-    o3tl::sorted_vector< std::u16string_view >            m_aChartCommands;
+    o3tl::sorted_vector<std::u16string_view> m_aAdditionalChartCommands;
 
     DrawCommandDispatch* m_pDrawCommandDispatch;
     ShapeController* m_pShapeController;
diff --git a/chart2/source/controller/inc/ControllerCommandDispatch.hxx 
b/chart2/source/controller/inc/ControllerCommandDispatch.hxx
index 0a6444d867c9..f4ca42525ea8 100644
--- a/chart2/source/controller/inc/ControllerCommandDispatch.hxx
+++ b/chart2/source/controller/inc/ControllerCommandDispatch.hxx
@@ -65,6 +65,7 @@ public:
     virtual void initialize() override;
 
     bool commandAvailable(const OUString& rCommand) const;
+    bool commandHandled(const OUString& rCommand) const;
 
 protected:
     // ____ XDispatch ____
diff --git a/chart2/source/controller/main/ChartController.cxx 
b/chart2/source/controller/main/ChartController.cxx
index def6c2736caa..bdee1f41486b 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -544,8 +544,8 @@ sal_Bool SAL_CALL ChartController::attachModel( const 
uno::Reference< frame::XMo
     pDispatch->initialize();
 
     // the dispatch container will return "this" for all commands returned by
-    // impl_getAvailableCommands().  That means, for those commands dispatch()
-    // is called here at the ChartController.
+    // impl_getAvailableCommands(), and also for which 
ControllerCommandDispatch::commandHandled()
+    // gives true. That means, for those commands dispatch() is called here at 
the ChartController.
     m_aDispatchContainer.setChartDispatch( pDispatch, 
impl_getAvailableCommands() );
 
     rtl::Reference<DrawCommandDispatch> pDrawDispatch = new 
DrawCommandDispatch( m_xCC, this );
@@ -1679,69 +1679,8 @@ const o3tl::sorted_vector< std::u16string_view >& 
ChartController::impl_getAvail
         u"Save",                u"SaveAs",                u"SendMail",
         u"EditDoc",             u"ExportDirectToPDF",     u"PrintDefault",
 
-        // own commands
-        u"Cut",                u"Copy",                 u"Paste",
-        u"DataRanges",         u"DiagramData",
-        // insert objects
-        u"InsertMenuTitles",   u"InsertTitles",
-        u"InsertMenuLegend",   u"InsertLegend",         u"DeleteLegend",
-        u"InsertMenuDataLabels",
-        u"InsertMenuAxes",     u"InsertRemoveAxes",         u"InsertMenuGrids",
-        u"InsertSymbol",
-        u"InsertTrendlineEquation",  u"InsertTrendlineEquationAndR2",
-        u"InsertR2Value",      u"DeleteR2Value",
-        u"InsertMenuTrendlines",  u"InsertTrendline",
-        u"InsertMenuMeanValues", u"InsertMeanValue",
-        u"InsertMenuXErrorBars",  u"InsertXErrorBars",
-        u"InsertMenuYErrorBars",   u"InsertYErrorBars",
-        u"InsertDataLabels",   u"InsertDataLabel",
-        u"DeleteTrendline",    u"DeleteMeanValue",      
u"DeleteTrendlineEquation",
-        u"DeleteXErrorBars",   u"DeleteYErrorBars",
-        u"DeleteDataLabels",   u"DeleteDataLabel",
-        u"InsertMenuDataTable",
-        u"InsertDataTable", u"DeleteDataTable",
-        //format objects
-        u"FormatSelection",    u"FontDialog",           u"TransformDialog",
-        u"DiagramType",        u"View3D",
-        u"Forward",            u"Backward",
-        u"MainTitle",          u"SubTitle",
-        u"XTitle",             u"YTitle",               u"ZTitle",
-        u"SecondaryXTitle",    u"SecondaryYTitle",
-        u"AllTitles",          u"Legend",
-        u"DiagramAxisX",       u"DiagramAxisY",         u"DiagramAxisZ",
-        u"DiagramAxisA",       u"DiagramAxisB",         u"DiagramAxisAll",
-        u"DiagramGridXMain",   u"DiagramGridYMain",     u"DiagramGridZMain",
-        u"DiagramGridXHelp",   u"DiagramGridYHelp",     u"DiagramGridZHelp",
-        u"DiagramGridAll",
-        u"DiagramWall",        u"DiagramFloor",         u"DiagramArea",
-
-        //context menu - format objects entries
-        u"FormatWall",        u"FormatFloor",         u"FormatChartArea",
-        u"FormatLegend",
-
-        u"FormatAxis",           u"FormatTitle",
-        u"FormatDataSeries",     u"FormatDataPoint",
-        u"ResetAllDataPoints",   u"ResetDataPoint",
-        u"FormatDataLabels",     u"FormatDataLabel",
-        u"FormatMeanValue",      u"FormatTrendline",      
u"FormatTrendlineEquation",
-        u"FormatXErrorBars",     u"FormatYErrorBars",
-        u"FormatStockLoss",      u"FormatStockGain",
-
-        u"FormatMajorGrid",      u"InsertMajorGrid",      u"DeleteMajorGrid",
-        u"FormatMinorGrid",      u"InsertMinorGrid",      u"DeleteMinorGrid",
-        u"InsertAxis",           u"DeleteAxis",           u"InsertAxisTitle",
-
         // toolbar commands
-        u"ToggleGridHorizontal", u"ToggleGridVertical", u"ToggleLegend",       
  u"ScaleText",
-        u"NewArrangement",     u"Update",
-        u"DefaultColors",      u"BarWidth",             u"NumberOfLines",
-        u"ArrangeRow",
         u"ChartElementSelector",
-
-        // sidebar commands
-        u"CharFontName" , u"FontHeight" , u"Italic", u"Underline",
-        u"Bold", u"Strikeout",u"Shadowed", u"Color", u"FontColor", 
u"ResetAttributes",
-        u"Grow", u"Shrink", u"Spacing", u"SuperScript", u"SubScript"
     };
     return s_AvailableCommands;
 }
diff --git a/chart2/source/controller/main/CommandDispatchContainer.cxx 
b/chart2/source/controller/main/CommandDispatchContainer.cxx
index f3b547eebd30..1dc98f1f88b6 100644
--- a/chart2/source/controller/main/CommandDispatchContainer.cxx
+++ b/chart2/source/controller/main/CommandDispatchContainer.cxx
@@ -67,7 +67,7 @@ void CommandDispatchContainer::setChartDispatch(
 {
     OSL_ENSURE(rChartDispatch.is(),"Invalid fall back dispatcher!");
     m_xChartDispatcher = rChartDispatch;
-    m_aChartCommands = rChartCommands;
+    m_aAdditionalChartCommands = rChartCommands;
     m_aToBeDisposedDispatches.push_back( m_xChartDispatcher );
 }
 
@@ -119,7 +119,9 @@ Reference< frame::XDispatch > 
CommandDispatchContainer::getDispatchForURL(
         }
     }
 
-    if (m_xChartDispatcher.is() && m_aChartCommands.count(rURL.Path) > 0)
+    if (m_xChartDispatcher.is()
+        && (m_xChartDispatcher->commandHandled(rURL.Complete)
+            || m_aAdditionalChartCommands.count(rURL.Path) > 0))
         return cacheIt(m_xChartDispatcher);
 
     // #i12587# support for shapes in chart
@@ -156,7 +158,7 @@ void CommandDispatchContainer::DisposeAndClear()
     DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
     m_aToBeDisposedDispatches.clear();
     m_xChartDispatcher.clear();
-    m_aChartCommands.clear();
+    m_aAdditionalChartCommands.clear();
     m_pDrawCommandDispatch = nullptr;
     m_pShapeController = nullptr;
 }
diff --git a/chart2/source/controller/main/ControllerCommandDispatch.cxx 
b/chart2/source/controller/main/ControllerCommandDispatch.cxx
index 2c0dc35d4ad9..517fb3c6d4ad 100644
--- a/chart2/source/controller/main/ControllerCommandDispatch.cxx
+++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx
@@ -881,6 +881,11 @@ bool ControllerCommandDispatch::commandAvailable(const 
OUString& rCommand) const
     return false;
 }
 
+bool ControllerCommandDispatch::commandHandled(const OUString& rCommand) const
+{
+    return m_aCommandAvailability.contains(rCommand);
+}
+
 bool ControllerCommandDispatch::isShapeControllerCommandAvailable( const 
OUString& rCommand )
 {
     ShapeController* pShapeController(nullptr);

Reply via email to