Skip to content

Commit c5aa40c

Browse files
Add back 'Pen Style' keyboard shortcuts (#1515)
1 parent 26b670f commit c5aa40c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

crates/rnote-ui/src/appwindow/actions.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use rnote_compose::SplitOrder;
1212
use rnote_compose::penevent::ShortcutKey;
1313
use rnote_engine::engine::StrokeContent;
1414
use rnote_engine::ext::GraphenePointExt;
15+
use rnote_engine::pens::PenStyle;
1516
use rnote_engine::strokes::resize::{ImageSizeOption, Resize};
1617
use rnote_engine::{Camera, Engine};
1718
use std::path::PathBuf;
19+
use std::str::FromStr;
1820
use std::time::Instant;
1921
use tracing::{debug, error};
2022

@@ -160,6 +162,13 @@ impl RnAppWindow {
160162
let action_visual_debug = gio::PropertyAction::new("visual-debug", self, "visual-debug");
161163
self.add_action(&action_visual_debug);
162164

165+
let action_pen_style = gio::SimpleAction::new_stateful(
166+
"pen-style",
167+
Some(&String::static_variant_type()),
168+
&String::from("brush").to_variant(),
169+
);
170+
self.add_action(&action_pen_style);
171+
163172
// Open settings
164173
action_open_settings.connect_activate(clone!(
165174
#[weak(rename_to = appwindow)]
@@ -295,6 +304,35 @@ impl RnAppWindow {
295304
}
296305
));
297306

307+
// Pen style
308+
action_pen_style.connect_activate(clone!(
309+
#[weak(rename_to=appwindow)]
310+
self,
311+
move |action, target| {
312+
let pen_style_str = target.unwrap().str().unwrap();
313+
314+
let pen_style = match PenStyle::from_str(pen_style_str) {
315+
Ok(s) => s,
316+
Err(e) => {
317+
error!("Activated pen-style action with invalid target, Err: {e:}");
318+
return;
319+
}
320+
};
321+
322+
let Some(canvas) = appwindow.active_tab_canvas() else {
323+
return;
324+
};
325+
// don't change the style if the current style with override is already the same
326+
// (e.g. when switched to from the pen button, not by clicking the pen page)
327+
if pen_style != canvas.engine_ref().current_pen_style_w_override() {
328+
let mut widget_flags = canvas.engine_mut().change_pen_style(pen_style);
329+
widget_flags |= canvas.engine_mut().change_pen_style_override(None);
330+
appwindow.handle_widget_flags(widget_flags, &canvas);
331+
}
332+
action.set_state(&pen_style_str.to_variant());
333+
}
334+
));
335+
298336
// Tab actions
299337
action_active_tab_move_left.connect_activate(clone!(
300338
#[weak(rename_to=appwindow)]

0 commit comments

Comments
 (0)