@@ -450,18 +450,18 @@ pub fn item_from_entry(
450
450
451
451
pub fn item_from_path < P : Into < PathBuf > > ( path : P , sizes : IconSizes ) -> Result < Item , String > {
452
452
let path = path. into ( ) ;
453
- let name_os = path
454
- . file_name ( )
455
- . ok_or_else ( || format ! ( "failed to get file name from path {:?}" , path ) ) ? ;
456
- let name = name_os
457
- . to_str ( )
458
- . ok_or_else ( || {
459
- format ! (
460
- "failed to parse file name for {:?}: {:?} is not valid UTF-8" ,
461
- path , name_os
462
- )
463
- } ) ?
464
- . to_string ( ) ;
453
+ let name = match path. file_name ( ) {
454
+ Some ( name_os ) => name_os
455
+ . to_str ( )
456
+ . ok_or_else ( || {
457
+ format ! (
458
+ "failed to parse file name for {:?}: {:?} is not valid UTF-8" ,
459
+ path , name_os
460
+ )
461
+ } ) ?
462
+ . to_string ( ) ,
463
+ None => fl ! ( "filesystem" ) ,
464
+ } ;
465
465
let metadata = fs:: metadata ( & path)
466
466
. map_err ( |err| format ! ( "failed to read metadata for {:?}: {}" , path, err) ) ?;
467
467
Ok ( item_from_entry ( path, name, metadata, sizes) )
@@ -942,6 +942,7 @@ impl Location {
942
942
pub enum Command {
943
943
Action ( Action ) ,
944
944
AddNetworkDrive ,
945
+ AddToSidebar ( PathBuf ) ,
945
946
ChangeLocation ( String , Location , Option < PathBuf > ) ,
946
947
DropFiles ( PathBuf , ClipboardPaste ) ,
947
948
EmptyTrash ,
@@ -1014,6 +1015,7 @@ pub enum LocationMenuAction {
1014
1015
OpenInNewTab ( usize ) ,
1015
1016
OpenInNewWindow ( usize ) ,
1016
1017
Preview ( usize ) ,
1018
+ AddToSidebar ( usize ) ,
1017
1019
}
1018
1020
1019
1021
impl MenuAction for LocationMenuAction {
@@ -2200,6 +2202,16 @@ impl Tab {
2200
2202
}
2201
2203
}
2202
2204
}
2205
+ LocationMenuAction :: AddToSidebar ( ancestor_index) => {
2206
+ if let Some ( path) = path_for_index ( ancestor_index) {
2207
+ commands. push ( Command :: AddToSidebar ( path) ) ;
2208
+ } else {
2209
+ log:: warn!(
2210
+ "no ancestor {ancestor_index} for location {:?}" ,
2211
+ self . location
2212
+ ) ;
2213
+ }
2214
+ }
2203
2215
}
2204
2216
}
2205
2217
Message :: Drag ( rect_opt) => match rect_opt {
0 commit comments