Merge branch 'cfix5/rest' into area/app-1

This commit is contained in:
Dylan M. Taylor committed 2026-11-18 17:22:46 -05:00
commit abe1bf7be4
1 file changed
+57
+57
View File
@@ -1,11 +1,68 @@
use craft::ui::runtime::drag::OsFile; // PLAN: assumed path of `OsFile` in the facade (ui-contract `runtime/drag.rs`)
use super::PdfCraftApp;
use craft::platform::open::{DroppedFile, Intake};
/// The name a dropped file is opened under when the OS gave none.
const DROPPED_NAME: &str = "dropped.pdf";
/// The action a `--combine` launch sends with its files (`single_instance::deliver`).
#[cfg(not(target_arch = "wasm32"))]
const COMBINE_ACTION: &str = "combine";
/// Raises the window for an open request from the OS.
fn bring_to_front(ctx: &egui::Context) {
ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(false));
ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
}
fn os_file(file: DroppedFile) -> OsFile {
OsFile { name: file.name, path: file.path, mime: String::new(), bytes: file.bytes }
}
impl PdfCraftApp {
/// Opens what the file intake holds, batch by batch in arrival order: another launch's paths
/// like File ▸ Open, its `combine` files in the Combine files tab, bytes as a new tab, drops
/// as [`Self::open_dropped`]. A batch from the OS brings the window to the front.
pub(crate) fn open_intake(&mut self, ctx: &egui::Context) {
for batch in self.intake.take() {
match batch {
Intake::Open(paths) => {
#[cfg(not(target_arch = "wasm32"))]
for path in &paths {
self.open_path(&path.to_string_lossy());
}
#[cfg(target_arch = "wasm32")]
drop(paths);
bring_to_front(ctx);
}
Intake::OpenFor { paths, action } => {
#[cfg(not(target_arch = "wasm32"))]
{
let paths: Vec<String> = paths.iter().map(|p| p.to_string_lossy().into_owned()).collect();
if action == COMBINE_ACTION {
self.combine_paths(&paths);
} else {
for path in &paths {
self.open_path(path);
}
}
}
#[cfg(target_arch = "wasm32")]
drop((paths, action));
bring_to_front(ctx);
}
Intake::Bytes { name, bytes } => {
let name = if name.is_empty() { DROPPED_NAME.to_string() } else { name };
if let Err(error) = self.open_bytes(&name, None, bytes.to_vec()) {
self.notify_fmt("Couldn't open {name}: {e}", &[("name", &name), ("e", &error)]);
}
}
Intake::Dropped { files, .. } => self.open_dropped(files.into_iter().map(os_file).collect()),
}
}
}
/// Opens the files dropped on the window: a file with a path like File ▸ Open, one that
/// arrived as bytes (the web) as a new tab.
pub(crate) fn open_dropped(&mut self, files: Vec<OsFile>) {