[Libreoffice-commits] core.git: 4 commits - libreofficekit/qa

Pranav Kant pranavk at collabora.co.uk
Mon Jan 30 12:21:15 UTC 2017


 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   92 +++++++++++++++-----
 1 file changed, 70 insertions(+), 22 deletions(-)

New commits:
commit d1a5c549d7908ca4b73ab9562fb3517ca1b00050
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon Jan 30 16:30:48 2017 +0530

    gtktiledviewer: Handle comment callback with Modify flag
    
    Change-Id: I8333876cc4b540c385e316ce8dcbc5f7bd1f7902

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index c947bb4..4307426 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -1589,33 +1589,44 @@ static void commentCallback(LOKDocView* pLOKDocView, gchar* pComment, gpointer /
     boost::property_tree::ptree aComment = aRoot.get_child("comment");
     GtkWidget* pCommentsGrid = rWindow.m_pCommentsSidebar->m_pCommentsVBox;
     GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pCommentsGrid));
+    GtkWidget* pSelf = nullptr;
+    GtkWidget* pParent = nullptr;
     for (GList* l = pChildren; l != nullptr; l = l->next)
     {
         int *id = static_cast<int*>(g_object_get_data(G_OBJECT(l->data), "id"));
 
-        if (aComment.get<std::string>("action") == "Add")
-        {
-            if (*id == aComment.get<int>("parent"))
-            {
-                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;
-        }
+        if (*id == aComment.get<int>("id"))
+            pSelf = GTK_WIDGET(l->data);
+
+        // There is no 'parent' in Remove callbacks
+        if (*id == aComment.get("parent", -1))
+            pParent = GTK_WIDGET(l->data);
     }
 
-    if (aComment.get<std::string>("action") == "Add")
+    if (aComment.get<std::string>("action") == "Remove")
+    {
+        if (pSelf)
+            gtk_widget_destroy(pSelf);
+        else
+            g_warning("Can't find the comment to remove in the list !!");
+    }
+    else if (aComment.get<std::string>("action") == "Add" || aComment.get<std::string>("action") == "Modify")
     {
         GtkWidget* pCommentBox = CommentsSidebar::createCommentBox(aComment);
-        gtk_container_add(GTK_CONTAINER(pCommentsGrid), pCommentBox);
+        if (pSelf != nullptr || pParent != nullptr)
+        {
+            gtk_grid_insert_next_to(GTK_GRID(pCommentsGrid), pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM);
+            gtk_grid_attach_next_to(GTK_GRID(pCommentsGrid), pCommentBox, pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM, 1, 1);
+        }
+        else
+            gtk_container_add(GTK_CONTAINER(pCommentsGrid), pCommentBox);
+
         gtk_widget_show_all(pCommentBox);
+
+        // We added the widget already below the existing one, so destroy the
+        // already existing one now
+        if (pSelf)
+            gtk_widget_destroy(pSelf);
     }
 }
 
commit c4b76c46db899776545fb7ea66abe1d708ffcef3
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon Jan 30 15:33:06 2017 +0530

    gtktiledviewer: Unused variable
    
    Change-Id: I1bf8833041cf0e0a42aca1b6d851f6f4ca28d68f

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 4381fc5..c947bb4 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -1587,10 +1587,9 @@ 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++)
+    for (GList* l = pChildren; l != nullptr; l = l->next)
     {
         int *id = static_cast<int*>(g_object_get_data(G_OBJECT(l->data), "id"));
 
commit a9153b4e1c00f7e85e50c333fdba94cc5601acb8
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon Jan 30 15:00:02 2017 +0530

    gtktiledviewer: Mark reply comments with lightgreen background
    
    Change-Id: Ic6623ebc05f1a09d5fc1b6bae5fab149d98724ab

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index bfdaea5..4381fc5 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -354,6 +354,16 @@ GtkWidget* CommentsSidebar::createCommentBox(const boost::property_tree::ptree&
     *id =  aComment.get<int>("id");
     g_object_set_data_full(G_OBJECT(pCommentVBox), "id", id, g_free);
 
+    // Set left-margin if its a reply comment
+    if (aComment.get<int>("parent") > 0)
+    {
+        GtkStyleContext* pStyleContext = gtk_widget_get_style_context(pCommentVBox);
+        GtkCssProvider* pCssProvider = gtk_css_provider_get_default();
+        gtk_style_context_add_class(pStyleContext, "commentbox");
+        gtk_style_context_add_provider(pStyleContext, GTK_STYLE_PROVIDER(pCssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+        gtk_css_provider_load_from_data(pCssProvider, ".commentbox {background-color: lightgreen;}", -1, nullptr);
+    }
+
     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());
@@ -437,6 +447,9 @@ gboolean CommentsSidebar::docConfigureEvent(GtkWidget* pDocView, GdkEventConfigu
             gtk_container_add(GTK_CONTAINER(rWindow.m_pMainHBox), rWindow.m_pCommentsSidebar->m_pMainVBox);
 
             rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton = gtk_button_new_with_label(".uno:ViewAnnotations");
+            // Hack to make sidebar grid wide enough to not need any horizontal scrollbar
+            gtk_widget_set_margin_start(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton, 20);
+            gtk_widget_set_margin_end(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton, 20);
             gtk_container_add(GTK_CONTAINER(rWindow.m_pCommentsSidebar->m_pMainVBox), rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton);
             g_signal_connect(rWindow.m_pCommentsSidebar->m_pViewAnnotationsButton, "clicked", G_CALLBACK(CommentsSidebar::unoViewAnnotations), nullptr);
 
commit bc713d0670b02c9f267fcf1e5f3373525bcda047
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon Jan 30 13:11:05 2017 +0530

    gtktiledviewer: Can edit comment from comment sidebar now
    
    TODO: Ideal would be to replace these buttons with a popover menu
    containing all the actions that can be taken on a comment
    
    Change-Id: Iec19e6c4a934394f84bcf4bb20cc14f207ef95be

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 6ea864b..bfdaea5 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -282,6 +282,30 @@ static void userPromptDialog(GtkWidget* pDocView, const std::string& aTitle, std
     gtk_widget_destroy(pDialog);
 }
 
+static void editButtonClicked(GtkWidget* pWidget, gpointer userdata)
+{
+    TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
+    std::map<std::string, std::string> aEntries;
+    aEntries["Text"] = "";
+
+    userPromptDialog(rWindow.m_pDocView, "Edit 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:EditAnnotation", aArguments.c_str(), false);
+}
+
 static void replyButtonClicked(GtkWidget* pWidget, gpointer userdata)
 {
     TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
@@ -334,13 +358,14 @@ GtkWidget* CommentsSidebar::createCommentBox(const boost::property_tree::ptree&
     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* pEditButton = gtk_button_new_with_label("Edit");
     GtkWidget* pReplyButton = gtk_button_new_with_label("Reply");
     GtkWidget* pDeleteButton = gtk_button_new_with_label("Delete");
+    g_signal_connect(G_OBJECT(pEditButton), "clicked", G_CALLBACK(editButtonClicked), pCommentVBox);
     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), pEditButton);
     gtk_container_add(GTK_CONTAINER(pControlsHBox), pReplyButton);
     gtk_container_add(GTK_CONTAINER(pControlsHBox), pDeleteButton);
     GtkWidget* pCommentSeparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);


More information about the Libreoffice-commits mailing list