Skip to content

Commit

Permalink
Merge branch develop into docs/update_changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxcode committed Nov 18, 2024
2 parents a1d014a + 3f6cc40 commit 3cad414
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 64 deletions.
39 changes: 34 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ env:
RUSTFLAGS: "-Dwarnings"

jobs:
lint-fmt-test:
runs-on: ubuntu-latest
ci:
name: Check (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2

- name: Cargo check --all
run: cargo check
- name: Build
run: cargo build --all --all-features

- name: Cargo check
run: cargo check --all --all-features

- name: Rustfmt
run: cargo fmt --all -- --check
Expand All @@ -35,3 +43,24 @@ jobs:

- name: Test
run: cargo test --all --all-features

cargo-machete:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Machete
uses: bnjbvr/cargo-machete@main

typos:
# https://github.com/crate-ci/typos
# install and run locally: cargo install typos-cli && typos
name: typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Check spelling of entire workspace
uses: crate-ci/typos@master
6 changes: 6 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[default.extend-words]
# Don't correct german words
Ordner = "Ordner"
Elemente = "Elemente"
Alle = "Alle"
Ein = "Ein"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added `FileDialog::update_with_right_panel_ui` to add a custom right panel to the file dialog [#170](https://github.com/fluxxcode/egui-file-dialog/pull/170) (thanks [@crumblingstatue](https://github.com/crumblingstatue)!)
- Added `FileDialog::active_selected_entries` and `FileDialog::active_entry` to get information about the current active item/s [#170](https://github.com/fluxxcode/egui-file-dialog/pull/170) (thanks [@crumblingstatue](https://github.com/crumblingstatue)!)
- Added option to show system files in the hamburger menu [#173](https://github.com/fluxxcode/egui-file-dialog/pull/173) (thanks [@crumblingstatue](https://github.com/crumblingstatue)!)
- Support mapped network devices on Windows [#189](https://github.com/fluxxcode/egui-file-dialog/pull/189)
- Added the ability to drag and drop files and folders to open their respective path [#192](https://github.com/fluxxcode/egui-file-dialog/pull/192) (thanks [@hacknus](https://github.com/hacknus)!)

### 🐛 Bug Fixes
Expand All @@ -18,6 +19,7 @@
- Filter directory when loading to improve performance [#169](https://github.com/fluxxcode/egui-file-dialog/pull/169)
- Implement non blocking directory loading [#177](https://github.com/fluxxcode/egui-file-dialog/pull/177)
- Only update visible items in the central panel if the search value is empty and the create directory dialog is currently closed [#181](https://github.com/fluxxcode/egui-file-dialog/pull/181)
- Improve CI [#186](https://github.com/fluxxcode/egui-file-dialog/pull/186) (thanks [@bircni](https://github.com/bircni)!)

### 📚 Documentation
- Updated `README.md` to include latest features [#176](https://github.com/fluxxcode/egui-file-dialog/pull/176)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ serde = ["dep:serde"]
default_fonts = ["egui/default_fonts"]

[lints.rust]
unsafe_code = "forbid"
unsafe_code = "warn"

[lints.clippy]
nursery = { level = "deny", priority = 0 }
Expand Down
2 changes: 1 addition & 1 deletion src/config/keybindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub struct FileDialogKeyBindings {
}

impl FileDialogKeyBindings {
/// Checks wether any of the given keybindings is pressed.
/// Checks whether any of the given keybindings is pressed.
pub fn any_pressed(
ctx: &egui::Context,
keybindings: &Vec<KeyBinding>,
Expand Down
4 changes: 2 additions & 2 deletions src/data/directory_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ pub enum DirectoryContentState {
/// If we are currently waiting for the loading process on another thread.
/// The value is the timestamp when the loading process started.
Pending(SystemTime),
/// If loading the direcotry content finished since the last update call.
/// If loading the directory content finished since the last update call.
/// This is only returned once.
Finished,
/// If loading the directory content was successfull.
/// If loading the directory content was successful.
Success,
/// If there was an error loading the directory content.
/// The value contains the error message.
Expand Down
125 changes: 84 additions & 41 deletions src/data/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,32 @@ pub struct Disk {
}

impl Disk {
/// Create a new Disk object based on the data of a `sysinfo::Disk`.
pub fn from_sysinfo_disk(disk: &sysinfo::Disk, canonicalize_paths: bool) -> Self {
pub fn new(
name: Option<&str>,
mount_point: &Path,
is_removable: bool,
canonicalize_paths: bool,
) -> Self {
Self {
mount_point: Self::canonicalize(disk.mount_point(), canonicalize_paths),
display_name: gen_display_name(disk),
is_removable: disk.is_removable(),
mount_point: canonicalize(mount_point, canonicalize_paths),
display_name: gen_display_name(
name.unwrap_or_default(),
mount_point.to_str().unwrap_or_default(),
),
is_removable,
}
}

/// Create a new Disk object based on the data of a `sysinfo::Disk`.
pub fn from_sysinfo_disk(disk: &sysinfo::Disk, canonicalize_paths: bool) -> Self {
Self::new(
disk.name().to_str(),
disk.mount_point(),
disk.is_removable(),
canonicalize_paths,
)
}

/// Returns the mount point of the disk
pub fn mount_point(&self) -> &Path {
&self.mount_point
Expand All @@ -33,16 +50,6 @@ impl Disk {
pub const fn is_removable(&self) -> bool {
self.is_removable
}

/// Canonicalizes the given path.
/// Returns the input path in case of an error.
fn canonicalize(path: &Path, canonicalize: bool) -> PathBuf {
if canonicalize {
dunce::canonicalize(path).unwrap_or_else(|_| path.to_path_buf())
} else {
path.to_path_buf()
}
}
}

/// Wrapper above the `sysinfo::Disks` struct
Expand All @@ -54,14 +61,9 @@ pub struct Disks {
impl Disks {
/// Creates a new Disks object with a refreshed list of the system disks.
pub fn new_with_refreshed_list(canonicalize_paths: bool) -> Self {
let disks = sysinfo::Disks::new_with_refreshed_list();

let mut result: Vec<Disk> = Vec::new();
for disk in &disks {
result.push(Disk::from_sysinfo_disk(disk, canonicalize_paths));
Self {
disks: load_disks(canonicalize_paths),
}

Self { disks: result }
}

/// Very simple wrapper method of the disks `.iter()` method.
Expand All @@ -71,39 +73,80 @@ impl Disks {
}
}

/// Canonicalizes the given path.
/// Returns the input path in case of an error.
fn canonicalize(path: &Path, canonicalize: bool) -> PathBuf {
if canonicalize {
dunce::canonicalize(path).unwrap_or_else(|_| path.to_path_buf())
} else {
path.to_path_buf()
}
}

#[cfg(windows)]
fn gen_display_name(disk: &sysinfo::Disk) -> String {
// TODO: Get display name of the devices.
// Currently on Windows it returns an empty string for the C:\\ drive.

let mut name = disk.name().to_str().unwrap_or_default().to_string();
let mount_point = disk
.mount_point()
.to_str()
.unwrap_or_default()
.to_string()
.replace('\\', "");
fn gen_display_name(name: &str, mount_point: &str) -> String {
let mount_point = mount_point.replace('\\', "");

// Try using the mount point as the display name if the specified name
// from sysinfo::Disk is empty or contains invalid characters
if name.is_empty() {
return mount_point;
}

name.push_str(format!(" ({mount_point})").as_str());

name
format!("{name} ({mount_point})")
}

#[cfg(not(windows))]
fn gen_display_name(disk: &sysinfo::Disk) -> String {
let name = disk.name().to_str().unwrap_or_default().to_string();

fn gen_display_name(name: &str, mount_point: &str) -> String {
// Try using the mount point as the display name if the specified name
// from sysinfo::Disk is empty or contains invalid characters
if name.is_empty() {
return disk.mount_point().to_str().unwrap_or_default().to_string();
return mount_point.to_string();
}

name
name.to_string()
}

#[cfg(windows)]
fn load_disks(canonicalize_paths: bool) -> Vec<Disk> {
let mut disks: Vec<Disk> = sysinfo::Disks::new_with_refreshed_list()
.iter()
.map(|d| Disk::from_sysinfo_disk(d, canonicalize_paths))
.collect();

// `sysinfo::Disks` currently do not include mapped network drives on Windows.
// We will load all other available drives using the Windows API.
// However, the sysinfo disks have priority, we are just adding to the list.
#[allow(unsafe_code)]
let mut drives = unsafe { GetLogicalDrives() };
let mut letter = b'A';

while drives > 0 {
if drives & 1 != 0 {
let path = PathBuf::from(format!("{}:\\", letter as char));
let mount_point = canonicalize(&path, canonicalize_paths);

if !disks.iter().any(|d| d.mount_point == mount_point) {
disks.push(Disk::new(None, &path, false, canonicalize_paths));
}
}

drives >>= 1;
letter += 1;
}

disks
}

#[cfg(windows)]
extern "C" {
pub fn GetLogicalDrives() -> u32;
}

#[cfg(not(windows))]
fn load_disks(canonicalize_paths: bool) -> Vec<Disk> {
sysinfo::Disks::new_with_refreshed_list()
.iter()
.map(|d| Disk::from_sysinfo_disk(d, canonicalize_paths))
.collect()
}
Loading

0 comments on commit 3cad414

Please sign in to comment.