diff --git a/crates/ui-egui/locales/ar.toml b/crates/ui-egui/locales/ar.toml index 4e6ebfea1..6d6f14192 100644 --- a/crates/ui-egui/locales/ar.toml +++ b/crates/ui-egui/locales/ar.toml @@ -459,7 +459,6 @@ status = "draft — needs native review" "Dots" = "نقاط" "Dotted" = "منقّط" "Down" = "لأسفل" -"Drafts" = "المسودات" "Drag the stroke to add a width point" = "اسحب الحد الخارجي لإضافة نقطة عرض" "Draw" = "رسم" "Draw a frame" = "رسم إطار" diff --git a/crates/ui-egui/locales/bn.toml b/crates/ui-egui/locales/bn.toml index 7cca3919c..42677c434 100644 --- a/crates/ui-egui/locales/bn.toml +++ b/crates/ui-egui/locales/bn.toml @@ -439,7 +439,6 @@ status = "draft — needs native review" "Dots" = "বিন্দুসমূহ" "Dotted" = "ডটেড" "Down" = "নিচে" -"Drafts" = "ড্রাফট" "Drag the stroke to add a width point" = "প্রস্থ বিন্দু যোগ করতে স্ট্রোকে ড্র্যাগ করুন" "Draw" = "আঁকুন" "Draw a frame" = "একটি ফ্রেম আঁকুন" diff --git a/crates/ui-egui/locales/bs.toml b/crates/ui-egui/locales/bs.toml index 73693d7be..fc0c5a983 100644 --- a/crates/ui-egui/locales/bs.toml +++ b/crates/ui-egui/locales/bs.toml @@ -464,7 +464,6 @@ status = "draft — needs native review" "Down" = "Dolje" "Download" = "Preuzmi" "Downloading… {percent}%" = "Preuzimanje… {percent}%" -"Drafts" = "Nacrti" "Drag the stroke to add a width point" = "Prevucite obrub da dodate tačku širine" "Draw" = "Crtanje" "Draw a frame" = "Nacrtaj okvir" diff --git a/crates/ui-egui/locales/cs.toml b/crates/ui-egui/locales/cs.toml index afafe7928..b4f92aee6 100644 --- a/crates/ui-egui/locales/cs.toml +++ b/crates/ui-egui/locales/cs.toml @@ -429,7 +429,6 @@ status = "draft — needs native review" "Dots" = "Tečky" "Dotted" = "Tečkovaný" "Down" = "Dolů" -"Drafts" = "Koncepty" "Drag the stroke to add a width point" = "Tažením tahu přidáte bod šířky" "Draw" = "Kreslení" "Draw a frame" = "Nakreslit rámec" diff --git a/crates/ui-egui/locales/de.toml b/crates/ui-egui/locales/de.toml index 17345d7e6..5e3135c85 100644 --- a/crates/ui-egui/locales/de.toml +++ b/crates/ui-egui/locales/de.toml @@ -429,7 +429,6 @@ status = "draft — needs native review" "Dots" = "Punkte" "Dotted" = "Gepunktet" "Down" = "Nach unten" -"Drafts" = "Entwürfe" "Drag the stroke to add a width point" = "Ziehen Sie an der Kontur, um einen Breitenpunkt hinzuzufügen" "Draw" = "Zeichnen" "Drawing tools" = "Zeichenwerkzeuge" diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index 61a12c37f..51081d100 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -149,6 +149,7 @@ name = "English" "Arc start" = "Arc start" "Arc sweep" = "Arc sweep" "Archive" = "Archive" +"Archive branch" = "Archive branch" "Archived" = "Archived" "Arrange" = "Arrange" "Arrow" = "Arrow" @@ -217,6 +218,7 @@ name = "English" "Branch updated from main" = "Branch updated from main" "Branch {name}" = "Branch {name}" "Branches" = "Branches" +"Branches and version history" = "Branches and version history" "Bound to {name}. Click to detach the variable." = "Bound to {name}. Click to detach the variable." "Bring forward" = "Bring forward" "Bring the main file's changes into the branch" = "Bring the main file's changes into the branch" @@ -390,6 +392,7 @@ name = "English" "Create a variable first" = "Create a variable first" "Create alias" = "Create alias" "Create branch" = "Create branch" +"Create branch…" = "Create branch…" "Create collection" = "Create collection" "Create component" = "Create component" "Create component property" = "Create component property" @@ -531,7 +534,6 @@ name = "English" "Down" = "Down" "Download" = "Download" "Downloading… {percent}%" = "Downloading… {percent}%" -"Drafts" = "Drafts" "Drag the stroke to add a width point" = "Drag the stroke to add a width point" "Draw" = "Draw" "Draw a frame" = "Draw a frame" @@ -903,6 +905,7 @@ name = "English" "Luminance" = "Luminance" "Luminosity" = "Luminosity" "Main" = "Main" +"Main · {n}" = "Main · {n}" "Main component deleted" = "Main component deleted" "Main menu" = "Main menu" "Make a component" = "Make a component" @@ -1385,6 +1388,7 @@ name = "English" "Save" = "Save" "Save as" = "Save as" "Save as preset…" = "Save as preset…" +"Save to version history…" = "Save to version history…" "Save version {key}" = "Save version {key}" "Saved" = "Saved" "Saved {name}" = "Saved {name}" @@ -1484,6 +1488,7 @@ name = "English" "Show section contents" = "Show section contents" "Show this layer" = "Show this layer" "Show usage" = "Show usage" +"Show version history" = "Show version history" "Show/Hide" = "Show/Hide" "Show/Hide UI" = "Show/Hide UI" "Side by side" = "Side by side" @@ -1992,6 +1997,7 @@ name = "English" "{count} in it now · Changed {date}" = "{count} in it now · Changed {date}" "{insertions} · {detachments}" = "{insertions} · {detachments}" "{instances} in {files}" = "{instances} in {files}" +"{label}, branches and version history" = "{label}, branches and version history" "{language}: draft translation, waiting for a native speaker's review." = "{language}: draft translation, waiting for a native speaker's review." "{length} bleed" = "{length} bleed" "{month} {day}, {year}" = "{month} {day}, {year}" @@ -2016,6 +2022,7 @@ name = "English" "{name} · published version {v}" = "{name} · published version {v}" "{name} · version {v} on the server" = "{name} · version {v} on the server" "{name} ×{n}" = "{name} ×{n}" +"{name}, branch of {file}" = "{name}, branch of {file}" "{name}, in a live session" = "{name}, in a live session" "{name}, online, open only to you" = "{name}, online, open only to you" "{name}, {kind}, {w} by {h}, selected" = "{name}, {kind}, {w} by {h}, selected" diff --git a/crates/ui-egui/locales/es.toml b/crates/ui-egui/locales/es.toml index 06c32c2d0..07a50560e 100644 --- a/crates/ui-egui/locales/es.toml +++ b/crates/ui-egui/locales/es.toml @@ -466,7 +466,6 @@ status = "draft — needs native review" "Dots" = "Puntos" "Dotted" = "Punteado" "Down" = "Abajo" -"Drafts" = "Borradores" "Drag the stroke to add a width point" = "Arrastra el trazo para añadir un punto de ancho" "Draw" = "Dibujar" "Draw a frame" = "Dibuja un marco" diff --git a/crates/ui-egui/locales/fi.toml b/crates/ui-egui/locales/fi.toml index ba6bd13d9..6239da58f 100644 --- a/crates/ui-egui/locales/fi.toml +++ b/crates/ui-egui/locales/fi.toml @@ -477,7 +477,6 @@ status = "draft — needs native review" "Down" = "Alas" "Download" = "Lataa" "Downloading… {percent}%" = "Ladataan… {percent} %" -"Drafts" = "Luonnokset" "Drag the stroke to add a width point" = "Lisää leveyspiste vetämällä reunaviivaa" "Draw" = "Piirrä" "Draw a frame" = "Piirrä kehys" diff --git a/crates/ui-egui/locales/fr.toml b/crates/ui-egui/locales/fr.toml index dbcd9150d..f3eb26296 100644 --- a/crates/ui-egui/locales/fr.toml +++ b/crates/ui-egui/locales/fr.toml @@ -440,7 +440,6 @@ status = "draft — needs native review" "Dots" = "Points" "Dotted" = "Pointillé" "Down" = "Bas" -"Drafts" = "Brouillons" "Drag the stroke to add a width point" = "Faites glisser le contour pour ajouter un point de largeur" "Draw" = "Dessin" "Draw a frame" = "Tracer un cadre" diff --git a/crates/ui-egui/locales/he.toml b/crates/ui-egui/locales/he.toml index 7fc803c08..8995d92c3 100644 --- a/crates/ui-egui/locales/he.toml +++ b/crates/ui-egui/locales/he.toml @@ -491,7 +491,6 @@ Dismiss = "סגירה" "Down" = "למטה" Download = "הורדה" "Downloading… {percent}%" = "מוריד… {percent}%" -"Drafts" = "טיוטות" "Drag the stroke to add a width point" = "גרירת קו המתאר תוסיף נקודת עובי" "Draw" = "ציור" "Draw a frame" = "ציור מסגרת" diff --git a/crates/ui-egui/locales/id.toml b/crates/ui-egui/locales/id.toml index 998c80887..a32128a12 100644 --- a/crates/ui-egui/locales/id.toml +++ b/crates/ui-egui/locales/id.toml @@ -443,7 +443,6 @@ status = "draft — needs native review" "Dots" = "Titik" "Dotted" = "Bertitik" "Down" = "Bawah" -"Drafts" = "Draf" "Drag the stroke to add a width point" = "Seret stroke untuk menambah titik lebar" "Draw" = "Gambar" "Draw a frame" = "Gambar frame" diff --git a/crates/ui-egui/locales/it.toml b/crates/ui-egui/locales/it.toml index 15963bb8e..d4ce5618e 100644 --- a/crates/ui-egui/locales/it.toml +++ b/crates/ui-egui/locales/it.toml @@ -421,7 +421,6 @@ status = "draft — needs native review" "Dots" = "Punti" "Dotted" = "Puntinato" "Down" = "Giù" -"Drafts" = "Bozze" "Drag the stroke to add a width point" = "Trascina il contorno per aggiungere un punto di larghezza" "Draw" = "Disegna" "Draw a frame" = "Disegna un frame" diff --git a/crates/ui-egui/locales/ja.toml b/crates/ui-egui/locales/ja.toml index 62efd18fd..925e5c6ed 100644 --- a/crates/ui-egui/locales/ja.toml +++ b/crates/ui-egui/locales/ja.toml @@ -438,7 +438,6 @@ status = "draft — needs native review" "Dots" = "ドット" "Dotted" = "点線" "Down" = "下" -"Drafts" = "下書き" "Drag the stroke to add a width point" = "線をドラッグして幅のポイントを追加" "Draw" = "描画" "Draw a frame" = "フレームを描く" diff --git a/crates/ui-egui/locales/ka.toml b/crates/ui-egui/locales/ka.toml index 8669e509d..d2b83c106 100644 --- a/crates/ui-egui/locales/ka.toml +++ b/crates/ui-egui/locales/ka.toml @@ -498,7 +498,6 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Down" = "ქვემოთ" "Download" = "ჩამოტვირთვა" "Downloading… {percent}%" = "ჩამოტვირთვა… {percent}%" -"Drafts" = "მონახაზები" "Drag the stroke to add a width point" = "გადაათრიეთ კონტური სიგანის წერტილის დასამატებლად" "Draw" = "ხატვა" "Draw a frame" = "დახატეთ ჩარჩო" diff --git a/crates/ui-egui/locales/ko.toml b/crates/ui-egui/locales/ko.toml index b1eacb2ab..5b90d3945 100644 --- a/crates/ui-egui/locales/ko.toml +++ b/crates/ui-egui/locales/ko.toml @@ -422,7 +422,6 @@ status = "draft — needs native review" "Dots" = "점" "Dotted" = "점선" "Down" = "아래" -"Drafts" = "임시 보관함" "Drag the stroke to add a width point" = "선을 드래그해 너비 점 추가" "Draw" = "그리기" "Drawing tools" = "그리기 도구" diff --git a/crates/ui-egui/locales/nl.toml b/crates/ui-egui/locales/nl.toml index a1512216e..88cf9b3ee 100644 --- a/crates/ui-egui/locales/nl.toml +++ b/crates/ui-egui/locales/nl.toml @@ -441,7 +441,6 @@ status = "draft — needs native review" "Dots" = "Dots" "Dotted" = "Gestippeld" "Down" = "Onder" -"Drafts" = "Concepten" "Drag the stroke to add a width point" = "Sleep de lijn om een breedtepunt toe te voegen" "Draw" = "Tekenen" "Draw a frame" = "Teken een frame" diff --git a/crates/ui-egui/locales/pl.toml b/crates/ui-egui/locales/pl.toml index b051b3a9d..385f90391 100644 --- a/crates/ui-egui/locales/pl.toml +++ b/crates/ui-egui/locales/pl.toml @@ -441,7 +441,6 @@ name = "Polski" "Dots" = "Kropki" "Dotted" = "Kropkowany" "Down" = "W dół" -"Drafts" = "Szkice" "Drag the stroke to add a width point" = "Przeciągnij obrys, aby dodać punkt szerokości" "Draw" = "Rysuj" "Draw a frame" = "Narysuj ramkę" diff --git a/crates/ui-egui/locales/pt-BR.toml b/crates/ui-egui/locales/pt-BR.toml index 0a0147944..51c7466f7 100644 --- a/crates/ui-egui/locales/pt-BR.toml +++ b/crates/ui-egui/locales/pt-BR.toml @@ -421,7 +421,6 @@ status = "draft — needs native review" "Dots" = "Pontos" "Dotted" = "Pontilhado" "Down" = "Para baixo" -"Drafts" = "Rascunhos" "Drag the stroke to add a width point" = "Arraste o traço para adicionar um ponto de largura" "Draw" = "Desenhar" "Drawing tools" = "Ferramentas de desenho" diff --git a/crates/ui-egui/locales/ru.toml b/crates/ui-egui/locales/ru.toml index 6a3d4e70e..1cb3da1df 100644 --- a/crates/ui-egui/locales/ru.toml +++ b/crates/ui-egui/locales/ru.toml @@ -442,7 +442,6 @@ name = "Русский" "Dots" = "Точки" "Dotted" = "Точечный" "Down" = "Вниз" -"Drafts" = "Черновики" "Drag the stroke to add a width point" = "Перетащите обводку, чтобы добавить точку ширины" "Draw" = "Рисование" "Draw a frame" = "Нарисовать Frame" diff --git a/crates/ui-egui/locales/sv.toml b/crates/ui-egui/locales/sv.toml index 5e0962c53..a632b29ec 100644 --- a/crates/ui-egui/locales/sv.toml +++ b/crates/ui-egui/locales/sv.toml @@ -525,7 +525,6 @@ name = "Svenska" "Down" = "Ned" "Download" = "Hämta" "Downloading… {percent}%" = "Hämtar… {percent} %" -"Drafts" = "Utkast" "Drag the stroke to add a width point" = "Dra i konturen för att lägga till en breddpunkt" "Draw" = "Rita" "Draw a frame" = "Rita en frame" diff --git a/crates/ui-egui/locales/ta.toml b/crates/ui-egui/locales/ta.toml index 32d841ce5..66ca8a9cc 100644 --- a/crates/ui-egui/locales/ta.toml +++ b/crates/ui-egui/locales/ta.toml @@ -487,7 +487,6 @@ status = "draft — needs native review" "Down" = "கீழே" "Download" = "பதிவிறக்கு" "Downloading… {percent}%" = "பதிவிறக்குகிறது… {percent}%" -"Drafts" = "வரைவுகள்" "Drag the stroke to add a width point" = "அகலப் புள்ளியைச் சேர்க்க ஸ்ட்ரோக்கை இழுக்கவும்" "Draw" = "வரை" "Draw a frame" = "ஃப்ரேம் வரை" diff --git a/crates/ui-egui/locales/th.toml b/crates/ui-egui/locales/th.toml index da5e0f2f2..4bc56d032 100644 --- a/crates/ui-egui/locales/th.toml +++ b/crates/ui-egui/locales/th.toml @@ -439,7 +439,6 @@ status = "draft — needs native review" "Dots" = "จุด" "Dotted" = "เส้นจุด" "Down" = "ลง" -"Drafts" = "แบบร่าง" "Drag the stroke to add a width point" = "ลากเส้นขอบเพื่อเพิ่มจุดความกว้าง" "Draw" = "วาด" "Draw a frame" = "วาดเฟรม" diff --git a/crates/ui-egui/locales/tr.toml b/crates/ui-egui/locales/tr.toml index 3b8a58610..d878f0913 100644 --- a/crates/ui-egui/locales/tr.toml +++ b/crates/ui-egui/locales/tr.toml @@ -434,7 +434,6 @@ name = "Türkçe" "Dots" = "Noktalar" "Dotted" = "Noktalı" "Down" = "Aşağı" -"Drafts" = "Taslaklar" "Drag the stroke to add a width point" = "Genişlik noktası eklemek için konturu sürükleyin" "Draw" = "Çiz" "Draw a frame" = "Çerçeve çiz" diff --git a/crates/ui-egui/locales/vi.toml b/crates/ui-egui/locales/vi.toml index a275cd2f1..fc686db20 100644 --- a/crates/ui-egui/locales/vi.toml +++ b/crates/ui-egui/locales/vi.toml @@ -422,7 +422,6 @@ status = "draft — needs native review" "Dots" = "Chấm" "Dotted" = "Chấm tròn" "Down" = "Xuống" -"Drafts" = "Bản nháp" "Drag the stroke to add a width point" = "Kéo nét để thêm điểm độ rộng" "Draw" = "Vẽ" "Draw a frame" = "Vẽ khung" diff --git a/crates/ui-egui/locales/zh-Hans.toml b/crates/ui-egui/locales/zh-Hans.toml index 01bcb6dca..b5ebd91c5 100644 --- a/crates/ui-egui/locales/zh-Hans.toml +++ b/crates/ui-egui/locales/zh-Hans.toml @@ -426,7 +426,6 @@ status = "draft — needs native review" "Dots" = "圆点" "Dotted" = "点线" "Down" = "向下" -"Drafts" = "草稿" "Drag the stroke to add a width point" = "拖动描边以添加宽度点" "Draw" = "绘制" "Drawing tools" = "绘图工具" diff --git a/crates/ui-egui/locales/zh-Hant.toml b/crates/ui-egui/locales/zh-Hant.toml index 499640ca7..c7c6f6295 100644 --- a/crates/ui-egui/locales/zh-Hant.toml +++ b/crates/ui-egui/locales/zh-Hant.toml @@ -483,7 +483,6 @@ status = "draft — needs native review" "Down" = "下" "Download" = "下載" "Downloading… {percent}%" = "正在下載… {percent}%" -"Drafts" = "草稿" "Drag the stroke to add a width point" = "拖曳邊框以新增寬度節點" "Draw" = "繪製" "Draw a frame" = "繪製框架" diff --git a/crates/ui-egui/src/a11y.rs b/crates/ui-egui/src/a11y.rs index c1181a2ce..8717d8b0f 100644 --- a/crates/ui-egui/src/a11y.rs +++ b/crates/ui-egui/src/a11y.rs @@ -926,6 +926,11 @@ pub fn toggle(resp: &Response, tip: &str, on: bool) { }); } +/// A static, non-editable text label. +pub fn label(resp: &Response, text: &str) { + node(resp, text, |n| n.set_role(Role::Label)); +} + /// A status shown in place (a badge), with what it means. pub fn status(resp: &Response, label: &str, description: &str) { node(resp, label, |n| { diff --git a/crates/ui-egui/src/branch_ui_tests.rs b/crates/ui-egui/src/branch_ui_tests.rs index 4cc7d0227..5d6fb7c89 100644 --- a/crates/ui-egui/src/branch_ui_tests.rs +++ b/crates/ui-egui/src/branch_ui_tests.rs @@ -35,3 +35,218 @@ fn review_dialog_opens_keeps_choices_and_closes() { u.frame(vec![]); assert!(u.app.ui.branch_review.is_none()); } + +/// Find the centre of the first painted text shape containing `needle`. +fn find_text(out: &egui::FullOutput, needle: &str) -> Option { + fn walk(shape: &egui::Shape, needle: &str) -> Option { + match shape { + egui::Shape::Vec(v) => v.iter().find_map(|s| walk(s, needle)), + egui::Shape::Text(t) if t.galley.text().contains(needle) => Some(t.pos + t.galley.size() / 2.0), + _ => None, + } + } + out.shapes.iter().find_map(|c| walk(&c.shape, needle)) +} + +/// Click at `p` and return the following frame's output. +fn click(u: &mut Ui, p: egui::Pos2) -> egui::FullOutput { + u.button(p, true); + u.button(p, false); + u.frame_output(vec![]) +} + +/// Press and release `key` on the next frame. +fn press_key(u: &mut Ui, key: Key) { + u.frame(vec![ + egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }, + egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::NONE }, + ]); +} + +/// Collect the AccessKit nodes emitted for the current frame. +fn accesskit_nodes(u: &mut Ui) -> Vec { + u.ctx.enable_accesskit(); + u.frame(vec![]); + let out = u.frame_output(vec![]); + out.platform_output.accesskit_update.expect("an AccessKit update").nodes.into_iter().map(|(_, n)| n).collect() +} + +#[test] +fn file_header_branch_menu_switches_branches_and_opens_history() { + let mut s = Session::new(); + s.execute("file.rename", &json!({"name": "App"})).unwrap(); + let mut u = Ui::new(s); + let out = u.frame_output(vec![]); + assert!(find_text(&out, "Main").is_some(), "main file header shows Main"); + assert!(find_text(&out, "Drafts").is_none(), "static Drafts placeholder is gone"); + + // Create a branch, then verify the header shows the main file name and the branch name. + u.run("branch.create", json!({"name": "Try"})); + let out = u.frame_output(vec![]); + assert_eq!(u.app.session.active, 1); + assert!(find_text(&out, "App").is_some(), "branch tab header still names the main file"); + let btn = u.ctx.read_response(egui::Id::unique("branch_menu_button")).expect("branch menu button").rect; + assert!(btn.height() >= 24.0, "branch menu target is at least 24 pt tall"); + let out = click(&mut u, btn.center()); + + // Review and merge is available from the header menu on a branch tab. + let review_pos = find_text(&out, "Review and merge").expect("Review and merge item"); + click(&mut u, review_pos); + assert!(u.app.ui.branch_review.is_some()); + u.app.ui.branch_review = None; + u.frame(vec![]); + + // Switch back to Main from the branch menu. + let btn = u.ctx.read_response(egui::Id::unique("branch_menu_button")).expect("branch menu button").rect; + let out = click(&mut u, btn.center()); + let main_item = out + .shapes + .iter() + .rev() + .find_map(|c| match &c.shape { + egui::Shape::Text(t) if t.galley.text().trim() == "Main" => Some(t.pos + t.galley.size() / 2.0), + _ => None, + }) + .expect("Main menu item"); + click(&mut u, main_item); + assert_eq!(u.app.session.active, 0, "clicking Main switches back to the main file tab"); + + // Main now shows the active branch count and opens the branch again from the menu. + let out = u.frame_output(vec![]); + assert!(find_text(&out, "Main · 1").is_some(), "header shows active branch count on Main"); + let btn = u.ctx.read_response(egui::Id::unique("branch_menu_button")).expect("branch menu button").rect; + let out = click(&mut u, btn.center()); + let branch_item = out + .shapes + .iter() + .rev() + .find_map(|c| match &c.shape { + egui::Shape::Text(t) if t.galley.text().trim() == "Try" => Some(t.pos + t.galley.size() / 2.0), + _ => None, + }) + .expect("Try branch menu item"); + click(&mut u, branch_item); + assert_eq!(u.app.session.active, 1, "clicking a branch switches to it"); + + // Create branch… from a branch tab switches to main and opens the branch creation form. + let btn = u.ctx.read_response(egui::Id::unique("branch_menu_button")).expect("branch menu button").rect; + let out = click(&mut u, btn.center()); + let create_pos = find_text(&out, "Create branch…").expect("Create branch item"); + click(&mut u, create_pos); + assert_eq!(u.app.session.active, 0, "Create branch switches to main first"); + assert!(u.app.ui.versions.open); + assert!(u.app.ui.versions.form.as_ref().is_some_and(|f| f.branch)); + + // Close version history, then open it again via Show version history. + u.app.ui.versions = Default::default(); + u.frame(vec![]); + let btn = u.ctx.read_response(egui::Id::unique("branch_menu_button")).expect("branch menu button").rect; + let out = click(&mut u, btn.center()); + let hist_pos = find_text(&out, "Show version history").expect("Show version history item"); + click(&mut u, hist_pos); + assert!(u.app.ui.versions.open, "Show version history opens the panel"); +} + +#[test] +fn file_header_branch_menu_keyboard_and_accessibility() { + use egui::accesskit::{HasPopup, Role}; + + let mut s = Session::new(); + let long_name = "Very Long Main File Name That Truncates In Sidebar"; + s.execute("file.rename", &json!({"name": long_name})).unwrap(); + let mut u = Ui::new(s); + u.run("branch.create", json!({"name": "Try"})); + + let nodes = accesskit_nodes(&mut u); + assert!( + nodes.iter().any(|n| n.role() == Role::Label && n.label() == Some(long_name)), + "branch tab header exposes the full main file name as a non-editable label" + ); + let expected_tab = format!("Try, branch of {long_name}"); + assert!( + nodes.iter().any(|n| n.role() == Role::Tab && n.label() == Some(expected_tab.as_str())), + "branch tab exposes its parent file in its accessible name" + ); + let btn_node = nodes + .iter() + .find(|n| n.role() == Role::Button && n.label() == Some("Try, branches and version history")) + .expect("branch menu button exposes a name starting with its visible label"); + assert_eq!(btn_node.has_popup(), Some(HasPopup::Menu)); + assert_eq!(btn_node.is_expanded(), Some(false)); + + // Focus the branch menu button, open it with Enter, then close it with Escape. + let btn_id = egui::Id::unique("branch_menu_button"); + u.ctx.memory_mut(|m| m.request_focus(btn_id)); + u.frame(vec![]); + press_key(&mut u, Key::Enter); + u.frame(vec![]); + u.frame(vec![]); + assert_eq!(crate::a11y::focused_name(&u.ctx), "Main", "opening the menu moves focus to its first item"); + let open_nodes = accesskit_nodes(&mut u); + let open_btn = open_nodes + .iter() + .find(|n| n.role() == Role::Button && n.label() == Some("Try, branches and version history")) + .expect("branch menu button stays named while open"); + assert_eq!(open_btn.is_expanded(), Some(true)); + + press_key(&mut u, Key::Escape); + u.frame(vec![]); + assert_eq!(crate::a11y::focused_name(&u.ctx), "Try, branches and version history", "Escape returns focus to the branch menu button"); +} + +#[test] +fn detached_branch_window_focuses_main_window_and_omits_create_branch() { + let mut s = Session::new(); + s.execute("file.rename", &json!({"name": "App"})).unwrap(); + let mut u = Ui::new(s); + u.ctx.set_embed_viewports(false); + u.run("branch.create", json!({"name": "Try"})); + let main_uid = u.app.session.docs[0].uid; + let branch_win = crate::windows::open(&mut u.app, &u.ctx, Some(1), None, None).expect("detached branch window"); + + u.app.windows.current = branch_win; + u.app.session.active = 1; + let run_branch_frame = |u: &mut Ui, events: Vec| -> egui::FullOutput { + u.time += 1.0 / 60.0; + let input = egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0))), + time: Some(u.time), + events, + ..Default::default() + }; + let app = &mut u.app; + let mut out = u.ctx.run_ui(input, |ui| app.frame(ui)); + out.textures_delta.clear(); + out + }; + let click_branch = |u: &mut Ui, p: egui::Pos2| -> egui::FullOutput { + let btn = |pressed| { + vec![ + egui::Event::PointerMoved(p), + egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }, + ] + }; + run_branch_frame(u, btn(true)); + run_branch_frame(u, btn(false)); + run_branch_frame(u, vec![]) + }; + + run_branch_frame(&mut u, vec![]); + let btn = u.ctx.read_response(egui::Id::unique("branch_menu_button")).expect("branch menu button").rect; + let out = click_branch(&mut u, btn.center()); + assert!(find_text(&out, "Create branch…").is_none(), "Create branch is omitted when Main is in another window"); + + let main_item = out + .shapes + .iter() + .rev() + .find_map(|c| match &c.shape { + egui::Shape::Text(t) if t.galley.text().trim() == "Main" => Some(t.pos + t.galley.size() / 2.0), + _ => None, + }) + .expect("Main menu item"); + click_branch(&mut u, main_item); + assert_eq!(u.app.session.active, 1, "detached window stays on its own branch tab"); + assert_eq!(u.app.windows.focused, 0, "clicking Main focuses the window that owns Main"); + assert_eq!(u.app.windows.active_doc(&u.app.session, 0), Some(main_uid), "Main becomes active in its owning window"); +} diff --git a/crates/ui-egui/src/icons.rs b/crates/ui-egui/src/icons.rs index 1c67509c7..99e846f67 100644 --- a/crates/ui-egui/src/icons.rs +++ b/crates/ui-egui/src/icons.rs @@ -167,6 +167,8 @@ icons! { Detach, Variable, Clock, + /// A branch of a file: a vertical stem with a second track forking off it. + Branch, Eraser, /// Variable width: a stroke swelling in the middle with a width handle above and below. VariableWidth, diff --git a/crates/ui-egui/src/icons/draw.rs b/crates/ui-egui/src/icons/draw.rs index f271b0d4a..4aa155a78 100644 --- a/crates/ui-egui/src/icons/draw.rs +++ b/crates/ui-egui/src/icons/draw.rs @@ -1097,6 +1097,22 @@ fn draw(p: &P, icon: Icon) { p.poly(&[(5.5, 5.5), (3.0, 8.0), (5.5, 10.5)], false); p.poly(&[(10.5, 5.5), (13.0, 8.0), (10.5, 10.5)], false); } + Branch => { + p.circle(4.5, 3.8, 1.7); + p.circle(4.5, 12.2, 1.7); + p.circle(11.5, 5.2, 1.7); + p.line(4.5, 5.5, 4.5, 10.5); + let curve: Vec<(f32, f32)> = (0..=10) + .map(|i| { + let t = i as f32 / 10.0; + let u = 1.0 - t; + let x = u * u * u * 11.5 + 3.0 * u * u * t * 11.5 + 3.0 * u * t * t * 4.5 + t * t * t * 4.5; + let y = u * u * u * 6.9 + 3.0 * u * u * t * 9.8 + 3.0 * u * t * t * 8.2 + t * t * t * 10.5; + (x, y) + }) + .collect(); + p.path(&curve, false); + } Logo => { // FigCraft's own mark: the curled tail of the chameleon on the app icon. One bold // stroke: a shaft along the bottom, then three half turns, each tighter than the last. diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 741babeac..d73b8ca3d 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -140,7 +140,7 @@ pub fn rail(app: &mut FigApp, ui: &mut Ui) { } /// Draw the left panel: versions when open, otherwise the file/Assets header with in-place -/// file rename and collapse control, followed by Pages and Layers or the Assets panel. +/// file rename, branch/version menu and collapse control, followed by Pages and Layers or Assets. pub fn left_panel(app: &mut FigApp, ui: &mut Ui) { if app.ui.versions.open { crate::versions::panel(app, ui); @@ -148,7 +148,7 @@ pub fn left_panel(app: &mut FigApp, ui: &mut Ui) { } let t = Tokens::get(ui.ctx()); let full = ui.max_rect(); - // Header: file name (or "Assets") + drafts + collapse. + // Header: file name (or "Assets") + branch menu + collapse. let (head, _) = ui.allocate_exact_size(vec2(full.width(), 64.0), Sense::hover()); // Laid out left to right, mirrored inside the header in a right-to-left window. let rtl = crate::widgets::rtl(ui); @@ -157,14 +157,29 @@ pub fn left_panel(app: &mut FigApp, ui: &mut Ui) { if app.ui.left_tab == LeftTab::Assets { ui.painter().text(pos2(fx(head.min.x + 16.0), head.min.y + 24.0), align, tr("Assets"), semibold(13.0), t.text); } else { - let name = app.session.doc().map(|d| d.name.clone()).unwrap_or_default(); + let main_idx = figcraft_engine::branches::file_tab(&app.session); + let on_branch = app.session.ds().ok().is_some_and(|d| d.branch_of.is_some()); let nr = Rect::from_min_max(pos2(head.min.x + 14.0, head.min.y + 14.0), pos2(head.max.x - 48.0, head.min.y + 34.0)); let nr = crate::widgets::flip_rect(rtl, head, nr); let start = std::mem::take(&mut app.ui.rename_file); - if let (Some(new), _) = crate::widgets::rename_field(ui, Id::unique("filename"), &name, nr, semibold(13.0), start) { - app.run("file.rename", json!({"name": new})); + if on_branch { + let main_name = app.session.docs.get(main_idx).map(|d| d.doc.name.clone()).unwrap_or_default(); + let text_w = (nr.width() - 4.0).max(0.0); + let shown = crate::widgets::elide_font(ui, &main_name, text_w, semibold(13.0)); + let tx = if rtl { nr.max.x - 2.0 } else { nr.min.x + 2.0 }; + ui.painter().text(pos2(tx, nr.center().y), align, &shown, semibold(13.0), t.text); + let resp = ui.interact(nr, ui.scope_id().with("branch_main_name"), Sense::hover()); + a11y::label(&resp, &main_name); + if shown != main_name { + resp.on_hover_text(&main_name); + } + } else { + let name = app.session.doc().map(|d| d.name.clone()).unwrap_or_default(); + if let (Some(new), _) = crate::widgets::rename_field(ui, Id::unique("filename"), &name, nr, semibold(13.0), start) { + app.run("file.rename", json!({"name": new})); + } } - ui.painter().text(pos2(fx(head.min.x + 16.0), head.min.y + 46.0), align, tr("Drafts"), regular(11.0), t.text_secondary); + branch_header(app, ui, head, rtl); } let hr = Rect::from_center_size(pos2(fx(head.max.x - 24.0), head.min.y + 24.0), vec2(24.0, 24.0)); // Minimize, by the file name: "click Minimize next to the file name to collapse the @@ -187,6 +202,175 @@ pub fn left_panel(app: &mut FigApp, ui: &mut Ui) { } } +/// Branch and version control trigger below the file name: shows Main or the active branch, +/// with a menu to switch or create branches, review and merge, save a version, or open history. +fn branch_header(app: &mut FigApp, ui: &mut Ui, head: Rect, rtl: bool) { + use figcraft_engine::branches::BranchState; + + enum MenuAction { + SwitchMain(u64), + OpenBranch(String), + Review, + Archive, + CreateBranch(u64, bool), + SaveVersion, + ShowHistory, + } + + let t = Tokens::get(ui.ctx()); + let main_idx = figcraft_engine::branches::file_tab(&app.session); + let current_branch_id: Option = app.session.ds().ok().and_then(|d| d.branch_of.as_ref().map(|(_, id)| id.clone())); + let (main_uid, main_name, branches): (u64, String, Vec<(String, String, BranchState)>) = app + .session + .docs + .get(main_idx) + .map(|m| (m.uid, m.doc.name.clone(), m.branches.iter().map(|b| (b.id.clone(), b.name.clone(), b.state)).collect())) + .unwrap_or_default(); + let main_in_window = app.shows(main_uid); + let active_count = branches.iter().filter(|(_, _, s)| *s == BranchState::Active).count(); + let current_branch = current_branch_id.as_deref().and_then(|id| branches.iter().find(|(bid, _, _)| bid == id)); + + let state_label = |state: BranchState| match state { + BranchState::Active => tr("Active"), + BranchState::Merged => tr("Merged"), + BranchState::Archived => tr("Archived"), + }; + + let (label, on_active_branch, font, text_col, icon_col) = match current_branch { + Some((_, bname, BranchState::Active)) => (bname.clone(), true, semibold(11.0), t.accent_text, t.accent_text), + Some((_, bname, st)) => (format!("{bname} · {}", state_label(*st)), false, regular(11.0), t.text_secondary, t.icon_secondary), + None if active_count > 0 => { + (trf("Main · {n}", &[("n", &active_count.to_string())]), false, regular(11.0), t.text_secondary, t.icon_secondary) + } + None => (tr("Main").to_string(), false, regular(11.0), t.text_secondary, t.icon_secondary), + }; + + const ICON_W: f32 = 12.0; + const CHEV_W: f32 = 10.0; + const PAD_X: f32 = 6.0; + const GAP: f32 = 4.0; + let max_pill_w = (head.width() - 24.0).max(40.0); + let max_label_w = (max_pill_w - PAD_X * 2.0 - ICON_W - CHEV_W - GAP * 2.0).max(16.0); + let shown = crate::widgets::elide_font(ui, &label, max_label_w, font.clone()); + let galley = ui.painter().layout_no_wrap(shown, font, Color32::PLACEHOLDER); + let pill_w = (PAD_X * 2.0 + ICON_W + GAP + galley.size().x + GAP + CHEV_W).min(max_pill_w); + let pill_ltr = Rect::from_min_size(pos2(head.min.x + 10.0, head.min.y + 35.0), vec2(pill_w, 24.0)); + let pill = crate::widgets::flip_rect(rtl, head, pill_ltr); + + let tip = match current_branch { + Some(_) => trf("Branch of {file}", &[("file", &main_name)]), + None => tr("Branches and version history").to_string(), + }; + let resp = ui.interact(pill, Id::unique("branch_menu_button"), Sense::click()).tip(&tip); + let open = a11y::menu_open(&resp); + let a11y_label = trf("{label}, branches and version history", &[("label", &label)]); + a11y::menu_button(&resp, &a11y_label, open); + a11y::ring_around(ui, pill, &resp); + + if open { + ui.painter().rect_filled(pill, CornerRadius::same(5), t.selected_row); + } else if resp.hovered() { + ui.painter().rect_filled(pill, CornerRadius::same(5), t.hover); + } + + let (text_col, icon_col, chev_col) = if open { (t.accent_text, t.accent_text, t.accent_text) } else { (text_col, icon_col, t.icon_secondary) }; + let cy = pill.center().y; + if rtl { + let icon_x = pill.max.x - PAD_X - ICON_W / 2.0; + let text_x = pill.max.x - PAD_X - ICON_W - GAP - galley.size().x; + let chev_x = pill.min.x + PAD_X + CHEV_W / 2.0; + icons::paint(ui.painter(), Rect::from_center_size(pos2(icon_x, cy), Vec2::splat(ICON_W)), Icon::Branch, icon_col); + ui.painter().galley(pos2(text_x, cy - galley.size().y / 2.0), galley, text_col); + icons::paint(ui.painter(), Rect::from_center_size(pos2(chev_x, cy), Vec2::splat(CHEV_W)), Icon::Chevron, chev_col); + } else { + let icon_x = pill.min.x + PAD_X + ICON_W / 2.0; + let text_x = pill.min.x + PAD_X + ICON_W + GAP; + let chev_x = pill.max.x - PAD_X - CHEV_W / 2.0; + icons::paint(ui.painter(), Rect::from_center_size(pos2(icon_x, cy), Vec2::splat(ICON_W)), Icon::Branch, icon_col); + ui.painter().galley(pos2(text_x, cy - galley.size().y / 2.0), galley, text_col); + icons::paint(ui.painter(), Rect::from_center_size(pos2(chev_x, cy), Vec2::splat(CHEV_W)), Icon::Chevron, chev_col); + } + + let mut chosen = None; + let save_key = crate::shortcuts::shortcut("file.saveVersion").unwrap_or(""); + crate::right::menu_popup(&resp).width(220.0).show(|ui| { + if crate::right::menu_check(ui, current_branch_id.is_none(), tr("Main"), "") { + if current_branch_id.is_some() { + chosen = Some(MenuAction::SwitchMain(main_uid)); + } + ui.close(); + } + for (id, bname, st) in &branches { + let is_cur = current_branch_id.as_deref() == Some(id.as_str()); + if *st != BranchState::Active && !is_cur { + continue; + } + let row_label = if *st == BranchState::Active { bname.clone() } else { format!("{bname} · {}", state_label(*st)) }; + if crate::right::menu_check(ui, is_cur, &row_label, "") { + if !is_cur { + chosen = Some(MenuAction::OpenBranch(id.clone())); + } + ui.close(); + } + } + ui.separator(); + if on_active_branch { + if crate::right::menu_item_beside_checks(ui, tr("Review and merge"), "") { + chosen = Some(MenuAction::Review); + ui.close(); + } + if crate::right::menu_item_beside_checks(ui, tr("Archive branch"), "") { + chosen = Some(MenuAction::Archive); + ui.close(); + } + ui.separator(); + } + if main_in_window && crate::right::menu_item_beside_checks(ui, tr("Create branch…"), "") { + chosen = Some(MenuAction::CreateBranch(main_uid, current_branch_id.is_some())); + ui.close(); + } + if crate::right::menu_item_beside_checks(ui, tr("Save to version history…"), save_key) { + chosen = Some(MenuAction::SaveVersion); + ui.close(); + } + if crate::right::menu_item_beside_checks(ui, tr("Show version history"), "") { + chosen = Some(MenuAction::ShowHistory); + ui.close(); + } + }); + + match chosen { + Some(MenuAction::SwitchMain(uid)) => crate::windows::focus_doc(app, ui.ctx(), uid), + Some(MenuAction::OpenBranch(id)) => { + let open_uid = figcraft_engine::branches::tab_of(&app.session, main_uid, &id).and_then(|i| app.session.docs.get(i)).map(|d| d.uid); + if let Some(uid) = open_uid + && !app.shows(uid) + { + crate::windows::focus_doc(app, ui.ctx(), uid); + } else { + app.run("branch.open", json!({"id": id})); + } + } + Some(MenuAction::Review) => crate::branch_ui::open(app, None), + Some(MenuAction::Archive) => { + if app.run("branch.archive", json!({})).is_some() { + app.toast(tr("Branch archived")); + } + } + Some(MenuAction::CreateBranch(uid, from_branch)) => { + if from_branch { + crate::windows::focus_doc(app, ui.ctx(), uid); + } + crate::versions::start_branch(app); + } + Some(MenuAction::SaveVersion) => crate::versions::start_save(app), + Some(MenuAction::ShowHistory) => { + app.run("file.versionHistory", json!({})); + } + None => {} + } +} + /// Draw the page list with open/search/add controls, filtering, selection, rename, /// reorder/drag and layer drop-to-page; Dev Mode allows opening pages but blocks mutations. fn pages(app: &mut FigApp, ui: &mut Ui) { diff --git a/crates/ui-egui/src/tabs.rs b/crates/ui-egui/src/tabs.rs index 9da32e4c6..c8f8fb3d8 100644 --- a/crates/ui-egui/src/tabs.rs +++ b/crates/ui-egui/src/tabs.rs @@ -182,13 +182,17 @@ pub fn tab_bar(app: &mut FigApp, ui: &mut Ui) { } }); } - let label = if lost { trf("{name}, disconnected from its live session", &[("name", name)]) } else { tab_label(name, live) }; - let resp = if live.is_some() || lost { resp.on_hover_text(&label) } else { resp }; + let branch_parent = + d.branch_of.as_ref().and_then(|(main, _)| app.session.docs.iter().find(|m| m.uid == *main)).map(|m| m.doc.name.as_str()); + let label = + if lost { trf("{name}, disconnected from its live session", &[("name", name)]) } else { tab_label(name, branch_parent, live) }; + let resp = if live.is_some() || lost || branch_parent.is_some() { resp.on_hover_text(&label) } else { resp }; crate::a11y::tab(&resp, &label, active); let progress = open_progress(&opening, d.uid, now); let tab = TabPaint { name, kind: d.doc.kind, + branch: d.branch_of.is_some(), rects: [r, close_r], width: w, state: [active, resp.hovered(), cresp.hovered(), dirty], @@ -451,12 +455,17 @@ fn preferred_width(app: &FigApp, i: usize) -> f32 { (regular(12.0).size * 0.6 * d.doc.name.chars().count() as f32 + 64.0 + mark_w + dot_w).clamp(120.0, 220.0) } -/// A tab's accessible name: `name`, and in a live session whether others get in. -fn tab_label(name: &str, live: Option) -> String { - match live { - Some(true) => trf("{name}, in a live session", &[("name", &name)]), - Some(false) => trf("{name}, online, open only to you", &[("name", &name)]), +/// A tab's accessible name: `name`, its main file when a branch, and in a live session whether +/// others get in. +fn tab_label(name: &str, branch_of: Option<&str>, live: Option) -> String { + let base = match branch_of { + Some(file) => trf("{name}, branch of {file}", &[("name", &name), ("file", &file)]), None => name.to_string(), + }; + match live { + Some(true) => trf("{name}, in a live session", &[("name", &base)]), + Some(false) => trf("{name}, online, open only to you", &[("name", &base)]), + None => base, } } @@ -464,6 +473,7 @@ fn tab_label(name: &str, live: Option) -> String { struct TabPaint<'a> { name: &'a str, kind: figcraft_doc::FileKind, + branch: bool, /// The tab, and its close target. rects: [Rect; 2], width: f32, @@ -479,7 +489,7 @@ struct TabPaint<'a> { /// Draws a document tab: background, icon, name, live mark, unsaved dot and close button. fn paint_tab(ui: &Ui, t: &Tokens, tab: &TabPaint) { - let TabPaint { name, kind, rects: [r, close_r], width: w, state: [active, hovered, close_hovered, dirty], live, lost, progress } = *tab; + let TabPaint { name, kind, branch, rects: [r, close_r], width: w, state: [active, hovered, close_hovered, dirty], live, lost, progress } = *tab; let mark_w = if live.is_some() || lost { LIVE_MARK_WIDTH } else { 0.0 }; let paint_r = r.translate(vec2(-28.0 * (1.0 - progress).powi(2), 0.0)); let painter = ui.painter().with_clip_rect(r); @@ -491,7 +501,7 @@ fn paint_tab(ui: &Ui, t: &Tokens, tab: &TabPaint) { icons::paint( &painter, Rect::from_center_size(pos2(paint_r.min.x + 17.0, paint_r.center().y), Vec2::splat(BAR_ICON)), - icons::file_mark(kind), + if branch { Icon::Branch } else { icons::file_mark(kind) }, crate::theme::ACCENT.linear_multiply(progress), ); // The unsaved-changes dot follows the name on screen, whichever way the name reads. diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index ef05dc9ac..4ebc345cd 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -335,6 +335,25 @@ pub fn focus(app: &mut FigApp, ctx: &Context, id: u64) -> Result Ok(json!({"focused": id})) } +/// Switch to open document `uid`: in this window when it owns the tab, else activate `uid` in its +/// owning window and bring that window to the front. +pub fn focus_doc(app: &mut FigApp, ctx: &Context, uid: u64) { + let win = app.windows.of(uid); + if win == app.windows.current { + if let Some(index) = app.session.docs.iter().position(|d| d.uid == uid) { + app.run("doc.switch", json!({"index": index})); + } + return; + } + if win == 0 { + app.windows.main_active = Some(uid); + } else if let Some(w) = app.windows.list.iter_mut().find(|w| w.id == win) { + w.active = Some(uid); + } + let _ = focus(app, ctx, win); + ctx.request_repaint_of(viewport(win)); +} + /// Act on `window.new` / `window.focus` asked for by commands (menus, the Actions palette, /// `engine.execute`). pub(crate) fn requests(app: &mut FigApp, ctx: &Context) {