connect spell check by libspelling

This commit is contained in:
yggverse 2024-12-19 16:49:06 +02:00
parent 045092cc2d
commit 6f7f50b5a2
3 changed files with 22 additions and 4 deletions

View File

@ -48,6 +48,9 @@ version = "0.9.1"
[dependencies.plurify] [dependencies.plurify]
version = "0.1.1" version = "0.1.1"
[dependencies.libspelling]
version = "0.3.0"
# development # development
[patch.crates-io] [patch.crates-io]
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" } # ggemini = { git = "https://github.com/YGGverse/ggemini.git" }

View File

@ -132,13 +132,14 @@ GTK 4 / Libadwaita client written in Rust
* Glib `2.80` * Glib `2.80`
* Gtk `4.14` * Gtk `4.14`
* GtkSourceView `5.14` * GtkSourceView `5.14`
* Libadwaita `1.5` (Ubuntu 24.04+) * libadwaita `1.5` (Ubuntu 24.04+)
* libspelling `0.1`
#### Debian #### Debian
``` bash ``` bash
sudo apt install git curl build-essential\ sudo apt install git curl build-essential\
libgtk-4-dev libgtksourceview-5-dev libadwaita-1-dev\ libgtk-4-dev libgtksourceview-5-dev libadwaita-1-dev libspelling-1-dev\
libsqlite3-dev libssl-dev libsqlite3-dev libssl-dev
``` ```
@ -146,7 +147,7 @@ sudo apt install git curl build-essential\
``` bash ``` bash
sudo dnf install git curl gcc\ sudo dnf install git curl gcc\
gtk4-devel gtksourceview5-devel libadwaita-devel\ gtk4-devel gtksourceview5-devel libadwaita-devel libspelling-devel\
sqlite-devel openssl-devel sqlite-devel openssl-devel
``` ```

View File

@ -1,9 +1,11 @@
use gtk::{ use gtk::{
gio::SimpleAction, gio::SimpleAction,
glib::GString, glib::GString,
prelude::{ActionExt, TextBufferExt, TextViewExt}, prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
TextView, WrapMode, TextView, WrapMode,
}; };
use libspelling::{Checker, TextBufferAdapter};
use sourceview::Buffer;
const MARGIN: i32 = 8; const MARGIN: i32 = 8;
@ -14,15 +16,27 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new(action_update: SimpleAction) -> Self { pub fn new(action_update: SimpleAction) -> Self {
// Init [SourceView](https://gitlab.gnome.org/GNOME/gtksourceview) type buffer
let buffer = Buffer::builder().build();
// Init [libspelling](https://gitlab.gnome.org/GNOME/libspelling)
let checker = Checker::default();
let adapter = TextBufferAdapter::new(&buffer, &checker);
adapter.set_enabled(true);
// Init main widget // Init main widget
let text_view = TextView::builder() let text_view = TextView::builder()
.bottom_margin(MARGIN) .bottom_margin(MARGIN)
.buffer(&buffer)
.extra_menu(&adapter.menu_model())
.left_margin(MARGIN) .left_margin(MARGIN)
.right_margin(MARGIN) .right_margin(MARGIN)
.top_margin(MARGIN) .top_margin(MARGIN)
.wrap_mode(WrapMode::Word) .wrap_mode(WrapMode::Word)
.build(); .build();
text_view.insert_action_group("spelling", Some(&adapter));
// Init events // Init events
text_view.buffer().connect_changed(move |_| { text_view.buffer().connect_changed(move |_| {
action_update.activate(None); action_update.activate(None);