1use crate::{KeyModifiers, Length};
2use std::sync::Arc;
3
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
5pub enum DragAction {
6 #[default]
7 None,
8 Copy,
9 Move,
10 Link,
11}
12
13impl KeyModifiers {
14 #[doc(hidden)]
15 pub fn drag_action(self) -> Option<DragAction> {
16 match (self.control, self.shift) {
17 (false, false) => None,
18 (true, false) => Some(DragAction::Copy),
19 (false, true) => Some(DragAction::Move),
20 (true, true) => Some(DragAction::Link),
21 }
22 }
23}
24
25#[derive(Clone, Debug, PartialEq)]
26pub enum DragEvent {
27 Started,
28 Finished(DragAction),
29 Entered { data: String, action: DragAction },
30 FilesEntered(Arc<[String]>),
31 Moved { x: Length, y: Length },
32 Exited,
33 Dropped { data: String, action: DragAction },
34 FilesDropped(Arc<[String]>),
35}
36
37#[doc(hidden)]
39pub enum DragArguments<'a> {
40 None,
41 Action(DragAction),
42 Data(&'a str, DragAction),
43 Files(&'a [String]),
44 Position(Length, Length),
45}
46
47impl DragEvent {
48 #[doc(hidden)]
49 pub fn notification(&self) -> (&'static str, DragArguments<'_>) {
50 use DragArguments::*;
51 match self {
52 Self::Started => ("drag-started", None),
53 Self::Finished(action) => ("drag-finished", Action(*action)),
54 Self::Entered { data, action } => ("entered", Data(data, *action)),
55 Self::Dropped { data, action } => ("dropped", Data(data, *action)),
56 Self::FilesEntered(paths) => ("files-entered", Files(paths)),
57 Self::FilesDropped(paths) => ("files-dropped", Files(paths)),
58 Self::Moved { x, y } => ("position-changed", Position(*x, *y)),
59 Self::Exited => ("exited", None),
60 }
61 }
62
63 #[doc(hidden)]
64 pub fn target_kind(&self) -> &'static str {
65 match self {
66 Self::Started | Self::Finished(_) => "DragArea",
67 _ => "DropArea",
68 }
69 }
70
71 #[doc(hidden)]
72 pub fn is_terminal(&self) -> bool {
73 matches!(self, Self::Exited | Self::Finished(_))
74 }
75}
76
77pub fn is_drag_area(kind: &str) -> bool {
78 matches!(kind, "DragArea" | "DropArea")
79}