Skip to content

Commit d772af3

Browse files
committed
feat: remove border from file drop
1 parent bbb713d commit d772af3

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/files_panel.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use gtk4::{
77
};
88
use gtk4::{gdk, glib};
99
use std::cell::RefCell;
10+
use std::path::Path;
1011
use std::rc::Rc;
1112

1213
pub fn build_files_panel(fmstate: Rc<RefCell<FmState>>) -> (ScrolledWindow, StringList, ListView) {
@@ -36,8 +37,8 @@ pub fn build_files_panel(fmstate: Rc<RefCell<FmState>>) -> (ScrolledWindow, Stri
3637
item,
3738
move |_, _, _| {
3839
if let Some(obj) = item.item() {
39-
let file_name = obj.downcast_ref::<gtk4::StringObject>().unwrap().string();
40-
fmstate.borrow_mut().hovered_file = Some(file_name);
40+
let file_path = obj.downcast_ref::<gtk4::StringObject>().unwrap().string();
41+
fmstate.borrow_mut().hovered_file = Some(file_path);
4142
}
4243
}
4344
));
@@ -96,7 +97,44 @@ pub fn build_files_panel(fmstate: Rc<RefCell<FmState>>) -> (ScrolledWindow, Stri
9697
}
9798
));
9899

100+
// add drop target
101+
let drop_target = gtk4::DropTarget::new(String::static_type(), gdk::DragAction::COPY);
102+
103+
drop_target.connect_enter(glib::clone!(
104+
#[weak_allow_none]
105+
hbox,
106+
#[weak_allow_none]
107+
item,
108+
move |_, _, _| {
109+
// nesting looks fire, doesn't it?
110+
if let Some(item) = item.as_ref() {
111+
if let Some(obj) = item.item() {
112+
let file_path = obj.downcast_ref::<gtk4::StringObject>().unwrap().string();
113+
if let Some(hbox) = hbox.as_ref() {
114+
if !Path::new(&file_path).is_dir() {
115+
// remove styles if it is a file
116+
hbox.add_css_class("remove_styles");
117+
}
118+
}
119+
}
120+
}
121+
122+
gdk::DragAction::COPY
123+
}
124+
));
125+
126+
drop_target.connect_drop(glib::clone!(
127+
#[weak_allow_none]
128+
hbox,
129+
move |_, _, _, _| {
130+
// TODO
131+
132+
false
133+
}
134+
));
135+
99136
hbox.add_controller(drag_source);
137+
hbox.add_controller(drop_target);
100138
}
101139
));
102140

src/style.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pub fn load_css() {
1010
.pathbar {
1111
margin: 5px;
1212
}
13+
.remove_styles {
14+
all: unset;
15+
}
1316
",
1417
);
1518

0 commit comments

Comments
 (0)