diff options
author | Jakub Trzebiatowski <ubap.dev@gmail.com> | 2016-08-11 20:22:39 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-08-16 07:35:12 +0000 |
commit | 592a8657fa6bdc6ed72281d792c19ff0bff31387 (patch) | |
tree | 0386d09d1a3de82a8dd0d0a4a21348a263165af2 | |
parent | 1fd006b020212d8f4743eac105f8d36889a21071 (diff) |
GSoC Writer Table Styles; Update by example
+ Added possibility to update style by example.
+ Fixed SwTableAutoFormat::GetBoxFormat
Change-Id: I80d9334ceda0ef7e0984fb54731850034b44cd44
Reviewed-on: https://gerrit.libreoffice.org/28063
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r-- | sw/inc/doc.hxx | 2 | ||||
-rw-r--r-- | sw/inc/swundo.hxx | 3 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 26 | ||||
-rw-r--r-- | sw/source/core/doc/tblafmt.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/docnode/ndtbl.cxx | 29 | ||||
-rw-r--r-- | sw/source/core/inc/UndoTable.hxx | 14 | ||||
-rw-r--r-- | sw/source/core/undo/undo.hrc | 3 | ||||
-rw-r--r-- | sw/source/core/undo/undo.src | 4 | ||||
-rw-r--r-- | sw/source/core/undo/untbl.cxx | 26 | ||||
-rw-r--r-- | sw/source/uibase/app/docst.cxx | 19 |
10 files changed, 127 insertions, 7 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index cbc3145e595a..f28bd22013e7 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1263,6 +1263,8 @@ public: SwTableAutoFormat* MakeTableStyle(const OUString& rName, bool bBroadcast = false); // Delete table style named rName. If pAffectedTables is not null, it contains pointers to affected tables. Tracked by undo. std::unique_ptr<SwTableAutoFormat> DelTableStyle(const OUString& rName, bool bBroadcast = false, std::vector<SwTable*>* pAffectedTables = nullptr); + // Change (replace) a table style named rName. Tracked by undo. + void ChgTableStyle(const OUString& rName, const SwTableAutoFormat& rNewFormat); const SwCellStyleTable& GetCellStyles() const { return *mpCellStyles.get(); } SwCellStyleTable& GetCellStyles() { return *mpCellStyles.get(); } diff --git a/sw/inc/swundo.hxx b/sw/inc/swundo.hxx index 9a90d4af312f..e33ee7bd48d6 100644 --- a/sw/inc/swundo.hxx +++ b/sw/inc/swundo.hxx @@ -152,7 +152,8 @@ enum SwUndoId UNDO_FLYFRMFMT_DESCRIPTION, // 113 UNDO_TBLSTYLE_CREATE, // 114 UNDO_TBLSTYLE_DELETE, // 115 - UNDO_STD_END= UNDO_TBLSTYLE_DELETE, + UNDO_TBLSTYLE_UPDATE, // 116 + UNDO_STD_END= UNDO_TBLSTYLE_UPDATE, // UI undo ID's... UNDO_UI_REPLACE = UNDO_STD_END + 1, diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 813f548411dc..a835533a0032 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -3796,8 +3796,32 @@ void SwUiWriterTest::testTableStyleUndo() // check if attributes are preserved CPPUNIT_ASSERT(pStyle); CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground); - rUndoManager.Undo(); + rUndoManager.Redo(); CPPUNIT_ASSERT_EQUAL(sal_Int32(pDoc->GetTableStyles().size()), nStyleCount); + + // undo delete so we can replace the style + rUndoManager.Undo(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(pDoc->GetTableStyles().size()), nStyleCount +1 ); + pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style"); + CPPUNIT_ASSERT(pStyle); + CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground); + + SwTableAutoFormat aNewStyle("Test Style2"); + SvxBrushItem aBackground2(Color(0x00FF00), RES_BACKGROUND); + aNewStyle.GetBoxFormat(0).SetBackground(aBackground2); + + pDoc->ChgTableStyle("Test Style", aNewStyle); + pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style"); + CPPUNIT_ASSERT(pStyle); + CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground2); + rUndoManager.Undo(); + pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style"); + CPPUNIT_ASSERT(pStyle); + CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground); + rUndoManager.Redo(); + pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style"); + CPPUNIT_ASSERT(pStyle); + CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground2); } CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx index 3d461021af0f..45937fd63e4d 100644 --- a/sw/source/core/doc/tblafmt.cxx +++ b/sw/source/core/doc/tblafmt.cxx @@ -702,15 +702,15 @@ SwBoxAutoFormat& SwTableAutoFormat::GetBoxFormat( sal_uInt8 nPos ) { SAL_WARN_IF(!(nPos < 16), "sw.core", "GetBoxFormat wrong area"); - SwBoxAutoFormat* pFormat = aBoxAutoFormat[ nPos ]; - if( !pFormat ) + SwBoxAutoFormat** pFormat = &aBoxAutoFormat[ nPos ]; + if( !*pFormat ) { // If default doesn't exist yet: if( !pDfltBoxAutoFormat ) pDfltBoxAutoFormat = new SwBoxAutoFormat(); - pFormat = pDfltBoxAutoFormat; + *pFormat = new SwBoxAutoFormat(*pDfltBoxAutoFormat); } - return *pFormat; + return **pFormat; } const SwBoxAutoFormat& SwTableAutoFormat::GetDefaultBoxFormat() diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index c9c9511c3dea..9bff35ab1b50 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -4671,4 +4671,33 @@ std::unique_ptr<SwTableAutoFormat> SwDoc::DelTableStyle(const OUString& rName, b return pReleasedFormat; } +void SwDoc::ChgTableStyle(const OUString& rName, const SwTableAutoFormat& rNewFormat) +{ + SwTableAutoFormat* pFormat = GetTableStyles().FindAutoFormat(rName); + if (pFormat) + { + SwTableAutoFormat aOldFormat = *pFormat; + *pFormat = rNewFormat; + pFormat->SetName(rName); + + size_t nTableCount = GetTableFrameFormatCount(true); + for (size_t i=0; i < nTableCount; ++i) + { + SwFrameFormat* pFrameFormat = &GetTableFrameFormat(i, true); + SwTable* pTable = SwTable::FindTable(pFrameFormat); + if (pTable->GetTableStyleName() == rName) + GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(pTable->GetTableNode()); + } + + getIDocumentState().SetModified(); + + if (GetIDocumentUndoRedo().DoesUndo()) + { + SwUndo * pUndo = new SwUndoTableStyleUpdate(rName, aOldFormat, this); + + GetIDocumentUndoRedo().AppendUndo(pUndo); + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/inc/UndoTable.hxx b/sw/source/core/inc/UndoTable.hxx index d7bacd3ff9ed..e0ad12498011 100644 --- a/sw/source/core/inc/UndoTable.hxx +++ b/sw/source/core/inc/UndoTable.hxx @@ -408,6 +408,20 @@ public: virtual SwRewriter GetRewriter() const override; }; +class SwUndoTableStyleUpdate : public SwUndo +{ + std::unique_ptr<SwTableAutoFormat> m_pOldFormat, m_pNewFormat; +public: + SwUndoTableStyleUpdate(const OUString& rName, const SwTableAutoFormat& rOldFormat, const SwDoc* pDoc); + + virtual ~SwUndoTableStyleUpdate(); + + virtual void UndoImpl( ::sw::UndoRedoContext & ) override; + virtual void RedoImpl( ::sw::UndoRedoContext & ) override; + + virtual SwRewriter GetRewriter() const override; +}; + #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOTABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/undo/undo.hrc b/sw/source/core/undo/undo.hrc index 7ed5cdf48724..7e134d3491e7 100644 --- a/sw/source/core/undo/undo.hrc +++ b/sw/source/core/undo/undo.hrc @@ -140,9 +140,10 @@ #define STR_UNDO_FLYFRMFMT_DESCRITPTION (CORE_REPEAT_END +68) #define STR_UNDO_TBLSTYLE_CREATE (CORE_REPEAT_END +69) #define STR_UNDO_TBLSTYLE_DELETE (CORE_REPEAT_END +70) +#define STR_UNDO_TBLSTYLE_UPDATE (CORE_REPEAT_END +71) // !!!!!! umsetzen !!!!!!!!!!! umsetzen !!!!!!!!!!! umsetzen !!!! -#define CORE_UNDO_END STR_UNDO_TBLSTYLE_DELETE// !!!! umsetzen !!! +#define CORE_UNDO_END STR_UNDO_TBLSTYLE_UPDATE// !!!! umsetzen !!! // UI-Undo Klammerungen #define UI_UNDO_BEGIN (CORE_UNDO_END + 1) diff --git a/sw/source/core/undo/undo.src b/sw/source/core/undo/undo.src index b293b4e2c458..c92e71620d9b 100644 --- a/sw/source/core/undo/undo.src +++ b/sw/source/core/undo/undo.src @@ -658,6 +658,10 @@ String STR_UNDO_TBLSTYLE_DELETE { Text[ en-US ] = "Delete table style: $1"; }; +String STR_UNDO_TBLSTYLE_UPDATE +{ + Text[ en-US ] = "Update table style: $1"; +}; String STR_UNDO_TABLE_DELETE { Text [ en-US ] = "Delete table" ; diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx index be0801b6936e..f6e96d668b35 100644 --- a/sw/source/core/undo/untbl.cxx +++ b/sw/source/core/undo/untbl.cxx @@ -3233,4 +3233,30 @@ SwRewriter SwUndoTableStyleDelete::GetRewriter() const return aResult; } +SwUndoTableStyleUpdate::SwUndoTableStyleUpdate(const OUString& rName, const SwTableAutoFormat& rOldFormat, const SwDoc* pDoc) + : SwUndo(UNDO_TBLSTYLE_UPDATE, pDoc), + m_pOldFormat(new SwTableAutoFormat(rOldFormat)), + m_pNewFormat(new SwTableAutoFormat(*pDoc->GetTableStyles().FindAutoFormat(rName))) +{ } + +SwUndoTableStyleUpdate::~SwUndoTableStyleUpdate() +{ } + +void SwUndoTableStyleUpdate::UndoImpl(::sw::UndoRedoContext & rContext) +{ + rContext.GetDoc().ChgTableStyle(m_pNewFormat->GetName(), *m_pOldFormat); +} + +void SwUndoTableStyleUpdate::RedoImpl(::sw::UndoRedoContext & rContext) +{ + rContext.GetDoc().ChgTableStyle(m_pNewFormat->GetName(), *m_pNewFormat); +} + +SwRewriter SwUndoTableStyleUpdate::GetRewriter() const +{ + SwRewriter aResult; + aResult.AddRule(UndoArg1, m_pNewFormat->GetName()); + return aResult; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index 28428082341f..13558bfd5938 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -466,6 +466,12 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) aParam = static_cast<const SfxStringItem*>(pItem)->GetValue(); } break; + case SfxStyleFamily::Table: + if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem)) + { + aParam = static_cast<const SfxStringItem*>(pItem)->GetValue(); + } + break; default: break; } rReq.AppendItem(SfxStringItem(nSlot, aParam)); @@ -1124,6 +1130,19 @@ SfxStyleFamily SwDocShell::UpdateStyle(const OUString &rName, SfxStyleFamily nFa } } break; + case SfxStyleFamily::Table: + { + + SwTableAutoFormat aFormat(rName); + if (pCurrWrtShell->GetTableAutoFormat(aFormat)) + { + pCurrWrtShell->StartAllAction(); + pCurrWrtShell->GetDoc()->ChgTableStyle(rName, aFormat); + pCurrWrtShell->EndAllAction(); + } + + } + break; default: break; } return nFamily; |