compilerplugins/clang/test/trivialconstructor.cxx | 46 ++++++++++++++++++++++ compilerplugins/clang/trivialconstructor.cxx | 16 +++++-- solenv/CompilerTest_compilerplugins_clang.mk | 1 sw/inc/redline.hxx | 3 + sw/inc/strings.hrc | 2 sw/qa/uitest/writer_tests/trackedChanges.py | 31 ++++++++++++++ sw/source/core/doc/docredln.cxx | 14 ++++++ sw/source/uibase/misc/redlndlg.cxx | 6 -- 8 files changed, 111 insertions(+), 8 deletions(-)
New commits: commit 3a14b2040ecd95a23acbc3e8d0f8087505135f11 Author: László Németh <nem...@numbertext.org> AuthorDate: Wed Mar 16 14:29:34 2022 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Mar 16 16:09:47 2022 +0100 tdf#148032 sw: add redline comment for tracked comments Tracked insertion/deletion of comments were shown as plain text insertion/deletion in that case, too, when there is no other text change in the redline (only the invisible placeholder character CH_TXTATR_INWORD of the comment). This was fixed by the new action icons of the Manage Changes dialog window before, but for better accessibility, now redline of a newly inserted/deleted comment gets also a redline comment "Comment added"/"Comment deleted", shown in Manage Changes dialog window with the Comment added/Comment deleted action icons, as suggested by Heiko Tietze. Note: because the redline comment (at least the tracked insertions) are stored in the document, this is a back-compatible solution. Follow-up to commit 128d3b454467e34538903b2eab45e866f976b314 "tdf#73125 sw: add Insert/Delete Comment Manage Changes action icons". Change-Id: I7a9e82ae1b9519e4883956f69de0aafc289f7f99 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131659 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx index 5e01cfa8349f..37c7e536d52c 100644 --- a/sw/inc/redline.hxx +++ b/sw/inc/redline.hxx @@ -208,6 +208,9 @@ public: OUString const & GetAuthorString( sal_uInt16 nPos = 0 ) const; const DateTime& GetTimeStamp( sal_uInt16 nPos = 0) const; RedlineType GetType( sal_uInt16 nPos = 0 ) const; + // text content of the redline is only an annotation placeholder + // (i.e. a comment, but don't confuse it with comment of the redline) + bool IsAnnotation() const; const OUString& GetComment( sal_uInt16 nPos = 0 ) const; void SetComment( const OUString& rS ) { m_pRedlineData->SetComment( rS ); } diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index afcbbb86335e..b9a5cd8b6d82 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -1280,6 +1280,8 @@ #define STR_REDLINE_FORMATTED NC_("STR_REDLINE_FORMATTED", "Formats") #define STR_REDLINE_TABLECHG NC_("STR_REDLINE_TABLECHG", "Table Changes") #define STR_REDLINE_FMTCOLLSET NC_("STR_REDLINE_FMTCOLLSET", "Applied Paragraph Styles") +#define STR_REDLINE_COMMENT_ADDED NC_("STR_REDLINE_COMMENT_ADDED", "Comment added") +#define STR_REDLINE_COMMENT_DELETED NC_("STR_REDLINE_COMMENT_DELETED", "Comment deleted") #define STR_PAGE NC_("STR_PAGE", "Page ") #define STR_PAGE_COUNT NC_("STR_PAGE_COUNT", "Page %1 of %2") #define STR_PAGE_COUNT_CUSTOM NC_("STR_PAGE_COUNT_CUSTOM", "Page %1 of %2 (Page %3)") diff --git a/sw/qa/uitest/writer_tests/trackedChanges.py b/sw/qa/uitest/writer_tests/trackedChanges.py index 58f4957cc03d..c04034e7149b 100644 --- a/sw/qa/uitest/writer_tests/trackedChanges.py +++ b/sw/qa/uitest/writer_tests/trackedChanges.py @@ -10,6 +10,7 @@ # tests for tracked changes ; tdf912270 from uitest.framework import UITestCase from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, type_text +from libreoffice.uno.propertyvalue import mkPropertyValues class trackedchanges(UITestCase): @@ -322,4 +323,34 @@ class trackedchanges(UITestCase): tables = document.getTextTables() self.assertEqual(3, len(tables)) + def test_tdf148032(self): + + with self.ui_test.load_file(get_url_for_data_file("trackedChanges.odt")) as document: + + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + + # adding new Comment + self.xUITest.executeCommand(".uno:InsertAnnotation") + + # wait until the comment is available + xComment1 = self.ui_test.wait_until_child_is_available('Comment1') + + xEditView1 = xComment1.getChild("editview") + xEditView1.executeAction("TYPE", mkPropertyValues({"TEXT": "This is the First Comment"})) + self.assertEqual(get_state_as_dict(xComment1)["Text"], "This is the First Comment" ) + self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" ) + self.assertEqual(get_state_as_dict(xComment1)["Author"], "Unknown Author" ) + self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" ) + + xComment1.executeAction("LEAVE", mkPropertyValues({})) + + with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg: + changesList = xTrackDlg.getChild("writerchanges") + self.assertEqual(6, len(changesList.getChildren())) + + xChild = changesList.getChild(0) + # This was False (missing comment) + self.assertEqual(True, get_state_as_dict(xChild)["Text"].endswith('\tComment added')) + # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index c6d469678fa3..bb139a1b1781 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -53,6 +53,7 @@ #include <viscrs.hxx> #include <rootfrm.hxx> #include <strings.hrc> +#include <swtypes.hxx> #include <wrtsh.hxx> #include <txtfld.hxx> @@ -1103,6 +1104,14 @@ SwRangeRedline::SwRangeRedline(RedlineType eTyp, const SwPaM& rPam ) m_bIsVisible = true; if( !rPam.HasMark() ) DeleteMark(); + + // set default comment for single annotations added or deleted + if ( IsAnnotation() ) + { + SetComment( RedlineType::Delete == eTyp + ? SwResId(STR_REDLINE_COMMENT_DELETED) + : SwResId(STR_REDLINE_COMMENT_ADDED) ); + } } SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam ) @@ -1912,6 +1921,11 @@ RedlineType SwRangeRedline::GetType( sal_uInt16 nPos ) const return GetRedlineData(nPos).m_eType; } +bool SwRangeRedline::IsAnnotation() const +{ + return GetText().getLength() == 1 && GetText()[0] == CH_TXTATR_INWORD; +} + const OUString& SwRangeRedline::GetComment( sal_uInt16 nPos ) const { return GetRedlineData(nPos).m_sComment; diff --git a/sw/source/uibase/misc/redlndlg.cxx b/sw/source/uibase/misc/redlndlg.cxx index b18123d89ec9..538467c8561c 100644 --- a/sw/source/uibase/misc/redlndlg.cxx +++ b/sw/source/uibase/misc/redlndlg.cxx @@ -308,16 +308,14 @@ OUString SwRedlineAcceptDlg::GetActionImage(const SwRangeRedline& rRedln, sal_uI ? OUString(BMP_REDLINE_ROW_INSERTION) : rRedln.IsMoved() ? OUString(BMP_REDLINE_MOVED_INSERTION) - : ( rRedln.GetText().getLength() == 1 && - rRedln.GetText()[0] == CH_TXTATR_INWORD ) + : rRedln.IsAnnotation() ? OUString(BMP_REDLINE_COMMENT_INSERTION) : OUString(BMP_REDLINE_INSERTED); case RedlineType::Delete: return bRowChanges ? OUString(BMP_REDLINE_ROW_DELETION) : rRedln.IsMoved() ? OUString(BMP_REDLINE_MOVED_DELETION) - : ( rRedln.GetText().getLength() == 1 && - rRedln.GetText()[0] == CH_TXTATR_INWORD ) + : rRedln.IsAnnotation() ? OUString(BMP_REDLINE_COMMENT_DELETION) : OUString(BMP_REDLINE_DELETED); case RedlineType::Format: return BMP_REDLINE_FORMATTED; commit 0c50141cfc475768debb77127bc8ebb173b4a30f Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Wed Mar 16 14:23:07 2022 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Wed Mar 16 16:09:34 2022 +0100 Fix loplugin:trivialconstructor handling of ctor templates Change-Id: Ic8b2f26498099c77b834d8e152f06d2834dfee3a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131658 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/test/trivialconstructor.cxx b/compilerplugins/clang/test/trivialconstructor.cxx new file mode 100644 index 000000000000..ef17e9c60fee --- /dev/null +++ b/compilerplugins/clang/test/trivialconstructor.cxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +struct S1 +{ + // expected-error@+1 {{no need for explicit constructor decl [loplugin:trivialconstructor]}} + S1() {} +}; + +struct S2 +{ + S2() {} + S2(int) {} +}; + +struct S3 +{ + S3() {} + template <typename T> S3(T); +}; + +template <typename> struct S4 +{ + // expected-error@+1 {{no need for explicit constructor decl [loplugin:trivialconstructor]}} + S4() {} +}; + +template <typename> struct S5 +{ + S5() {} + S5(int); +}; + +template <typename> struct S6 +{ + S6() {} + template <typename T> S6(T); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/trivialconstructor.cxx b/compilerplugins/clang/trivialconstructor.cxx index 6f5bb640b760..dd830058fac9 100644 --- a/compilerplugins/clang/trivialconstructor.cxx +++ b/compilerplugins/clang/trivialconstructor.cxx @@ -65,13 +65,21 @@ bool TrivialConstructor::VisitCXXConstructorDecl(CXXConstructorDecl const* const const CXXRecordDecl* recordDecl = constructorDecl->getParent(); if (std::distance(recordDecl->ctor_begin(), recordDecl->ctor_end()) != 1) return true; + // Constructor templates are not included in ctor_begin()..ctor_end() above, so also do a slow + // check across all decls(): + for (auto d : recordDecl->decls()) + { + if (auto const d2 = dyn_cast<FunctionTemplateDecl>(d)) + { + if (isa<CXXConstructorDecl>(d2->getTemplatedDecl())) + { + return true; + } + } + } if (!HasTrivialConstructorBody(recordDecl, recordDecl)) return true; - // template magic in sc/inc/stlalgorithm.hxx - if (recordDecl->getIdentifier() && recordDecl->getName() == "AlignedAllocator") - return true; - report(DiagnosticsEngine::Warning, "no need for explicit constructor decl", constructorDecl->getLocation()) << constructorDecl->getSourceRange(); diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk index b95771b75dff..2520dd2192e9 100644 --- a/solenv/CompilerTest_compilerplugins_clang.mk +++ b/solenv/CompilerTest_compilerplugins_clang.mk @@ -94,6 +94,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \ compilerplugins/clang/test/stringstatic \ compilerplugins/clang/test/stringview \ compilerplugins/clang/test/stringviewparam \ + compilerplugins/clang/test/trivialconstructor \ compilerplugins/clang/test/trivialdestructor \ compilerplugins/clang/test/typedefparam \ compilerplugins/clang/test/typeidcomparison \