Skip to content

Commit 7c5ffef

Browse files
Merge pull request #3 from JuliaGtk/jw/gtk4
Gtk4 port
2 parents 788801d + 99b8840 commit 7c5ffef

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ uuid = "26d59822-f2b6-4a0d-bae1-4d8fc12fd86b"
33
version = "0.1.0"
44

55
[deps]
6-
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
6+
Gtk4 = "9db2cae5-386f-4011-9d63-a5602296539b"
77
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
88

99
[compat]
10-
Gtk = "0.17.0, 1.0"
11-
julia = "1.0"
10+
julia = "1.6"
11+
Gtk4 = "0.5"
1212

1313
[extras]
1414
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/GtkMarkdownTextView.jl

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module GtkMarkdownTextView
22

3-
using Gtk
4-
import Gtk.GtkTextIter
3+
using Gtk4
4+
import Gtk4: _GtkTextIter, create_tag, apply_tag
5+
import Gtk4.GLib: gobject_move_ref, GObject
56

67
using Markdown
78

@@ -18,15 +19,14 @@ module GtkMarkdownTextView
1819
MarkdownColors() = MarkdownColors(13, "#000", "#fff", "#111", "#eee")
1920

2021
mutable struct MarkdownTextView <: GtkTextView
21-
22-
handle::Ptr{Gtk.GObject}
22+
handle::Ptr{GObject}
2323
view::GtkTextView
2424
buffer::GtkTextBuffer
2525

2626
function MarkdownTextView(m::Markdown.MD, prelude::String, mc::MarkdownColors = MarkdownColors())
2727

2828
buffer = GtkTextBuffer()
29-
buffer.text[String] = prelude
29+
buffer.text = prelude
3030
view = GtkTextView(buffer)
3131

3232
style_css(view,
@@ -39,28 +39,28 @@ module GtkMarkdownTextView
3939
)
4040

4141
#set_gtk_property!(view, :margin_left, 1)
42-
view.monospace[Bool] = true
43-
view.wrap_mode[Bool] = true
42+
view.monospace = true
43+
view.wrap_mode = true
4444

4545
fs = mc.font_size
4646

47-
Gtk.create_tag(buffer, "normal", font = "$fs")
48-
Gtk.create_tag(buffer, "h1", font = "bold $(fs+3)")
49-
Gtk.create_tag(buffer, "h2", font = "bold $(fs+2)")
50-
Gtk.create_tag(buffer, "h3", font = "bold $(fs+1)")
51-
Gtk.create_tag(buffer, "h4", font = "bold $(fs)")
52-
Gtk.create_tag(buffer, "h5", font = "$(fs)")
53-
Gtk.create_tag(buffer, "h6", font = "$(fs-1)")
54-
Gtk.create_tag(buffer, "bold", font = "bold $(fs)")
55-
Gtk.create_tag(buffer, "italic", font = "italic $fs")
56-
Gtk.create_tag(buffer, "code", font = "bold $fs",
47+
create_tag(buffer, "normal", font = "$fs")
48+
create_tag(buffer, "h1", font = "bold $(fs+3)")
49+
create_tag(buffer, "h2", font = "bold $(fs+2)")
50+
create_tag(buffer, "h3", font = "bold $(fs+1)")
51+
create_tag(buffer, "h4", font = "bold $(fs)")
52+
create_tag(buffer, "h5", font = "$(fs)")
53+
create_tag(buffer, "h6", font = "$(fs-1)")
54+
create_tag(buffer, "bold", font = "bold $(fs)")
55+
create_tag(buffer, "italic", font = "italic $fs")
56+
create_tag(buffer, "code", font = "bold $fs",
5757
foreground=mc.highlight_color, background=mc.highlight_background)
5858

5959
insert_MD!(buffer, m)
6060
# tag(buffer, "normal", 1, length(buffer))
6161

6262
n = new(view.handle, view, buffer)
63-
Gtk.gobject_move_ref(n, view)
63+
gobject_move_ref(n, view)
6464
end
6565

6666
MarkdownTextView(m::String) = MarkdownTextView(Markdown.parse(m), "")
@@ -70,14 +70,14 @@ module GtkMarkdownTextView
7070
end
7171

7272
function tag(buffer, what, i, j)
73-
Gtk.apply_tag(buffer, what,
74-
GtkTextIter(buffer, i), GtkTextIter(buffer, j)
73+
apply_tag(buffer, what,
74+
_GtkTextIter(buffer, i), _GtkTextIter(buffer, j)
7575
)
7676
end
7777

78-
function style_css(w::Gtk.GtkWidget, css::String)
79-
sc = Gtk.G_.style_context(w)
80-
push!(sc, GtkCssProvider(data=css), 600)
78+
function style_css(w::GtkWidget, css::String)
79+
sc = Gtk4.style_context(w)
80+
push!(sc, GtkCssProvider(css), 600)
8181
end
8282

8383
function insert_MD!(buffer, m::Markdown.Header{N}, i) where N
@@ -177,4 +177,4 @@ module GtkMarkdownTextView
177177

178178

179179
end
180-
180+

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GtkMarkdownTextView, Test
2-
using Gtk
2+
using Gtk4
33

44
@testset "MarkdownTextView" begin
55

@@ -19,8 +19,8 @@ When `data` is not given, the buffer will be both readable and writable by defau
1919

2020
v = MarkdownTextView(md)
2121
push!(w,v)
22-
showall(w)
22+
show(w)
2323
sleep(1)
2424
destroy(w)
2525

26-
end
26+
end

0 commit comments

Comments
 (0)