Skip to content

Commit

Permalink
file_ops: Add source args manipulation to file dialog right panel
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 25, 2024
1 parent af43e21 commit 61ebfa3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ parking_lot = "0.12.1"
egui_code_editor = "0.2.10"
# luajit breaks with panic=abort, because it relies on unwinding for exception handling
mlua = { version = "0.9.7", features = ["lua54", "vendored"] }
egui-file-dialog = { git = "https://github.com/crumblingstatue/egui-file-dialog.git", branch = "active-entry" }
egui-file-dialog = { git = "https://github.com/crumblingstatue/egui-file-dialog.git", branch = "hexerator" }
human_bytes = "0.4.3"
shlex = "1.3.0"
smart-default = "0.7.1"
Expand Down
19 changes: 16 additions & 3 deletions src/gui/file_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use {
anyhow::Context as _,
egui_file_dialog::FileDialog,
std::{
fs::OpenOptions,
io::Write as _,
path::{Path, PathBuf},
},
Expand All @@ -30,6 +29,7 @@ pub struct FileOps {
pub dialog: FileDialog,
pub op: Option<FileOp>,
preview_cache: PathCache<EntInfo>,
file_dialog_source_args: SourceArgs,
}

impl Default for FileOps {
Expand All @@ -40,6 +40,7 @@ impl Default for FileOps {
.allow_path_edit_to_save_file_without_extension(true),
op: Default::default(),
preview_cache: PathCache::default(),
file_dialog_source_args: SourceArgs::default(),
}
}
}
Expand Down Expand Up @@ -127,6 +128,9 @@ impl FileOps {
if ft.is_symlink() {
ui.label("Symbolic link");
}
if !(ft.is_file() || ft.is_dir()) {
ui.label(format!("Special (size: {})", meta.len()));
}
}
Err(e) => {
ui.label(e.to_string());
Expand All @@ -140,6 +144,9 @@ impl FileOps {
} else {
ui.heading("Hexerator");
}
ui.separator();
ui.checkbox(&mut self.file_dialog_source_args.stream, "stream");
ui.checkbox(&mut self.file_dialog_source_args.read_only, "read-only");
});
if let Some(path) = self.dialog.take_selected()
&& let Some(op) = self.op.take()
Expand All @@ -159,9 +166,15 @@ impl FileOps {
advanced_open_window.path_to_meta = Some(path);
}
FileOp::LoadFile => {
let write = OpenOptions::new().write(true).open(&path).is_ok();
self.file_dialog_source_args.file = Some(path);
msg_if_fail(
app.load_file(path, !write, msg, font_size, line_spacing),
app.load_file_args(
self.file_dialog_source_args.clone(),
None,
msg,
font_size,
line_spacing,
),
"Failed to load file (read-write)",
msg,
);
Expand Down

0 comments on commit 61ebfa3

Please sign in to comment.