Save file on Cmd+S in editor example

This commit is contained in:
Héctor Ramón Jiménez 2023-09-19 19:39:23 +02:00
parent 06dc12bfbf
commit c0a141ab02
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -1,10 +1,14 @@
use iced::executor;
use iced::keyboard;
use iced::theme::{self, Theme};
use iced::widget::{
button, column, container, horizontal_space, pick_list, row, text,
text_editor, tooltip,
};
use iced::{Alignment, Application, Command, Element, Font, Length, Settings};
use iced::{
Alignment, Application, Command, Element, Font, Length, Settings,
Subscription,
};
use highlighter::Highlighter;
@ -147,6 +151,15 @@ impl Application for Editor {
}
}
fn subscription(&self) -> Subscription<Message> {
keyboard::on_key_press(|key_code, modifiers| match key_code {
keyboard::KeyCode::S if modifiers.command() => {
Some(Message::SaveFile)
}
_ => None,
})
}
fn view(&self) -> Element<Message> {
let controls = row![
action(new_icon(), "New file", Some(Message::NewFile)),