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 | 46 +++++++++++--------------- sc/source/ui/view/cellsh3.cxx | 13 ++++++- 14 files changed, 109 insertions(+), 50 deletions(-)
New commits: commit bdd06e255cf89cbc1ee100306d27739dbb5290a4 Author: Pranam Lashkari <[email protected]> AuthorDate: Wed Jun 26 09:16:43 2024 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Thu Aug 15 18:40:21 2024 +0200 tdf#162475 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 <[email protected]> Reviewed-by: Szymon Kłos <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170915 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 8cf3091a9b7b..f550dc60d8f6 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -229,6 +229,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 = "") @@ -238,6 +240,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 7ff8b9ca5471..efd9c27c2ba0 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 017e26028376..6e39cda9a7c3 100644 --- a/sc/sdi/cellsh.sdi +++ b/sc/sdi/cellsh.sdi @@ -221,7 +221,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 e06be41b3419..dc6441a3e29b 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -1190,6 +1190,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 80abea22829e..34aae130fd0e 100644 --- a/sc/source/ui/attrdlg/scdlgfact.cxx +++ b/sc/source/ui/attrdlg/scdlgfact.cxx @@ -739,9 +739,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 3c57277a54d2..588fd758fcf0 100644 --- a/sc/source/ui/attrdlg/scdlgfact.hxx +++ b/sc/source/ui/attrdlg/scdlgfact.hxx @@ -116,7 +116,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 9379bc323b18..5b131d8e2361 100644 --- a/sc/source/ui/condformat/condformateasydlg.cxx +++ b/sc/source/ui/condformat/condformateasydlg.cxx @@ -91,6 +91,8 @@ ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings, meMode = *CurrentData.Mode; mbIsManaged = CurrentData.IsManaged; msFormula = CurrentData.Formula; + mnFormatKey = CurrentData.FormatKey; + mnEntryIndex = CurrentData.EntryIndex; } mxNumberEntry2->hide(); switch (meMode) @@ -247,12 +249,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()); @@ -310,6 +321,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 ff7f9889afaf..33ccc466d2ff 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() @@ -148,6 +163,7 @@ ScCondFormatManagerDlg::ScCondFormatManagerDlg(weld::Window* pParent, ScDocument m_xDialog->set_window_state(aDlgOpt.GetWindowState()); UpdateButtonSensitivity(); + this->EntryFocus(*m_xTreeView); } ScCondFormatManagerDlg::~ScCondFormatManagerDlg() @@ -176,13 +192,15 @@ ScConditionalFormat* ScCondFormatManagerDlg::GetCondFormatSelected() return m_xCtrlManager->GetSelection(); } -void ScCondFormatManagerDlg::ShowEasyConditionalDialog() +void ScCondFormatManagerDlg::ShowEasyConditionalDialog(bool isEdit) { if (!SfxViewShell::Current()) return; 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 @@ -191,16 +209,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 @@ -208,7 +226,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 2848bac154fa..1e4b9f1bdc33 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2932,33 +2932,29 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) if (rDlgItem) pDlg->SetModified(); - pDlg->StartExecuteAsync([this, pDlg, &rData, pTabViewShell, rDlgItem, aPos](sal_Int32 nRet){ - std::unique_ptr<ScConditionalFormatList> pCondFormatList = pDlg->GetConditionalFormatList(); - if(nRet == RET_OK && pDlg->CondFormatsChanged()) - { - rData.GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList.release(), aPos.Tab()); - } - else if(nRet == DLG_RET_ADD) - { - pDlg->ShowEasyConditionalDialog(); - } - else if (nRet == DLG_RET_EDIT) + pDlg->StartExecuteAsync( + [pDlg, &rData, aPos](sal_Int32 nRet) { - 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->setScCondFormatDlgItem(std::make_shared<ScCondFormatDlgData>( - std::shared_ptr<ScConditionalFormatList>(pCondFormatList.release()), nIndex, true)); - - // Queue message to open Conditional Format Dialog - GetViewData().GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON ); - } - else - pCondFormatList.reset(); + std::unique_ptr<ScConditionalFormatList> pCondFormatList + = pDlg->GetConditionalFormatList(); + if (nRet == RET_OK && pDlg->CondFormatsChanged()) + { + rData.GetDocShell()->GetDocFunc().SetConditionalFormatList( + pCondFormatList.release(), aPos.Tab()); + } + else if (nRet == DLG_RET_ADD) + { + pDlg->ShowEasyConditionalDialog(); + } + else if (nRet == DLG_RET_EDIT) + { + pDlg->ShowEasyConditionalDialog(true); + } + else + pCondFormatList.reset(); - pDlg->disposeOnce(); - }); + pDlg->disposeOnce(); + }); } break; diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx index ffced295b5be..c4dbfe89833d 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 ); }
