Prepare for external file drop in pane

This commit is contained in:
Kirill Bulatov 2024-01-07 01:17:49 +02:00
parent dc7f9bbc54
commit 8ff05c6a72
8 changed files with 63 additions and 28 deletions

View file

@ -1099,12 +1099,6 @@ impl AppContext {
pub fn has_active_drag(&self) -> bool {
self.active_drag.is_some()
}
pub fn active_drag<T: 'static>(&self) -> Option<&T> {
self.active_drag
.as_ref()
.and_then(|drag| drag.value.downcast_ref())
}
}
impl Context for AppContext {

View file

@ -214,7 +214,7 @@ impl Render for ExternalPaths {
pub enum FileDropEvent {
Entered {
position: Point<Pixels>,
files: ExternalPaths,
paths: ExternalPaths,
},
Pending {
position: Point<Pixels>,

View file

@ -1673,10 +1673,7 @@ extern "C" fn dragging_entered(this: &Object, _: Sel, dragging_info: id) -> NSDr
if send_new_event(&window_state, {
let position = drag_event_position(&window_state, dragging_info);
let paths = external_paths_from_event(dragging_info);
InputEvent::FileDrop(FileDropEvent::Entered {
position,
files: paths,
})
InputEvent::FileDrop(FileDropEvent::Entered { position, paths })
}) {
NSDragOperationCopy
} else {

View file

@ -1462,12 +1462,12 @@ impl<'a> WindowContext<'a> {
// Translate dragging and dropping of external files from the operating system
// to internal drag and drop events.
InputEvent::FileDrop(file_drop) => match file_drop {
FileDropEvent::Entered { position, files } => {
FileDropEvent::Entered { position, paths } => {
self.window.mouse_position = position;
if self.active_drag.is_none() {
self.active_drag = Some(AnyDrag {
value: Box::new(files.clone()),
view: self.new_view(|_| files).into(),
value: Box::new(paths.clone()),
view: self.new_view(|_| paths).into(),
cursor_offset: position,
});
}