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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170915
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Pranam Lashkari 2024-06-26 09:16:43 +01:00 committed by Caolán McNamara
parent fcd18913d5
commit bdd06e255c
14 changed files with 109 additions and 50 deletions

View file

@ -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() {}
};

View file

@ -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;

View file

@ -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()

View file

@ -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):

View file

@ -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;

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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;

View file

@ -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;

View file

@ -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())
pDlg->StartExecuteAsync(
[pDlg, &rData, aPos](sal_Int32 nRet)
{
rData.GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList.release(), aPos.Tab());
}
else if(nRet == DLG_RET_ADD)
{
pDlg->ShowEasyConditionalDialog();
}
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->setScCondFormatDlgItem(std::make_shared<ScCondFormatDlgData>(
std::shared_ptr<ScConditionalFormatList>(pCondFormatList.release()), nIndex, true));
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();
// Queue message to open Conditional Format Dialog
GetViewData().GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
}
else
pCondFormatList.reset();
pDlg->disposeOnce();
});
pDlg->disposeOnce();
});
}
break;

View file

@ -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 );
}