desktop/qa/desktop_lib/test_desktop_lib.cxx | 25 ++++ desktop/source/lib/init.cxx | 53 ++++++++++ libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 101 +++++++++++++++++++- sw/qa/extras/uiwriter/uiwriter.cxx | 33 ++++++ sw/sdi/swriter.sdi | 6 - sw/source/uibase/uiview/view2.cxx | 20 +++ 6 files changed, 230 insertions(+), 8 deletions(-)
New commits: commit 1a0fa139e50b0718a2a19ded10366af76d656058 Author: Miklos Vajna <[email protected]> Date: Wed Aug 17 15:40:14 2016 +0200 sw: allow accept/reject of redline by index Previously .uno:AcceptTrackedChange / .uno:RejectTrackedChange always worked by cursor position, but redlines are stored in the redline table, so they have a unique index. Allow specifying that index when invoking the command, and in that case ignore the cursor position. The index is not stable after an insertion / deletion. Reviewed-on: https://gerrit.libreoffice.org/28192 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins <[email protected]> (cherry picked from commit 087b71f423cf6c047137fb1316527132bb47fc05) Conflicts: sw/qa/extras/uiwriter/uiwriter.cxx Change-Id: I493a22e84800ded224fb6b9c61261744dc0fb64f diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index e30f9a8e..2b3090e 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -466,8 +466,10 @@ static void documentRedline(GtkWidget* pButton, gpointer /*pItem*/) GtkWidget* pDialog = gtk_dialog_new_with_buttons("Manage Changes", GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), GTK_DIALOG_MODAL, - "Close", - GTK_RESPONSE_OK, + "Accept", + GTK_RESPONSE_YES, + "Reject", + GTK_RESPONSE_NO, nullptr); GtkWidget* pContentArea = gtk_dialog_get_content_area(GTK_DIALOG (pDialog)); @@ -486,7 +488,7 @@ static void documentRedline(GtkWidget* pButton, gpointer /*pItem*/) -1); } GtkWidget* pTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pTreeStore)); - std::vector<std::string> aColumns = {"Index", "Type", "Comment", "Author", "Timestamp"}; + std::vector<std::string> aColumns = {"Index", "Author", "Type", "Comment", "Timestamp"}; for (size_t nColumn = 0; nColumn < aColumns.size(); ++nColumn) { GtkCellRenderer* pRenderer = gtk_cell_renderer_text_new(); @@ -500,7 +502,38 @@ static void documentRedline(GtkWidget* pButton, gpointer /*pItem*/) // Show the dialog. gtk_widget_show_all(pDialog); - gtk_dialog_run(GTK_DIALOG(pDialog)); + gint res = gtk_dialog_run(GTK_DIALOG(pDialog)); + + // Dispatch the matching command, if necessary. + if (res == GTK_RESPONSE_YES || res == GTK_RESPONSE_NO) + { + GtkTreeSelection* pSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pTreeView)); + GtkTreeIter aTreeIter; + GtkTreeModel* pTreeModel; + if (gtk_tree_selection_get_selected(pSelection, &pTreeModel, &aTreeIter)) + { + gint nIndex = 0; + // 0: index + gtk_tree_model_get(pTreeModel, &aTreeIter, 0, &nIndex, -1); + std::string aCommand; + if (res == GTK_RESPONSE_YES) + aCommand = ".uno:AcceptTrackedChange"; + else + aCommand = ".uno:RejectTrackedChange"; + // Without the '.uno:' prefix. + std::string aKey = aCommand.substr(strlen(".uno:")); + + // Post the command. + boost::property_tree::ptree aCommandTree; + aCommandTree.put(boost::property_tree::ptree::path_type(aKey + "/type", '/'), "unsigned short"); + aCommandTree.put(boost::property_tree::ptree::path_type(aKey + "/value", '/'), nIndex); + + aStream.str(std::string()); + boost::property_tree::write_json(aStream, aCommandTree); + std::string aArguments = aStream.str(); + lok_doc_view_post_command(pDocView, aCommand.c_str(), aArguments.c_str(), false); + } + } gtk_widget_destroy(pDialog); } diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index ca524d3..b6838bd 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -188,6 +188,7 @@ public: void testTdf99004(); void testTdf84695(); void testClassificationPaste(); + void testRedlineParam(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -281,6 +282,7 @@ public: CPPUNIT_TEST(testTdf99004); CPPUNIT_TEST(testTdf84695); CPPUNIT_TEST(testClassificationPaste); + CPPUNIT_TEST(testRedlineParam); CPPUNIT_TEST_SUITE_END(); private: @@ -3261,6 +3263,37 @@ void SwUiWriterTest::testClassificationPaste() xSourceComponent->dispose(); } +void SwUiWriterTest::testRedlineParam() +{ + // Create a document with minimal content. + SwDoc* pDoc = createDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Insert("middle"); + + // Turn on track changes, and add changes to the start and end of the document. + uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true)); + pWrtShell->SttDoc(); + pWrtShell->Insert("aaa"); + pWrtShell->EndDoc(); + pWrtShell->Insert("zzz"); + + // Move the cursor to the start again, and reject the second change. + pWrtShell->SttDoc(); + uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( + { + {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(1))} + })); + lcl_dispatchCommand(mxComponent, ".uno:RejectTrackedChange", aPropertyValues); + Scheduler::ProcessEventsToIdle(); + SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false); + + // This was 'middlezzz', the uno command rejected the redline under the + // cursor, instead of the requested one. + CPPUNIT_ASSERT_EQUAL(OUString("aaamiddle"), pShellCursor->GetPoint()->nNode.GetNode().GetTextNode()->GetText()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index a80d38c..f7e7291 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -9924,6 +9924,7 @@ SfxBoolItem SpellingAndGrammarDialog FN_SPELL_GRAMMAR_DIALOG ] SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT +( SfxUInt16Item AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT ) [ /* flags: */ AutoUpdate = FALSE, @@ -9938,8 +9939,6 @@ SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT RecordPerSet; Asynchron; - Readonly = FALSE, - /* config: */ AccelConfig = TRUE, MenuConfig = TRUE, @@ -9949,6 +9948,7 @@ SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT ] SfxVoidItem RejectTrackedChange FN_REDLINE_REJECT_DIRECT +( SfxUInt16Item RejectTrackedChange FN_REDLINE_REJECT_DIRECT ) [ /* flags: */ AutoUpdate = FALSE, @@ -9963,8 +9963,6 @@ SfxVoidItem RejectTrackedChange FN_REDLINE_REJECT_DIRECT RecordPerSet; Asynchron; - Readonly = FALSE, - /* config: */ AccelConfig = TRUE, MenuConfig = TRUE, diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index 207da4d..69e7dc9 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -673,7 +673,11 @@ void SwView::Execute(SfxRequest &rReq) { SwDoc *pDoc = m_pWrtShell->GetDoc(); SwPaM *pCursor = m_pWrtShell->GetCursor(); - if( pCursor->HasMark()) + sal_uInt16 nRedline = USHRT_MAX; + if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET) + nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + + if( pCursor->HasMark() && nRedline == USHRT_MAX) { if (FN_REDLINE_ACCEPT_DIRECT == nSlot) m_pWrtShell->AcceptRedlinesInSelection(); @@ -686,8 +690,18 @@ void SwView::Execute(SfxRequest &rReq) // This ensures we work properly with FN_REDLINE_NEXT_CHANGE, which leaves the // point at the *end* of the redline and the mark at the start (so GetRedline // would return NULL if called on the point) - sal_uInt16 nRedline = 0; - const SwRangeRedline *pRedline = pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline); + const SwRangeRedline* pRedline = nullptr; + if (nRedline < USHRT_MAX) + { + // A redline was explicitly requested by specifying an + // index, don't guess based on the cursor position. + const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); + if (nRedline < rTable.size()) + pRedline = rTable[nRedline]; + } + else + pRedline = pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline); + assert(pRedline != nullptr); if (pRedline) { commit 1fe18e95c56e66812b7d7c0e0d18ad4829dd5aa1 Author: Miklos Vajna <[email protected]> Date: Wed Aug 17 12:17:19 2016 +0200 lok::Document::getCommandValues: expose redline info Index is added as a property for each item, so that later changes can be identified by the index when they are accepted/rejected. Change-Id: I9362d208fdbed1f46d64558d44498d2b19150c81 (cherry picked from commit 69fb6a307172e244497bc618a102afccdd7c93b7) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 5a34036..29b3d02 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -92,6 +92,7 @@ public: void testContextMenuWriter(); void testContextMenuImpress(); void testNotificationCompression(); + void testRedlineWriter(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testModifiedStatus); @@ -119,6 +120,7 @@ public: CPPUNIT_TEST(testContextMenuWriter); CPPUNIT_TEST(testContextMenuImpress); CPPUNIT_TEST(testNotificationCompression); + CPPUNIT_TEST(testRedlineWriter); CPPUNIT_TEST_SUITE_END(); uno::Reference<lang::XComponent> mxComponent; @@ -1149,6 +1151,29 @@ void DesktopLOKTest::testNotificationCompression() CPPUNIT_ASSERT_EQUAL(std::string("1"), std::get<1>(notifs[i++])); } +void DesktopLOKTest::testRedlineWriter() +{ + // Load a Writer document, enable change recording and press a key. + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true)); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 't', 0); + + // Get redline info. + boost::property_tree::ptree aTree; + char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:AcceptTrackedChanges"); + std::stringstream aStream(pJSON); + free(pJSON); + CPPUNIT_ASSERT(!aStream.str().empty()); + boost::property_tree::read_json(aStream, aTree); + // Make sure that pressing a key creates exactly one redline. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aTree.get_child("redlines").size()); + + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 851fc91..cc2ab9f 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -52,6 +52,7 @@ #include <com/sun/star/util/URLTransformer.hpp> #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> #include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/document/XRedlinesSupplier.hpp> #include <editeng/fontitem.hxx> #include <editeng/flstitem.hxx> @@ -83,6 +84,7 @@ #include <comphelper/sequence.hxx> #include <sfx2/sfxbasemodel.hxx> #include <svl/undo.hxx> +#include <unotools/datetime.hxx> #include <app.hxx> @@ -1826,8 +1828,55 @@ static char* getUndoOrRedo(LibreOfficeKitDocument* pThis, UndoOrRedo eCommand) return pJson; } +/// Returns the JSON representation of the redline stack. +static char* getTrackedChanges(LibreOfficeKitDocument* pThis) +{ + LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); + + uno::Reference<document::XRedlinesSupplier> xRedlinesSupplier(pDocument->mxComponent, uno::UNO_QUERY); + if (!xRedlinesSupplier.is()) + return nullptr; + + uno::Reference<container::XEnumeration> xRedlines = xRedlinesSupplier->getRedlines()->createEnumeration(); + boost::property_tree::ptree aRedlines; + for (size_t nIndex = 0; xRedlines->hasMoreElements(); ++nIndex) + { + uno::Reference<beans::XPropertySet> xRedline(xRedlines->nextElement(), uno::UNO_QUERY); + boost::property_tree::ptree aRedline; + aRedline.put("index", nIndex); + + OUString sAuthor; + xRedline->getPropertyValue("RedlineAuthor") >>= sAuthor; + aRedline.put("author", sAuthor.toUtf8().getStr()); + + OUString sType; + xRedline->getPropertyValue("RedlineType") >>= sType; + aRedline.put("type", sType.toUtf8().getStr()); + + OUString sComment; + xRedline->getPropertyValue("RedlineComment") >>= sComment; + aRedline.put("comment", sComment.toUtf8().getStr()); + + util::DateTime aDateTime; + xRedline->getPropertyValue("RedlineDateTime") >>= aDateTime; + OUString sDateTime = utl::toISO8601(aDateTime); + aRedline.put("dateTime", sDateTime.toUtf8().getStr()); + + aRedlines.push_back(std::make_pair("", aRedline)); + } + + boost::property_tree::ptree aTree; + aTree.add_child("redlines", aRedlines); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + char* pJson = strdup(aStream.str().c_str()); + return pJson; +} + static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand) { + SolarMutexGuard aGuard; + OString aCommand(pCommand); static const OString aViewRowColumnHeaders(".uno:ViewRowColumnHeaders"); static const OString aCellCursor(".uno:CellCursor"); @@ -1848,6 +1897,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo { return getUndoOrRedo(pThis, UndoOrRedo::REDO); } + else if (aCommand == ".uno:AcceptTrackedChanges") + { + return getTrackedChanges(pThis); + } else if (aCommand.startsWith(aViewRowColumnHeaders)) { ITiledRenderable* pDoc = getTiledRenderable(pThis); diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index b52c256..e30f9a8e 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -445,13 +445,73 @@ static void addMoreUnoParam(GtkWidget* /*pWidget*/, gpointer userdata) gtk_widget_show_all(pUnoParamAreaBox); } +/// Exposes the info returned for tracked changes. +static void documentRedline(GtkWidget* pButton, gpointer /*pItem*/) +{ + TiledWindow& rWindow = lcl_getTiledWindow(pButton); + LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView); + // Get the data. + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pDocView); + char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:AcceptTrackedChanges"); + std::stringstream aInfo; + aInfo << "lok::Document::getCommandValues('.uno:AcceptTrackedChanges') returned '" << pValues << "'" << std::endl; + g_info("%s", aInfo.str().c_str()); + std::stringstream aStream(pValues); + free(pValues); + assert(!aStream.str().empty()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + // Create the dialog. + GtkWidget* pDialog = gtk_dialog_new_with_buttons("Manage Changes", + GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), + GTK_DIALOG_MODAL, + "Close", + GTK_RESPONSE_OK, + nullptr); + GtkWidget* pContentArea = gtk_dialog_get_content_area(GTK_DIALOG (pDialog)); + + // Build the table. + GtkTreeStore* pTreeStore = gtk_tree_store_new(5, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + for (const auto& rValue : aTree.get_child("redlines")) + { + GtkTreeIter aTreeIter; + gtk_tree_store_append(pTreeStore, &aTreeIter, nullptr); + gtk_tree_store_set(pTreeStore, &aTreeIter, + 0, rValue.second.get<int>("index"), + 1, rValue.second.get<std::string>("author").c_str(), + 2, rValue.second.get<std::string>("type").c_str(), + 3, rValue.second.get<std::string>("comment").c_str(), + 4, rValue.second.get<std::string>("dateTime").c_str(), + -1); + } + GtkWidget* pTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pTreeStore)); + std::vector<std::string> aColumns = {"Index", "Type", "Comment", "Author", "Timestamp"}; + for (size_t nColumn = 0; nColumn < aColumns.size(); ++nColumn) + { + GtkCellRenderer* pRenderer = gtk_cell_renderer_text_new(); + GtkTreeViewColumn* pColumn = gtk_tree_view_column_new_with_attributes(aColumns[nColumn].c_str(), + pRenderer, + "text", nColumn, + nullptr); + gtk_tree_view_append_column(GTK_TREE_VIEW(pTreeView), pColumn); + } + gtk_box_pack_start(GTK_BOX(pContentArea), pTreeView, TRUE, TRUE, 2); + + // Show the dialog. + gtk_widget_show_all(pDialog); + gtk_dialog_run(GTK_DIALOG(pDialog)); + + gtk_widget_destroy(pDialog); +} + static void documentRepair(GtkWidget* pButton, gpointer /*pItem*/) { TiledWindow& rWindow = lcl_getTiledWindow(pButton); LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView); // Get the data. LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pDocView); - // How it in linear time, so first redo in reverse order, then undo. + // Show it in linear time, so first redo in reverse order, then undo. std::vector<std::string> aTypes = {".uno:Redo", ".uno:Undo"}; std::vector<boost::property_tree::ptree> aTrees; for (size_t nType = 0; nType < aTypes.size(); ++nType) @@ -1410,6 +1470,12 @@ static GtkWidget* createWindow(TiledWindow& rWindow) gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pDocumentRepair, -1); g_signal_connect(G_OBJECT(pDocumentRepair), "clicked", G_CALLBACK(documentRepair), nullptr); + GtkToolItem* pDocumentRedline = gtk_tool_button_new(nullptr, nullptr); + gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pDocumentRedline), "system-run"); + gtk_tool_item_set_tooltip_text(pDocumentRedline, "Document redlines"); + gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pDocumentRedline, -1); + g_signal_connect(G_OBJECT(pDocumentRedline), "clicked", G_CALLBACK(documentRedline), nullptr); + gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), gtk_separator_tool_item_new(), -1); // Find. _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
