bugfix(zoom): use global modifiers for checking if ctrl is used for zoom instead of mouse area events
example(copy): fixing copy example to use correct Method type
This commit is contained in:
parent
037190babd
commit
16c8c0df30
3 changed files with 7 additions and 67 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
use cosmic_files::operation::{recursive::Context, Controller, ReplaceResult};
|
use cosmic_files::operation::{recursive::Context, Controller, ReplaceResult};
|
||||||
use std::{error::Error, io, path::PathBuf};
|
use std::{error::Error, io, path::PathBuf};
|
||||||
|
use cosmic_files::operation::recursive::Method;
|
||||||
|
|
||||||
#[compio::main]
|
#[compio::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
@ -30,13 +31,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
context
|
context
|
||||||
.recursive_copy_or_move(
|
.recursive_copy_or_move(
|
||||||
vec![(PathBuf::from("test/a"), PathBuf::from("test/b"))],
|
vec![(PathBuf::from("test/a"), PathBuf::from("test/b"))],
|
||||||
false,
|
Method::Copy,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
context
|
context
|
||||||
.recursive_copy_or_move(
|
.recursive_copy_or_move(
|
||||||
vec![(PathBuf::from("test/b"), PathBuf::from("test/c"))],
|
vec![(PathBuf::from("test/b"), PathBuf::from("test/c"))],
|
||||||
true,
|
Method::Move { cross_device_copy: false },
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,6 @@ use cosmic::{
|
||||||
iced_core::{
|
iced_core::{
|
||||||
border::Border,
|
border::Border,
|
||||||
event::{self, Event},
|
event::{self, Event},
|
||||||
keyboard::{
|
|
||||||
self,
|
|
||||||
key::{self, Key},
|
|
||||||
Event::{KeyPressed, KeyReleased},
|
|
||||||
Modifiers,
|
|
||||||
},
|
|
||||||
layout,
|
layout,
|
||||||
mouse::{self, click},
|
mouse::{self, click},
|
||||||
overlay,
|
overlay,
|
||||||
|
|
@ -201,9 +195,9 @@ impl<'a, Message, F> OnDrag<'a, Message> for F where F: Fn(Option<Rectangle>) ->
|
||||||
pub trait OnResize<'a, Message>: Fn(Size, Rectangle) -> Message + 'a {}
|
pub trait OnResize<'a, Message>: Fn(Size, Rectangle) -> Message + 'a {}
|
||||||
impl<'a, Message, F> OnResize<'a, Message> for F where F: Fn(Size, Rectangle) -> Message + 'a {}
|
impl<'a, Message, F> OnResize<'a, Message> for F where F: Fn(Size, Rectangle) -> Message + 'a {}
|
||||||
|
|
||||||
pub trait OnScroll<'a, Message>: Fn(mouse::ScrollDelta, Modifiers) -> Option<Message> + 'a {}
|
pub trait OnScroll<'a, Message>: Fn(mouse::ScrollDelta) -> Option<Message> + 'a {}
|
||||||
impl<'a, Message, F> OnScroll<'a, Message> for F where
|
impl<'a, Message, F> OnScroll<'a, Message> for F where
|
||||||
F: Fn(mouse::ScrollDelta, Modifiers) -> Option<Message> + 'a
|
F: Fn(mouse::ScrollDelta) -> Option<Message> + 'a
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,7 +210,6 @@ struct State {
|
||||||
last_position: Option<Point>,
|
last_position: Option<Point>,
|
||||||
last_virtual_position: Option<Point>,
|
last_virtual_position: Option<Point>,
|
||||||
drag_initiated: Option<Point>,
|
drag_initiated: Option<Point>,
|
||||||
modifiers: Modifiers,
|
|
||||||
prev_click: Option<(mouse::Click, Instant)>,
|
prev_click: Option<(mouse::Click, Instant)>,
|
||||||
size: Option<Size>,
|
size: Option<Size>,
|
||||||
}
|
}
|
||||||
|
|
@ -680,17 +673,13 @@ fn update<Message: Clone>(
|
||||||
|
|
||||||
if let Some(on_scroll) = widget.on_scroll.as_ref() {
|
if let Some(on_scroll) = widget.on_scroll.as_ref() {
|
||||||
if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event {
|
if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event {
|
||||||
if let Some(message) = on_scroll(*delta, state.modifiers) {
|
if let Some(message) = on_scroll(*delta) {
|
||||||
shell.publish(message);
|
shell.publish(message);
|
||||||
return event::Status::Captured;
|
return event::Status::Captured;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Event::Keyboard(key_event) = event {
|
|
||||||
handle_key_event(key_event, state)
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some((message, drag_rect)) = widget.on_drag.as_ref().zip(state.drag_rect(cursor)) {
|
if let Some((message, drag_rect)) = widget.on_drag.as_ref().zip(state.drag_rect(cursor)) {
|
||||||
shell.publish(message(drag_rect.intersection(&layout_bounds).map(
|
shell.publish(message(drag_rect.intersection(&layout_bounds).map(
|
||||||
|mut rect| {
|
|mut rect| {
|
||||||
|
|
@ -703,53 +692,3 @@ fn update<Message: Clone>(
|
||||||
|
|
||||||
event::Status::Ignored
|
event::Status::Ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_key_event(key_event: &keyboard::Event, state: &mut State) {
|
|
||||||
if let KeyPressed {
|
|
||||||
key: Key::Named(key::Named::Control),
|
|
||||||
..
|
|
||||||
} = key_event
|
|
||||||
{
|
|
||||||
state.modifiers.insert(Modifiers::CTRL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let KeyReleased {
|
|
||||||
key: Key::Named(key::Named::Control),
|
|
||||||
..
|
|
||||||
} = key_event
|
|
||||||
{
|
|
||||||
state.modifiers.remove(Modifiers::CTRL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let KeyPressed {
|
|
||||||
key: Key::Named(key::Named::Shift),
|
|
||||||
..
|
|
||||||
} = key_event
|
|
||||||
{
|
|
||||||
state.modifiers.insert(Modifiers::SHIFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let KeyReleased {
|
|
||||||
key: Key::Named(key::Named::Shift),
|
|
||||||
..
|
|
||||||
} = key_event
|
|
||||||
{
|
|
||||||
state.modifiers.remove(Modifiers::SHIFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let KeyPressed {
|
|
||||||
key: Key::Named(key::Named::Alt),
|
|
||||||
..
|
|
||||||
} = key_event
|
|
||||||
{
|
|
||||||
state.modifiers.insert(Modifiers::ALT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let KeyReleased {
|
|
||||||
key: Key::Named(key::Named::Alt),
|
|
||||||
..
|
|
||||||
} = key_event
|
|
||||||
{
|
|
||||||
state.modifiers.remove(Modifiers::ALT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4924,7 +4924,7 @@ impl Tab {
|
||||||
.on_resize(|_, _| Message::ScrollToFocus)
|
.on_resize(|_, _| Message::ScrollToFocus)
|
||||||
.on_back_press(move |_point_opt| Message::GoPrevious)
|
.on_back_press(move |_point_opt| Message::GoPrevious)
|
||||||
.on_forward_press(move |_point_opt| Message::GoNext)
|
.on_forward_press(move |_point_opt| Message::GoNext)
|
||||||
.on_scroll(respond_to_scroll_direction);
|
.on_scroll(|delta| respond_to_scroll_direction(delta, self.modifiers));
|
||||||
|
|
||||||
if self.context_menu.is_some() {
|
if self.context_menu.is_some() {
|
||||||
mouse_area = mouse_area.on_right_press(move |_point_opt| Message::ContextMenu(None));
|
mouse_area = mouse_area.on_right_press(move |_point_opt| Message::ContextMenu(None));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue