sc/inc/document.hxx                           |   12 ++++++++
 sc/inc/scabstdlg.hxx                          |    2 -
 sc/qa/uitest/conditional_format/tdf100793.py  |    9 +++---
 sc/qa/uitest/conditional_format/tdf96453.py   |    1 
 sc/sdi/cellsh.sdi                             |    4 ++
 sc/source/core/data/documen2.cxx              |    2 +
 sc/source/ui/attrdlg/scdlgfact.cxx            |    4 +-
 sc/source/ui/attrdlg/scdlgfact.hxx            |    2 -
 sc/source/ui/condformat/condformateasydlg.cxx |   18 +++++++++++-
 sc/source/ui/condformat/condformatmgr.cxx     |   38 +++++++++++++++++++-------
 sc/source/ui/inc/condformateasydlg.hxx        |    2 +
 sc/source/ui/inc/condformatmgr.hxx            |    6 ++--
 sc/source/ui/view/cellsh1.cxx                 |   12 +-------
 sc/source/ui/view/cellsh3.cxx                 |   13 +++++++-
 14 files changed, 90 insertions(+), 35 deletions(-)

New commits:
commit 8115c82f1f7f2621e2d99c93e1a3b2196279602a
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Wed Jun 26 09:16:43 2024 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Fri Jul 19 18:51:14 2024 +0200

    sc: now conditions can be edited from easy conditional format dialog
    
    now when a conditional format entry is edited,
    instead of editing entry in the same format,
    we delete entry from the origianal format and create
    a new format with modified entry alone.
    
    This way it easier to manage formats, and it also aligns
    with implementation of how format manager adds new
    format condition(it adds new format for each condition instead
    of adding new entry to existing format)
    
    Change-Id: Iaa92292ca67eaf90374d2af44d2402f9ebe29787
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169537
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index a4e096f03881..a7f1c8322991 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -216,6 +216,8 @@ struct ScConditionEasyDialogData
 {
     ScConditionMode* Mode = nullptr;
     bool IsManaged : 1 = false;
+    sal_Int32 FormatKey = -1;
+    sal_Int32 EntryIndex = -1;
     OUString Formula;
 
     ScConditionEasyDialogData(ScConditionMode* mode, bool isManaged, const 
OUString& formula = "")
@@ -225,6 +227,16 @@ struct ScConditionEasyDialogData
     {
     }
 
+    ScConditionEasyDialogData(ScConditionMode* mode, bool isManaged, sal_Int32 
formatKey,
+                              sal_Int32 entryIndex, const OUString& formula = 
"")
+        : Mode(mode)
+        , IsManaged(isManaged)
+        , FormatKey(formatKey)
+        , EntryIndex(entryIndex)
+        , Formula(formula)
+    {
+    }
+
     ScConditionEasyDialogData() {}
 };
 
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index 6ea7a913c88c..93541ca1dcea 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -93,7 +93,7 @@ public:
     virtual std::unique_ptr<ScConditionalFormatList> 
GetConditionalFormatList() = 0;
 
     virtual bool CondFormatsChanged() const = 0;
-    virtual void ShowEasyConditionalDialog() = 0;
+    virtual void ShowEasyConditionalDialog(bool isEdit = false) = 0;
 
     virtual void SetModified() = 0;
 
diff --git a/sc/qa/uitest/conditional_format/tdf100793.py 
b/sc/qa/uitest/conditional_format/tdf100793.py
index f0d2c3854db7..b7d253ea2ba4 100644
--- a/sc/qa/uitest/conditional_format/tdf100793.py
+++ b/sc/qa/uitest/conditional_format/tdf100793.py
@@ -5,7 +5,6 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
 
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
@@ -39,7 +38,7 @@ class tdf100793(UITestCase):
                 with self.ui_test.execute_dialog_through_action(xEditBtn, 
"CLICK", event_name = "ModelessDialogVisible") as xCondFormatDlg:
 
                     #modify textbox
-                    xedassign = xCondFormatDlg.getChild("edassign")
+                    xedassign = xCondFormatDlg.getChild("entryRange")
                     #go at the beginning
                     xedassign.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "END"}))
                     xedassign.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "HOME"}))
@@ -67,7 +66,7 @@ class tdf100793(UITestCase):
                 list_state = get_state_as_dict(xList)
                 self.assertEqual(list_state['Children'], '3')
 
-                self.assertEqual(conditional_format_list.getLength(), 1)
+                self.assertEqual(conditional_format_list.getLength(), 2)
 
                 # close the conditional format manager
                 xOKBtn = xCondFormatMgr.getChild("ok")
@@ -75,9 +74,11 @@ class tdf100793(UITestCase):
 
             #verify - reopen, check range
             with 
self.ui_test.execute_dialog_through_command(".uno:ConditionalFormatManagerDialog",
 close_button="") as xCondFormatMgr:
+                xCondFormatMgr.getChild("CONTAINER").executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "DOWN"}))
+                xCondFormatMgr.getChild("CONTAINER").executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "DOWN"}))
                 xEditBtn = xCondFormatMgr.getChild("edit")
                 with self.ui_test.execute_dialog_through_action(xEditBtn, 
"CLICK", event_name = "ModelessDialogVisible") as xCondFormatDlg:
-                    xedassign = xCondFormatDlg.getChild("edassign")
+                    xedassign = xCondFormatDlg.getChild("entryRange")
                     self.assertEqual(get_state_as_dict(xedassign)["Text"], 
"G18:K29,F18:K33,F20:F29")
 
                 xCondFormatMgr = self.xUITest.getTopFocusWindow()
diff --git a/sc/qa/uitest/conditional_format/tdf96453.py 
b/sc/qa/uitest/conditional_format/tdf96453.py
index 50ba86e51eec..bcb602ad3452 100644
--- a/sc/qa/uitest/conditional_format/tdf96453.py
+++ b/sc/qa/uitest/conditional_format/tdf96453.py
@@ -11,7 +11,6 @@ from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
 from libreoffice.calc.document import get_sheet_from_doc
 from libreoffice.calc.conditional_format import 
get_conditional_format_from_sheet
-import sys
 
 class ConditionalFormatDlgTest(UITestCase):
 
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index d3d7a4dfec3d..8dcd11b63f36 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -220,7 +220,9 @@ interface CellSelection
     (
         SfxInt16Item FormatRule FN_PARAM_1,
         SfxBoolItem  Managed FN_PARAM_2,
-        SfxStringItem Formula FN_PARAM_3
+        SfxInt32Item FormatKey FN_PARAM_3,
+        SfxInt32Item EntryIndex FN_PARAM_4,
+        SfxStringItem Formula FN_PARAM_5
     )
     [
         ExecMethod = Execute;
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 9abcda14e745..ecc503b8cd30 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1175,6 +1175,8 @@ void ScDocument::SetEasyConditionalFormatDialogData(const 
ScConditionEasyDialogD
     pConditionalFormatDialogData.Mode = data.Mode;
     pConditionalFormatDialogData.IsManaged = data.IsManaged;
     pConditionalFormatDialogData.Formula = data.Formula;
+    pConditionalFormatDialogData.FormatKey = data.FormatKey;
+    pConditionalFormatDialogData.EntryIndex = data.EntryIndex;
 }
 
 void ScDocument::SetChangeViewSettings(const ScChangeViewSettings& rNew)
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx 
b/sc/source/ui/attrdlg/scdlgfact.cxx
index bc8422d0fc3e..22f13d19bbf0 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -719,9 +719,9 @@ ScConditionalFormat* 
AbstractScCondFormatManagerDlg_Impl::GetCondFormatSelected(
     return m_xDlg->GetCondFormatSelected();
 }
 
-void AbstractScCondFormatManagerDlg_Impl::ShowEasyConditionalDialog()
+void AbstractScCondFormatManagerDlg_Impl::ShowEasyConditionalDialog(bool 
isEdit)
 {
-    m_xDlg->ShowEasyConditionalDialog();
+    m_xDlg->ShowEasyConditionalDialog(isEdit);
 }
 
 int AbstractScMetricInputDlg_Impl::GetInputValue() const
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx 
b/sc/source/ui/attrdlg/scdlgfact.hxx
index e2b27738f53a..eaa6eefb1378 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -115,7 +115,7 @@ public:
     virtual bool CondFormatsChanged() const override;
     virtual void SetModified() override;
     virtual ScConditionalFormat* GetCondFormatSelected() override;
-    virtual void ShowEasyConditionalDialog() override;
+    virtual void ShowEasyConditionalDialog(bool isEdit = false) override;
 };
 
 class AbstractScDataPilotDatabaseDlg_Impl  :public 
AbstractScDataPilotDatabaseDlg
diff --git a/sc/source/ui/condformat/condformateasydlg.cxx 
b/sc/source/ui/condformat/condformateasydlg.cxx
index 04a49f65e10a..96e8a76c7bf7 100644
--- a/sc/source/ui/condformat/condformateasydlg.cxx
+++ b/sc/source/ui/condformat/condformateasydlg.cxx
@@ -89,6 +89,8 @@ 
ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings,
         meMode = *CurrentData.Mode;
         mbIsManaged = CurrentData.IsManaged;
         msFormula = CurrentData.Formula;
+        mnFormatKey = CurrentData.FormatKey;
+        mnEntryIndex = CurrentData.EntryIndex;
     }
     mxNumberEntry2->hide();
     switch (meMode)
@@ -245,12 +247,21 @@ 
ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings,
 
     ScRangeList aRange;
     mpViewData->GetMarkData().FillRangeListWithMarks(&aRange, false);
-    if (aRange.empty())
+    if (aRange.empty() && mnFormatKey != -1 && mnEntryIndex != -1)
+    {
+        aRange = mpDocument->GetCondFormList(mpViewData->GetTabNo())
+                     ->GetFormat(mnFormatKey)
+                     ->GetRangeList();
+    }
+    else if (aRange.empty())
     {
         ScAddress aPosition(mpViewData->GetCurX(), mpViewData->GetCurY(), 
mpViewData->GetTabNo());
         aRange.push_back(ScRange(aPosition));
     }
     maPosition = aRange.GetTopLeftCorner();
+    // FIX me: Tab is always 0 in some cases
+    // Refer to test tdf100793
+    maPosition.SetTab(mpViewData->GetTabNo());
 
     OUString sRangeString;
     aRange.Format(sRangeString, ScRefFlags::VALID, *mpDocument, 
mpDocument->GetAddressConvention());
@@ -307,6 +318,11 @@ IMPL_LINK(ConditionalFormatEasyDialog, ButtonPressed, 
weld::Button&, rButton, vo
 {
     if (&rButton == mxButtonOk.get())
     {
+        if (mnEntryIndex != -1 && mnFormatKey != -1) // isEdit
+            mpDocument->GetCondFormList(maPosition.Tab())
+                ->GetFormat(mnFormatKey)
+                ->RemoveEntry(mnEntryIndex);
+
         std::unique_ptr<ScConditionalFormat> pFormat(new 
ScConditionalFormat(0, mpDocument));
 
         OUString sExpression1
diff --git a/sc/source/ui/condformat/condformatmgr.cxx 
b/sc/source/ui/condformat/condformatmgr.cxx
index 13a4c49cfc79..495d325d8fc3 100644
--- a/sc/source/ui/condformat/condformatmgr.cxx
+++ b/sc/source/ui/condformat/condformatmgr.cxx
@@ -102,15 +102,30 @@ ScConditionalFormat* 
ScCondFormatManagerWindow::GetSelection()
     return mpFormatList->GetFormat(nKey);
 }
 
-const ScFormatEntry* ScCondFormatManagerWindow::GetSelectedEntry()
+const ScFormatEntry* ScCondFormatManagerWindow::GetSelectedEntry() const
+{
+    sal_Int32 nKey = GetSelectedFormatKey();
+    sal_Int32 nEntryIndex = GetSelectedEntryIndex();
+
+    if (nKey == -1 || nEntryIndex == -1)
+        return nullptr;
+    return mpFormatList->GetFormat(nKey)->GetEntry(nEntryIndex);
+}
+
+sal_Int32 ScCondFormatManagerWindow::GetSelectedFormatKey() const
 {
     OUString id = mrTreeView.get_selected_id();
     if (id.isEmpty())
-        return nullptr;
+        return -1;
+    return getKeyFromId(id);
+}
 
-    sal_Int32 nKey = getKeyFromId(id);
-    sal_Int32 nEntryIndex = getEntryIndexFromId(id);
-    return mpFormatList->GetFormat(nKey)->GetEntry(nEntryIndex);
+sal_Int32 ScCondFormatManagerWindow::GetSelectedEntryIndex() const
+{
+    OUString id = mrTreeView.get_selected_id();
+    if (id.isEmpty())
+        return -1;
+    return getEntryIndexFromId(id);
 }
 
 void ScCondFormatManagerWindow::setColSizes()
@@ -149,6 +164,7 @@ 
ScCondFormatManagerDlg::ScCondFormatManagerDlg(weld::Window* pParent, ScDocument
         m_xDialog->set_window_state(aDlgOpt.GetWindowState());
 
     UpdateButtonSensitivity();
+    this->EntryFocus(*m_xTreeView);
 }
 
 ScCondFormatManagerDlg::~ScCondFormatManagerDlg()
@@ -177,10 +193,12 @@ ScConditionalFormat* 
ScCondFormatManagerDlg::GetCondFormatSelected()
     return m_xCtrlManager->GetSelection();
 }
 
-void ScCondFormatManagerDlg::ShowEasyConditionalDialog()
+void ScCondFormatManagerDlg::ShowEasyConditionalDialog(bool isEdit)
 {
     auto id = m_xConditionalType->get_active();
     SfxBoolItem IsManaged(FN_PARAM_2, true);
+    SfxInt32Item FormatKey(FN_PARAM_3, isEdit ? 
m_xCtrlManager->GetSelectedFormatKey() : -1);
+    SfxInt32Item EntryIndex(FN_PARAM_4, isEdit ? 
m_xCtrlManager->GetSelectedEntryIndex() : -1);
     switch (id)
     {
         case 0: // Cell value
@@ -189,16 +207,16 @@ void ScCondFormatManagerDlg::ShowEasyConditionalDialog()
                                     
m_xConditionalCellValue->get_active_id().toUInt32());
             SfxViewShell::Current()->GetDispatcher()->ExecuteList(
                 SID_EASY_CONDITIONAL_FORMAT_DIALOG, SfxCallMode::ASYNCHRON,
-                { &FormatRule, &IsManaged });
+                { &FormatRule, &IsManaged, &FormatKey, &EntryIndex });
         }
         break;
         case 1: // Formula
         {
             SfxInt16Item FormatRule(FN_PARAM_1, 
static_cast<sal_Int16>(ScConditionMode::Formula));
-            SfxStringItem Formula(FN_PARAM_3, 
m_xConditionalFormula->GetText());
+            SfxStringItem Formula(FN_PARAM_5, 
m_xConditionalFormula->GetText());
             SfxViewShell::Current()->GetDispatcher()->ExecuteList(
                 SID_EASY_CONDITIONAL_FORMAT_DIALOG, SfxCallMode::ASYNCHRON,
-                { &FormatRule, &IsManaged, &Formula });
+                { &FormatRule, &IsManaged, &FormatKey, &EntryIndex, &Formula 
});
         }
         break;
         case 2: // Date
@@ -206,7 +224,7 @@ void ScCondFormatManagerDlg::ShowEasyConditionalDialog()
             SfxInt16Item FormatRule(FN_PARAM_1, 
m_xConditionalDate->get_active_id().toUInt32());
             SfxViewShell::Current()->GetDispatcher()->ExecuteList(
                 SID_EASY_CONDITIONAL_FORMAT_DIALOG, SfxCallMode::ASYNCHRON,
-                { &FormatRule, &IsManaged });
+                { &FormatRule, &IsManaged, &FormatKey, &EntryIndex });
         }
         break;
         default:
diff --git a/sc/source/ui/inc/condformateasydlg.hxx 
b/sc/source/ui/inc/condformateasydlg.hxx
index baa6208dc061..d9eb8b5cd49f 100644
--- a/sc/source/ui/inc/condformateasydlg.hxx
+++ b/sc/source/ui/inc/condformateasydlg.hxx
@@ -45,6 +45,8 @@ private:
     bool mbIsManaged;
     OUString msFormula;
     ScAddress maPosition;
+    sal_Int32 mnFormatKey;
+    sal_Int32 mnEntryIndex;
 
     SvxFontPrevWindow maWdPreview;
     std::unique_ptr<weld::Entry> mxNumberEntry;
diff --git a/sc/source/ui/inc/condformatmgr.hxx 
b/sc/source/ui/inc/condformatmgr.hxx
index 09b6c571e562..564415186ac0 100644
--- a/sc/source/ui/inc/condformatmgr.hxx
+++ b/sc/source/ui/inc/condformatmgr.hxx
@@ -32,7 +32,9 @@ public:
 
     void DeleteSelection();
     ScConditionalFormat* GetSelection();
-    const ScFormatEntry* GetSelectedEntry();
+    const ScFormatEntry* GetSelectedEntry() const;
+    sal_Int32 GetSelectedFormatKey() const;
+    sal_Int32 GetSelectedEntryIndex() const;
 };
 
 class ScCondFormatManagerDlg : public weld::GenericDialogController
@@ -47,7 +49,7 @@ public:
     void SetModified();
 
     ScConditionalFormat* GetCondFormatSelected();
-    void ShowEasyConditionalDialog();
+    void ShowEasyConditionalDialog(bool isEdit = false);
 
 private:
     bool m_bModified;
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 38d1e4682111..7c09aaf404c2 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2918,7 +2918,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 if (pDlgItem)
                     pDlg->SetModified();
 
-                pDlg->StartExecuteAsync([this, pDlg, &rData, pTabViewShell, 
pDlgItem, aPos](sal_Int32 nRet){
+                pDlg->StartExecuteAsync([pDlg, &rData, pTabViewShell, 
pDlgItem, aPos](sal_Int32 nRet){
                     std::unique_ptr<ScConditionalFormatList> pCondFormatList = 
pDlg->GetConditionalFormatList();
                     if(nRet == RET_OK && pDlg->CondFormatsChanged())
                     {
@@ -2930,15 +2930,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                     }
                     else if (nRet == DLG_RET_EDIT)
                     {
-                        ScConditionalFormat* pFormat = 
pDlg->GetCondFormatSelected();
-                        sal_Int32 nIndex = pFormat ? pFormat->GetKey() : -1;
-                        // Put the xml string parameter to initialize the
-                        // Conditional Format Dialog. ( edit selected 
conditional format )
-                        
pTabViewShell->GetPool().DirectPutItemInPool(ScCondFormatDlgItem(
-                                    
std::shared_ptr<ScConditionalFormatList>(pCondFormatList.release()), nIndex, 
true));
-
-                        // Queue message to open Conditional Format Dialog
-                        GetViewData().GetDispatcher().Execute( 
SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
+                        pDlg->ShowEasyConditionalDialog(true);
                     }
                     else
                         pCondFormatList.reset();
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 6df959030245..de6a7167f388 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -470,13 +470,22 @@ void ScCellShell::Execute( SfxRequest& rReq )
 
                         const SfxPoolItem* pFormula;
                         OUString formula;
-                        if (pReqArgs->HasItem(FN_PARAM_3, &pFormula))
+                        if (pReqArgs->HasItem(FN_PARAM_5, &pFormula))
                         {
                             formula = static_cast<const 
SfxStringItem*>(pFormula)->GetValue();
                         }
+                        const SfxPoolItem *pFormatKey, *pEntryIndex;
+                        sal_Int32 nFormatKey = -1, nEntryIndex = -1;
+                        if (pReqArgs->HasItem(FN_PARAM_3, &pFormatKey)
+                            && pReqArgs->HasItem(FN_PARAM_4, &pEntryIndex))
+                        {
+                            nFormatKey = static_cast<const 
SfxInt32Item*>(pFormatKey)->GetValue();
+                            nEntryIndex = static_cast<const 
SfxInt32Item*>(pEntryIndex)->GetValue();
+                        }
 
                         
GetViewData().GetDocument().SetEasyConditionalFormatDialogData(
-                            ScConditionEasyDialogData(&nFormat, bManaged, 
formula));
+                            ScConditionEasyDialogData(&nFormat, bManaged, 
nFormatKey, nEntryIndex,
+                                                      formula));
 
                         pScMod->SetRefDialog( nId, pWindow == nullptr );
                     }

Reply via email to