From 9c4eef7d809ad7d283860c7b47b0f561aa240906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20N=C3=A9meth?= Date: Tue, 29 Jan 2019 14:53:43 +0100 Subject: [PATCH] tdf#52391 reject/clear formatting of format-only changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Format-only changes had 1) disabled (in Manage Changes dialog window) or 2) bad rejection (Track Changes toolbar icons and Edit->Track Changes menu item functions "Reject"/"Reject All" resulted acception of the tracked format-only changes instead of rejection). Because format-only changes haven't had real rejection support, yet, this commit 1) adds an often useful reject-like function in the Manage Changes dialog window: instead of disabling Reject/Reject All, now these buttons clears direct text formatting in the area of the tracked format-only changes. Because this may be not a rejection (ie. the original text can contain direct text formatting), the labels of the button warn about it: "Reject/Clear formatting" and "Reject All/Clear formatting". Note: "Reject All" still rejects only insertions/deletions at (now first) pressing, as from commit a8a3928bd3614e52edc0a4df6f67ce53e787905c. 2) Icons and menu items "Reject"/"Reject All" clear direct text formatting in the areas of the tracked format-only changes. Note: this is still not ideal, but it can help to avoid of unintended direct text formatting until implementing upcoming ODF 1.3 change tracking. Change-Id: I87c3ac6165019cae9c49ed4591eaadef9e06beb5 Reviewed-on: https://gerrit.libreoffice.org/67080 Tested-by: Jenkins Reviewed-by: László Németh --- include/svx/ctredlin.hxx | 3 ++ svx/source/dialog/ctredlin.cxx | 40 ++++++++++++++ svx/uiconfig/ui/acceptrejectchangesdialog.ui | 5 ++ sw/qa/extras/uiwriter/data2/tdf52391.fodt | 54 +++++++++++++++++++ sw/qa/extras/uiwriter/uiwriter2.cxx | 18 +++++++ sw/source/core/doc/DocumentRedlineManager.cxx | 14 ++++- sw/source/uibase/misc/redlndlg.cxx | 21 +++++--- 7 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 sw/qa/extras/uiwriter/data2/tdf52391.fodt diff --git a/include/svx/ctredlin.hxx b/include/svx/ctredlin.hxx index e83b9eec7e0c..7e2260b4f1c4 100644 --- a/include/svx/ctredlin.hxx +++ b/include/svx/ctredlin.hxx @@ -329,6 +329,9 @@ public: void EnableAcceptAll(bool bFlag); void EnableReject(bool bFlag); void EnableRejectAll(bool bFlag); + static void EnableClearFormatButton(VclPtr, bool bFlag); + void EnableClearFormat(bool bFlag); + void EnableClearFormatAll(bool bFlag); void EnableUndo(bool bFlag=true); void DisableUndo() {EnableUndo(false);} void ShowUndo(); diff --git a/svx/source/dialog/ctredlin.cxx b/svx/source/dialog/ctredlin.cxx index 188d7bc582e3..5e1aefc7f7c2 100644 --- a/svx/source/dialog/ctredlin.cxx +++ b/svx/source/dialog/ctredlin.cxx @@ -32,6 +32,8 @@ #include #include +#include +#include #define WRITER_DATE 2 #define CALC_DATE 3 @@ -371,6 +373,11 @@ SvxTPView::SvxTPView(vcl::Window *pParent, VclBuilderContainer *pTopLevel) pTopLevel->get(m_pRejectAll, "rejectall"); pTopLevel->get(m_pUndo, "undo"); + // set wider window for the optional extending button labels + // eg. "Reject/Clear formatting" instead of "Reject" + EnableClearFormat(true); + EnableClearFormatAll(true); + SvSimpleTableContainer* pTable = get("changes"); Size aControlSize(80, 65); aControlSize = LogicToPixel(aControlSize, MapMode(MapUnit::MapAppFont)); @@ -483,6 +490,39 @@ void SvxTPView::EnableRejectAll(bool bFlag) m_pRejectAll->Enable(bFlag); } +void SvxTPView::EnableClearFormatButton(VclPtr pButton, bool bFlag) +{ + OUString sText = pButton->GetText(); + OUString sClearFormat = SvxResId(RID_SVXSTR_CLEARFORM); + sal_Int32 nPos = sText.indexOf(sClearFormat); + + // add or remove "Clear formatting" to get "Reject" or "Reject/Clear formatting" + if (bFlag) + { + if (nPos == -1) + { + pButton->SetText(sText + "/" + sClearFormat); + } + } + else + { + if (nPos > 0) + { + pButton->SetText(sText.copy(0, nPos - 1)); + } + } +} + +void SvxTPView::EnableClearFormat(bool bFlag) +{ + EnableClearFormatButton( m_pReject, bFlag ); +} + +void SvxTPView::EnableClearFormatAll(bool bFlag) +{ + EnableClearFormatButton( m_pRejectAll, bFlag ); +} + void SvxTPView::ShowUndo() { m_pUndo->Show(); diff --git a/svx/uiconfig/ui/acceptrejectchangesdialog.ui b/svx/uiconfig/ui/acceptrejectchangesdialog.ui index 0161bff86885..7e9817689a99 100644 --- a/svx/uiconfig/ui/acceptrejectchangesdialog.ui +++ b/svx/uiconfig/ui/acceptrejectchangesdialog.ui @@ -28,6 +28,7 @@ False True 0 + True @@ -42,6 +43,7 @@ False True 1 + True @@ -56,6 +58,7 @@ False True 2 + True @@ -70,6 +73,7 @@ False True 3 + True @@ -84,6 +88,7 @@ False True 4 + True diff --git a/sw/qa/extras/uiwriter/data2/tdf52391.fodt b/sw/qa/extras/uiwriter/data2/tdf52391.fodt new file mode 100644 index 000000000000..b61d76f716d9 --- /dev/null +++ b/sw/qa/extras/uiwriter/data2/tdf52391.fodt @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + anonymous + 2019-01-29T12:09:20 + + + + + + + anonymous + 2018-12-03T20:35:00 + + + + + + + anonymous + 2018-12-03T20:34:58 + + + + + + + + + + + + Portion1Portion2 + + Format-only change in Portion1... + ...its rejection results also acception, but now rejection clears direct formatting in its text area. + + + + diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 8a54f0a97910..93334ddc5027 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -59,6 +59,7 @@ public: void testTdf122893(); void testTdf122901(); void testTdf122942(); + void testTdf52391(); CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST(testRedlineMoveInsertInDelete); @@ -79,6 +80,7 @@ public: CPPUNIT_TEST(testTdf122893); CPPUNIT_TEST(testTdf122901); CPPUNIT_TEST(testTdf122942); + CPPUNIT_TEST(testTdf52391); CPPUNIT_TEST_SUITE_END(); private: @@ -823,6 +825,22 @@ void SwUiWriterTest2::testTdf122942() CPPUNIT_ASSERT_LESS(static_cast(0), rVert.GetPos()); } +void SwUiWriterTest2::testTdf52391() +{ + load(DATA_DIRECTORY, "tdf52391.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + lcl_dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {}); + + const uno::Reference xRun = getRun(getParagraph(1), 1); + // this was "Portion1", because the tracked background color of Portion1 was + // accepted for "Reject All". Now rejection clears formatting of the text + // in format-only changes, concatenating the text portions in the first paragraph. + CPPUNIT_ASSERT_EQUAL(OUString("Portion1Portion2"), xRun->getString()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index 5eddd00f0ebf..39a083977b96 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -654,7 +654,19 @@ namespace { if( pRedl->GetExtraData() ) pRedl->GetExtraData()->Reject( *pRedl ); - rArr.DeleteAndDestroy( rPos-- ); + + // tdf#52391 instead of hidden acception at the requested + // rejection, remove direct text formatting to get the potential + // original state of the text (FIXME if the original text + // has already contained direct text formatting: unfortunately + // ODF 1.2 doesn't support rejection of format-only changes) + if ( pRedl->GetType() == nsRedlineType_t::REDLINE_FORMAT ) + { + SwPaM aPam( *(pRedl->Start()), *(pRedl->End()) ); + rArr.DeleteAndDestroy( rPos-- ); + rDoc.ResetAttrs(aPam); + } else + rArr.DeleteAndDestroy( rPos-- ); } break; diff --git a/sw/source/uibase/misc/redlndlg.cxx b/sw/source/uibase/misc/redlndlg.cxx index 8d71eaafd69b..5c1b8156a864 100644 --- a/sw/source/uibase/misc/redlndlg.cxx +++ b/sw/source/uibase/misc/redlndlg.cxx @@ -316,10 +316,12 @@ void SwRedlineAcceptDlg::InitAuthors() } m_pTPView->EnableAccept( bEnable && bSel ); - m_pTPView->EnableReject( bEnable && bIsNotFormated && bSel ); + m_pTPView->EnableReject( bEnable && bSel ); + m_pTPView->EnableClearFormat( bEnable && !bIsNotFormated && bSel ); m_pTPView->EnableAcceptAll( bEnable ); - m_pTPView->EnableRejectAll( bEnable && - !m_bOnlyFormatedRedlines ); + m_pTPView->EnableRejectAll( bEnable ); + m_pTPView->EnableClearFormatAll( bEnable && + m_bOnlyFormatedRedlines ); } OUString SwRedlineAcceptDlg::GetRedlineText(const SwRangeRedline& rRedln, DateTime &rDateTime, sal_uInt16 nStack) @@ -793,8 +795,11 @@ void SwRedlineAcceptDlg::CallAcceptReject( bool bSelect, bool bAccept ) bool bIsNotFormatted = true; - // don't accept format-only changes secretly for Reject all - if ( !bSelect && !bAccept ) + // first remove only changes with insertion/deletion, if they exist + // (format-only changes haven't had real rejection yet, only an + // approximation: clear direct formatting, so try to warn + // with the extended button label "Reject All/Clear formatting") + if ( !bSelect && !bAccept && !m_bOnlyFormatedRedlines ) { SwRedlineTable::size_type nPosition = GetRedlinePos( *pEntry ); const SwRangeRedline& rRedln = pSh->GetRedline(nPosition); @@ -1002,8 +1007,10 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, void) } bool bEnable = !pSh->getIDocumentRedlineAccess().GetRedlinePassword().getLength(); m_pTPView->EnableAccept( bEnable && bSel /*&& !bReadonlySel*/ ); - m_pTPView->EnableReject( bEnable && bSel && bIsNotFormated /*&& !bReadonlySel*/ ); - m_pTPView->EnableRejectAll( bEnable && !m_bOnlyFormatedRedlines ); + m_pTPView->EnableReject( bEnable && bSel /*&& !bReadonlySel*/ ); + m_pTPView->EnableClearFormat( bEnable && bSel && !bIsNotFormated /*&& !bReadonlySel*/ ); + m_pTPView->EnableRejectAll( bEnable ); + m_pTPView->EnableClearFormatAll( bEnable && m_bOnlyFormatedRedlines ); } IMPL_LINK_NOARG(SwRedlineAcceptDlg, CommandHdl, SvSimpleTable*, void)