diff options
author | Siddhant Chaudhary <urssidd@gmail.com> | 2022-05-29 14:52:58 +0530 |
---|---|---|
committer | Heiko Tietze <heiko.tietze@documentfoundation.org> | 2022-06-21 15:02:22 +0200 |
commit | 9d0ca8ee3f0c2a4e6c0bebec6ef1523cd04e849a (patch) | |
tree | bb6c603c4aea6d21219ba660056b4740130d685c /sc/source/ui/miscdlgs | |
parent | 36d3fa20a5e0ebd7d3befd789a6930c777972e8c (diff) |
tdf#69750 Preserve last used Paste Special options for next session.
This feature stores the Paste Special options for Calc in the LO
registry for use across sessions, so that users don't have to set
options everytime they start a new Calc session. A new group named
"PasteSpecial" has been added in
`officecfg/registry/schema/org/openoffice/Office/Common.xcs`. The
function `ScInsertContentsDlg::storeFlagsInRegistry()` has been added,
which is responsible for storing the state whenever the dialog is closed
by clicking either the OK button, or one of the four shortcut buttons.
Also, whenever the dialog is opened for the first time in a new session
(represented by the `firstLoad` boolean flag), the options are loaded
from the registry.
Change-Id: Icc879b11feb5bfe32777b6e548d9c0804d93a33e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135110
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Diffstat (limited to 'sc/source/ui/miscdlgs')
-rw-r--r-- | sc/source/ui/miscdlgs/inscodlg.cxx | 140 |
1 files changed, 138 insertions, 2 deletions
diff --git a/sc/source/ui/miscdlgs/inscodlg.cxx b/sc/source/ui/miscdlgs/inscodlg.cxx index 879ed28354f3..ca4fd1cfa8bd 100644 --- a/sc/source/ui/miscdlgs/inscodlg.cxx +++ b/sc/source/ui/miscdlgs/inscodlg.cxx @@ -20,12 +20,59 @@ #undef SC_DLLIMPLEMENTATION #include <inscodlg.hxx> +#include <officecfg/Office/Common.hxx> -InsertDeleteFlags ScInsertContentsDlg::nPreviousChecks = InsertDeleteFlags::VALUE | InsertDeleteFlags::DATETIME | InsertDeleteFlags::STRING; +InsertDeleteFlags ScInsertContentsDlg::nPreviousChecks = InsertDeleteFlags::NONE; ScPasteFunc ScInsertContentsDlg::nPreviousFormulaChecks = ScPasteFunc::NONE; InsertContentsFlags ScInsertContentsDlg::nPreviousChecks2 = InsertContentsFlags::NONE; InsCellCmd ScInsertContentsDlg::nPreviousMoveMode = InsCellCmd::INS_NONE; +//whether the dialog has loaded for the first time +static bool firstLoad = true; + +void ScInsertContentsDlg::storeFlagsInRegistry() +{ + //store the flags in the registry + std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create()); + + //InsertDeleteFlags + officecfg::Office::Common::PasteSpecial::Paste::All::set(ScInsertContentsDlg::mxBtnInsAll->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Paste::Numbers::set(ScInsertContentsDlg::mxBtnInsNumbers->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Paste::Text::set(ScInsertContentsDlg::mxBtnInsStrings->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Paste::DateTime::set(ScInsertContentsDlg::mxBtnInsDateTime->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Paste::Formats::set(ScInsertContentsDlg::mxBtnInsAttrs->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Paste::Comments::set(ScInsertContentsDlg::mxBtnInsNotes->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Paste::Objects::set(ScInsertContentsDlg::mxBtnInsObjects->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Paste::Formulas::set(ScInsertContentsDlg::mxBtnInsFormulas->get_active(), batch); + + //ScPasteFunc + if(ScInsertContentsDlg::mxRbNoOp->get_active()) + officecfg::Office::Common::PasteSpecial::Operations::set(0, batch); + else if(ScInsertContentsDlg::mxRbAdd->get_active()) + officecfg::Office::Common::PasteSpecial::Operations::set(1, batch); + else if(ScInsertContentsDlg::mxRbSub->get_active()) + officecfg::Office::Common::PasteSpecial::Operations::set(2, batch); + else if(ScInsertContentsDlg::mxRbMul->get_active()) + officecfg::Office::Common::PasteSpecial::Operations::set(3, batch); + else if(ScInsertContentsDlg::mxRbDiv->get_active()) + officecfg::Office::Common::PasteSpecial::Operations::set(4, batch); + + //InsertContentsFlags + officecfg::Office::Common::PasteSpecial::Options::AsLink::set(ScInsertContentsDlg::mxBtnLink->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Options::Transpose::set(ScInsertContentsDlg::mxBtnTranspose->get_active(), batch); + officecfg::Office::Common::PasteSpecial::Options::SkipEmptyCells::set(ScInsertContentsDlg::mxBtnSkipEmptyCells->get_active(), batch); + + //InsCellCmd + if(ScInsertContentsDlg::mxRbMoveNone->get_active()) + officecfg::Office::Common::PasteSpecial::ShiftCells::set(4, batch); + else if(ScInsertContentsDlg::mxRbMoveDown->get_active()) + officecfg::Office::Common::PasteSpecial::ShiftCells::set(0, batch); + else if(ScInsertContentsDlg::mxRbMoveRight->get_active()) + officecfg::Office::Common::PasteSpecial::ShiftCells::set(1, batch); + + batch->commit(); +} + ScInsertContentsDlg::ScInsertContentsDlg(weld::Window* pParent, const OUString* pStrTitle ) : GenericDialogController(pParent, "modules/scalc/ui/pastespecial.ui", "PasteSpecial") @@ -57,11 +104,88 @@ ScInsertContentsDlg::ScInsertContentsDlg(weld::Window* pParent, , mxBtnShortCutPasteValuesFormats(m_xBuilder->weld_button("paste_values_formats")) , mxBtnShortCutPasteTranspose(m_xBuilder->weld_button("paste_transpose")) , mxBtnShortCutPasteFormats(m_xBuilder->weld_button("paste_formats")) + , mxOKBtn(m_xBuilder->weld_button("ok")) , mxImmediately(m_xBuilder->weld_check_button("cbImmediately")) { if (pStrTitle) m_xDialog->set_title(*pStrTitle); + if (firstLoad) + { + //unset firstLoad + firstLoad = false; + + //set the flags from the registry + + /* + * Flags for nPreviousChecks + */ + if(officecfg::Office::Common::PasteSpecial::Paste::All::get()) + nPreviousChecks |= InsertDeleteFlags::ALL; + if(officecfg::Office::Common::PasteSpecial::Paste::Numbers::get()) + nPreviousChecks |= InsertDeleteFlags::VALUE; + if(officecfg::Office::Common::PasteSpecial::Paste::Text::get()) + nPreviousChecks |= InsertDeleteFlags::STRING; + if(officecfg::Office::Common::PasteSpecial::Paste::DateTime::get()) + nPreviousChecks |= InsertDeleteFlags::DATETIME; + if(officecfg::Office::Common::PasteSpecial::Paste::Formats::get()) + nPreviousChecks |= InsertDeleteFlags::ATTRIB; + if(officecfg::Office::Common::PasteSpecial::Paste::Comments::get()) + nPreviousChecks |= InsertDeleteFlags::NOTE; + if(officecfg::Office::Common::PasteSpecial::Paste::Objects::get()) + nPreviousChecks |= InsertDeleteFlags::OBJECTS; + if(officecfg::Office::Common::PasteSpecial::Paste::Formulas::get()) + nPreviousChecks |= InsertDeleteFlags::FORMULA; + + /* + * Flags for nPreviousFormulaChecks + */ + int optionFlagValue = officecfg::Office::Common::PasteSpecial::Operations::get(); + switch(optionFlagValue) + { + case 0: nPreviousFormulaChecks = ScPasteFunc::NONE; + break; + + case 1: nPreviousFormulaChecks = ScPasteFunc::ADD; + break; + + case 2: nPreviousFormulaChecks = ScPasteFunc::SUB; + break; + + case 3: nPreviousFormulaChecks = ScPasteFunc::MUL; + break; + + case 4: nPreviousFormulaChecks = ScPasteFunc::DIV; + break; + } + + /* + * Flags for nPreviousChecks2 + */ + if(officecfg::Office::Common::PasteSpecial::Options::AsLink::get()) + nPreviousChecks2 |= InsertContentsFlags::Link; + if(officecfg::Office::Common::PasteSpecial::Options::Transpose::get()) + nPreviousChecks2 |= InsertContentsFlags::Trans; + if(officecfg::Office::Common::PasteSpecial::Options::SkipEmptyCells::get()) + nPreviousChecks2 |= InsertContentsFlags::NoEmpty; + + /* + * Flags for nPreviousMoveMode + */ + int shiftFlagValue = officecfg::Office::Common::PasteSpecial::ShiftCells::get(); + switch(shiftFlagValue) + { + case 0: nPreviousMoveMode = InsCellCmd::INS_CELLSDOWN; + break; + + case 1: nPreviousMoveMode = InsCellCmd::INS_CELLSRIGHT; + break; + + case 4: nPreviousMoveMode = InsCellCmd::INS_NONE; + break; + } + } + SetInsContentsCmdBits( ScInsertContentsDlg::nPreviousChecks ); SetFormulaCmdBits( ScInsertContentsDlg::nPreviousFormulaChecks ); SetCellCmdFlags( ScInsertContentsDlg::nPreviousMoveMode ); @@ -74,6 +198,7 @@ ScInsertContentsDlg::ScInsertContentsDlg(weld::Window* pParent, mxBtnShortCutPasteValuesFormats->connect_clicked( LINK( this, ScInsertContentsDlg, ShortCutHdl ) ); mxBtnShortCutPasteTranspose->connect_clicked( LINK( this, ScInsertContentsDlg, ShortCutHdl ) ); mxBtnShortCutPasteFormats->connect_clicked( LINK( this, ScInsertContentsDlg, ShortCutHdl ) ); + mxOKBtn->connect_clicked( LINK( this, ScInsertContentsDlg, ClickHdl ) ); } InsertDeleteFlags ScInsertContentsDlg::GetInsContentsCmdBits() const @@ -316,7 +441,18 @@ IMPL_LINK(ScInsertContentsDlg, ShortCutHdl, weld::Button&, rBtn, void) SetCellCmdFlags( InsCellCmd::INS_NONE ); SetFormulaCmdBits(ScPasteFunc::NONE); - if (mxImmediately->get_active()) m_xDialog->response(RET_OK); + + if (mxImmediately->get_active()) + { + storeFlagsInRegistry(); + m_xDialog->response(RET_OK); + } +} + +IMPL_LINK_NOARG(ScInsertContentsDlg, ClickHdl, weld::Button&, void) +{ + storeFlagsInRegistry(); + m_xDialog->response(RET_OK); } IMPL_LINK_NOARG(ScInsertContentsDlg, InsAllHdl, weld::Toggleable&, void) |