diff options
author | Andrzej Hunt <andrzej@ahunt.org> | 2015-08-07 08:25:48 +0100 |
---|---|---|
committer | Andrzej Hunt <andrzej@ahunt.org> | 2015-10-21 10:23:48 +0200 |
commit | 2daa56a63baea4cb3f946e3bc2f662dbfa0a45cd (patch) | |
tree | c1da7e911bc8f0ccfe3630712983098b28a18ab6 | |
parent | 03ab4a1945ccf5f4e194bcaf64e88c1680018b9a (diff) |
Implement undoing conversion of individual locally annotated cells
Change-Id: I16b62f1105f7839b047a96fdab0e3e6089d400ee
-rw-r--r-- | sc/inc/sc.hrc | 5 | ||||
-rw-r--r-- | sc/source/ui/src/units.src | 5 | ||||
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 99 |
3 files changed, 96 insertions, 13 deletions
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc index ede086accbdb..318c5bb5feda 100644 --- a/sc/inc/sc.hrc +++ b/sc/inc/sc.hrc @@ -1008,7 +1008,10 @@ #define STR_UNITS_CONVERSION_RECOMMENDED (STR_START + 455) #define BT_UNITS_CONVERT_THIS_CELL (STR_START + 456) #define BT_UNITS_CONV_ALL (STR_START + 457) -#define STR_END (BT_UNITS_CONV_ALL) + +#define STR_UNDO_UNITSCONVERSION (STR_START + 458) + +#define STR_END (STR_UNDO_UNITSCONVERSION) #define BMP_START (STR_END) diff --git a/sc/source/ui/src/units.src b/sc/source/ui/src/units.src index d666923f0d51..bc9a315a30e9 100644 --- a/sc/source/ui/src/units.src +++ b/sc/source/ui/src/units.src @@ -55,4 +55,9 @@ PushButton BT_UNITS_CONV_ALL Text [ en-US ] = "Convert (automatically for all cells needing $2)" ; }; +String STR_UNDO_UNITSCONVERSION +{ + Text [ en-US ] = "Units conversion"; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index cd3a0ba3c2ab..f04655181e5f 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -2984,8 +2984,7 @@ void ScViewFunc::NotifyUnitConversionRecommended( const ScAddress& rCellAddress, rCellAddress, pDoc, rsHeaderUnit, - rsCellUnit, - pDocSh ); + rsCellUnit ); pButtonConvertCell->SetClickHdl( LINK( this, ScViewFunc, UnitConversionRecommendedHandler ) ); OUString sConvertText = pButtonConvertCell->GetText(); @@ -3002,32 +3001,108 @@ IMPL_LINK( ScViewFunc, UnitConversionRecommendedHandler, UnitConversionPushButto #ifdef ENABLE_CALC_UNITVERIFICATION boost::shared_ptr< Units > pUnits = Units::GetUnits(); - ScDocShell* pDocShell = static_cast<ScDocShell*>(pButton->mpDoc->GetDocumentShell()); + ScDocument* pDoc = pButton->mpDoc; + ScDocShell* pDocShell = static_cast<ScDocShell*>(pDoc->GetDocumentShell()); ScDocShellModificator aModificator( *pDocShell ); + bool bUndo = pDoc->IsUndoEnabled(); + ScCellValue aOldVal; + ScDocument* pUndoDoc; + ScMarkData aMark; - OUString sOriginalValue = pButton->mpDoc->GetString( pButton->aCellAddress ); + svl::IUndoManager* pUndoManager; + ScDrawLayer* pDrawLayer; + + if ( bUndo ) + { + pUndoManager = pDocShell->GetUndoManager(); + + aOldVal.assign( *pDoc, pButton->aCellAddress ); + + aMark.SetMarkArea( pButton->aCellAddress ); + pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); + pUndoDoc->InitUndo( pDoc, pButton->aCellAddress.Tab(), pButton->aCellAddress.Tab() ); + pDoc->CopyToDocument( ScRange( pButton->aCellAddress ), IDF_ATTRIB, false, pUndoDoc, &aMark ); + + // This commences logging of changes to the drawing layer + // (i.e. notes) for storing in an undo. (See more below.) + pDrawLayer = pDoc->GetDrawLayer(); + pDrawLayer->BeginCalcUndo(false); + } + + OUString sOriginalValue = pDoc->GetString( pButton->aCellAddress ); pUnits->convertCellToHeaderUnit( pButton->aCellAddress, - pButton->mpDoc, + pDoc, pButton->sHeaderUnit, pButton->sCellUnit ); - ScPostIt* pNote = pButton->mpDoc->GetOrCreateNote( pButton->aCellAddress ); - OUString sCurrentNote = pNote->GetText(); - - OUString sConversionNote("Original input: " + sOriginalValue); + const OUString sCurrentNoteText = pDoc->GetOrCreateNote( pButton->aCellAddress )->GetText(); + const OUString sConversionNote("Original input: " + sOriginalValue); + OUString sNewNoteText; - if (sCurrentNote.isEmpty()) + if (sCurrentNoteText.isEmpty()) { - pNote->SetText( pButton->aCellAddress, sConversionNote ); + sNewNoteText = sConversionNote; } else { - pNote->SetText( pButton->aCellAddress, sCurrentNote + "\n\n" + sConversionNote ); + sNewNoteText = sCurrentNoteText + "\n\n" + sConversionNote; } + // ensure existing caption object before draw undo tracking starts + ScPostIt* pOldNote = pDoc->ReleaseNote( pButton->aCellAddress ); + ScNoteData aOldNoteData = pOldNote->GetNoteData(); + delete pOldNote; + + ScPostIt* pNewNote = ScNoteUtil::CreateNoteFromString( *pDoc, pButton->aCellAddress, sNewNoteText, false, true ); + assert( pNewNote ); + + if ( bUndo ) + { + const OUString aUndo( ScResId( STR_UNDO_UNITSCONVERSION ) ); + pUndoManager->EnterListAction( aUndo, aUndo ); + + ScCellValue aNewVal; + aNewVal.assign( *pDoc, pButton->aCellAddress ); + const ScPatternAttr* pNewPat = pDoc->GetPattern( pButton->aCellAddress ); + + pUndoManager->AddUndoAction( new ScUndoSetCell( pDocShell, pButton->aCellAddress, aOldVal, aNewVal ) ); + pUndoManager->AddUndoAction( new ScUndoSelectionAttr( pDocShell, + aMark, + pButton->aCellAddress.Col(), pButton->aCellAddress.Row(), pButton->aCellAddress.Tab(), + pButton->aCellAddress.Col(), pButton->aCellAddress.Row(), pButton->aCellAddress.Tab(), + pUndoDoc, + false, + pNewPat) ); + ScNoteData aNewNoteData = pNewNote->GetNoteData(); + + // We specifically need to differentiate between a completely new + // note, or editing an existing note. ScUndoReplaceNote has two + // different constructors for each case. + if ( sCurrentNoteText.isEmpty() ) + { + pUndoManager->AddUndoAction( new ScUndoReplaceNote( *pDocShell, pButton->aCellAddress, + aNewNoteData, true, nullptr ) ); + } + else + { + // Actual note content changes are stored in the DrawLayer CalcUndo, + // as opposed to being the NoteData (which just seems to store note + // metadata) - hence we need to make sure that we save that too. + pUndoManager->AddUndoAction( new ScUndoReplaceNote( *pDocShell, pButton->aCellAddress, + aOldNoteData, aNewNoteData, + pDrawLayer->GetCalcUndo() ) ); + } + pUndoManager->LeaveListAction(); + } + + pDocShell->PostPaint(ScRange( pButton->aCellAddress), PAINT_GRID); + aModificator.SetDocumentModified(); + SfxGetpApp()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED)); + + #endif OUString sAddress; |