Handle Windows hidden attribute
This commit is contained in:
parent
cca00e2d67
commit
dcf871e538
1 changed files with 29 additions and 5 deletions
34
src/tab.rs
34
src/tab.rs
|
|
@ -57,29 +57,50 @@ fn folder_icon(path: &PathBuf, icon_size: u16) -> widget::icon::Icon {
|
||||||
.icon()
|
.icon()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
fn hidden_attribute(_path: &PathBuf) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn hidden_attribute(path: &PathBuf) -> bool {
|
||||||
|
use std::os::windows::fs::MetadataExt;
|
||||||
|
match fs::metadata(path) {
|
||||||
|
Ok(metadata) => {
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
|
||||||
|
const FILE_ATTRIBUTE_HIDDEN: u32 = 2;
|
||||||
|
metadata.file_attributes() & FILE_ATTRIBUTE_HIDDEN == FILE_ATTRIBUTE_HIDDEN
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::warn!("failed to get hidden attribute for {:?}: {}", path, err);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn open_command(path: &PathBuf) -> process::Command {
|
fn open_command(path: &PathBuf) -> process::Command {
|
||||||
let mut command = process::Command::new("xdg-open");
|
let mut command = process::Command::new("xdg-open");
|
||||||
command.arg(path);
|
command.arg(path);
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub fn open_command(path: &PathBuf) -> process::Command {
|
fn open_command(path: &PathBuf) -> process::Command {
|
||||||
let mut command = process::Command::new("open");
|
let mut command = process::Command::new("open");
|
||||||
command.arg(path);
|
command.arg(path);
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
pub fn open_command(path: &PathBuf) -> process::Command {
|
fn open_command(path: &PathBuf) -> process::Command {
|
||||||
let mut command = process::Command::new("launcher");
|
let mut command = process::Command::new("launcher");
|
||||||
command.arg(path);
|
command.arg(path);
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn open_command(path: &PathBuf) -> process::Command {
|
fn open_command(path: &PathBuf) -> process::Command {
|
||||||
let mut command = process::Command::new("cmd");
|
let mut command = process::Command::new("cmd");
|
||||||
command.arg("/c");
|
command.arg("/c");
|
||||||
command.arg("start");
|
command.arg("start");
|
||||||
|
|
@ -97,6 +118,7 @@ pub enum Message {
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
|
pub hidden: bool,
|
||||||
pub is_dir: bool,
|
pub is_dir: bool,
|
||||||
pub icon: widget::icon::Icon,
|
pub icon: widget::icon::Icon,
|
||||||
pub select_time: Option<Instant>,
|
pub select_time: Option<Instant>,
|
||||||
|
|
@ -153,6 +175,7 @@ impl Tab {
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
let hidden = name.starts_with(".") || hidden_attribute(&path);
|
||||||
let is_dir = path.is_dir();
|
let is_dir = path.is_dir();
|
||||||
//TODO: configurable size
|
//TODO: configurable size
|
||||||
let icon_size = 32;
|
let icon_size = 32;
|
||||||
|
|
@ -165,6 +188,7 @@ impl Tab {
|
||||||
self.items.push(Item {
|
self.items.push(Item {
|
||||||
name,
|
name,
|
||||||
path,
|
path,
|
||||||
|
hidden,
|
||||||
is_dir,
|
is_dir,
|
||||||
icon,
|
icon,
|
||||||
select_time: None,
|
select_time: None,
|
||||||
|
|
@ -238,7 +262,7 @@ impl Tab {
|
||||||
|
|
||||||
let mut column = widget::column();
|
let mut column = widget::column();
|
||||||
for (i, item) in self.items.iter().enumerate() {
|
for (i, item) in self.items.iter().enumerate() {
|
||||||
if item.name.starts_with(".") {
|
if item.hidden {
|
||||||
//TODO: SHOW HIDDEN OPTION
|
//TODO: SHOW HIDDEN OPTION
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue