/
jazz_sourceview.cpp
76 lines (70 loc) · 2.51 KB
/
jazz_sourceview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "jazz_sourceview.hpp"
#include <gtksourceview/gtksource.h>
#include <gtksourceview/gtksourcebuffer.h>
namespace Jazz
{
SourceView::SourceView():
Gtk::ScrolledWindow(), source_view(GTK_SOURCE_VIEW(gtk_source_view_new()))
{
add(*Glib::wrap(GTK_WIDGET(source_view)));
completion = gtk_source_view_get_completion(source_view);
completion_words = gtk_source_completion_words_new("Suggestions", nullptr);
gtk_source_completion_words_register(completion_words, gtk_text_view_get_buffer(GTK_TEXT_VIEW(source_view)));
gtk_source_completion_add_provider(completion,
GTK_SOURCE_COMPLETION_PROVIDER(completion_words), nullptr);
gtk_source_buffer_set_highlight_matching_brackets(GetSourceBuffer(), TRUE);
gtk_source_view_set_show_line_marks(source_view, TRUE);
ShowLineNumbers(true);
show_all();
}
SourceView::SourceView(GtkSourceBuffer* source_buffer):
Gtk::ScrolledWindow(), source_view(GTK_SOURCE_VIEW(gtk_source_view_new_with_buffer(GTK_SOURCE_BUFFER(source_buffer))))
{
add(*Glib::wrap(GTK_WIDGET(source_view)));
completion = gtk_source_view_get_completion(source_view);
completion_words = gtk_source_completion_words_new("Suggestions", nullptr);
gtk_source_completion_words_register(completion_words, gtk_text_view_get_buffer(GTK_TEXT_VIEW(source_view)));
gtk_source_completion_add_provider(completion,
GTK_SOURCE_COMPLETION_PROVIDER(completion_words), nullptr);
gtk_source_buffer_set_highlight_matching_brackets(GetSourceBuffer(), TRUE);
gtk_source_view_set_show_line_marks(source_view, TRUE);
ShowLineNumbers(true);
show_all();
}
SourceView::~SourceView()
{
g_object_unref(completion_words);
}
GtkSourceBuffer* SourceView::GetSourceBuffer() const
{
return GTK_SOURCE_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(source_view)));
}
GtkSourceView* SourceView::GetSourceView() const
{
return source_view;
}
GtkTextIter SourceView::GetTextIterAtLine(const int num)
{
GtkTextIter iter;
gtk_text_buffer_get_iter_at_line(
GTK_TEXT_BUFFER(GetSourceBuffer()),
&iter, num
);
return iter;
}
void SourceView::ScrollToLine(int line)
{
GtkTextIter iter = GetTextIterAtLine(line);
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(GetSourceView()),
&iter, 0.0, FALSE, 1.0, 1.0);
}
GtkSourceMark* SourceView::CreateMarkAtLine(
const int line,
const Glib::ustring& name,
const Glib::ustring& category)
{
auto text_iter = GetTextIterAtLine(line);
return gtk_source_buffer_create_source_mark(
GetSourceBuffer(), name.c_str(), category.c_str(), &text_iter);
}
}