cool#13988 sw redline render mode: expose old/new author/date when comparing
Document compare works best when you open the new document, then perform document compare taking the old document as a parameter. This way insertions and deletions are correct (instead of being the other way around.) This is not intuitive, so help a LOK client provide hints to the user by exposing the last modified date and the last modifying user when comparing. Unfortunately this info is just available when comparing, so we can't send it again on document load, since the "this document" model doesn't have both the old and new metadata, we only compare content. Change-Id: I24c1968ea359536efbe26d7a673374ad42c2ff83 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199464 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -9,7 +9,13 @@
|
||||
|
||||
#include <swmodeltestbase.hxx>
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
#include <editeng/wghtitem.hxx>
|
||||
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
||||
#include <test/lokcallback.hxx>
|
||||
#include <comphelper/propertyvalue.hxx>
|
||||
#include <sfx2/lokhelper.hxx>
|
||||
|
||||
#include <docsh.hxx>
|
||||
#include <view.hxx>
|
||||
@@ -32,6 +38,33 @@ public:
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// LOK view callback for test purposes.
|
||||
struct ViewCallback
|
||||
{
|
||||
std::vector<OUString> m_aStateChanges;
|
||||
|
||||
static void callback(int nType, const char* pPayload, void* pData);
|
||||
void callbackImpl(int nType, const char* pPayload);
|
||||
};
|
||||
|
||||
void ViewCallback::callback(int nType, const char* pPayload, void* pData)
|
||||
{
|
||||
static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
|
||||
}
|
||||
|
||||
void ViewCallback::callbackImpl(int nType, const char* pPayload)
|
||||
{
|
||||
switch (nType)
|
||||
{
|
||||
case LOK_CALLBACK_STATE_CHANGED:
|
||||
{
|
||||
OUString aPayload = OUString::fromUtf8(pPayload);
|
||||
m_aStateChanges.push_back(aPayload);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(Test, testRedlineHidden)
|
||||
@@ -451,6 +484,53 @@ CPPUNIT_TEST_FIXTURE(Test, testRedlineReinstateSelf)
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rRedlines.size());
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(Test, testDocumentCompareCallback)
|
||||
{
|
||||
// Set up LOK:
|
||||
comphelper::LibreOfficeKit::setActive(true);
|
||||
|
||||
// Given a new document:
|
||||
createSwDoc("compare-new.odt");
|
||||
SwDocShell* pDocShell = getSwDocShell();
|
||||
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
|
||||
ViewCallback aCallback;
|
||||
TestLokCallbackWrapper aCallbackWrapper(&ViewCallback::callback, &aCallback);
|
||||
pWrtShell->GetSfxViewShell()->setLibreOfficeKitViewCallback(&aCallbackWrapper);
|
||||
aCallbackWrapper.setLOKViewId(SfxLokHelper::getView(*pWrtShell->GetSfxViewShell()));
|
||||
|
||||
// When comparing with an old document:
|
||||
OUString aOther = createFileURL(u"compare-old.odt");
|
||||
uno::Sequence<beans::PropertyValue> aArgs = {
|
||||
comphelper::makePropertyValue("URL", aOther),
|
||||
comphelper::makePropertyValue("NoAcceptDialog", true),
|
||||
};
|
||||
dispatchCommand(mxComponent, ".uno:CompareDocuments", aArgs);
|
||||
|
||||
// Then make sure a JSON callback with the expected content is emitted:
|
||||
auto it = std::find_if(aCallback.m_aStateChanges.begin(), aCallback.m_aStateChanges.end(),
|
||||
[](const OUString& i) -> bool { return i.startsWith("{"); });
|
||||
CPPUNIT_ASSERT(it != aCallback.m_aStateChanges.end());
|
||||
std::stringstream aStream((std::string(it->toUtf8())));
|
||||
boost::property_tree::ptree aTree;
|
||||
boost::property_tree::read_json(aStream, aTree);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("CompareDocumentsProperties"),
|
||||
aTree.get<std::string>("commandName"));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Alice"),
|
||||
aTree.get<std::string>("state.metadata.otherDocument.modifiedBy"));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("2010-02-12T13:51:17.860434211"),
|
||||
aTree.get<std::string>("state.metadata.otherDocument.modificationDate"));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Bob"),
|
||||
aTree.get<std::string>("state.metadata.thisDocument.modifiedBy"));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("2026-02-12T13:52:55.923182809"),
|
||||
aTree.get<std::string>("state.metadata.thisDocument.modificationDate"));
|
||||
|
||||
// Tear down LOK:
|
||||
pWrtShell->GetSfxViewShell()->setLibreOfficeKitViewCallback(nullptr);
|
||||
mxComponent->dispose();
|
||||
mxComponent.clear();
|
||||
comphelper::LibreOfficeKit::setActive(false);
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
|
||||
|
||||
#include <hintids.hxx>
|
||||
#include <osl/diagnose.h>
|
||||
#include <vcl/commandevent.hxx>
|
||||
@@ -27,6 +29,9 @@
|
||||
#include <i18nutil/guessparadirection.hxx>
|
||||
#include <editeng/autodiritem.hxx>
|
||||
#include <editeng/frmdiritem.hxx>
|
||||
#include <tools/json_writer.hxx>
|
||||
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
||||
#include <sax/tools/converter.hxx>
|
||||
#include <fmtsrnd.hxx>
|
||||
#include <fmtinfmt.hxx>
|
||||
#include <txtinet.hxx>
|
||||
@@ -59,6 +64,7 @@
|
||||
#include <SwNodeNum.hxx>
|
||||
#include <unocrsr.hxx>
|
||||
#include <calbck.hxx>
|
||||
#include <docsh.hxx>
|
||||
|
||||
using namespace com::sun::star;
|
||||
|
||||
@@ -888,11 +894,57 @@ sal_Int32 SwEditShell::GetLineCount()
|
||||
return nRet;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/// Write document compare metadata about rDoc into rWriter.
|
||||
void WriteCompareDocMetadata(tools::JsonWriter& rWriter, const SwDoc& rDoc)
|
||||
{
|
||||
const SwDocShell* pDocShell = rDoc.GetDocShell();
|
||||
if (!pDocShell)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(pDocShell->GetModel(),
|
||||
uno::UNO_QUERY);
|
||||
uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
|
||||
rWriter.put("modifiedBy", xDocProps->getModifiedBy());
|
||||
|
||||
util::DateTime aModificationDate = xDocProps->getModificationDate();
|
||||
OUStringBuffer aBuffer;
|
||||
sax::Converter::convertDateTime(aBuffer, aModificationDate, nullptr, true);
|
||||
rWriter.put("modificationDate", aBuffer.makeStringAndClear());
|
||||
}
|
||||
}
|
||||
|
||||
tools::Long SwEditShell::CompareDoc( const SwDoc& rDoc )
|
||||
{
|
||||
SwDoc* pThisDoc = GetDoc();
|
||||
StartAllAction();
|
||||
tools::Long nRet = GetDoc()->CompareDoc( rDoc );
|
||||
tools::Long nRet = pThisDoc->CompareDoc( rDoc );
|
||||
EndAllAction();
|
||||
|
||||
SfxViewShell* pSfxViewShell = GetSfxViewShell();
|
||||
if (pSfxViewShell && pSfxViewShell->getLibreOfficeKitViewCallback())
|
||||
{
|
||||
tools::JsonWriter aWriter;
|
||||
aWriter.put("commandName", "CompareDocumentsProperties");
|
||||
{
|
||||
auto aState = aWriter.startNode("state");
|
||||
auto aMetadata = aWriter.startNode("metadata");
|
||||
{
|
||||
auto aDocument = aWriter.startNode("otherDocument");
|
||||
WriteCompareDocMetadata(aWriter, rDoc);
|
||||
}
|
||||
{
|
||||
auto aDocument = aWriter.startNode("thisDocument");
|
||||
WriteCompareDocMetadata(aWriter, *pThisDoc);
|
||||
}
|
||||
}
|
||||
OString aPayload = aWriter.finishAndGetAsOString();
|
||||
pSfxViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aPayload);
|
||||
}
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user