@@ -7,6 +7,7 @@ use gtk4::{
77} ;
88use gtk4:: { gdk, glib} ;
99use std:: cell:: RefCell ;
10+ use std:: path:: Path ;
1011use std:: rc:: Rc ;
1112
1213pub 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
0 commit comments