Project panel: Replace with Precomposition (used N times)

Right-clicking a footage item or solid in the Project panel offers
"Replace with Precomposition (used N times)": the item goes into a new
composition of its size, pixel aspect and frame rate, in the same folder, and
every layer in every composition that used it switches to that composition,
keeping timing, transforms, effects and masks. One undo step. Agents run it as
`file.replaceWithPrecomp`.

The Project panel's details header also shows how often the selected item is
used ("Name ▾, used 3 times"); the ▾ lists and opens the comps that use it.
`Project::item_users` and the `project.usedIn` query back both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Themolx
2026-10-12 15:14:43 +02:00
co-authored by Claude Opus 5.5
parent 9efe75330c
commit fcf56415dc
10 changed files with 282 additions and 3 deletions
+24
View File
@@ -317,6 +317,7 @@ const JAPANESE: &[(&str, &str)] = &[
("Navigation", "ナビゲーション"),
("New", "新規"),
("New Comp from Selection", "選択範囲から新規コンポジション"),
("Replace with Precomposition", "プリコンポジションに置き換え"),
("New Duration:", "新しいデュレーション:"),
("New composition name:", "新規コンポジション名:"),
("New from Render Queue item:", "レンダーキュー項目から新規作成:"),
@@ -352,6 +353,9 @@ const JAPANESE: &[(&str, &str)] = &[
("One-Node Camera", "1ノードカメラ"),
("Opacity:", "不透明度:"),
("Open Composition", "コンポジションを開く"),
("used once", "1 回使用"),
("used {} times", "{} 回使用"),
("Compositions that use this item", "このアイテムを使用しているコンポジション"),
("Open Last Saved Project", "最後に保存したプロジェクトを開く"),
("Open New Composition", "新規コンポジションを開く"),
("Open Output", "出力を開く"),
@@ -764,6 +768,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
("Navigation", "导航"),
("New", "新建"),
("New Comp from Selection", "由所选项目新建合成"),
("Replace with Precomposition", "替换为预合成"),
("New Duration:", "新持续时间:"),
("New composition name:", "新合成名称:"),
("New from Render Queue item:", "由渲染队列项新建:"),
@@ -796,6 +801,9 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
("One-Node Camera", "单节点摄像机"),
("Opacity:", "不透明度:"),
("Open Composition", "打开合成"),
("used once", "使用 1 次"),
("used {} times", "使用 {} 次"),
("Compositions that use this item", "使用此项目的合成"),
("Open Last Saved Project", "打开上次保存的项目"),
("Open New Composition", "打开新建合成"),
("Open Output", "打开输出"),
@@ -1299,6 +1307,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
("Navigation", "導航"),
("New", "新建"),
("New Comp from Selection", "由所選專案新建合成"),
("Replace with Precomposition", "取代為預先合成"),
("New Duration:", "新持續時間:"),
("New composition name:", "新合成名稱:"),
("New from Render Queue item:", "由算圖佇列項新建:"),
@@ -1331,6 +1340,9 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
("One-Node Camera", "單節點攝影機"),
("Opacity:", "不透明度:"),
("Open Composition", "開啟合成"),
("used once", "使用 1 次"),
("used {} times", "使用 {} 次"),
("Compositions that use this item", "使用此項目的合成"),
("Open Last Saved Project", "開啟上次儲存的專案"),
("Open New Composition", "開啟新建合成"),
("Open Output", "開啟輸出"),
@@ -1837,6 +1849,7 @@ const UKRAINIAN: &[(&str, &str)] = &[
("Navigation", "Навігація"),
("New", "Створити"),
("New Comp from Selection", "Нова композиція з виділеного"),
("Replace with Precomposition", "Замінити попередньою композицією"),
("New Duration:", "Нова тривалість:"),
("New composition name:", "Назва нової композиції:"),
("New from Render Queue item:", "Створити з елемента черги рендерингу:"),
@@ -1875,6 +1888,9 @@ const UKRAINIAN: &[(&str, &str)] = &[
("One-Node Camera", "Одновузлова камера"),
("Opacity:", "Непрозорість:"),
("Open Composition", "Відкрити композицію"),
("used once", "використано 1 раз"),
("used {} times", "використань: {}"),
("Compositions that use this item", "Композиції, що використовують цей елемент"),
("Open Last Saved Project", "Відкрити останній збережений проєкт"),
("Open New Composition", "Відкрити нову композицію"),
("Open Output", "Відкрити результат"),
@@ -2373,6 +2389,10 @@ const PORTUGUESE: &[(&str, &str)] = &[
("Navigation", "Navegação"),
("New", "Novo"),
("New Comp from Selection", "Nova composição a partir da seleção"),
("Replace with Precomposition", "Substituir por pré-composição"),
("used once", "usado uma vez"),
("used {} times", "usado {} vezes"),
("Compositions that use this item", "Composições que usam este item"),
("New Duration:", "Nova duração:"),
("New composition name:", "Nome da nova composição:"),
("New from Render Queue item:", "Novo a partir do item da fila de renderização:"),
@@ -2817,6 +2837,10 @@ const CZECH: &[(&str, &str)] = &[
("Navigation", "Navigace"),
("New", "Nový"),
("New Comp from Selection", "Nová kompozice z výběru"),
("Replace with Precomposition", "Nahradit předkompozicí"),
("used once", "použito jednou"),
("used {} times", "použito {}×"),
("Compositions that use this item", "Kompozice, které tuto položku používají"),
("New Duration:", "Nová délka trvání:"),
("New composition name:", "Název nové kompozice:"),
("New from Render Queue item:", "Nová šablona z položky fronty vykreslování:"),
+59 -2
View File
@@ -361,8 +361,53 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
// The details stay inside the panel (a margin on the right), cut short with "…".
let tx = thumb.max.x + 10.0;
let max_w = head.max.x - 10.0 - tx;
let r = widgets::text_fit(&p, pos2(tx, thumb.min.y + 6.0), Align2::LEFT_CENTER, &it.name, Tokens::semibold(12.0), max_w, t.text);
app.auto.add("project.details.name", r, &it.name);
// "Name ▾, used 3 times" (After Effects): the layers in every comp whose source the item
// is; the ▾ lists those comps and opens the one picked. Nothing for an unused item.
let users = app.session.project.item_users(it.id);
let count = users.iter().fold(0usize, |n, (_, k)| n.saturating_add(*k));
let name_y = thumb.min.y + 6.0;
if count == 0 {
let r = widgets::text_fit(&p, pos2(tx, name_y), Align2::LEFT_CENTER, &it.name, Tokens::semibold(12.0), max_w, t.text);
app.auto.add("project.details.name", r, &it.name);
} else {
let used = if count == 1 { crate::i18n::tr("used once").to_owned() } else { crate::i18n::tr_args("used {} times", &[&count]) };
let used = format!(", {used}");
let used_w = p.layout_no_wrap(used.clone(), Tokens::ui(11.0), t.text_dim).size().x;
let arrow_w = 14.0;
// The name gives way first, but keeps at least half the room; the count is cut after it.
let name_max = (max_w - arrow_w - used_w).max(max_w * 0.5);
let r = widgets::text_fit(&p, pos2(tx, name_y), Align2::LEFT_CENTER, &it.name, Tokens::semibold(12.0), name_max, t.text);
app.auto.add("project.details.name", r, &it.name);
let ar = Rect::from_min_size(pos2(r.max.x + 1.0, name_y - 7.0), vec2(arrow_w, 14.0));
let tip = crate::i18n::tr("Compositions that use this item");
let aresp = ui.interact(ar, egui::Id::new("proj-used-in"), Sense::click()).on_hover_text(tip);
icons::paint(&p, Rect::from_center_size(ar.center(), vec2(9.0, 9.0)), Icon::ChevronDown, if aresp.hovered() { t.text } else { t.text_dim });
app.auto.add("project.details.usedIn", ar, tip);
// The comma sits right after the arrow (its glyph ends short of the hit area).
let ux = ar.max.x - 3.0;
let room = (head.max.x - 10.0 - ux).max(0.0);
let ur = widgets::text_fit(&p, pos2(ux, name_y), Align2::LEFT_CENTER, &used, Tokens::ui(11.0), room, t.text_dim);
app.auto.add("project.details.used", ur, &used);
let names: Vec<(u64, String, usize)> =
users.iter().map(|(cid, n)| (cid.0, app.session.project.item(*cid).map(|c| c.name.clone()).unwrap_or_default(), *n)).collect();
let mut open = None;
egui::Popup::menu(&aresp).show(|ui| {
for (cid, name, n) in &names {
let label = if *n == 1 { name.clone() } else { format!("{name} ({n})") };
let b = ui.button(label);
app.auto.add(&format!("project.details.usedIn.{cid}"), b.rect, name);
if b.clicked() {
open = Some(*cid);
ui.close();
}
}
});
if let Some(cid) = open
&& let Err(e) = crate::menus::invoke(app, &ctx, "comp.open", json!({"comp": cid}))
{
app.ui.status = e;
}
}
let mut lines = vec![];
if let Some((w, h)) = it.dimensions() {
lines.push(format!("{w} x {h} (1.00)"));
@@ -808,6 +853,18 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
actions.push(("file.newCompFromSelection".into(), json!({})));
ui.close();
}
// File ▸ Replace Footage ▸ With Precomposition: every layer using the item uses a
// new composition holding it instead. The label says how many layers that changes.
let uses: usize = app.session.project.item_users(*id).iter().map(|(_, n)| n).sum();
let label = match uses {
0 => crate::i18n::tr("Replace with Precomposition").to_owned(),
1 => format!("{} ({})", crate::i18n::tr("Replace with Precomposition"), crate::i18n::tr("used once")),
n => format!("{} ({})", crate::i18n::tr("Replace with Precomposition"), crate::i18n::tr_args("used {} times", &[&n])),
};
if (footage || matches!(it.kind, ItemKind::Solid(_))) && ui.button(label).clicked() {
actions.push(("file.replaceWithPrecomp".into(), json!({"item": id.0})));
ui.close();
}
ui.separator();
ui.menu_button(crate::i18n::tr("Label"), |ui| {
for l in Label::ALL {