diff options
author | Paris Oplopoios <paris.oplopoios@collabora.com> | 2023-09-11 23:20:50 +0300 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2023-10-27 18:15:38 +0200 |
commit | 217f23f6437b1cac10fb4ea09b72fa896d46bd6b (patch) | |
tree | d8a26ca82721327f78c892c7c857bb7e355858d9 /sc/source/ui/condformat | |
parent | 334d3aff8d411ee5f2d612c8899a171716b8a3d1 (diff) |
tdf#157930 sc: Add easy to use conditional formatting menu
Add menu options that open a dialog that can add conditional formatting
in a cell range with common options.
Change-Id: Ia54baba08e4b78c4c6e37fa7bff744af8cf06037
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156831
Tested-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sc/source/ui/condformat')
-rw-r--r-- | sc/source/ui/condformat/condformateasydlg.cxx | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/sc/source/ui/condformat/condformateasydlg.cxx b/sc/source/ui/condformat/condformateasydlg.cxx new file mode 100644 index 000000000000..8ddb297269dc --- /dev/null +++ b/sc/source/ui/condformat/condformateasydlg.cxx @@ -0,0 +1,192 @@ +#include <docfunc.hxx> +#include <condformateasydlg.hxx> +#include <stlpool.hxx> +#include <viewdata.hxx> +#include <reffact.hxx> +#include <svl/style.hxx> + +namespace +{ +void FillStyleListBox(const ScDocument* pDocument, weld::ComboBox& rCombo) +{ + std::set<OUString> aStyleNames; + SfxStyleSheetIterator aStyleIter(pDocument->GetStyleSheetPool(), SfxStyleFamily::Para); + for (SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next()) + { + aStyleNames.insert(pStyle->GetName()); + } + for (const auto& rStyleName : aStyleNames) + { + rCombo.append_text(rStyleName); + } +} + +void UpdateStyleList(const ScDocument* pDocument, weld::ComboBox& rCombo) +{ + OUString sSelectedStyle = rCombo.get_active_text(); + for (sal_Int32 i = rCombo.get_count(); i > 1; --i) + rCombo.remove(i - 1); + FillStyleListBox(pDocument, rCombo); + rCombo.set_active_text(sSelectedStyle); +} + +ScTabViewShell* GetTabViewShell(const SfxBindings* pBindings) +{ + if (!pBindings) + return nullptr; + SfxDispatcher* pDispacher = pBindings->GetDispatcher(); + if (!pDispacher) + return nullptr; + SfxViewFrame* pFrame = pDispacher->GetFrame(); + if (!pFrame) + return nullptr; + SfxViewShell* pViewShell = pFrame->GetViewShell(); + if (!pViewShell) + return nullptr; + return dynamic_cast<ScTabViewShell*>(pViewShell); +} +} + +namespace sc +{ +ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings, + SfxChildWindow* pChildWindow, + weld::Window* pParent, + ScViewData* pViewData) + : ScAnyRefDlgController(pBindings, pChildWindow, pParent, + "modules/scalc/ui/conditionaleasydialog.ui", "CondFormatEasyDlg") + , mpViewData(pViewData) + , mpDocument(&mpViewData->GetDocument()) + , mxNumberEntry(m_xBuilder->weld_spin_button("entryNumber")) + , mxNumberEntry2(m_xBuilder->weld_spin_button("entryNumber2")) + , mxRangeEntry(new formula::RefEdit(m_xBuilder->weld_entry("entryRange"))) + , mxStyles(m_xBuilder->weld_combo_box("themeCombo")) + , mxDescription(m_xBuilder->weld_label("description")) + , mxButtonOk(m_xBuilder->weld_button("ok")) + , mxButtonCancel(m_xBuilder->weld_button("cancel")) +{ + mpTabViewShell = GetTabViewShell(pBindings); + if (!mpTabViewShell) + mpTabViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current()); + OSL_ENSURE(mpTabViewShell, "Missing view shell!"); + const ScConditionMode* pCurrentMode + = pViewData->GetDocument().GetEasyConditionalFormatDialogData(); + if (!pCurrentMode) + { + SAL_WARN( + "sc", + "Condition mode not set for easy conditional format dialog, this should not happen"); + meMode = ScConditionMode::Greater; + } + else + { + meMode = *pCurrentMode; + } + mxNumberEntry2->hide(); + mxNumberEntry->set_range(SAL_MIN_INT64, SAL_MAX_INT64); + mxNumberEntry2->set_range(SAL_MIN_INT64, SAL_MAX_INT64); + mxNumberEntry->set_increments(1, 0); + mxNumberEntry2->set_increments(1, 0); + switch (meMode) + { + case ScConditionMode::Greater: + mxDescription->set_label(mxDescription->get_label() + " greater than "); + break; + case ScConditionMode::Less: + mxDescription->set_label(mxDescription->get_label() + " less than "); + break; + case ScConditionMode::Equal: + mxDescription->set_label(mxDescription->get_label() + " equal to "); + break; + case ScConditionMode::Between: + mxDescription->set_label(mxDescription->get_label() + " between "); + mxNumberEntry2->show(); + break; + default: + SAL_WARN("sc", + "ConditionalFormatEasyDialog::ConditionalFormatEasyDialog: invalid format"); + break; + } + + mxButtonOk->connect_clicked(LINK(this, ConditionalFormatEasyDialog, ButtonPressed)); + mxButtonCancel->connect_clicked(LINK(this, ConditionalFormatEasyDialog, ButtonPressed)); + + ScRangeList aRange; + mpViewData->GetMarkData().FillRangeListWithMarks(&aRange, false); + if (aRange.empty()) + { + ScAddress aPosition(mpViewData->GetCurX(), mpViewData->GetCurY(), mpViewData->GetTabNo()); + aRange.push_back(ScRange(aPosition)); + } + maPosition = aRange.GetTopLeftCorner(); + + OUString sRangeString; + aRange.Format(sRangeString, ScRefFlags::VALID, *mpDocument, mpDocument->GetAddressConvention()); + mxRangeEntry->SetText(sRangeString); + + StartListening(*mpDocument->GetStyleSheetPool(), DuplicateHandling::Prevent); + FillStyleListBox(mpDocument, *mxStyles); + + mxStyles->set_active(1); +} + +ConditionalFormatEasyDialog::~ConditionalFormatEasyDialog() {} + +void ConditionalFormatEasyDialog::Notify(SfxBroadcaster&, const SfxHint& rHint) +{ + if (rHint.GetId() == SfxHintId::StyleSheetModified) + UpdateStyleList(mpDocument, *mxStyles); +} + +void ConditionalFormatEasyDialog::SetReference(const ScRange& rRange, ScDocument&) +{ + formula::RefEdit* pEdit = mxRangeEntry.get(); + if (rRange.aStart != rRange.aEnd) + RefInputStart(pEdit); + + ScRefFlags nFlags = ScRefFlags::RANGE_ABS; + const ScDocument& rDoc = mpViewData->GetDocument(); + OUString sRange( + rRange.Format(rDoc, nFlags, ScAddress::Details(mpDocument->GetAddressConvention(), 0, 0))); + pEdit->SetRefString(sRange); + maPosition = rRange.aStart; +} + +void ConditionalFormatEasyDialog::SetActive() +{ + mxRangeEntry->GrabFocus(); + RefInputDone(); +} + +void ConditionalFormatEasyDialog::Close() +{ + DoClose(ConditionalFormatEasyDialogWrapper::GetChildWindowId()); +} + +IMPL_LINK(ConditionalFormatEasyDialog, ButtonPressed, weld::Button&, rButton, void) +{ + if (&rButton == mxButtonOk.get()) + { + std::unique_ptr<ScConditionalFormat> pFormat(new ScConditionalFormat(0, mpDocument)); + ScFormatEntry* pEntry + = new ScCondFormatEntry(meMode, mxNumberEntry->get_text(), mxNumberEntry2->get_text(), + *mpDocument, maPosition, mxStyles->get_active_text()); + ScRangeList aRange; + ScRefFlags nFlags + = aRange.Parse(mxRangeEntry->GetText(), mpViewData->GetDocument(), + mpViewData->GetDocument().GetAddressConvention(), maPosition.Tab()); + if ((nFlags & ScRefFlags::VALID) && !aRange.empty()) + { + pFormat->AddEntry(pEntry); + pFormat->SetRange(aRange); + auto& rRangeList = pFormat->GetRange(); + mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat( + 0, std::move(pFormat), maPosition.Tab(), rRangeList); + } + m_xDialog->response(RET_OK); + } + else if (&rButton == mxButtonCancel.get()) + m_xDialog->response(RET_CANCEL); +} + +} // namespace sc
\ No newline at end of file |