Fix z-index targeting for drag and drop
This commit is contained in:
@@ -1033,13 +1033,13 @@ impl Deref for MouseExitEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct DroppedFiles(pub(crate) SmallVec<[PathBuf; 2]>);
|
pub struct ExternalPaths(pub(crate) SmallVec<[PathBuf; 2]>);
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum FileDropEvent {
|
pub enum FileDropEvent {
|
||||||
Entered {
|
Entered {
|
||||||
position: Point<Pixels>,
|
position: Point<Pixels>,
|
||||||
files: DroppedFiles,
|
files: ExternalPaths,
|
||||||
},
|
},
|
||||||
Pending {
|
Pending {
|
||||||
position: Point<Pixels>,
|
position: Point<Pixels>,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use super::{display_bounds_from_native, ns_string, MacDisplay, MetalRenderer, NSRange};
|
use super::{display_bounds_from_native, ns_string, MacDisplay, MetalRenderer, NSRange};
|
||||||
use crate::{
|
use crate::{
|
||||||
display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, DroppedFiles, Executor,
|
display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, ExternalPaths, Executor,
|
||||||
FileDropEvent, GlobalPixels, InputEvent, KeyDownEvent, Keystroke, Modifiers,
|
FileDropEvent, GlobalPixels, InputEvent, KeyDownEvent, Keystroke, Modifiers,
|
||||||
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
|
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
|
||||||
PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, Scene, Size,
|
PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, Scene, Size,
|
||||||
@@ -1679,7 +1679,7 @@ extern "C" fn perform_drag_operation(this: &Object, _: Sel, dragging_info: id) -
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn external_paths_from_event(dragging_info: *mut Object) -> DroppedFiles {
|
fn external_paths_from_event(dragging_info: *mut Object) -> ExternalPaths {
|
||||||
let mut paths = SmallVec::new();
|
let mut paths = SmallVec::new();
|
||||||
let pasteboard: id = unsafe { msg_send![dragging_info, draggingPasteboard] };
|
let pasteboard: id = unsafe { msg_send![dragging_info, draggingPasteboard] };
|
||||||
let filenames = unsafe { NSPasteboard::propertyListForType(pasteboard, NSFilenamesPboardType) };
|
let filenames = unsafe { NSPasteboard::propertyListForType(pasteboard, NSFilenamesPboardType) };
|
||||||
@@ -1690,7 +1690,7 @@ fn external_paths_from_event(dragging_info: *mut Object) -> DroppedFiles {
|
|||||||
};
|
};
|
||||||
paths.push(PathBuf::from(path))
|
paths.push(PathBuf::from(path))
|
||||||
}
|
}
|
||||||
DroppedFiles(paths)
|
ExternalPaths(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) {
|
extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,
|
px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,
|
||||||
Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, DroppedFiles,
|
Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, ExternalPaths,
|
||||||
Edges, Effect, Element, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId,
|
Edges, Effect, Element, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId,
|
||||||
GlobalElementId, GlyphId, Handle, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch,
|
GlobalElementId, GlyphId, Handle, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch,
|
||||||
KeyMatcher, Keystroke, LayoutId, MainThread, MainThreadOnly, Modifiers, MonochromeSprite,
|
KeyMatcher, Keystroke, LayoutId, MainThread, MainThreadOnly, Modifiers, MonochromeSprite,
|
||||||
@@ -903,7 +903,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
|||||||
drag_handle_view: None,
|
drag_handle_view: None,
|
||||||
cursor_offset: position,
|
cursor_offset: position,
|
||||||
state: Box::new(files),
|
state: Box::new(files),
|
||||||
state_type: TypeId::of::<DroppedFiles>(),
|
state_type: TypeId::of::<ExternalPaths>(),
|
||||||
});
|
});
|
||||||
InputEvent::MouseDown(MouseDownEvent {
|
InputEvent::MouseDown(MouseDownEvent {
|
||||||
position,
|
position,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use gpui2::{hsla, red, AnyElement, DroppedFiles, ElementId, Hsla, Length, Size};
|
use gpui2::{hsla, red, AnyElement, ElementId, ExternalPaths, Hsla, Length, Size};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
@@ -49,18 +49,24 @@ impl<S: 'static + Send + Sync> Pane<S> {
|
|||||||
.w(self.size.width)
|
.w(self.size.width)
|
||||||
.h(self.size.height)
|
.h(self.size.height)
|
||||||
.relative()
|
.relative()
|
||||||
.children(cx.stack(0, |_| self.children.drain(..)))
|
.child(
|
||||||
.child(cx.stack(1, |_| {
|
div()
|
||||||
|
.z_index(0)
|
||||||
|
.size_full()
|
||||||
|
.children(self.children.drain(..)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
// TODO kb! Figure out why we can't we see the red background when we drag a file over this div.
|
// TODO kb! Figure out why we can't we see the red background when we drag a file over this div.
|
||||||
div()
|
div()
|
||||||
|
.z_index(1)
|
||||||
.id("drag-target")
|
.id("drag-target")
|
||||||
.drag_over::<DroppedFiles>(|d| d.bg(red()))
|
.drag_over::<ExternalPaths>(|d| d.bg(red()))
|
||||||
.on_drop(|_, files: DroppedFiles, _| {
|
.on_drop(|_, files: ExternalPaths, _| {
|
||||||
dbg!("dropped files!", files);
|
dbg!("dropped files!", files);
|
||||||
})
|
})
|
||||||
.absolute()
|
.absolute()
|
||||||
.inset_0()
|
.inset_0(),
|
||||||
}))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user