From 99b884085803e3bbf2bcc7f0d4b965f9a2fcb7e4 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sun, 10 Sep 2023 19:45:02 -0400 Subject: [PATCH] port to Gtk4 --- Project.toml | 6 ++--- src/GtkMarkdownTextView.jl | 48 +++++++++++++++++++------------------- test/runtests.jl | 6 ++--- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Project.toml b/Project.toml index 26fb6fe..3125d3f 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/GtkMarkdownTextView.jl b/src/GtkMarkdownTextView.jl index ab14d24..a871296 100644 --- a/src/GtkMarkdownTextView.jl +++ b/src/GtkMarkdownTextView.jl @@ -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 @@ -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, @@ -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), "") @@ -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 @@ -177,4 +177,4 @@ module GtkMarkdownTextView end - \ No newline at end of file + diff --git a/test/runtests.jl b/test/runtests.jl index 8d645dc..3bdc543 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using GtkMarkdownTextView, Test -using Gtk +using Gtk4 @testset "MarkdownTextView" begin @@ -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 \ No newline at end of file +end