Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ uuid = "26d59822-f2b6-4a0d-bae1-4d8fc12fd86b"
version = "0.1.0"

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

[compat]
Gtk = "0.17.0, 1.0"
julia = "1.0"
julia = "1.6"
Gtk4 = "0.5"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
48 changes: 24 additions & 24 deletions src/GtkMarkdownTextView.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module GtkMarkdownTextView

using Gtk
import Gtk.GtkTextIter
using Gtk4
import Gtk4: _GtkTextIter, create_tag, apply_tag
import Gtk4.GLib: gobject_move_ref, GObject

using Markdown

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

mutable struct MarkdownTextView <: GtkTextView

handle::Ptr{Gtk.GObject}
handle::Ptr{GObject}
view::GtkTextView
buffer::GtkTextBuffer

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

buffer = GtkTextBuffer()
buffer.text[String] = prelude
buffer.text = prelude
view = GtkTextView(buffer)

style_css(view,
Expand All @@ -39,28 +39,28 @@ module GtkMarkdownTextView
)

#set_gtk_property!(view, :margin_left, 1)
view.monospace[Bool] = true
view.wrap_mode[Bool] = true
view.monospace = true
view.wrap_mode = true

fs = mc.font_size

Gtk.create_tag(buffer, "normal", font = "$fs")
Gtk.create_tag(buffer, "h1", font = "bold $(fs+3)")
Gtk.create_tag(buffer, "h2", font = "bold $(fs+2)")
Gtk.create_tag(buffer, "h3", font = "bold $(fs+1)")
Gtk.create_tag(buffer, "h4", font = "bold $(fs)")
Gtk.create_tag(buffer, "h5", font = "$(fs)")
Gtk.create_tag(buffer, "h6", font = "$(fs-1)")
Gtk.create_tag(buffer, "bold", font = "bold $(fs)")
Gtk.create_tag(buffer, "italic", font = "italic $fs")
Gtk.create_tag(buffer, "code", font = "bold $fs",
create_tag(buffer, "normal", font = "$fs")
create_tag(buffer, "h1", font = "bold $(fs+3)")
create_tag(buffer, "h2", font = "bold $(fs+2)")
create_tag(buffer, "h3", font = "bold $(fs+1)")
create_tag(buffer, "h4", font = "bold $(fs)")
create_tag(buffer, "h5", font = "$(fs)")
create_tag(buffer, "h6", font = "$(fs-1)")
create_tag(buffer, "bold", font = "bold $(fs)")
create_tag(buffer, "italic", font = "italic $fs")
create_tag(buffer, "code", font = "bold $fs",
foreground=mc.highlight_color, background=mc.highlight_background)

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

n = new(view.handle, view, buffer)
Gtk.gobject_move_ref(n, view)
gobject_move_ref(n, view)
end

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

function tag(buffer, what, i, j)
Gtk.apply_tag(buffer, what,
GtkTextIter(buffer, i), GtkTextIter(buffer, j)
apply_tag(buffer, what,
_GtkTextIter(buffer, i), _GtkTextIter(buffer, j)
)
end

function style_css(w::Gtk.GtkWidget, css::String)
sc = Gtk.G_.style_context(w)
push!(sc, GtkCssProvider(data=css), 600)
function style_css(w::GtkWidget, css::String)
sc = Gtk4.style_context(w)
push!(sc, GtkCssProvider(css), 600)
end

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


end


6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GtkMarkdownTextView, Test
using Gtk
using Gtk4

@testset "MarkdownTextView" begin

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

v = MarkdownTextView(md)
push!(w,v)
showall(w)
show(w)
sleep(1)
destroy(w)

end
end