mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
connect spell check by libspelling
This commit is contained in:
parent
045092cc2d
commit
6f7f50b5a2
3 changed files with 22 additions and 4 deletions
|
|
@ -1,9 +1,11 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::GString,
|
||||
prelude::{ActionExt, TextBufferExt, TextViewExt},
|
||||
prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
TextView, WrapMode,
|
||||
};
|
||||
use libspelling::{Checker, TextBufferAdapter};
|
||||
use sourceview::Buffer;
|
||||
|
||||
const MARGIN: i32 = 8;
|
||||
|
||||
|
|
@ -14,15 +16,27 @@ pub struct Widget {
|
|||
impl Widget {
|
||||
// Construct
|
||||
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
|
||||
let text_view = TextView::builder()
|
||||
.bottom_margin(MARGIN)
|
||||
.buffer(&buffer)
|
||||
.extra_menu(&adapter.menu_model())
|
||||
.left_margin(MARGIN)
|
||||
.right_margin(MARGIN)
|
||||
.top_margin(MARGIN)
|
||||
.wrap_mode(WrapMode::Word)
|
||||
.build();
|
||||
|
||||
text_view.insert_action_group("spelling", Some(&adapter));
|
||||
|
||||
// Init events
|
||||
text_view.buffer().connect_changed(move |_| {
|
||||
action_update.activate(None);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue