|
@@ -29,10 +29,10 @@ const WINDOW_FOCUS_EVENT: &str = "tauri://focus";
|
|
|
const WINDOW_BLUR_EVENT: &str = "tauri://blur";
|
|
|
const WINDOW_SCALE_FACTOR_CHANGED_EVENT: &str = "tauri://scale-change";
|
|
|
const WINDOW_THEME_CHANGED: &str = "tauri://theme-changed";
|
|
|
-pub const DRAG_EVENT: &str = "tauri://drag";
|
|
|
-pub const DROP_EVENT: &str = "tauri://drop";
|
|
|
-pub const DROP_HOVER_EVENT: &str = "tauri://drop-over";
|
|
|
-pub const DROP_CANCELLED_EVENT: &str = "tauri://drag-cancelled";
|
|
|
+pub(crate) const DRAG_ENTER_EVENT: &str = "tauri://drag-enter";
|
|
|
+pub(crate) const DRAG_OVER_EVENT: &str = "tauri://drag-over";
|
|
|
+pub(crate) const DRAG_DROP_EVENT: &str = "tauri://drag-drop";
|
|
|
+pub(crate) const DRAG_LEAVE_EVENT: &str = "tauri://drag-leave";
|
|
|
|
|
|
pub struct WindowManager<R: Runtime> {
|
|
|
pub windows: Mutex<HashMap<String, Window<R>>>,
|
|
@@ -144,13 +144,9 @@ impl<R: Runtime> Window<R> {
|
|
|
}
|
|
|
|
|
|
#[derive(Serialize, Clone)]
|
|
|
-pub struct DragDropPayload<'a> {
|
|
|
- pub paths: &'a Vec<PathBuf>,
|
|
|
- pub position: &'a PhysicalPosition<f64>,
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Serialize, Clone)]
|
|
|
-pub struct DragOverPayload<'a> {
|
|
|
+pub(crate) struct DragDropPayload<'a> {
|
|
|
+ #[serde(skip_serializing_if = "Option::is_none")]
|
|
|
+ pub paths: Option<&'a Vec<PathBuf>>,
|
|
|
pub position: &'a PhysicalPosition<f64>,
|
|
|
}
|
|
|
|
|
@@ -194,28 +190,38 @@ fn on_window_event<R: Runtime>(window: &Window<R>, event: &WindowEvent) -> crate
|
|
|
},
|
|
|
)?,
|
|
|
WindowEvent::DragDrop(event) => match event {
|
|
|
- DragDropEvent::Dragged { paths, position } => {
|
|
|
- let payload = DragDropPayload { paths, position };
|
|
|
+ DragDropEvent::Enter { paths, position } => {
|
|
|
+ let payload = DragDropPayload {
|
|
|
+ paths: Some(paths),
|
|
|
+ position,
|
|
|
+ };
|
|
|
|
|
|
if window.is_webview_window() {
|
|
|
- window.emit_to(EventTarget::labeled(window.label()), DRAG_EVENT, payload)?
|
|
|
+ window.emit_to(
|
|
|
+ EventTarget::labeled(window.label()),
|
|
|
+ DRAG_ENTER_EVENT,
|
|
|
+ payload,
|
|
|
+ )?
|
|
|
} else {
|
|
|
- window.emit_to_window(DRAG_EVENT, payload)?
|
|
|
+ window.emit_to_window(DRAG_ENTER_EVENT, payload)?
|
|
|
}
|
|
|
}
|
|
|
- DragDropEvent::DragOver { position } => {
|
|
|
- let payload = DragOverPayload { position };
|
|
|
+ DragDropEvent::Over { position } => {
|
|
|
+ let payload = DragDropPayload {
|
|
|
+ position,
|
|
|
+ paths: None,
|
|
|
+ };
|
|
|
if window.is_webview_window() {
|
|
|
window.emit_to(
|
|
|
EventTarget::labeled(window.label()),
|
|
|
- DROP_HOVER_EVENT,
|
|
|
+ DRAG_OVER_EVENT,
|
|
|
payload,
|
|
|
)?
|
|
|
} else {
|
|
|
- window.emit_to_window(DROP_HOVER_EVENT, payload)?
|
|
|
+ window.emit_to_window(DRAG_OVER_EVENT, payload)?
|
|
|
}
|
|
|
}
|
|
|
- DragDropEvent::Dropped { paths, position } => {
|
|
|
+ DragDropEvent::Drop { paths, position } => {
|
|
|
let scopes = window.state::<Scopes>();
|
|
|
for path in paths {
|
|
|
if path.is_file() {
|
|
@@ -224,23 +230,26 @@ fn on_window_event<R: Runtime>(window: &Window<R>, event: &WindowEvent) -> crate
|
|
|
let _ = scopes.allow_directory(path, true);
|
|
|
}
|
|
|
}
|
|
|
- let payload = DragDropPayload { paths, position };
|
|
|
+ let payload = DragDropPayload {
|
|
|
+ paths: Some(paths),
|
|
|
+ position,
|
|
|
+ };
|
|
|
|
|
|
if window.is_webview_window() {
|
|
|
- window.emit_to(EventTarget::labeled(window.label()), DROP_EVENT, payload)?
|
|
|
+ window.emit_to(
|
|
|
+ EventTarget::labeled(window.label()),
|
|
|
+ DRAG_DROP_EVENT,
|
|
|
+ payload,
|
|
|
+ )?
|
|
|
} else {
|
|
|
- window.emit_to_window(DROP_EVENT, payload)?
|
|
|
+ window.emit_to_window(DRAG_DROP_EVENT, payload)?
|
|
|
}
|
|
|
}
|
|
|
- DragDropEvent::Cancelled => {
|
|
|
+ DragDropEvent::Leave => {
|
|
|
if window.is_webview_window() {
|
|
|
- window.emit_to(
|
|
|
- EventTarget::labeled(window.label()),
|
|
|
- DROP_CANCELLED_EVENT,
|
|
|
- (),
|
|
|
- )?
|
|
|
+ window.emit_to(EventTarget::labeled(window.label()), DRAG_LEAVE_EVENT, ())?
|
|
|
} else {
|
|
|
- window.emit_to_window(DROP_CANCELLED_EVENT, ())?
|
|
|
+ window.emit_to_window(DRAG_LEAVE_EVENT, ())?
|
|
|
}
|
|
|
}
|
|
|
_ => unimplemented!(),
|