Import: dropped and picked files show an Importing card (#270)
Files dropped on the window or picked in the Import dialog were probed
one after the other on the UI thread: the app froze while a video was
read, nothing said what was being imported or how many files were
left, and only the last new item was selected. People ended up
importing the same file again and again.
file.import takes `background`: the files are probed in a background
job (Window > Progress, jobs.list / jobs.cancel) that names the file
being read and how many there are ("b.png (2 of 3)"); then they are
added in one undo step, all selected (the Project panel scrolls to
them, a file already in the project arrives again as in After
Effects) and a toast reports the count ("Imported 3 items", with the
first error). Drops and the Import dialog use it, and an Importing
card at the bottom left shows the job with its progress bar and
Cancel. Agents and scripts still import at once by default. The
toast registers an automation id.
Test: background_imports_report_progress_and_select_what_arrived
(engine), dropped_files_show_import_progress_then_the_items_they_made
(ui_drag_drop).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
285297ed93
commit
3318cb0da1
@@ -342,9 +342,7 @@ pub fn progress(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let frac = j.fraction.unwrap_or(0.0) as f32;
|
||||
let pct = j.fraction.map(|f| format!("{:.0} %", f * 100.0)).unwrap_or_else(|| "…".into());
|
||||
p.text(pos2(x0 + w - 70.0, y + 8.0), Align2::RIGHT_CENTER, format!("{pct} {}", j.message), Tokens::ui(11.0), t.text_dim);
|
||||
let bar = Rect::from_min_size(pos2(x0, y + 20.0), vec2(w - 76.0, 6.0));
|
||||
p.rect_filled(bar, 3.0, t.field_bg);
|
||||
p.rect_filled(Rect::from_min_size(bar.min, vec2(bar.width() * frac.clamp(0.0, 1.0), bar.height())), 3.0, t.accent);
|
||||
progress_bar(&p, Rect::from_min_size(pos2(x0, y + 20.0), vec2(w - 76.0, 6.0)), frac, &t);
|
||||
app.auto.add(&format!("progress.job.{}", j.id), Rect::from_min_size(pos2(x0, y), vec2(w, 28.0)), &j.label);
|
||||
if j.cancellable
|
||||
&& kit::button(app, ui, Rect::from_min_size(pos2(x0 + w - 64.0, y + 12.0), vec2(64.0, 18.0)), &format!("progress.cancel.{}", j.id), "Cancel", false)
|
||||
@@ -374,3 +372,39 @@ pub fn progress(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A job's progress bar (`frac` 0…1).
|
||||
fn progress_bar(p: &egui::Painter, bar: Rect, frac: f32, t: &Tokens) {
|
||||
p.rect_filled(bar, 3.0, t.field_bg);
|
||||
p.rect_filled(Rect::from_min_size(bar.min, vec2(bar.width() * frac.clamp(0.0, 1.0), bar.height())), 3.0, t.accent);
|
||||
}
|
||||
|
||||
/// The Importing card, bottom left over the panels while files import in the background (dropped
|
||||
/// or picked in the Import dialog): the file being read, how many are left, and Cancel (#270).
|
||||
/// Returns the height it takes, so toasts sit above it.
|
||||
pub fn import_card(app: &mut EffectcraftApp, ui: &mut egui::Ui, full: Rect) -> f32 {
|
||||
if app.session.tasks.is_empty() {
|
||||
return 0.0;
|
||||
}
|
||||
let t = app.tokens;
|
||||
let w = 320.0_f32.min(full.width() - 32.0).max(120.0);
|
||||
let mut bottom = full.max.y - 16.0;
|
||||
for j in app.session.jobs().into_iter().filter(|j| j.kind == "import" && j.running) {
|
||||
let r = Rect::from_min_max(pos2(full.min.x + 16.0, bottom - 56.0), pos2(full.min.x + 16.0 + w, bottom));
|
||||
let p = ui.painter();
|
||||
p.rect_filled(r, 6.0, t.panel_bg);
|
||||
p.rect_stroke(r, 6.0, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);
|
||||
let x0 = r.min.x + 12.0;
|
||||
let inner = w - 24.0;
|
||||
widgets::text_fit(p, pos2(x0, r.min.y + 15.0), Align2::LEFT_CENTER, &j.label, Tokens::medium(12.0), inner - 64.0, t.text);
|
||||
widgets::text_fit(p, pos2(x0, r.min.y + 32.0), Align2::LEFT_CENTER, &j.message, Tokens::ui(11.5), inner, t.text_dim);
|
||||
progress_bar(p, Rect::from_min_size(pos2(x0, r.min.y + 42.0), vec2(inner, 6.0)), j.fraction.unwrap_or(0.0) as f32, &t);
|
||||
app.auto.add(&format!("import.job.{}", j.id), r, &j.message);
|
||||
if kit::button(app, ui, Rect::from_min_size(pos2(r.max.x - 68.0, r.min.y + 6.0), vec2(56.0, 18.0)), &format!("import.cancel.{}", j.id), "Cancel", false)
|
||||
{
|
||||
kit::exec(app, "jobs.cancel", json!({"job": j.id}));
|
||||
}
|
||||
bottom = r.min.y - 8.0;
|
||||
}
|
||||
full.max.y - 16.0 - bottom
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user