lib/mdv/markdown_viewer.rb in mdv-0.4.1 vs lib/mdv/markdown_viewer.rb in mdv-0.5.0
- old
+ new
@@ -1,10 +1,12 @@
# frozen_string_literal: true
-require 'webkit2-gtk'
-require 'mdv/document'
+require "gir_ffi-gtk3"
+require "mdv/document"
+GirFFI.setup :WebKit2, "4.0"
+
module MDV
# Markdown viewer window class
class MarkdownViewer
def initialize(file)
@document = Document.new(file)
@@ -21,45 +23,45 @@
connect_destroy_signal
connect_web_view_signals
end
def connect_destroy_signal
- @win.signal_connect('destroy') { Gtk.main_quit }
+ @win.signal_connect("destroy") { Gtk.main_quit }
end
def connect_key_press_event_signal
- @win.signal_connect 'key-press-event' do |_wdg, evt, _ud|
- handle_key(evt) if evt.state.control_mask?
+ @win.signal_connect "key-press-event" do |_wdg, evt, _ud|
+ handle_key(evt) if evt.state[:control_mask]
false
end
end
def connect_web_view_signals
- web_view.signal_connect('context-menu') { true }
- web_view.signal_connect('decide-policy') do |_wv, decision, decision_type|
+ web_view.signal_connect("context-menu") { true }
+ web_view.signal_connect("decide-policy") do |_wv, decision, decision_type|
handle_decide_policy(decision, decision_type)
end
end
def handle_key(evt)
case evt.keyval
- when 'q'.ord
+ when "q".ord
@win.destroy
- when 'r'.ord
+ when "r".ord
reload
end
end
def handle_decide_policy(decision, decision_type)
- case decision_type.nick
- when 'navigation-action'
+ case decision_type
+ when :navigation_action
action = decision.navigation_action
if action.user_gesture?
Gtk.show_uri_on_window(@win, action.request.uri, 0)
true
end
- when 'new-window-action'
+ when :new_window_action
true
end
end
def setup_gui
@@ -74,10 +76,10 @@
it.add web_view
end
end
def web_view
- @web_view ||= WebKit2Gtk::WebView.new
+ @web_view ||= WebKit2::WebView.new
end
def reload
web_view.load_html @document.html, @document.base_uri
end