From 21c6d5cb9bea7bfe9d83066536c05534ac268b4f Mon Sep 17 00:00:00 2001 From: Tobias Bernard Date: Sat, 14 Dec 2024 19:04:41 +0100 Subject: [PATCH] wip: port to sourceview --- Cargo.lock | 36 ++++++++++++++++++++++++++++++++++ aardvark-app/Cargo.toml | 1 + aardvark-app/src/textbuffer.rs | 6 ++++-- aardvark-app/src/window.rs | 5 +++-- aardvark-app/src/window.ui | 3 ++- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fab072..3912354 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,7 @@ dependencies = [ "libadwaita", "serde", "serde_json", + "sourceview5", "tokio", ] @@ -4296,6 +4297,41 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sourceview5" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0e07d99b15f12767aa1c84870c45667f42bf24fd6a989dc70088e32854ef56e" +dependencies = [ + "futures-channel", + "futures-core", + "gdk-pixbuf", + "gdk4", + "gio", + "glib", + "gtk4", + "libc", + "pango", + "sourceview5-sys", +] + +[[package]] +name = "sourceview5-sys" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3759467713554a8063faa380237ee2c753e89026bbe1b8e9611d991cb106ff" +dependencies = [ + "gdk-pixbuf-sys", + "gdk4-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "gtk4-sys", + "libc", + "pango-sys", + "system-deps", +] + [[package]] name = "spin" version = "0.9.8" diff --git a/aardvark-app/Cargo.toml b/aardvark-app/Cargo.toml index 448bcbb..6b59aa6 100644 --- a/aardvark-app/Cargo.toml +++ b/aardvark-app/Cargo.toml @@ -12,6 +12,7 @@ gtk = { version = "0.9", package = "gtk4", features = ["gnome_47"] } serde = { version = "1.0.215", features = ["derive"] } serde_json = "1.0.128" tokio = { version = "1.42.0", features = ["full"] } +sourceview = { package = "sourceview5", version = "0.9" } [dependencies.adw] package = "libadwaita" diff --git a/aardvark-app/src/textbuffer.rs b/aardvark-app/src/textbuffer.rs index 6416087..d061058 100644 --- a/aardvark-app/src/textbuffer.rs +++ b/aardvark-app/src/textbuffer.rs @@ -22,8 +22,10 @@ use adw::subclass::prelude::*; use glib::subclass::Signal; use gtk::glib; use gtk::prelude::*; +use gtk::*; use std::cell::Cell; use std::sync::OnceLock; +use sourceview::*; mod imp { use super::*; @@ -37,7 +39,7 @@ mod imp { impl ObjectSubclass for AardvarkTextBuffer { const NAME: &'static str = "AardvarkTextBuffer"; type Type = super::AardvarkTextBuffer; - type ParentType = gtk::TextBuffer; + type ParentType = sourceview::Buffer; } impl ObjectImpl for AardvarkTextBuffer { @@ -82,7 +84,7 @@ mod imp { glib::wrapper! { pub struct AardvarkTextBuffer(ObjectSubclass) - @extends gtk::TextBuffer; + @extends sourceview::Buffer; } impl AardvarkTextBuffer { diff --git a/aardvark-app/src/window.rs b/aardvark-app/src/window.rs index 5b81556..cf9d0f0 100644 --- a/aardvark-app/src/window.rs +++ b/aardvark-app/src/window.rs @@ -25,6 +25,7 @@ use adw::subclass::prelude::*; use glib::subclass::Signal; use gtk::prelude::*; use gtk::{gio, glib}; +use sourceview::*; use crate::AardvarkTextBuffer; @@ -36,7 +37,7 @@ mod imp { pub struct AardvarkWindow { // Template widgets #[template_child] - pub text_view: TemplateChild, + pub text_view: TemplateChild, #[template_child] pub open_document_button: TemplateChild, #[template_child] @@ -63,7 +64,7 @@ mod imp { self.parent_constructed(); let buffer = AardvarkTextBuffer::new(); - self.text_view.set_buffer(Some(&buffer)); + self.text_view.clone().upcast::().set_buffer(Some(&buffer)); let obj = self.obj().clone(); buffer.connect_changed(move |buffer| { diff --git a/aardvark-app/src/window.ui b/aardvark-app/src/window.ui index fe7df1f..dbea307 100644 --- a/aardvark-app/src/window.ui +++ b/aardvark-app/src/window.ui @@ -68,10 +68,11 @@ 180 300 - + 6 12 12 + GTK_WRAP_WORD_CHAR