window: New way to detect own window in d+d
This is a (hopefully) cleaner way to detect if we are dragging out of the own window to not show drag indicator in that case. Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/258>
This commit is contained in:
parent
78b16518e5
commit
cf8fa499d9
2 changed files with 12 additions and 20 deletions
|
|
@ -78,6 +78,8 @@ mod imp {
|
|||
#[template_child]
|
||||
pub sliding_view: TemplateChild<LpSlidingView>,
|
||||
|
||||
pub drag_source: gtk::DragSource,
|
||||
|
||||
pub(super) model: RefCell<LpFileModel>,
|
||||
pub(super) preserve_content: Cell<bool>,
|
||||
|
||||
|
|
@ -164,10 +166,9 @@ mod imp {
|
|||
|
||||
self.current_image_signals.set(signal_group).unwrap();
|
||||
|
||||
let source = gtk::DragSource::new();
|
||||
source.set_exclusive(true);
|
||||
self.drag_source.set_exclusive(true);
|
||||
|
||||
source.connect_prepare(
|
||||
self.drag_source.connect_prepare(
|
||||
glib::clone!(@weak obj => @default-return None, move |gesture, _, _| {
|
||||
let is_scrollable = obj
|
||||
.current_page()
|
||||
|
|
@ -184,7 +185,7 @@ mod imp {
|
|||
}),
|
||||
);
|
||||
|
||||
source.connect_drag_begin(glib::clone!(@weak obj => move |source, _| {
|
||||
self.drag_source.connect_drag_begin(glib::clone!(@weak obj => move |source, _| {
|
||||
if let Some(paintable) = obj.current_image().and_then(|p| p.thumbnail()) {
|
||||
// -6 for cursor width, +16 for margin in .drag-icon
|
||||
source.set_icon(Some(&paintable), paintable.intrinsic_width() / 2 - 6 + 16, -12);
|
||||
|
|
@ -198,7 +199,7 @@ mod imp {
|
|||
};
|
||||
}));
|
||||
|
||||
obj.add_controller(source);
|
||||
obj.add_controller(self.drag_source.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -545,6 +546,10 @@ impl LpImageView {
|
|||
.and_then(|x| x.image().file())
|
||||
}
|
||||
|
||||
pub fn drag_source(&self) -> gtk::DragSource {
|
||||
self.imp().drag_source.clone()
|
||||
}
|
||||
|
||||
/// Returns `true` if there is an image before the current one
|
||||
pub fn is_previous_available(&self) -> bool {
|
||||
if let Some(file) = self.current_file() {
|
||||
|
|
|
|||
|
|
@ -377,23 +377,10 @@ mod imp {
|
|||
|
||||
self.drop_target.set_types(&[gdk::FileList::static_type()]);
|
||||
|
||||
//only accept drops from out side the app
|
||||
//https://gitlab.gnome.org/GNOME/Incubator/loupe/-/merge_requests/244#note_1788260
|
||||
// Only accept drops from external sources or different windows
|
||||
self.drop_target.connect_accept(
|
||||
clone!(@weak obj => @default-return false, move |_drop_target, drop| {
|
||||
//drag is between Loupe windows
|
||||
if let Some(drop) = drop.drag() {
|
||||
let file = drop
|
||||
.content()
|
||||
.value(gdk::FileList::static_type())
|
||||
.ok()
|
||||
.and_then(|value| value.get::<gdk::FileList>().ok())
|
||||
.and_then(|files| files.files().first().and_then(|file| file.path()));
|
||||
let current_image = obj.image_view().current_file().and_then(|file| file.path());
|
||||
return file.ne(¤t_image);
|
||||
}
|
||||
//drag from another window, should always be accepted
|
||||
true
|
||||
drop.drag().is_none() || drop.drag() != obj.image_view().drag_source().drag()
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue