officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu |   16 ++
 sc/inc/document.hxx                                               |    2 
 sc/inc/sc.hrc                                                     |    3 
 sc/sdi/cellsh.sdi                                                 |    1 
 sc/sdi/scalc.sdi                                                  |   17 ++
 sc/source/core/data/document.cxx                                  |   28 ++++
 sc/source/ui/dialogs/SparklineDialog.cxx                          |   61 
+++++++---
 sc/source/ui/inc/SparklineDialog.hxx                              |   12 +
 sc/source/ui/view/cellsh.cxx                                      |   35 -----
 sc/source/ui/view/cellsh1.cxx                                     |    2 
 sc/uiconfig/scalc/popupmenu/cell.xml                              |    9 +
 11 files changed, 128 insertions(+), 58 deletions(-)

New commits:
commit b8358588ccc1660b38f982e005ae676ff90baac2
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Mar 22 23:24:05 2022 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Mar 22 23:24:05 2022 +0900

    sc: add "Edit Sparkline Group" context menu action
    
    This adds a context menu to edit the sparkline group for the
    current selected range (if it contains a sparkline group). This
    reuses the SparklineDialog that is used for inserting a new
    sparkline.
    
    The context menu was rearranged so that all actions for the
    sparklines are in a "Sparklines" submenu.
    
    Change-Id: Ia1a025b7c0bf1849c72fdca77ea2f8dc8860c6ab

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index eb32102d8e9c..ab35761c4deb 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -1074,6 +1074,14 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:FormatSparklineMenu" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Sparklines</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:InsertSparkline" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">Insert Sparkline...</value>
@@ -1090,6 +1098,14 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:EditSparklineGroup" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Edit Sparkline Group...</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:EditHeaderAndFooter" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">~Headers and Footers...</value>
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index da7c89eabdd4..f45c5f41be14 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1248,7 +1248,7 @@ public:
     SC_DLLPUBLIC sc::Sparkline* CreateSparkline(ScAddress const & rPosition, 
std::shared_ptr<sc::SparklineGroup> & pSparklineGroup);
     SC_DLLPUBLIC sc::SparklineList* GetSparklineList(SCTAB nTab);
     SC_DLLPUBLIC bool DeleteSparkline(ScAddress const& rPosition);
-
+    SC_DLLPUBLIC bool HasOneSparklineGroup(ScRange const& rRange);
     /** Notes **/
     SC_DLLPUBLIC ScPostIt*       GetNote(const ScAddress& rPos);
     SC_DLLPUBLIC ScPostIt*       GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab);
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index a0acd3f9c94a..8555e34ae0b3 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -310,7 +310,8 @@ class SvxZoomSliderItem;
 #define FID_DEFINE_CURRENT_NAME (INSERT_MENU_START + 24)
 #define SID_INSERT_SPARKLINE    (INSERT_MENU_START + 25)
 #define SID_DELETE_SPARKLINE    (INSERT_MENU_START + 26)
-#define INSERT_MENU_END         (INSERT_MENU_START + 27)
+#define SID_EDIT_SPARKLINE_GROUP    (INSERT_MENU_START + 27)
+#define INSERT_MENU_END         (INSERT_MENU_START + 28)
 
 #define FORMAT_MENU_START       (INSERT_MENU_END)
 #define FID_CELL_FORMAT         (FORMAT_MENU_START)
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 5ad7926b24c6..c330aeed2fd8 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -237,6 +237,7 @@ interface CellSelection
     SID_CURRENT_FORMULA_RANGE           [ ExecMethod = ExecuteEdit;]
     SID_INSERT_SPARKLINE                [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
     SID_DELETE_SPARKLINE                [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
+    SID_EDIT_SPARKLINE_GROUP            [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
 
     SID_THESAURUS   [ ExecMethod = ExecuteEdit; StateMethod = GetCellState; ]
     SID_SPELL_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index c95aa01a7e2c..a83578ea9693 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -2321,6 +2321,23 @@ SfxVoidItem DeleteSparkline SID_DELETE_SPARKLINE
     GroupId = SfxGroupId::Edit;
 ]
 
+SfxVoidItem EditSparklineGroup SID_EDIT_SPARKLINE_GROUP
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Edit;
+]
+
 SfxVoidItem SearchResultsDialog SID_SEARCH_RESULTS_DIALOG
 (SfxBoolItem Visible SID_SEARCH_RESULTS_DIALOG)
 [
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 92cd1c46f882..01bf9bcffa5b 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6555,6 +6555,34 @@ sc::SparklineList* ScDocument::GetSparklineList(SCTAB 
nTab)
     return nullptr;
 }
 
+
+bool ScDocument::HasOneSparklineGroup(ScRange const& rRange)
+{
+    sc::SparklineGroup* pGroup = nullptr;
+    SCTAB nTab = rRange.aStart.Tab();
+
+    for (SCCOL nX = rRange.aStart.Col(); nX <= rRange.aEnd.Col(); nX++)
+    {
+        for (SCROW nY = rRange.aStart.Row(); nY <= rRange.aEnd.Row(); nY++)
+        {
+            auto pSparkline = GetSparkline(ScAddress(nX, nY, nTab));
+            if (!pSparkline)
+            {
+                return false;
+            }
+            else if (!pGroup)
+            {
+               pGroup = pSparkline->getSparklineGroup().get();
+            }
+            else if (pGroup != pSparkline->getSparklineGroup().get())
+            {
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
 // Notes
 
 ScPostIt* ScDocument::GetNote(const ScAddress& rPos)
diff --git a/sc/source/ui/dialogs/SparklineDialog.cxx 
b/sc/source/ui/dialogs/SparklineDialog.cxx
index b285108bca6d..ba01a64912c6 100644
--- a/sc/source/ui/dialogs/SparklineDialog.cxx
+++ b/sc/source/ui/dialogs/SparklineDialog.cxx
@@ -29,7 +29,8 @@ SparklineDialog::SparklineDialog(SfxBindings* pBindings, 
SfxChildWindow* pChildW
     , mbDialogLostFocus(false)
     , mxButtonOk(m_xBuilder->weld_button("ok"))
     , mxButtonCancel(m_xBuilder->weld_button("cancel"))
-    , mxInputRangeText(m_xBuilder->weld_label("cell-range-label"))
+    , mxFrameData(m_xBuilder->weld_frame("frame-data"))
+    , mxInputRangeLabel(m_xBuilder->weld_label("cell-range-label"))
     , mxInputRangeEdit(new 
formula::RefEdit(m_xBuilder->weld_entry("cell-range-edit")))
     , mxInputRangeButton(new 
formula::RefButton(m_xBuilder->weld_button("cell-range-button")))
     , mxOutputRangeLabel(m_xBuilder->weld_label("output-range-label"))
@@ -58,9 +59,9 @@ SparklineDialog::SparklineDialog(SfxBindings* pBindings, 
SfxChildWindow* pChildW
     , mxRadioLine(m_xBuilder->weld_radio_button("line-radiobutton"))
     , mxRadioColumn(m_xBuilder->weld_radio_button("column-radiobutton"))
     , mxRadioStacked(m_xBuilder->weld_radio_button("stacked-radiobutton"))
-    , mpLocalSparklineGroup(new sc::SparklineGroup())
+    , mbEditMode(false)
 {
-    mxInputRangeEdit->SetReferences(this, mxInputRangeText.get());
+    mxInputRangeEdit->SetReferences(this, mxInputRangeLabel.get());
     mxInputRangeButton->SetReferences(this, mxInputRangeEdit.get());
 
     mxOutputRangeEdit->SetReferences(this, mxOutputRangeLabel.get());
@@ -102,18 +103,49 @@ SparklineDialog::SparklineDialog(SfxBindings* pBindings, 
SfxChildWindow* pChildW
     mxCheckButtonFirst->connect_toggled(aLink);
     mxCheckButtonLast->connect_toggled(aLink);
 
-    setupValues(mpLocalSparklineGroup);
-
-    GetRangeFromSelection();
+    setupValues();
 
     mxOutputRangeEdit->GrabFocus();
+    mxButtonOk->set_sensitive(checkValidInputOutput());
 }
 
-SparklineDialog::~SparklineDialog() {}
+SparklineDialog::~SparklineDialog() = default;
+
+void SparklineDialog::setInputSelection()
+{
+    mrViewData.GetSimpleArea(maInputRange);
+    OUString aString = maInputRange.Format(mrDocument, ScRefFlags::VALID | 
ScRefFlags::TAB_3D,
+                                           mrDocument.GetAddressConvention());
+    mxInputRangeEdit->SetRefString(aString);
+}
 
-void SparklineDialog::setupValues(std::shared_ptr<sc::SparklineGroup> const& 
pSparklineGroup)
+void SparklineDialog::setupValues()
 {
-    auto& rAttribute = pSparklineGroup->getAttributes();
+    ScRange aSelectionRange;
+    mrViewData.GetSimpleArea(aSelectionRange);
+
+    if (mrDocument.HasOneSparklineGroup(aSelectionRange))
+    {
+        if (auto pSparkline = mrDocument.GetSparkline(aSelectionRange.aStart))
+        {
+            mpLocalSparklineGroup = pSparkline->getSparklineGroup();
+            mxFrameData->set_visible(false);
+            mbEditMode = true;
+        }
+    }
+    else
+    {
+        maInputRange = aSelectionRange;
+    }
+
+    if (!mpLocalSparklineGroup)
+    {
+        mpLocalSparklineGroup = std::make_shared<sc::SparklineGroup>();
+    }
+
+    setInputSelection();
+
+    auto& rAttribute = mpLocalSparklineGroup->getAttributes();
 
     switch (rAttribute.getType())
     {
@@ -161,14 +193,6 @@ void SparklineDialog::SetActive()
     RefInputDone();
 }
 
-void SparklineDialog::GetRangeFromSelection()
-{
-    mrViewData.GetSimpleArea(maInputRange);
-    OUString aString = maInputRange.Format(mrDocument, ScRefFlags::VALID | 
ScRefFlags::TAB_3D,
-                                           mrDocument.GetAddressConvention());
-    mxInputRangeEdit->SetRefString(aString);
-}
-
 void SparklineDialog::SetReference(const ScRange& rReferenceRange, ScDocument& 
rDocument)
 {
     if (mpActiveEdit)
@@ -321,6 +345,9 @@ IMPL_LINK_NOARG(SparklineDialog, SelectSparklineType, 
weld::Toggleable&, void)
 
 bool SparklineDialog::checkValidInputOutput()
 {
+    if (mbEditMode)
+        return true;
+
     if (!maInputRange.IsValid() || !maOutputRange.IsValid())
         return false;
 
diff --git a/sc/source/ui/inc/SparklineDialog.hxx 
b/sc/source/ui/inc/SparklineDialog.hxx
index 1fe2616a4c59..25957d714033 100644
--- a/sc/source/ui/inc/SparklineDialog.hxx
+++ b/sc/source/ui/inc/SparklineDialog.hxx
@@ -32,7 +32,9 @@ private:
     std::unique_ptr<weld::Button> mxButtonOk;
     std::unique_ptr<weld::Button> mxButtonCancel;
 
-    std::unique_ptr<weld::Label> mxInputRangeText;
+    std::unique_ptr<weld::Frame> mxFrameData;
+
+    std::unique_ptr<weld::Label> mxInputRangeLabel;
     std::unique_ptr<formula::RefEdit> mxInputRangeEdit;
     std::unique_ptr<formula::RefButton> mxInputRangeButton;
 
@@ -59,8 +61,6 @@ private:
     std::unique_ptr<weld::RadioButton> mxRadioColumn;
     std::unique_ptr<weld::RadioButton> mxRadioStacked;
 
-    void GetRangeFromSelection();
-
     DECL_LINK(ButtonClicked, weld::Button&, void);
     DECL_LINK(EditFocusHandler, formula::RefEdit&, void);
     DECL_LINK(ButtonFocusHandler, formula::RefButton&, void);
@@ -72,7 +72,11 @@ private:
 
     std::shared_ptr<sc::SparklineGroup> mpLocalSparklineGroup;
 
-    void setupValues(std::shared_ptr<sc::SparklineGroup> const& 
pSparklineGroup);
+    bool mbEditMode;
+
+    void setupValues();
+    void setInputSelection();
+
     void perform();
     bool checkValidInputOutput();
 
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index f1df448a1288..de2a40da3daf 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -98,38 +98,6 @@ ScCellShell::~ScCellShell()
     delete pImpl->m_pRequest;
 }
 
-namespace
-{
-
-bool canShowDeleteSparkline(ScDocument& rDocument, ScRange const& rRange)
-{
-    sc::SparklineGroup* pGroup = nullptr;
-    SCTAB nTab = rRange.aStart.Tab();
-
-    for (SCCOL nX = rRange.aStart.Col(); nX <= rRange.aEnd.Col(); nX++)
-    {
-        for (SCROW nY = rRange.aStart.Row(); nY <= rRange.aEnd.Row(); nY++)
-        {
-            auto pSparkline = rDocument.GetSparkline(ScAddress(nX, nY, nTab));
-            if (!pSparkline)
-            {
-                return false;
-            }
-            else if (!pGroup)
-            {
-               pGroup = pSparkline->getSparklineGroup().get();
-            }
-            else if (pGroup != pSparkline->getSparklineGroup().get())
-            {
-                return false;
-            }
-        }
-    }
-    return true;
-}
-
-} // end anonymous namespace
-
 void ScCellShell::GetBlockState( SfxItemSet& rSet )
 {
     ScTabViewShell* pTabViewShell   = GetViewData().GetViewShell();
@@ -221,8 +189,9 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet )
             break;
 
             case SID_DELETE_SPARKLINE:
+            case SID_EDIT_SPARKLINE_GROUP:
             {
-                bDisable = !canShowDeleteSparkline(rDoc, ScRange(nCol1, nRow1, 
nTab, nCol2, nRow2, nTab));
+                bDisable = !rDoc.HasOneSparklineGroup(ScRange(nCol1, nRow1, 
nTab, nCol2, nRow2, nTab));
             }
             break;
 
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 04757e04e1b1..86e028b5396c 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -1052,11 +1052,13 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
         break;
 
         case SID_INSERT_SPARKLINE:
+        case SID_EDIT_SPARKLINE_GROUP:
         {
             sal_uInt16 nId  = sc::SparklineDialogWrapper::GetChildWindowId();
             SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
             SfxChildWindow* pWindow = pViewFrame->GetChildWindow(nId);
             pScMod->SetRefDialog(nId, pWindow == nullptr);
+            rReq.Done();
         }
         break;
 
diff --git a/sc/uiconfig/scalc/popupmenu/cell.xml 
b/sc/uiconfig/scalc/popupmenu/cell.xml
index 719de09ae8bc..55e33f7e09b2 100644
--- a/sc/uiconfig/scalc/popupmenu/cell.xml
+++ b/sc/uiconfig/scalc/popupmenu/cell.xml
@@ -63,8 +63,13 @@
   <menu:menuitem menu:id=".uno:ShowNote"/>
   <menu:menuitem menu:id=".uno:HideNote"/>
   <menu:menuseparator/>
-  <menu:menuitem menu:id=".uno:InsertSparkline"/>
-  <menu:menuitem menu:id=".uno:DeleteSparkline"/>
+  <menu:menu menu:id=".uno:FormatSparklineMenu">
+    <menu:menupopup>
+      <menu:menuitem menu:id=".uno:InsertSparkline"/>
+      <menu:menuitem menu:id=".uno:DeleteSparkline"/>
+      <menu:menuitem menu:id=".uno:EditSparklineGroup"/>
+    </menu:menupopup>
+  </menu:menu>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:CurrentConditionalFormatDialog"/>
   <menu:menuitem menu:id=".uno:CurrentConditionalFormatManagerDialog"/>

Reply via email to