1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 #include "gtv-application-window.hxx"
16 #include "gtv-signal-handlers.hxx"
17 #include "gtv-helpers.hxx"
18 #include "gtv-comments-sidebar.hxx"
21 #include <boost/property_tree/json_parser.hpp>
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Wunused-function"
28 #if __has_warning("-Wdeprecated-volatile")
29 #pragma clang diagnostic ignored "-Wdeprecated-volatile"
32 G_DEFINE_TYPE(GtvCommentsSidebar
, gtv_comments_sidebar
, GTK_TYPE_BOX
);
34 #pragma GCC diagnostic pop
38 gtv_comments_sidebar_view_annotations(GtvCommentsSidebar
* sidebar
)
40 GtvApplicationWindow
* window
= GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(sidebar
)));
42 LibreOfficeKitDocument
* pDocument
= lok_doc_view_get_document(LOK_DOC_VIEW(window
->lokdocview
));
43 char* pValues
= pDocument
->pClass
->getCommandValues(pDocument
, ".uno:ViewAnnotations");
44 g_info("lok::Document::getCommandValues(%s) : %s", ".uno:ViewAnnotations", pValues
);
45 std::stringstream
aStream(pValues
);
48 // empty the comments grid
49 GtvGtkWrapper
<GList
> children(gtk_container_get_children(GTK_CONTAINER(sidebar
->commentsgrid
)),
55 for (iter
= children
.get(); iter
!= nullptr; iter
= g_list_next(iter
))
56 gtk_widget_destroy(GTK_WIDGET(iter
->data
));
57 boost::property_tree::ptree aTree
;
58 boost::property_tree::read_json(aStream
, aTree
);
61 for (const boost::property_tree::ptree::value_type
& rValue
: aTree
.get_child("comments"))
63 GtkWidget
* pCommentBox
= GtvHelpers::createCommentBox(rValue
.second
);
64 gtk_container_add(GTK_CONTAINER(sidebar
->commentsgrid
), pCommentBox
);
66 gtk_widget_show_all(sidebar
->scrolledwindow
);
68 catch(boost::property_tree::ptree_bad_path
& rException
)
70 std::cerr
<< "CommentsSidebar::unoViewAnnotations: failed to get comments" << rException
.what() << std::endl
;
75 gtv_comments_sidebar_view_annotations_cb(GtkWidget
* pWidget
, gpointer
)
77 GtvCommentsSidebar
* sidebar
= GTV_COMMENTS_SIDEBAR(pWidget
);
78 gtv_comments_sidebar_view_annotations(sidebar
);
82 gtv_comments_sidebar_init(GtvCommentsSidebar
* sidebar
)
84 sidebar
->scrolledwindow
= gtk_scrolled_window_new(nullptr, nullptr);
85 gtk_widget_set_vexpand(sidebar
->scrolledwindow
, TRUE
);
86 sidebar
->commentsgrid
= gtk_grid_new();
87 g_object_set(sidebar
->commentsgrid
, "orientation", GTK_ORIENTATION_VERTICAL
, nullptr);
89 sidebar
->viewannotationsButton
= gtk_button_new_with_label(".uno:ViewAnnotations");
90 // Hack to make sidebar grid wide enough to not need any horizontal scrollbar
91 gtk_widget_set_margin_start(sidebar
->viewannotationsButton
, 20);
92 gtk_widget_set_margin_end(sidebar
->viewannotationsButton
, 20);
93 gtk_container_add(GTK_CONTAINER(sidebar
), sidebar
->viewannotationsButton
);
94 g_signal_connect_swapped(sidebar
->viewannotationsButton
, "clicked", G_CALLBACK(gtv_comments_sidebar_view_annotations_cb
), sidebar
);
96 gtk_container_add(GTK_CONTAINER(sidebar
), sidebar
->scrolledwindow
);
97 gtk_container_add(GTK_CONTAINER(sidebar
->scrolledwindow
), sidebar
->commentsgrid
);
99 gtk_widget_show_all(GTK_WIDGET(sidebar
));
103 gtv_comments_sidebar_class_init(GtvCommentsSidebarClass
* /*klass*/)
108 gtv_comments_sidebar_new()
110 return GTK_WIDGET(g_object_new(GTV_TYPE_COMMENTS_SIDEBAR
,
111 "orientation", GTK_ORIENTATION_VERTICAL
,
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */