Skip to content

Commit f838f5c

Browse files
Beagle123kou
andauthored
gtksourceview5 sample: use gtksourceview5 (ruby-gnome#1636)
This example was listed under gtksourceview5, but it used gtksourceview4. I updated it to use gtk4/gtksourceview5. --------- Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
1 parent 06802f6 commit f838f5c

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

gtksourceview5/sample/test.rb

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
#!/usr/bin/env ruby
22
#
3-
# test.rb - Ruby/GtkSourceView4 sample script.
3+
# test.rb - Ruby/GtkSourceView5 sample script.
44
#
5-
# Copyright (c) 2006-2020 Ruby-GNOME Project Team
5+
# Copyright (c) 2006-2024 Ruby-GNOME Project Team
66
# This program is licenced under the same licence as Ruby-GNOME.
77
#
88
# $Id: test.rb,v 1.4 2007/06/03 02:11:07 mutoh Exp $
99

10-
require 'gtksourceview4'
1110

12-
window = Gtk::Window.new
13-
window.signal_connect('delete-event') { Gtk.main_quit }
11+
require 'gtksourceview5'
1412

15-
view = GtkSource::View.new
16-
window.add(Gtk::ScrolledWindow.new.add(view))
17-
view.show_line_numbers = true
18-
view.insert_spaces_instead_of_tabs = true
19-
view.indent_width = 2
20-
view.show_right_margin = true
21-
view.right_margin_position = 80
2213

23-
lang = GtkSource::LanguageManager.new.get_language('ruby')
24-
view.buffer.language = lang
25-
view.buffer.highlight_syntax = true
26-
view.buffer.highlight_matching_brackets = true
27-
view.buffer.text = File.read(__FILE__)
28-
provider = Gtk::CssProvider.new
29-
provider.load(data: 'textview { font-family: Monospace; font-size: 8pt; }')
30-
view.style_context.add_provider(provider)
14+
app = Gtk::Application.new("io.github.ruby-gnome.gtksourceview5.sample")
3115

32-
window.set_default_size(480, 480)
33-
window.show_all
16+
app.signal_connect("activate") do
17+
window = Gtk::ApplicationWindow.new(app)
18+
19+
view = GtkSource::View.new
20+
scrolled_window = Gtk::ScrolledWindow.new
21+
scrolled_window.child = view
22+
window.child = scrolled_window
23+
view.show_line_numbers = true
24+
view.insert_spaces_instead_of_tabs = true
25+
view.indent_width = 2
26+
view.show_right_margin = true
27+
view.right_margin_position = 80
28+
29+
lang = GtkSource::LanguageManager.new.get_language('ruby')
30+
view.buffer.language = lang
31+
view.buffer.highlight_syntax = true
32+
view.buffer.highlight_matching_brackets = true
33+
view.buffer.text = File.read(__FILE__)
34+
provider = Gtk::CssProvider.new
35+
provider.load(data: 'textview { font-family: Monospace; font-size: 8pt; }')
36+
view.style_context.add_provider(provider)
37+
38+
window.set_default_size(480, 480)
39+
window.present
40+
end
41+
42+
app.run
3443

35-
Gtk.main

0 commit comments

Comments
 (0)