Kaydet (Commit) 288013f2 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw: emit LOK_CALLBACK_STATE_CHANGED when cursor enters/leaves a redline

For now only care about the start of the cursor, which can be only at a
single redline.

Add matching testcase + expose it in the gtktiledviewer status bar for
interactive manual testing.

Change-Id: Ib61757412d6b54bef64361d4a8563795ca0bab6c
üst aa51bf1e
...@@ -1203,6 +1203,7 @@ static void doc_iniUnoCommands () ...@@ -1203,6 +1203,7 @@ static void doc_iniUnoCommands ()
OUString(".uno:SortAscending"), OUString(".uno:SortAscending"),
OUString(".uno:SortDescending"), OUString(".uno:SortDescending"),
OUString(".uno:TrackChanges"), OUString(".uno:TrackChanges"),
OUString(".uno:AcceptTrackedChange"),
}; };
util::URL aCommandURL; util::URL aCommandURL;
......
...@@ -97,6 +97,7 @@ public: ...@@ -97,6 +97,7 @@ public:
GtkWidget* m_pStatusBar; GtkWidget* m_pStatusBar;
GtkWidget* m_pProgressBar; GtkWidget* m_pProgressBar;
GtkWidget* m_pStatusbarLabel; GtkWidget* m_pStatusbarLabel;
GtkWidget* m_pRedlineLabel;
GtkWidget* m_pZoomLabel; GtkWidget* m_pZoomLabel;
GtkToolItem* m_pSaveButton; GtkToolItem* m_pSaveButton;
GtkToolItem* m_pCopyButton; GtkToolItem* m_pCopyButton;
...@@ -145,6 +146,7 @@ public: ...@@ -145,6 +146,7 @@ public:
m_pStatusBar(nullptr), m_pStatusBar(nullptr),
m_pProgressBar(nullptr), m_pProgressBar(nullptr),
m_pStatusbarLabel(nullptr), m_pStatusbarLabel(nullptr),
m_pRedlineLabel(nullptr),
m_pZoomLabel(nullptr), m_pZoomLabel(nullptr),
m_pSaveButton(nullptr), m_pSaveButton(nullptr),
m_pCopyButton(nullptr), m_pCopyButton(nullptr),
...@@ -786,7 +788,7 @@ static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ ) ...@@ -786,7 +788,7 @@ static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
lok_doc_view_set_visible_area(LOK_DOC_VIEW(pDocView), &aVisibleArea); lok_doc_view_set_visible_area(LOK_DOC_VIEW(pDocView), &aVisibleArea);
} }
} }
std::string aZoom = std::to_string(int(fZoom * 100)) + std::string("%"); std::string aZoom = std::string("Zoom: ") + std::to_string(int(fZoom * 100)) + std::string("%");
gtk_label_set_text(GTK_LABEL(rWindow.m_pZoomLabel), aZoom.c_str()); gtk_label_set_text(GTK_LABEL(rWindow.m_pZoomLabel), aZoom.c_str());
} }
...@@ -1159,6 +1161,15 @@ static void signalCommand(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pD ...@@ -1159,6 +1161,15 @@ static void signalCommand(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pD
rWindow.m_aToolItemSensitivities[pItem] = bSensitive; rWindow.m_aToolItemSensitivities[pItem] = bSensitive;
} }
} }
else if (aKey == ".uno:TrackedChangeIndex")
{
std::string aText = std::string("Current redline: ");
if (aValue.empty())
aText += "none";
else
aText += aValue;
gtk_label_set_text(GTK_LABEL(rWindow.m_pRedlineLabel), aText.c_str());
}
} }
} }
...@@ -1800,7 +1811,9 @@ static GtkWidget* createWindow(TiledWindow& rWindow) ...@@ -1800,7 +1811,9 @@ static GtkWidget* createWindow(TiledWindow& rWindow)
gtk_widget_set_hexpand(rWindow.m_pStatusbarLabel, TRUE); gtk_widget_set_hexpand(rWindow.m_pStatusbarLabel, TRUE);
gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pStatusbarLabel); gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pStatusbarLabel);
rWindow.m_pZoomLabel = gtk_label_new("100%"); rWindow.m_pRedlineLabel = gtk_label_new("Current redline: none");
gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pRedlineLabel);
rWindow.m_pZoomLabel = gtk_label_new("Zoom: 100%");
gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pZoomLabel); gtk_container_add(GTK_CONTAINER(pStatusBar), rWindow.m_pZoomLabel);
gtk_widget_show_all(pWindow); gtk_widget_show_all(pWindow);
...@@ -1813,6 +1826,7 @@ static GtkWidget* createWindow(TiledWindow& rWindow) ...@@ -1813,6 +1826,7 @@ static GtkWidget* createWindow(TiledWindow& rWindow)
gtk_widget_hide(rWindow.m_pFormulabarEntry); gtk_widget_hide(rWindow.m_pFormulabarEntry);
// Hide the non-progressbar children of the status bar by default. // Hide the non-progressbar children of the status bar by default.
gtk_widget_hide(rWindow.m_pStatusbarLabel); gtk_widget_hide(rWindow.m_pStatusbarLabel);
gtk_widget_hide(rWindow.m_pRedlineLabel);
gtk_widget_hide(rWindow.m_pZoomLabel); gtk_widget_hide(rWindow.m_pZoomLabel);
g_aWindows[pWindow] = rWindow; g_aWindows[pWindow] = rWindow;
......
...@@ -971,7 +971,8 @@ static void InterceptLOKStateChangeEvent(const SfxViewFrame* pViewFrame, const c ...@@ -971,7 +971,8 @@ static void InterceptLOKStateChangeEvent(const SfxViewFrame* pViewFrame, const c
aEvent.FeatureURL.Path == "Strikeout" || aEvent.FeatureURL.Path == "Strikeout" ||
aEvent.FeatureURL.Path == "Underline" || aEvent.FeatureURL.Path == "Underline" ||
aEvent.FeatureURL.Path == "ModifiedStatus" || aEvent.FeatureURL.Path == "ModifiedStatus" ||
aEvent.FeatureURL.Path == "TrackChanges") aEvent.FeatureURL.Path == "TrackChanges" ||
aEvent.FeatureURL.Path == "AcceptTrackedChange")
{ {
bool bTemp = false; bool bTemp = false;
aEvent.State >>= bTemp; aEvent.State >>= bTemp;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <wrtsh.hxx> #include <wrtsh.hxx>
#include <view.hxx> #include <view.hxx>
#include <UndoManager.hxx> #include <UndoManager.hxx>
#include <cmdid.h>
#include <sfx2/viewsh.hxx> #include <sfx2/viewsh.hxx>
#include <sfx2/lokhelper.hxx> #include <sfx2/lokhelper.hxx>
...@@ -128,6 +129,7 @@ private: ...@@ -128,6 +129,7 @@ private:
int m_nInvalidations; int m_nInvalidations;
int m_nRedlineTableSizeChanged; int m_nRedlineTableSizeChanged;
int m_nRedlineTableEntryModified; int m_nRedlineTableEntryModified;
int m_nTrackedChangeIndex;
}; };
SwTiledRenderingTest::SwTiledRenderingTest() SwTiledRenderingTest::SwTiledRenderingTest()
...@@ -136,7 +138,8 @@ SwTiledRenderingTest::SwTiledRenderingTest() ...@@ -136,7 +138,8 @@ SwTiledRenderingTest::SwTiledRenderingTest()
m_nSelectionAfterSearchResult(0), m_nSelectionAfterSearchResult(0),
m_nInvalidations(0), m_nInvalidations(0),
m_nRedlineTableSizeChanged(0), m_nRedlineTableSizeChanged(0),
m_nRedlineTableEntryModified(0) m_nRedlineTableEntryModified(0),
m_nTrackedChangeIndex(-1)
{ {
} }
...@@ -157,6 +160,7 @@ void SwTiledRenderingTest::callback(int nType, const char* pPayload, void* pData ...@@ -157,6 +160,7 @@ void SwTiledRenderingTest::callback(int nType, const char* pPayload, void* pData
void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload) void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
{ {
OString aPayload(pPayload);
switch (nType) switch (nType)
{ {
case LOK_CALLBACK_INVALIDATE_TILES: case LOK_CALLBACK_INVALIDATE_TILES:
...@@ -220,6 +224,19 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload) ...@@ -220,6 +224,19 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
++m_nRedlineTableEntryModified; ++m_nRedlineTableEntryModified;
} }
break; break;
case LOK_CALLBACK_STATE_CHANGED:
{
OString aTrackedChangeIndexPrefix(".uno:TrackedChangeIndex=");
if (aPayload.startsWith(aTrackedChangeIndexPrefix))
{
OString sIndex = aPayload.copy(aTrackedChangeIndexPrefix.getLength());
if (sIndex.isEmpty())
m_nTrackedChangeIndex = -1;
else
m_nTrackedChangeIndex = sIndex.toInt32();
}
}
break;
} }
} }
...@@ -1274,6 +1291,15 @@ void SwTiledRenderingTest::testTrackChangesCallback() ...@@ -1274,6 +1291,15 @@ void SwTiledRenderingTest::testTrackChangesCallback()
// This was 0, as LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED wasn't sent. // This was 0, as LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED wasn't sent.
CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableSizeChanged); CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableSizeChanged);
CPPUNIT_ASSERT_EQUAL(-1, m_nTrackedChangeIndex);
pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
SfxItemSet aSet(pWrtShell->GetDoc()->GetAttrPool(), FN_REDLINE_ACCEPT_DIRECT, FN_REDLINE_ACCEPT_DIRECT);
SfxVoidItem aItem(FN_REDLINE_ACCEPT_DIRECT);
aSet.Put(aItem);
pWrtShell->GetView().GetState(aSet);
// This failed, LOK_CALLBACK_STATE_CHANGED wasn't sent.
CPPUNIT_ASSERT_EQUAL(0, m_nTrackedChangeIndex);
comphelper::LibreOfficeKit::setActive(false); comphelper::LibreOfficeKit::setActive(false);
} }
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include <svl/stritem.hxx> #include <svl/stritem.hxx>
#include <unotools/moduleoptions.hxx> #include <unotools/moduleoptions.hxx>
#include <comphelper/lok.hxx> #include <comphelper/lok.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <svl/visitem.hxx> #include <svl/visitem.hxx>
#include <redline.hxx> #include <redline.hxx>
#include <docary.hxx> #include <docary.hxx>
...@@ -285,12 +286,12 @@ void SwView::GetState(SfxItemSet &rSet) ...@@ -285,12 +286,12 @@ void SwView::GetState(SfxItemSet &rSet)
{ {
SwDoc *pDoc = m_pWrtShell->GetDoc(); SwDoc *pDoc = m_pWrtShell->GetDoc();
SwPaM *pCursor = m_pWrtShell->GetCursor(); SwPaM *pCursor = m_pWrtShell->GetCursor();
bool bDisable = false;
if (GetDocShell()->HasChangeRecordProtection()) if (GetDocShell()->HasChangeRecordProtection())
rSet.DisableItem(nWhich); bDisable = true;
else if (pCursor->HasMark() && !comphelper::LibreOfficeKit::isActive()) else if (pCursor->HasMark())
{ {
// If the selection does not contain redlines, disable accepting/rejecting changes. // If the selection does not contain redlines, disable accepting/rejecting changes.
// Though LibreOfficeKit wants to handle changes by index, so always allow there.
sal_uInt16 index = 0; sal_uInt16 index = 0;
const SwRedlineTable& table = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); const SwRedlineTable& table = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
const SwRangeRedline* redline = table.FindAtPosition( *pCursor->Start(), index ); const SwRangeRedline* redline = table.FindAtPosition( *pCursor->Start(), index );
...@@ -311,14 +312,26 @@ void SwView::GetState(SfxItemSet &rSet) ...@@ -311,14 +312,26 @@ void SwView::GetState(SfxItemSet &rSet)
} }
} }
if( redline == nullptr ) if( redline == nullptr )
rSet.DisableItem(nWhich); bDisable = true;
} }
else if (!comphelper::LibreOfficeKit::isActive()) else
{ {
// If the cursor position isn't on a redline, disable // If the cursor position isn't on a redline, disable
// accepting/rejecting changes. // accepting/rejecting changes.
if (nullptr == pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), nullptr)) if (nullptr == pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), nullptr))
rSet.DisableItem(nWhich); bDisable = true;
}
// LibreOfficeKit wants to handle changes by index, so always allow here.
if (bDisable && !comphelper::LibreOfficeKit::isActive())
rSet.DisableItem(nWhich);
if (comphelper::LibreOfficeKit::isActive())
{
OString aPayload(".uno:TrackedChangeIndex=");
sal_uInt16 nRedline = 0;
if (pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline))
aPayload += OString::number(nRedline);
libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aPayload.getStr());
} }
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment