diff options
author | 2023-09-19 19:39:23 +0200 | |
---|---|---|
committer | 2023-09-19 19:39:23 +0200 | |
commit | c0a141ab026f5686d6bd92c8807b174396cb9105 (patch) | |
tree | ae2b31a1bc2088175cb90da2a4e2d6e482f0b5bb /examples/editor | |
parent | 06dc12bfbf75958c6534306b3d1b57ae47bdb37a (diff) | |
download | iced-c0a141ab026f5686d6bd92c8807b174396cb9105.tar.gz iced-c0a141ab026f5686d6bd92c8807b174396cb9105.tar.bz2 iced-c0a141ab026f5686d6bd92c8807b174396cb9105.zip |
Save file on `Cmd+S` in `editor` example
Diffstat (limited to 'examples/editor')
-rw-r--r-- | examples/editor/src/main.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs index 6def2082..36d4287c 100644 --- a/examples/editor/src/main.rs +++ b/examples/editor/src/main.rs @@ -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)), |