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 <jenkinscollaboraoffice@gmail.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171809 Tested-by: Jenkins
This commit is contained in:
committed by
Caolán McNamara
parent
65f311e225
commit
8f591839b9
+4
-2
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user