file explorer fix
This commit is contained in:
@@ -30,11 +30,20 @@ pub fn select_export_target(settings: &UiSettings) -> Result<ExportTarget, Strin
|
||||
};
|
||||
let mut dialog = FileDialog::new().set_title(title);
|
||||
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()
|
||||
.ok_or_else(|| "Export canceled".to_string())?;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -48,12 +57,20 @@ pub fn select_export_target(settings: &UiSettings) -> Result<ExportTarget, Strin
|
||||
.add_filter(settings.export_format.label(), &[ext]);
|
||||
|
||||
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
|
||||
.save_file()
|
||||
.ok_or_else(|| "Export 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 mut path = path.ok_or_else(|| "Export canceled".to_string())?;
|
||||
|
||||
if path.extension().is_none() {
|
||||
path.set_extension(ext);
|
||||
|
||||
+22
-8
@@ -25,12 +25,19 @@ pub fn save_dungeon(
|
||||
layouts: Vec<DungeonLayout>,
|
||||
svgs: Vec<String>,
|
||||
) -> Result<PathBuf, String> {
|
||||
let path = FileDialog::new()
|
||||
let dialog = FileDialog::new()
|
||||
.set_title("Save Dungeon State")
|
||||
.add_filter("Dungeon File", &["dungeon"])
|
||||
.set_file_name("my_dungeon.dungeon")
|
||||
.save_file()
|
||||
.ok_or_else(|| "Save canceled".to_string())?;
|
||||
.set_file_name("my_dungeon.dungeon");
|
||||
|
||||
#[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 {
|
||||
settings: settings.clone(),
|
||||
@@ -48,11 +55,18 @@ pub fn save_dungeon(
|
||||
|
||||
// Loads dungeon state from a user-selected JSON file.
|
||||
pub fn load_dungeon() -> Result<DungeonSave, String> {
|
||||
let path = FileDialog::new()
|
||||
let dialog = FileDialog::new()
|
||||
.set_title("Load Dungeon State")
|
||||
.add_filter("Dungeon File", &["dungeon"])
|
||||
.pick_file()
|
||||
.ok_or_else(|| "Load canceled".to_string())?;
|
||||
.add_filter("Dungeon File", &["dungeon"]);
|
||||
|
||||
#[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}"))?;
|
||||
|
||||
|
||||
+8
-8
@@ -53,11 +53,11 @@ impl ExportFormat {
|
||||
// Returns the user-facing label for this option.
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
ExportFormat::Png => ".png",
|
||||
ExportFormat::Jpeg => ".jpeg",
|
||||
ExportFormat::Webp => ".webp",
|
||||
ExportFormat::Svg => ".svg",
|
||||
ExportFormat::Folder => "Folder (Composite)",
|
||||
ExportFormat::Png => "PNG Image",
|
||||
ExportFormat::Jpeg => "JPEG Image",
|
||||
ExportFormat::Webp => "WebP Image",
|
||||
ExportFormat::Svg => "SVG Vector Graphic",
|
||||
ExportFormat::Folder => "Folder",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ impl MaskFormat {
|
||||
// Returns the user-facing label for this option.
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
MaskFormat::Png => ".png",
|
||||
MaskFormat::Jpeg => ".jpeg",
|
||||
MaskFormat::Webp => ".webp",
|
||||
MaskFormat::Png => "PNG Image",
|
||||
MaskFormat::Jpeg => "JPEG Image",
|
||||
MaskFormat::Webp => "WebP Image",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user