diff options
-rw-r--r-- | sc/inc/postit.hxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/postit.cxx | 24 | ||||
-rw-r--r-- | sc/source/filter/inc/commentsbuffer.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/oox/commentsbuffer.cxx | 17 |
4 files changed, 38 insertions, 13 deletions
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 c750a16af6d3..0448bcb12f83 100644 --- a/sc/source/core/data/postit.cxx +++ b/sc/source/core/data/postit.cxx @@ -488,10 +488,15 @@ void ScPostIt::SetAuthor( const OUString& rAuthor ) maNoteData.maAuthor = rAuthor; } -void ScPostIt::AutoStamp() +void ScPostIt::AutoStamp(bool bCreate) { - maNoteData.maDate = ScGlobal::getLocaleData().getDate( Date( Date::SYSTEM ) ) + " " + - ScGlobal::getLocaleData().getTime(DateTime(DateTime::SYSTEM), false); + if (bCreate) + { + maNoteData.maDate = ScGlobal::getLocaleData().getDate(Date(Date::SYSTEM)) + " " + + ScGlobal::getLocaleData().getTime(DateTime(DateTime::SYSTEM), false); + } + if (!maNoteData.maAuthor.isEmpty()) + return; const OUString aAuthor = SvtUserOptions().GetFullName(); maNoteData.maAuthor = !aAuthor.isEmpty() ? aAuthor : ScResId(STR_CHG_UNKNOWN_AUTHOR); } @@ -840,8 +845,7 @@ rtl::Reference<SdrCaptionObj> ScNoteUtil::CreateTempCaption( else { aBuffer.append(pNote->GetAuthor() - + ", " - + pNote->GetDate()); + + (!pNote->GetDate().isEmpty() ? ", " + pNote->GetDate() : OUString())); } pNoteCaption = pNote->GetOrCreateCaption( rPos ); } @@ -970,17 +974,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 ); |