file explorer fix

This commit is contained in:
grimsace
2026-05-22 11:41:32 -05:00
parent fd574dd2ce
commit 0522317349
4 changed files with 56 additions and 25 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "desktop_dungeon_generator" name = "desktop_dungeon_generator"
version = "0.8.0" version = "0.8.1"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
+25 -8
View File
@@ -30,11 +30,20 @@ pub fn select_export_target(settings: &UiSettings) -> Result<ExportTarget, Strin
}; };
let mut dialog = FileDialog::new().set_title(title); let mut dialog = FileDialog::new().set_title(title);
if let Some(ref last_path) = settings.last_export_path { if let Some(ref last_path) = settings.last_export_path {
dialog = dialog.set_directory(last_path); let path = PathBuf::from(last_path);
if path.is_dir() {
dialog = dialog.set_directory(path);
}
} }
let folder = dialog
.pick_folder() #[cfg(target_os = "windows")]
.ok_or_else(|| "Export canceled".to_string())?; let folder = std::thread::spawn(move || dialog.pick_folder())
.join()
.map_err(|_| "Dialog thread panicked".to_string())?;
#[cfg(not(target_os = "windows"))]
let folder = dialog.pick_folder();
let folder = folder.ok_or_else(|| "Export canceled".to_string())?;
return Ok(ExportTarget::Folder(folder)); return Ok(ExportTarget::Folder(folder));
} }
@@ -48,12 +57,20 @@ pub fn select_export_target(settings: &UiSettings) -> Result<ExportTarget, Strin
.add_filter(settings.export_format.label(), &[ext]); .add_filter(settings.export_format.label(), &[ext]);
if let Some(ref last_path) = settings.last_export_path { if let Some(ref last_path) = settings.last_export_path {
dialog = dialog.set_directory(last_path); let path = PathBuf::from(last_path);
if path.is_dir() {
dialog = dialog.set_directory(path);
}
} }
let mut path = dialog #[cfg(target_os = "windows")]
.save_file() let path = std::thread::spawn(move || dialog.save_file())
.ok_or_else(|| "Export canceled".to_string())?; .join()
.map_err(|_| "Dialog thread panicked".to_string())?;
#[cfg(not(target_os = "windows"))]
let path = dialog.save_file();
let mut path = path.ok_or_else(|| "Export canceled".to_string())?;
if path.extension().is_none() { if path.extension().is_none() {
path.set_extension(ext); path.set_extension(ext);
+22 -8
View File
@@ -25,12 +25,19 @@ pub fn save_dungeon(
layouts: Vec<DungeonLayout>, layouts: Vec<DungeonLayout>,
svgs: Vec<String>, svgs: Vec<String>,
) -> Result<PathBuf, String> { ) -> Result<PathBuf, String> {
let path = FileDialog::new() let dialog = FileDialog::new()
.set_title("Save Dungeon State") .set_title("Save Dungeon State")
.add_filter("Dungeon File", &["dungeon"]) .add_filter("Dungeon File", &["dungeon"])
.set_file_name("my_dungeon.dungeon") .set_file_name("my_dungeon.dungeon");
.save_file()
.ok_or_else(|| "Save canceled".to_string())?; #[cfg(target_os = "windows")]
let path = std::thread::spawn(move || dialog.save_file())
.join()
.map_err(|_| "Dialog thread panicked".to_string())?;
#[cfg(not(target_os = "windows"))]
let path = dialog.save_file();
let path = path.ok_or_else(|| "Save canceled".to_string())?;
let save_data = DungeonSave { let save_data = DungeonSave {
settings: settings.clone(), settings: settings.clone(),
@@ -48,11 +55,18 @@ pub fn save_dungeon(
// Loads dungeon state from a user-selected JSON file. // Loads dungeon state from a user-selected JSON file.
pub fn load_dungeon() -> Result<DungeonSave, String> { pub fn load_dungeon() -> Result<DungeonSave, String> {
let path = FileDialog::new() let dialog = FileDialog::new()
.set_title("Load Dungeon State") .set_title("Load Dungeon State")
.add_filter("Dungeon File", &["dungeon"]) .add_filter("Dungeon File", &["dungeon"]);
.pick_file()
.ok_or_else(|| "Load canceled".to_string())?; #[cfg(target_os = "windows")]
let path = std::thread::spawn(move || dialog.pick_file())
.join()
.map_err(|_| "Dialog thread panicked".to_string())?;
#[cfg(not(target_os = "windows"))]
let path = dialog.pick_file();
let path = path.ok_or_else(|| "Load canceled".to_string())?;
let content = fs::read_to_string(path).map_err(|e| format!("Failed to read file: {e}"))?; let content = fs::read_to_string(path).map_err(|e| format!("Failed to read file: {e}"))?;
+8 -8
View File
@@ -53,11 +53,11 @@ impl ExportFormat {
// Returns the user-facing label for this option. // Returns the user-facing label for this option.
pub fn label(self) -> &'static str { pub fn label(self) -> &'static str {
match self { match self {
ExportFormat::Png => ".png", ExportFormat::Png => "PNG Image",
ExportFormat::Jpeg => ".jpeg", ExportFormat::Jpeg => "JPEG Image",
ExportFormat::Webp => ".webp", ExportFormat::Webp => "WebP Image",
ExportFormat::Svg => ".svg", ExportFormat::Svg => "SVG Vector Graphic",
ExportFormat::Folder => "Folder (Composite)", ExportFormat::Folder => "Folder",
} }
} }
@@ -94,9 +94,9 @@ impl MaskFormat {
// Returns the user-facing label for this option. // Returns the user-facing label for this option.
pub fn label(self) -> &'static str { pub fn label(self) -> &'static str {
match self { match self {
MaskFormat::Png => ".png", MaskFormat::Png => "PNG Image",
MaskFormat::Jpeg => ".jpeg", MaskFormat::Jpeg => "JPEG Image",
MaskFormat::Webp => ".webp", MaskFormat::Webp => "WebP Image",
} }
} }
} }