From 56cce6fd8151a916e1be540ac18724b46d1b15fc Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 2 May 2014 15:30:20 -0400 Subject: Implement "fill single edit" mode and map it to Ctrl-' by default. Excel does this apparently, and lots of people want it. Change-Id: Ia741ebb84526197d28caa323d36709e38b8f1323 --- .../data/org/openoffice/Office/Accelerators.xcu | 6 ++++ .../data/org/openoffice/Office/UI/CalcCommands.xcu | 8 +++++ sc/inc/sc.hrc | 1 + sc/inc/scmod.hxx | 2 +- sc/sdi/cellsh.sdi | 1 + sc/sdi/scalc.sdi | 25 +++++++++++++++ sc/source/ui/app/inputhdl.cxx | 8 ++++- sc/source/ui/app/scmod.cxx | 4 +-- sc/source/ui/inc/cellsh.hxx | 2 ++ sc/source/ui/inc/inputhdl.hxx | 2 +- sc/source/ui/view/cellsh.cxx | 4 ++- sc/source/ui/view/cellsh1.cxx | 37 ++++++++++++++++++++++ 12 files changed, 94 insertions(+), 6 deletions(-) diff --git a/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu b/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu index 624bcdf1e9a6..ef0ec1b539b0 100644 --- a/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu +++ b/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu @@ -967,6 +967,12 @@ .uno:ToggleFormula + + + I10N SHORTCUTS - NO TRANSLATE + .uno:FillSingleEdit + + I10N SHORTCUTS - NO TRANSLATE diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu index 18dc5d3fc4f5..1bfa929af358 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu @@ -632,6 +632,14 @@ ~Left + + + Fill Single ~Edit + + + Single ~Edit + + Fill ~Sheets... diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc index 757931f7914f..43bda66ddcb8 100644 --- a/sc/inc/sc.hrc +++ b/sc/inc/sc.hrc @@ -286,6 +286,7 @@ #define FID_FILL_TO_LEFT (EDIT_MENU_START + 7) #define FID_FILL_TAB (EDIT_MENU_START + 8) #define FID_FILL_SERIES (EDIT_MENU_START + 9) +#define FID_FILL_SINGLE_EDIT (EDIT_MENU_START + 10) #define SID_SC_EDIT_OBJECT (EDIT_MENU_START + 14) #define SID_HFEDIT (EDIT_MENU_START + 15) diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx index de9d9c2372ed..cafefdf5d836 100644 --- a/sc/inc/scmod.hxx +++ b/sc/inc/scmod.hxx @@ -205,7 +205,7 @@ SC_DLLPUBLIC void SetAppOptions ( const ScAppOptions& rO // InputHandler: bool IsEditMode(); // not for SC_INPUT_TYPE bool IsInputMode(); // also for SC_INPUT_TYPE - void SetInputMode( ScInputMode eMode ); + void SetInputMode( ScInputMode eMode, const OUString* pInitText = NULL ); bool InputKeyEvent( const KeyEvent& rKEvt, bool bStartEdit = false ); SC_DLLPUBLIC void InputEnterHandler( sal_uInt8 nBlockMode = 0 ); void InputCancelHandler(); diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi index b77b4f88cca8..62ce4858c957 100644 --- a/sc/sdi/cellsh.sdi +++ b/sc/sdi/cellsh.sdi @@ -150,6 +150,7 @@ interface CellSelection FID_FILL_TAB [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] FID_FILL_SERIES [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ] FID_FILL_AUTO [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] + FID_FILL_SINGLE_EDIT [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ] SID_RANDOM_NUMBER_GENERATOR_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ] SID_SAMPLING_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ] SID_DESCRIPTIVE_STATISTICS_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ] diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi index d260cdae945b..fe3d780e7ccc 100644 --- a/sc/sdi/scalc.sdi +++ b/sc/sdi/scalc.sdi @@ -2414,6 +2414,31 @@ SfxVoidItem FillLeft FID_FILL_TO_LEFT ] +SfxVoidItem FillSingleEdit FID_FILL_SINGLE_EDIT +() +[ + /* flags: */ + AutoUpdate = FALSE, + Cachable = Cachable, + FastCall = FALSE, + HasCoreId = FALSE, + HasDialog = TRUE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + Asynchron; + + /* config: */ + AccelConfig = TRUE, + MenuConfig = TRUE, + StatusBarConfig = FALSE, + ToolBoxConfig = TRUE, + GroupId = GID_EDIT; +] + + SfxVoidItem FillModeEnd SID_FILL_NONE () [ diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index 78481fa0ab73..f1a3da8a254b 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2381,7 +2381,7 @@ void ScInputHandler::InvalidateAttribs() // --------------- public Methoden -------------------------------------------- -void ScInputHandler::SetMode( ScInputMode eNewMode ) +void ScInputHandler::SetMode( ScInputMode eNewMode, const OUString* pInitText ) { if ( eMode == eNewMode ) return; @@ -2419,6 +2419,12 @@ void ScInputHandler::SetMode( ScInputMode eNewMode ) } } + if (pInitText) + { + pEngine->SetText(*pInitText); + bModified = true; + } + sal_Int32 nPara = pEngine->GetParagraphCount()-1; sal_Int32 nLen = pEngine->GetText(nPara).getLength(); sal_uInt16 nCount = pEngine->GetViewCount(); diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx index ec2ce296e670..586686de142c 100644 --- a/sc/source/ui/app/scmod.cxx +++ b/sc/source/ui/app/scmod.cxx @@ -1427,11 +1427,11 @@ void ScModule::ViewShellChanged() pShell->UpdateInputHandler(); } -void ScModule::SetInputMode( ScInputMode eMode ) +void ScModule::SetInputMode( ScInputMode eMode, const OUString* pInitText ) { ScInputHandler* pHdl = GetInputHdl(); if (pHdl) - pHdl->SetMode( eMode ); + pHdl->SetMode(eMode, pInitText); } bool ScModule::IsEditMode() diff --git a/sc/source/ui/inc/cellsh.hxx b/sc/source/ui/inc/cellsh.hxx index fa83707c6315..2318cf86acc5 100644 --- a/sc/source/ui/inc/cellsh.hxx +++ b/sc/source/ui/inc/cellsh.hxx @@ -61,6 +61,8 @@ private: void ExecuteXMLSourceDialog(); void ExecuteSubtotals(SfxRequest& rReq); + void ExecuteFillSingleEdit(); + DECL_LINK( ClipboardChanged, TransferableDataHelper* ); DECL_LINK( DialogClosed, void* ); diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx index 231e9ad81bce..937313832e1a 100644 --- a/sc/source/ui/inc/inputhdl.hxx +++ b/sc/source/ui/inc/inputhdl.hxx @@ -164,7 +164,7 @@ public: ScInputHandler(); virtual ~ScInputHandler(); - void SetMode( ScInputMode eNewMode ); + void SetMode( ScInputMode eNewMode, const OUString* pInitText = NULL ); bool IsInputMode() const { return (eMode != SC_INPUT_NONE); } bool IsEditMode() const { return (eMode != SC_INPUT_NONE && eMode != SC_INPUT_TYPE); } diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index 498d17387541..2a5aa5b17230 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -199,7 +199,9 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet ) nCol2, nRow1, nCol2, nRow2, rMark ); // last column } break; - + case FID_FILL_SINGLE_EDIT: + bDisable = false; + break; case SID_CUT: // cut case FID_INS_CELL: // insert cells, just simple selection bDisable = (!bSimpleArea); diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 858d1abb30e9..e53be77d85b9 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -79,6 +79,10 @@ #include "scui_def.hxx" #include #include "scabstdlg.hxx" +#include +#include +#include +#include #include #include @@ -901,6 +905,9 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) } } break; + case FID_FILL_SINGLE_EDIT: + ExecuteFillSingleEdit(); + break; case SID_RANDOM_NUMBER_GENERATOR_DIALOG: { sal_uInt16 nId = ScRandomNumberGeneratorDialogWrapper::GetChildWindowId(); @@ -2771,6 +2778,36 @@ void ScCellShell::ExecuteSubtotals(SfxRequest& rReq) delete pDlg; } +void ScCellShell::ExecuteFillSingleEdit() +{ + ScAddress aCurPos = GetViewData()->GetCurPos(); + + OUString aInit; + + if (aCurPos.Row() > 0) + { + // Get the initial text value from the above cell. + + ScDocument* pDoc = GetViewData()->GetDocument(); + ScRefCellValue aCell; + ScAddress aPrevPos = aCurPos; + aPrevPos.IncRow(-1); + aCell.assign(*pDoc, aPrevPos); + + if (aCell.meType == CELLTYPE_FORMULA) + { + aInit = "="; + const ScTokenArray* pCode = aCell.mpFormula->GetCode(); + sc::TokenStringContext aCxt(pDoc, pDoc->GetGrammar()); + aInit += pCode->CreateString(aCxt, aCurPos); + } + else + aInit = aCell.getString(pDoc); + } + + SC_MOD()->SetInputMode(SC_INPUT_TABLE, &aInit); +} + IMPL_LINK_NOARG(ScCellShell, DialogClosed) { OSL_ENSURE( pImpl->m_pLinkedDlg, "ScCellShell::DialogClosed(): invalid request" ); -- cgit v1.2.3