[Libreoffice-commits] core.git: 5 commits - basic/source libreofficekit/qa libreofficekit/source
Stephan Bergmann
sbergman at redhat.com
Fri Jan 27 16:29:18 UTC 2017
basic/source/comp/token.cxx | 6
basic/source/inc/token.hxx | 1
libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 209 ++++++++++++++++++--
libreofficekit/source/gtk/lokdocview.cxx | 36 +++
4 files changed, 225 insertions(+), 27 deletions(-)
New commits:
commit 71511385dd6b12c3a902424652087e780fd7f3ba
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Jan 27 17:27:22 2017 +0100
Just pass in OUString directly
Change-Id: Idf7d63672e8b330499e53c1395dedb92d25bb76a
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index 40397d3..f422147 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -242,12 +242,6 @@ void SbiTokenizer::Push( SbiToken t )
else ePush = t;
}
-void SbiTokenizer::Error( SbError code, const char* pMsg )
-{
- aError = OUString::createFromAscii( pMsg );
- Error( code );
-}
-
void SbiTokenizer::Error( SbError code, const OUString &aMsg )
{
aError = aMsg;
diff --git a/basic/source/inc/token.hxx b/basic/source/inc/token.hxx
index 43f535b..f9d7c0d 100644
--- a/basic/source/inc/token.hxx
+++ b/basic/source/inc/token.hxx
@@ -158,7 +158,6 @@ public:
void Error( SbError c ) { GenError( c ); }
void Error( SbError, SbiToken );
- void Error( SbError, const char* );
void Error( SbError, const OUString &);
static bool IsEoln( SbiToken t )
commit 464d9249d44d2b36d5334d42ad8b38aab62c3f47
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Wed Jan 25 16:22:39 2017 +0530
gtktiledviewer: Can reply, delete comments from sidebar
... and put the sidebar in a scrolled window
Change-Id: I57e982c849ed0c4dda4e8f5fdbcb0b85e46da36c
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 8c81b66..8286b18 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -50,6 +50,8 @@ public:
GtkWidget* m_pViewAnnotationsButton;
/// top level container for all comments in the sidebar
GtkWidget* m_pCommentsVBox;
+ /// scrolled window for main comments box
+ GtkWidget* m_pScrolledWindow;
/// Prepare and return a comment object (GtkBox)
static GtkWidget* createCommentBox(const boost::property_tree::ptree& aComment);
@@ -279,6 +281,47 @@ static void userPromptDialog(GtkWidget* pDocView, const std::string& aTitle, std
gtk_widget_destroy(pDialog);
}
+static void replyButtonClicked(GtkWidget* pWidget, gpointer userdata)
+{
+ TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
+ std::map<std::string, std::string> aEntries;
+ aEntries["Text"] = "";
+
+ userPromptDialog(rWindow.m_pDocView, "Reply comment", aEntries);
+
+ int *commentId = static_cast<int*>(g_object_get_data(G_OBJECT(userdata), "id"));
+
+ boost::property_tree::ptree aTree;
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "long");
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::to_string(*commentId));
+
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string");
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]);
+
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ std::string aArguments = aStream.str();
+
+ lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), ".uno:ReplyComment", aArguments.c_str(), false);
+}
+
+static void deleteCommentButtonClicked(GtkWidget* pWidget, gpointer userdata)
+{
+ TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
+
+ int *commentid = static_cast<int*>(g_object_get_data(G_OBJECT(userdata), "id"));
+
+ boost::property_tree::ptree aTree;
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "type", nullptr), '/'), "long");
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Id", "/", "value", nullptr), '/'), std::to_string(*commentid));
+
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ std::string aArguments = aStream.str();
+
+ lok_doc_view_post_command(LOK_DOC_VIEW(rWindow.m_pDocView), ".uno:DeleteComment", aArguments.c_str(), false);
+}
+
GtkWidget* CommentsSidebar::createCommentBox(const boost::property_tree::ptree& aComment)
{
GtkWidget* pCommentVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
@@ -292,8 +335,13 @@ GtkWidget* CommentsSidebar::createCommentBox(const boost::property_tree::ptree&
GtkWidget* pControlsHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget* pGotoButton = gtk_button_new_with_label("Goto");
GtkWidget* pReplyButton = gtk_button_new_with_label("Reply");
+ GtkWidget* pDeleteButton = gtk_button_new_with_label("Delete");
+ g_signal_connect(G_OBJECT(pReplyButton), "clicked", G_CALLBACK(replyButtonClicked), pCommentVBox);
+ g_signal_connect(G_OBJECT(pDeleteButton), "clicked", G_CALLBACK(deleteCommentButtonClicked), pCommentVBox);
+
gtk_container_add(GTK_CONTAINER(pControlsHBox), pGotoButton);
gtk_container_add(GTK_CONTAINER(pControlsHBox), pReplyButton);
+ gtk_container_add(GTK_CONTAINER(pControlsHBox), pDeleteButton);
GtkWidget* pCommentSeparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentText);
@@ -318,11 +366,15 @@ void CommentsSidebar::unoViewAnnotations(GtkWidget* pWidget, gpointer /*userdata
std::stringstream aStream(pValues);
free(pValues);
- gtk_widget_destroy(rWindow.m_pCommentsSidebar->m_pCommentsVBox);
+ gtk_widget_destroy(rWindow.m_pCommentsSidebar->m_pScrolledWindow);
+ rWindow.m_pCommentsSidebar->m_pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr);
+ gtk_widget_set_vexpand(rWindow.m_pCommentsSidebar->m_pScrolledWindow, TRUE);
rWindow.m_pCommentsSidebar->m_pCommentsVBox = gtk_grid_new();
g_object_set(rWindow.m_pCommentsSidebar->m_pCommentsVBox, "orientation", GTK_ORIENTATION_VERTICAL, nullptr);
- gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pMainVBox), rWindow.m_pCommentsSidebar->m_pCommentsVBox);
+
+ gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pScrolledWindow), rWindow.m_pCommentsSidebar->m_pCommentsVBox);
+ gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pMainVBox), rWindow.m_pCommentsSidebar->m_pScrolledWindow);
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
@@ -333,7 +385,7 @@ void CommentsSidebar::unoViewAnnotations(GtkWidget* pWidget, gpointer /*userdata
GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(rValue.second);
gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pCommentsVBox), pCommentBox);
}
- gtk_widget_show_all(rWindow.m_pCommentsSidebar->m_pCommentsVBox);
+ gtk_widget_show_all(rWindow.m_pCommentsSidebar->m_pScrolledWindow);
}
catch(boost::property_tree::ptree_bad_path& rException)
{
@@ -1496,21 +1548,37 @@ static void commentCallback(LOKDocView* pLOKDocView, gchar* pComment, gpointer /
boost::property_tree::ptree aRoot;
boost::property_tree::read_json(aStream, aRoot);
boost::property_tree::ptree aComment = aRoot.get_child("comment");
+ gint nPos = 0;
+ GtkWidget* pCommentsGrid = rWindow.m_pCommentsSidebar->m_pCommentsVBox;
+ GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pCommentsGrid));
+ for (GList* l = pChildren; l != nullptr; l = l->next, nPos++)
+ {
+ int *id = static_cast<int*>(g_object_get_data(G_OBJECT(l->data), "id"));
- gtk_container_foreach(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pCommentsVBox), [](GtkWidget* pWidget, gpointer userdata) {
- boost::property_tree::ptree *pTree = static_cast<boost::property_tree::ptree*>(userdata);
-
- int *id = static_cast<int*>(g_object_get_data(G_OBJECT(pWidget), "id"));
- GtkWidget* pCommentsGrid = gtk_widget_get_parent(pWidget);
- if (*id == pTree->get<int>("parent"))
+ if (aComment.get<std::string>("action") == "Add")
+ {
+ if (*id == aComment.get<int>("parent"))
{
- GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(*pTree);
- gtk_grid_insert_next_to(GTK_GRID(pCommentsGrid), pWidget, GTK_POS_BOTTOM);
- gtk_grid_attach_next_to(GTK_GRID(pCommentsGrid), pCommentBox, pWidget, GTK_POS_BOTTOM, 1, 1);
+ GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(aComment);
+ gtk_grid_insert_next_to(GTK_GRID(pCommentsGrid), GTK_WIDGET(l->data), GTK_POS_BOTTOM);
+ gtk_grid_attach_next_to(GTK_GRID(pCommentsGrid), pCommentBox, GTK_WIDGET(l->data), GTK_POS_BOTTOM, 1, 1);
gtk_widget_show_all(pCommentBox);
+ return;
}
+ }
+ else if (aComment.get<std::string>("action") == "Remove" && *id == aComment.get<int>("id"))
+ {
+ gtk_widget_destroy(GTK_WIDGET(l->data));
+ return;
+ }
+ }
- } , &aComment);
+ if (aComment.get<std::string>("action") == "Add")
+ {
+ GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(aComment);
+ gtk_container_add(GTK_CONTAINER(pCommentsGrid), pCommentBox);
+ gtk_widget_show_all(pCommentBox);
+ }
}
static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
commit 621e143c1c9c071e024e287a9d63fe16c7eb4f49
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Wed Jan 25 16:04:47 2017 +0530
gtktiledviewer: factor out user prompt entry dialog
Change-Id: I282390f7319de2e24564e0122e8c0081235a0ef5
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index d3ab995..8c81b66 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -240,6 +240,45 @@ static void lcl_registerToolItem(TiledWindow& rWindow, GtkToolItem* pItem, const
rWindow.m_aToolItemSensitivities[pItem] = true;
}
+static void userPromptDialog(GtkWidget* pDocView, const std::string& aTitle, std::map<std::string, std::string>& aEntries)
+{
+ GtkWidget* pDialog = gtk_dialog_new_with_buttons (aTitle.c_str(),
+ GTK_WINDOW (gtk_widget_get_toplevel(pDocView)),
+ GTK_DIALOG_MODAL,
+ "Ok",
+ GTK_RESPONSE_OK,
+ nullptr);
+
+ GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pDialog));
+ GtkWidget* pEntryArea = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ gtk_container_add(GTK_CONTAINER(pDialogMessageArea), pEntryArea);
+ for (const auto& entry : aEntries)
+ {
+ GtkWidget* pEntry = gtk_entry_new();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(pEntry), entry.first.c_str());
+
+ gtk_container_add(GTK_CONTAINER(pEntryArea), pEntry);
+ }
+
+ gtk_widget_show_all(pDialog);
+
+ gint res = gtk_dialog_run(GTK_DIALOG(pDialog));
+ switch(res)
+ {
+ case GTK_RESPONSE_OK:
+ GList* pList = gtk_container_get_children(GTK_CONTAINER(pEntryArea));
+
+ for (GList* l = pList; l != nullptr; l = l->next)
+ {
+ const gchar* pKey = gtk_entry_get_placeholder_text(GTK_ENTRY(l->data));
+ aEntries[std::string(pKey)] = std::string(gtk_entry_get_text(GTK_ENTRY(l->data)));
+ }
+ break;
+ }
+
+ gtk_widget_destroy(pDialog);
+}
+
GtkWidget* CommentsSidebar::createCommentBox(const boost::property_tree::ptree& aComment)
{
GtkWidget* pCommentVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
@@ -1487,44 +1526,17 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
if (rString == ".uno:InsertAnnotation")
{
- LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
-
- GtkWidget* pAnnotationDialog = gtk_dialog_new_with_buttons ("Insert Comment",
- GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))),
- GTK_DIALOG_MODAL,
- "Insert",
- GTK_RESPONSE_OK,
- nullptr);
-
- GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pAnnotationDialog));
- GtkWidget* pHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pHBox, TRUE, TRUE, 2);
+ std::map<std::string, std::string> aEntries;
+ aEntries["Text"] = "";
+ userPromptDialog(rWindow.m_pDocView, "Insert Comment", aEntries);
- GtkWidget* pCommentLabel = gtk_label_new("Comment text");
- gtk_box_pack_start(GTK_BOX(pHBox), pCommentLabel, TRUE, TRUE, 2);
-
- GtkWidget* pCommentText = gtk_entry_new();
- gtk_box_pack_start(GTK_BOX(pHBox), pCommentText, TRUE, TRUE, 2);
-
- gtk_widget_show_all(pAnnotationDialog);
-
- gint res = gtk_dialog_run(GTK_DIALOG(pAnnotationDialog));
- switch(res)
- {
- case GTK_RESPONSE_OK:
- const gchar* sText = gtk_entry_get_text(GTK_ENTRY(pCommentText));
- boost::property_tree::ptree aTree;
- aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string");
- aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), sText);
-
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- rArguments = aStream.str();
-
- break;
- }
+ boost::property_tree::ptree aTree;
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string");
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), aEntries["Text"]);
- gtk_widget_destroy(pAnnotationDialog);
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ rArguments = aStream.str();
}
g_info("toggleToolItem: lok_doc_view_post_command('%s %s')", rString.c_str(), rArguments.c_str());
commit b3178e2fced804d37efc47fddb77b516ef8d2684
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Wed Jan 25 15:27:35 2017 +0530
lokdocview: 'comment' signal for comment callbacks
Change-Id: I82040893added83ff13395db3917b230ef6b01d5
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 7bac0eb..d3ab995 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -51,6 +51,8 @@ public:
/// top level container for all comments in the sidebar
GtkWidget* m_pCommentsVBox;
+ /// Prepare and return a comment object (GtkBox)
+ static GtkWidget* createCommentBox(const boost::property_tree::ptree& aComment);
/// Click even handler for m_pViewAnnotationsButton
static void unoViewAnnotations(GtkWidget* pWidget, gpointer userdata);
/// Configure event handler for window
@@ -238,6 +240,35 @@ static void lcl_registerToolItem(TiledWindow& rWindow, GtkToolItem* pItem, const
rWindow.m_aToolItemSensitivities[pItem] = true;
}
+GtkWidget* CommentsSidebar::createCommentBox(const boost::property_tree::ptree& aComment)
+{
+ GtkWidget* pCommentVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
+ int *id = g_new(int, 1);
+ *id = aComment.get<int>("id");
+ g_object_set_data_full(G_OBJECT(pCommentVBox), "id", id, g_free);
+
+ GtkWidget* pCommentText = gtk_label_new(aComment.get<std::string>("text").c_str());
+ GtkWidget* pCommentAuthor = gtk_label_new(aComment.get<std::string>("author").c_str());
+ GtkWidget* pCommentDate = gtk_label_new(aComment.get<std::string>("dateTime").c_str());
+ GtkWidget* pControlsHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+ GtkWidget* pGotoButton = gtk_button_new_with_label("Goto");
+ GtkWidget* pReplyButton = gtk_button_new_with_label("Reply");
+ gtk_container_add(GTK_CONTAINER(pControlsHBox), pGotoButton);
+ gtk_container_add(GTK_CONTAINER(pControlsHBox), pReplyButton);
+ GtkWidget* pCommentSeparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
+
+ gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentText);
+ gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentAuthor);
+ gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentDate);
+ gtk_container_add(GTK_CONTAINER(pCommentVBox), pControlsHBox);
+ gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentSeparator);
+
+ gtk_label_set_line_wrap(GTK_LABEL(pCommentText), TRUE);
+ gtk_label_set_max_width_chars(GTK_LABEL(pCommentText), 35);
+
+ return pCommentVBox;
+}
+
void CommentsSidebar::unoViewAnnotations(GtkWidget* pWidget, gpointer /*userdata*/)
{
TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
@@ -250,7 +281,8 @@ void CommentsSidebar::unoViewAnnotations(GtkWidget* pWidget, gpointer /*userdata
gtk_widget_destroy(rWindow.m_pCommentsSidebar->m_pCommentsVBox);
- rWindow.m_pCommentsSidebar->m_pCommentsVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
+ rWindow.m_pCommentsSidebar->m_pCommentsVBox = gtk_grid_new();
+ g_object_set(rWindow.m_pCommentsSidebar->m_pCommentsVBox, "orientation", GTK_ORIENTATION_VERTICAL, nullptr);
gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pMainVBox), rWindow.m_pCommentsSidebar->m_pCommentsVBox);
boost::property_tree::ptree aTree;
@@ -259,21 +291,8 @@ void CommentsSidebar::unoViewAnnotations(GtkWidget* pWidget, gpointer /*userdata
{
for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments"))
{
- GtkWidget* pCommentVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
- gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pCommentsVBox), pCommentVBox);
-
- GtkWidget* pCommentText = gtk_label_new(rValue.second.get<std::string>("text").c_str());
- GtkWidget* pCommentAuthor = gtk_label_new(rValue.second.get<std::string>("author").c_str());
- GtkWidget* pCommentDate = gtk_label_new(rValue.second.get<std::string>("dateTime").c_str());
- GtkWidget* pCommentSeparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
-
- gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentText);
- gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentAuthor);
- gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentDate);
- gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentSeparator);
-
- gtk_label_set_line_wrap(GTK_LABEL(pCommentText), TRUE);
- gtk_label_set_max_width_chars(GTK_LABEL(pCommentText), 35);
+ GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(rValue.second);
+ gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pCommentsVBox), pCommentBox);
}
gtk_widget_show_all(rWindow.m_pCommentsSidebar->m_pCommentsVBox);
}
@@ -305,6 +324,8 @@ gboolean CommentsSidebar::docConfigureEvent(GtkWidget* pDocView, GdkEventConfigu
g_signal_connect(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton, "clicked", G_CALLBACK(CommentsSidebar::unoViewAnnotations), nullptr);
gtk_widget_show_all(rWindow.m_pCommentsSidebar->m_pMainVBox);
+
+ gtk_button_clicked(GTK_BUTTON(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton));
}
}
@@ -1429,6 +1450,30 @@ static void passwordRequired(LOKDocView* pLOKDocView, gchar* pUrl, gboolean bMod
gtk_widget_destroy(pPasswordDialog);
}
+static void commentCallback(LOKDocView* pLOKDocView, gchar* pComment, gpointer /* pData */)
+{
+ TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView));
+ std::stringstream aStream(pComment);
+ boost::property_tree::ptree aRoot;
+ boost::property_tree::read_json(aStream, aRoot);
+ boost::property_tree::ptree aComment = aRoot.get_child("comment");
+
+ gtk_container_foreach(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pCommentsVBox), [](GtkWidget* pWidget, gpointer userdata) {
+ boost::property_tree::ptree *pTree = static_cast<boost::property_tree::ptree*>(userdata);
+
+ int *id = static_cast<int*>(g_object_get_data(G_OBJECT(pWidget), "id"));
+ GtkWidget* pCommentsGrid = gtk_widget_get_parent(pWidget);
+ if (*id == pTree->get<int>("parent"))
+ {
+ GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(*pTree);
+ gtk_grid_insert_next_to(GTK_GRID(pCommentsGrid), pWidget, GTK_POS_BOTTOM);
+ gtk_grid_attach_next_to(GTK_GRID(pCommentsGrid), pCommentBox, pWidget, GTK_POS_BOTTOM, 1, 1);
+ gtk_widget_show_all(pCommentBox);
+ }
+
+ } , &aComment);
+}
+
static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
{
TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
@@ -2014,6 +2059,7 @@ static void setupDocView(GtkWidget* pDocView)
g_signal_connect(pDocView, "cursor-changed", G_CALLBACK(cursorChanged), nullptr);
g_signal_connect(pDocView, "formula-changed", G_CALLBACK(formulaChanged), nullptr);
g_signal_connect(pDocView, "password-required", G_CALLBACK(passwordRequired), nullptr);
+ g_signal_connect(pDocView, "comment", G_CALLBACK(commentCallback), nullptr);
}
int main( int argc, char* argv[] )
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 80d40f5..b854473 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -276,6 +276,7 @@ enum
FORMULA_CHANGED,
TEXT_SELECTION,
PASSWORD_REQUIRED,
+ COMMENT,
LAST_SIGNAL
};
@@ -1399,6 +1400,7 @@ callback (gpointer pData)
break;
}
case LOK_CALLBACK_COMMENT:
+ g_signal_emit(pCallback->m_pDocView, doc_view_signals[COMMENT], 0, pCallback->m_aPayload.c_str());
break;
default:
g_assert(false);
@@ -3105,6 +3107,40 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_BOOLEAN);
+
+ /**
+ * LOKDocView::comment:
+ * @pDocView: the #LOKDocView on which the signal is emitted
+ * @pComment: the JSON string containing comment notification
+ * The has following structure containing the information telling whether
+ * the comment has been added, deleted or modified.
+ * The example:
+ * {
+ * "comment": {
+ * "action": "Add",
+ * "id": "11",
+ * "parent": "4",
+ * "author": "Unknown Author",
+ * "text": "This is a comment",
+ * "dateTime": "2016-08-18T13:13:00",
+ * "anchorPos": "4529, 3906",
+ * "textRange": "1418, 3906, 3111, 919"
+ * }
+ * }
+ * 'action' can be 'Add', 'Remove' or 'Modify' depending on whether
+ * comment has been added, removed or modified.
+ * 'parent' is a non-zero comment id if this comment is a reply comment,
+ * otherwise its a root comment.
+ */
+ doc_view_signals[COMMENT] =
+ g_signal_new("comment",
+ G_TYPE_FROM_CLASS(pGObjectClass),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ nullptr, nullptr,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
}
SAL_DLLPUBLIC_EXPORT GtkWidget*
commit 8b3ea2ad62fd781e2fe253ee0c2bb0ce143912f4
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Tue Jan 24 18:35:42 2017 +0530
gtktiledviewer: Comment dialog when tiled annotations are off
Change-Id: I6762baac6c387d968dc6ee94d3494907c817214c
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index c2faacd..7bac0eb 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -1438,7 +1438,50 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
const std::string& rString = rWindow.m_aToolItemCommandNames[pItem];
- const std::string& rArguments = rWindow.m_aToolItemCommandArgs[pItem];
+ std::string& rArguments = rWindow.m_aToolItemCommandArgs[pItem];
+
+ if (rString == ".uno:InsertAnnotation")
+ {
+ LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
+
+ GtkWidget* pAnnotationDialog = gtk_dialog_new_with_buttons ("Insert Comment",
+ GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))),
+ GTK_DIALOG_MODAL,
+ "Insert",
+ GTK_RESPONSE_OK,
+ nullptr);
+
+ GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pAnnotationDialog));
+ GtkWidget* pHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pHBox, TRUE, TRUE, 2);
+
+ GtkWidget* pCommentLabel = gtk_label_new("Comment text");
+ gtk_box_pack_start(GTK_BOX(pHBox), pCommentLabel, TRUE, TRUE, 2);
+
+ GtkWidget* pCommentText = gtk_entry_new();
+ gtk_box_pack_start(GTK_BOX(pHBox), pCommentText, TRUE, TRUE, 2);
+
+ gtk_widget_show_all(pAnnotationDialog);
+
+ gint res = gtk_dialog_run(GTK_DIALOG(pAnnotationDialog));
+ switch(res)
+ {
+ case GTK_RESPONSE_OK:
+ const gchar* sText = gtk_entry_get_text(GTK_ENTRY(pCommentText));
+ boost::property_tree::ptree aTree;
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "type", nullptr), '/'), "string");
+ aTree.put(boost::property_tree::ptree::path_type(g_strconcat("Text", "/", "value", nullptr), '/'), sText);
+
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ rArguments = aStream.str();
+
+ break;
+ }
+
+ gtk_widget_destroy(pAnnotationDialog);
+ }
+
g_info("toggleToolItem: lok_doc_view_post_command('%s %s')", rString.c_str(), rArguments.c_str());
// notify about the finished Save
More information about the Libreoffice-commits
mailing list