Make dnd_destination code more generic
This commit is contained in:
parent
a9dcdce525
commit
6f93a10560
1 changed files with 13 additions and 25 deletions
|
|
@ -6,6 +6,7 @@ use cosmic::{
|
||||||
iced::{
|
iced::{
|
||||||
self,
|
self,
|
||||||
advanced::layout::flex::Axis,
|
advanced::layout::flex::Axis,
|
||||||
|
clipboard::mime::AllowedMimeTypes,
|
||||||
widget::{column, row},
|
widget::{column, row},
|
||||||
Border,
|
Border,
|
||||||
},
|
},
|
||||||
|
|
@ -23,34 +24,19 @@ use crate::{
|
||||||
App, LayerSurface, Msg, Toplevel, Workspace,
|
App, LayerSurface, Msg, Toplevel, Workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn toplevel_dnd_destination<'a>(
|
fn dnd_destination_for_target<'a, T>(
|
||||||
target: DropTarget,
|
target: DropTarget,
|
||||||
child: cosmic::Element<'a, Msg>,
|
child: cosmic::Element<'a, Msg>,
|
||||||
) -> cosmic::Element<'a, Msg> {
|
on_finish: impl Fn(T) -> Msg + 'static,
|
||||||
|
) -> cosmic::Element<'a, Msg>
|
||||||
|
where
|
||||||
|
T: AllowedMimeTypes,
|
||||||
|
{
|
||||||
let target2 = target.clone();
|
let target2 = target.clone();
|
||||||
cosmic::widget::dnd_destination::dnd_destination_for_data(
|
cosmic::widget::dnd_destination::dnd_destination_for_data(
|
||||||
child,
|
child,
|
||||||
|data: Option<DragToplevel>, _action| match data {
|
move |data: Option<T>, _action| match data {
|
||||||
Some(toplevel) => Msg::DndToplevelDrop(toplevel),
|
Some(data) => on_finish(data),
|
||||||
None => Msg::Ignore,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.drag_id(target.drag_id())
|
|
||||||
.on_enter(move |actions, mime, pos| Msg::DndEnter(target.clone(), actions, mime, pos))
|
|
||||||
.on_leave(move || Msg::DndLeave(target2.clone()))
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn workspace_dnd_destination<'a>(
|
|
||||||
target: DropTarget,
|
|
||||||
child: cosmic::Element<'a, Msg>,
|
|
||||||
) -> cosmic::Element<'a, Msg> {
|
|
||||||
let target2 = target.clone();
|
|
||||||
cosmic::widget::dnd_destination::dnd_destination_for_data(
|
|
||||||
child,
|
|
||||||
|data: Option<DragWorkspace>, _action| match data {
|
|
||||||
Some(workspace) => Msg::DndWorkspaceDrop(workspace),
|
|
||||||
None => Msg::Ignore,
|
None => Msg::Ignore,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -100,9 +86,10 @@ pub(crate) fn layer_surface<'a>(
|
||||||
.workspaces_for_output(&surface.output)
|
.workspaces_for_output(&surface.output)
|
||||||
.find(|w| w.is_active);
|
.find(|w| w.is_active);
|
||||||
let toplevels = if let Some(workspace) = first_active_workspace {
|
let toplevels = if let Some(workspace) = first_active_workspace {
|
||||||
toplevel_dnd_destination(
|
dnd_destination_for_target(
|
||||||
DropTarget::OutputToplevels(workspace.handle.clone(), surface.output.clone()),
|
DropTarget::OutputToplevels(workspace.handle.clone(), surface.output.clone()),
|
||||||
toplevels,
|
toplevels,
|
||||||
|
Msg::DndToplevelDrop,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Shouldn't happen, but no drag destination if no active workspace found for output
|
// Shouldn't happen, but no drag destination if no active workspace found for output
|
||||||
|
|
@ -226,9 +213,10 @@ fn workspace_sidebar_entry<'a>(
|
||||||
*/
|
*/
|
||||||
//crate::widgets::mouse_interaction_wrapper(
|
//crate::widgets::mouse_interaction_wrapper(
|
||||||
// mouse_interaction,
|
// mouse_interaction,
|
||||||
toplevel_dnd_destination(
|
dnd_destination_for_target(
|
||||||
DropTarget::WorkspaceSidebarEntry(workspace.handle.clone(), output.clone()),
|
DropTarget::WorkspaceSidebarEntry(workspace.handle.clone(), output.clone()),
|
||||||
item,
|
item,
|
||||||
|
Msg::DndToplevelDrop,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue