sc/inc/postit.hxx | 6 ++++-- sc/source/core/data/postit.cxx | 26 ++++++++++++++++---------- sc/source/filter/inc/commentsbuffer.hxx | 4 ++++ sc/source/filter/oox/commentsbuffer.cxx | 17 +++++++++++++++-- 4 files changed, 39 insertions(+), 14 deletions(-)
New commits: commit 8f591839b9715e186708f661c95a2cf60d63cc73 Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Tue Aug 13 05:58:51 2024 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Aug 13 15:41:13 2024 +0200 Resolves: tdf#157851 sc comments loaded incorrectly in xlsx problem: 1. when loading xlsx files, comments in that format does not store date, there for libreoffice loaded comments with current date and time. 2. Author names were not loaded at all in xlsx, and by default name of user was used as author instead Change-Id: I7b1f7fcda01565a6ba131fbae72e7d86e5eaaf15 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171805 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171809 Tested-by: Jenkins diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx index 922a1ebae748..407ee0d3ce09 100644 --- a/sc/inc/postit.hxx +++ b/sc/inc/postit.hxx @@ -113,7 +113,7 @@ public: SC_DLLPUBLIC void SetAuthor( const OUString& rAuthor ); /** Sets date and author from system settings. */ - void AutoStamp(); + void AutoStamp(bool bCreate = true); /** Returns the pointer to the current outliner object, or null. */ const OutlinerParaObject* GetOutlinerObject() const; @@ -179,13 +179,15 @@ class GenerateNoteCaption public: virtual void Generate(SdrCaptionObj& rCaptionObj) = 0; virtual OUString GetSimpleText() const = 0; + virtual OUString GetAuthorName() const = 0; virtual ~GenerateNoteCaption() {}; }; class SC_DLLPUBLIC ScNoteUtil { static ScPostIt* InsertNote(ScDocument& rDoc, const ScAddress& rPos, ScNoteData&& rNoteData, - bool bAlwaysCreateCaption, sal_uInt32 nPostItId); + bool bAlwaysCreateCaption, sal_uInt32 nPostItId, + bool bShouldAutoStamp = true); static ScNoteData CreateNoteData(ScDocument& rDoc, const ScAddress& rPos, const tools::Rectangle& rCaptionRect, bool bShown); diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx index c17e941ca683..5316d13b0fa0 100644 --- a/sc/source/core/data/postit.cxx +++ b/sc/source/core/data/postit.cxx @@ -488,11 +488,16 @@ void ScPostIt::SetAuthor( const OUString& rAuthor ) maNoteData.maAuthor = rAuthor; } -void ScPostIt::AutoStamp() +void ScPostIt::AutoStamp(bool bCreate) { - DateTime aNow(DateTime::SYSTEM); - auto const & rLocaleData = ScGlobal::getLocaleData(); - maNoteData.maDate = rLocaleData.getDate( aNow ) + " " + rLocaleData.getTime(aNow, false); + if (bCreate) + { + DateTime aNow(DateTime::SYSTEM); + auto const & rLocaleData = ScGlobal::getLocaleData(); + maNoteData.maDate = rLocaleData.getDate(aNow) + " " + rLocaleData.getTime(aNow, false); + } + if (!maNoteData.maAuthor.isEmpty()) + return; const OUString aAuthor = SvtUserOptions().GetFullName(); maNoteData.maAuthor = !aAuthor.isEmpty() ? aAuthor : ScResId(STR_CHG_UNKNOWN_AUTHOR); } @@ -845,8 +850,7 @@ rtl::Reference<SdrCaptionObj> ScNoteUtil::CreateTempCaption( else { aBuffer.append(pNote->GetAuthor() - + ", " - + pNote->GetDate()); + + (!pNote->GetDate().isEmpty() ? ", " + pNote->GetDate() : OUString())); } pNoteCaption = pNote->GetOrCreateCaption( rPos ); } @@ -975,17 +979,19 @@ ScPostIt* ScNoteUtil::CreateNoteFromGenerator( // simple text now to supply any queries for that which don't require // creation of a full Caption rInitData.maSimpleText = rInitData.mxGenerator->GetSimpleText(); - - return InsertNote(rDoc, rPos, std::move(aNoteData), /*bAlwaysCreateCaption*/false, 0/*nPostItId*/); + aNoteData.maAuthor = rInitData.mxGenerator->GetAuthorName(); + return InsertNote(rDoc, rPos, std::move(aNoteData), /*bAlwaysCreateCaption*/ false, + 0 /*nPostItId*/, false /*bShouldAutoStamp*/); } ScPostIt* ScNoteUtil::InsertNote(ScDocument& rDoc, const ScAddress& rPos, ScNoteData&& rNoteData, - bool bAlwaysCreateCaption, sal_uInt32 nPostItId) + bool bAlwaysCreateCaption, sal_uInt32 nPostItId, + bool bShouldAutoStamp) { /* Create the note and insert it into the document. If the note is visible, the caption object will be created automatically. */ ScPostIt* pNote = new ScPostIt( rDoc, rPos, std::move(rNoteData), bAlwaysCreateCaption, nPostItId ); - pNote->AutoStamp(); + pNote->AutoStamp(bShouldAutoStamp); //insert takes ownership rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote)); return pNote; diff --git a/sc/source/filter/inc/commentsbuffer.hxx b/sc/source/filter/inc/commentsbuffer.hxx index c30d6765d6f6..04baa15b0b7e 100644 --- a/sc/source/filter/inc/commentsbuffer.hxx +++ b/sc/source/filter/inc/commentsbuffer.hxx @@ -60,6 +60,8 @@ public: /** Finalizes the formatted string of the comment. */ void finalizeImport(); + OUString getAuthorName(); + private: CommentModel maModel; }; @@ -79,6 +81,8 @@ public: /** Finalizes the formatted string of all comments. */ void finalizeImport(); + std::vector<OUString> getAuthors() const; + private: typedef RefVector< Comment > CommentVector; diff --git a/sc/source/filter/oox/commentsbuffer.cxx b/sc/source/filter/oox/commentsbuffer.cxx index 25f76087876b..48550e740388 100644 --- a/sc/source/filter/oox/commentsbuffer.cxx +++ b/sc/source/filter/oox/commentsbuffer.cxx @@ -154,9 +154,11 @@ namespace css::uno::Sequence<OUString> maPropertyNames; /// import filter Caption object formatting property names css::uno::Sequence<css::uno::Any> maPropertyValues; /// import filter Caption object formatting property values std::shared_ptr<RichString> mxText; + OUString msAuthorName; - OOXGenerateNoteCaption(std::shared_ptr<RichString>& rText) + OOXGenerateNoteCaption(std::shared_ptr<RichString>& rText, const OUString& rAuthorName = "") : mxText(rText) + , msAuthorName(rAuthorName) { } @@ -182,6 +184,8 @@ namespace { return mxText->getStringContent(); } + + virtual OUString GetAuthorName() const override { return msAuthorName; } }; } @@ -199,7 +203,7 @@ void Comment::finalizeImport() rtl::Reference<ScAnnotationsObj> xAnnos = static_cast<ScAnnotationsObj*>(pAnnosSupp->getAnnotations().get()); ScDocShell* pDocShell = xAnnos->GetDocShell(); - auto xGenerator = std::make_unique<OOXGenerateNoteCaption>(maModel.mxText); + auto xGenerator = std::make_unique<OOXGenerateNoteCaption>(maModel.mxText, getAuthorName()); // Add shape formatting properties (autoFill, colHidden and rowHidden are dropped) // vvv TODO vvv TextFitToSize should be a drawing::TextFitToSizeType not bool @@ -276,6 +280,13 @@ void Comment::finalizeImport() } } +OUString Comment::getAuthorName() +{ + if (o3tl::make_unsigned(this->maModel.mnAuthorId) < getComments().getAuthors().size()) + return getComments().getAuthors()[this->maModel.mnAuthorId]; + return ""; +} + // private -------------------------------------------------------------------- CommentsBuffer::CommentsBuffer( const WorksheetHelper& rHelper ) : @@ -288,6 +299,8 @@ void CommentsBuffer::appendAuthor( const OUString& rAuthor ) maAuthors.push_back( rAuthor ); } +std::vector<OUString> CommentsBuffer::getAuthors() const { return maAuthors; } + CommentRef CommentsBuffer::createComment() { CommentRef xComment = std::make_shared<Comment>( *this );