mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-21 20:38:15 +00:00
Merge pull request #3469 from dotCooCoo/feat/keywording-enter-keywords
LRC-LIB-KEYWORDS: the Keywording panel's Enter Keywords view edits keywords as text
This commit is contained in:
@@ -878,8 +878,14 @@ impl Catalog {
|
||||
/// appear together with `current` on other photos, then the most used ones. Most frequent
|
||||
/// first, at most `n`, never one of `current`.
|
||||
pub fn keyword_suggestions(&self, current: &[String], prefix: &str, n: usize) -> Vec<String> {
|
||||
self.keyword_suggestions_among(self.keywords(), current, prefix, n)
|
||||
}
|
||||
|
||||
/// [`Self::keyword_suggestions`] from the photos' keywords and their counts as
|
||||
/// [`Self::keywords`] gives them, for a caller that asks more than once of the same library.
|
||||
pub fn keyword_suggestions_among(&self, keywords: Vec<(String, usize)>, current: &[String], prefix: &str, n: usize) -> Vec<String> {
|
||||
// the photos' keywords with their counts, and those only the list has (none)
|
||||
let mut all = self.keywords();
|
||||
let mut all = keywords;
|
||||
for l in self.keyword_list.values() {
|
||||
if !all.iter().any(|(k, _)| same(k, &l.path)) {
|
||||
all.push((l.path.clone(), 0));
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
"New Folder in “{name}”": "Nová složka v „{name}“",
|
||||
"Created folder “{name}” in “{parent}”": "Vytvořena složka „{name}“ v „{parent}“",
|
||||
"On {have} of {of} selected photos": "Na {have} z {of} vybraných fotografií",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Název klíčového slova nemůže končit hvězdičkou: „{name}“",
|
||||
"Painting “{k}”: click photos to add or remove it · Esc stops": "Nanášení „{k}“: kliknutím na fotografie přidáte nebo odeberete slovo · Esc ukončí režim",
|
||||
"Paste into {n} photo{} — only settings that were copied are pasted": "Vložit do fotografií: {n}{:.0} — vloží se pouze zkopírovaná nastavení",
|
||||
"Preset: {name}": "Přednastavení: {name}",
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
" · in a burst": " · v sérii",
|
||||
"% of all commits": "% všech commitů",
|
||||
"& Containing": "& Obsahující",
|
||||
"Enter Keywords": "Zadat klíčová slova",
|
||||
"Keywords, separated by commas": "Klíčová slova oddělená čárkami",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Klávesou Return úpravu použijete na vybrané fotografie, klávesou Esc ji zrušíte. Hvězdička označuje klíčové slovo, které má jen část z nich.",
|
||||
"+ Group": "+ Skupina",
|
||||
"+ Rule": "+ Pravidlo",
|
||||
", picked": ", vybráno",
|
||||
|
||||
@@ -235,6 +235,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "„{keyword}“ zu {n} Foto{} hinzugefügt",
|
||||
"Add Keyword “{keywords}”": "Stichwort „{keywords}“ hinzufügen",
|
||||
"On {have} of {of} selected photos": "Bei {have} von {of} ausgewählten Fotos",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Ein Stichwortname darf nicht mit einem Sternchen enden: „{name}“",
|
||||
"Remove “{name}”": "„{name}“ entfernen",
|
||||
"There is a keyword set “{name}” already": "Es gibt bereits einen Stichwortsatz „{name}“",
|
||||
"Added {n} keyword{}": "Stichwörter hinzugefügt: {n}{:.0}",
|
||||
|
||||
@@ -2052,6 +2052,9 @@
|
||||
"Will Export": "Wird exportiert",
|
||||
"No keywords are exported": "Es werden keine Stichwörter exportiert",
|
||||
"& Containing": "& Übergeordnete",
|
||||
"Enter Keywords": "Stichwörter eingeben",
|
||||
"Keywords, separated by commas": "Stichwörter, durch Kommas getrennt",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Die Eingabetaste wendet die Änderung auf die ausgewählten Fotos an, Esc verwirft sie. Ein Sternchen kennzeichnet ein Stichwort, das nur einige von ihnen haben.",
|
||||
"Edit Set…": "Satz bearbeiten…",
|
||||
"Edit Keyword Set": "Stichwortsatz bearbeiten",
|
||||
"Edit Keywords": "Stichwörter bearbeiten",
|
||||
|
||||
@@ -236,6 +236,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "Se añadió “{keyword}” a {n} foto{}",
|
||||
"Add Keyword “{keywords}”": "Añadir palabra clave “{keywords}”",
|
||||
"On {have} of {of} selected photos": "En {have} de {of} fotos seleccionadas",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "El nombre de una palabra clave no puede terminar en asterisco: «{name}»",
|
||||
"Remove “{name}”": "Quitar “{name}”",
|
||||
"There is a keyword set “{name}” already": "Ya hay un conjunto de palabras clave “{name}”",
|
||||
"Added {n} keyword{}": "Palabras clave añadidas: {n}{:.0}",
|
||||
|
||||
@@ -2079,6 +2079,9 @@
|
||||
"Will Export": "Se exportará",
|
||||
"No keywords are exported": "No se exporta ninguna palabra clave",
|
||||
"& Containing": "y contenedoras",
|
||||
"Enter Keywords": "Introducir palabras clave",
|
||||
"Keywords, separated by commas": "Palabras clave separadas por comas",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Intro aplica el cambio a las fotos seleccionadas; Esc lo descarta. Un asterisco marca una palabra clave que solo tienen algunas de ellas.",
|
||||
"Edit Set…": "Editar conjunto…",
|
||||
"Edit Keyword Set": "Editar conjunto de palabras clave",
|
||||
"Edit Keywords": "Editar palabras clave",
|
||||
|
||||
@@ -140,6 +140,7 @@
|
||||
"New Folder in “{name}”": "Uusi kansio kohteessa ”{name}”",
|
||||
"Created folder “{name}” in “{parent}”": "Kansio ”{name}” luotu kohteeseen ”{parent}”",
|
||||
"On {have} of {of} selected photos": "{have} / {of} valitulla kuvalla",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Avainsanan nimi ei voi päättyä tähteen: ”{name}”",
|
||||
"Painting “{k}”: click photos to add or remove it · Esc stops": "Maalataan ”{k}”: napsauta kuvia lisätäksesi tai poistaaksesi sen · Esc lopettaa",
|
||||
"Paste into {n} photo{} — only settings that were copied are pasted": "Liitä kuviin: {n}{:.0} — vain kopioidut asetukset liitetään",
|
||||
"Preset: {name}": "Esiasetus: {name}",
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
" · in a burst": " · osa sarjaa",
|
||||
"% of all commits": "% kaikista commiteista",
|
||||
"& Containing": "& sisältää",
|
||||
"Enter Keywords": "Kirjoita avainsanat",
|
||||
"Keywords, separated by commas": "Avainsanat pilkuilla erotettuina",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Return tekee muutoksen valituille kuville, Esc peruu sen. Tähti merkitsee avainsanaa, joka on vain osalla niistä.",
|
||||
"(not in the library)": "(ei kirjastossa)",
|
||||
"+ Group": "+ Ryhmä",
|
||||
"+ Rule": "+ Sääntö",
|
||||
|
||||
@@ -236,6 +236,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "« {keyword} » ajouté à {n} photo{}",
|
||||
"Add Keyword “{keywords}”": "Ajouter le mot-clé « {keywords} »",
|
||||
"On {have} of {of} selected photos": "Sur {have} des {of} photos sélectionnées",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Un nom de mot-clé ne peut pas se terminer par un astérisque : « {name} »",
|
||||
"Remove “{name}”": "Retirer « {name} »",
|
||||
"There is a keyword set “{name}” already": "Un jeu de mots-clés « {name} » existe déjà",
|
||||
"Added {n} keyword{}": "Mots-clés ajoutés : {n}{:.0}",
|
||||
|
||||
@@ -1887,6 +1887,9 @@
|
||||
"Will Export": "Sera exporté",
|
||||
"No keywords are exported": "Aucun mot-clé n'est exporté",
|
||||
"& Containing": "et parents",
|
||||
"Enter Keywords": "Saisir des mots-clés",
|
||||
"Keywords, separated by commas": "Mots-clés séparés par des virgules",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Entrée applique la modification aux photos sélectionnées, Échap l'annule. Un astérisque marque un mot-clé que seules certaines d'entre elles ont.",
|
||||
"Edit Set…": "Modifier le jeu…",
|
||||
"Edit Keyword Set": "Modifier le jeu de mots-clés",
|
||||
"Edit Keywords": "Modifier les mots-clés",
|
||||
|
||||
@@ -236,6 +236,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "“{keyword}” ditambahkan ke {n} foto{:.0}",
|
||||
"Add Keyword “{keywords}”": "Tambahkan kata kunci “{keywords}”",
|
||||
"On {have} of {of} selected photos": "Pada {have} dari {of} foto yang dipilih",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Nama kata kunci tidak boleh diakhiri tanda bintang: “{name}”",
|
||||
"Remove “{name}”": "Hapus “{name}”",
|
||||
"There is a keyword set “{name}” already": "Set kata kunci “{name}” sudah ada",
|
||||
"Added {n} keyword{}": "{n} kata kunci ditambahkan{:.0}",
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
"#106): a DNG is checked against the raw data, written to a temp file, synced and read back before it gets its": "#106): DNG dicocokkan dengan data raw, ditulis ke file sementara, disinkronkan, lalu dibaca ulang sebelum diberi",
|
||||
"% of all commits": "% dari semua commit",
|
||||
"& Containing": "& kata kunci induk",
|
||||
"Enter Keywords": "Masukkan kata kunci",
|
||||
"Keywords, separated by commas": "Kata kunci, dipisahkan dengan koma",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Tekan Return untuk menerapkan perubahan ke foto yang dipilih, Esc untuk membatalkannya. Tanda bintang menandai kata kunci yang hanya dimiliki sebagian foto.",
|
||||
"(not in the library)": "(tidak ada di pustaka)",
|
||||
"+ Group": "+ Grup",
|
||||
"+ Rule": "+ Aturan",
|
||||
|
||||
@@ -229,6 +229,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "Aggiunta “{keyword}” a {n} foto{:.0}",
|
||||
"Add Keyword “{keywords}”": "Aggiungi parola chiave “{keywords}”",
|
||||
"On {have} of {of} selected photos": "Su {have} di {of} foto selezionate",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Il nome di una parola chiave non può terminare con un asterisco: “{name}”",
|
||||
"Remove “{name}”": "Rimuovi “{name}”",
|
||||
"There is a keyword set “{name}” already": "Esiste già un set di parole chiave “{name}”",
|
||||
"Added {n} keyword{}": "Parole chiave aggiunte: {n}{:.0}",
|
||||
|
||||
@@ -2007,6 +2007,9 @@
|
||||
"Will Export": "Verrà esportata",
|
||||
"No keywords are exported": "Nessuna parola chiave viene esportata",
|
||||
"& Containing": "e contenenti",
|
||||
"Enter Keywords": "Inserisci parole chiave",
|
||||
"Keywords, separated by commas": "Parole chiave separate da virgole",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Invio applica la modifica alle foto selezionate, Esc la annulla. Un asterisco indica una parola chiave che hanno solo alcune di esse.",
|
||||
"Edit Set…": "Modifica set…",
|
||||
"Edit Keyword Set": "Modifica set di parole chiave",
|
||||
"Edit Keywords": "Modifica parole chiave",
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "写真{n}枚に「{keyword}」を追加しました{:.0}",
|
||||
"Add Keyword “{keywords}”": "キーワード「{keywords}」を追加",
|
||||
"On {have} of {of} selected photos": "選択した写真{of}枚のうち{have}枚",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "キーワード名の末尾にアスタリスクは使えません:「{name}」",
|
||||
"Remove “{name}”": "「{name}」を削除",
|
||||
"There is a keyword set “{name}” already": "キーワードセット「{name}」はすでにあります",
|
||||
"Added {n} keyword{}": "{n}件のキーワードを追加しました{:.0}",
|
||||
|
||||
@@ -1900,6 +1900,9 @@
|
||||
"Will Export": "書き出されるキーワード",
|
||||
"No keywords are exported": "書き出されるキーワードはありません",
|
||||
"& Containing": "と親キーワード",
|
||||
"Enter Keywords": "キーワードを入力",
|
||||
"Keywords, separated by commas": "キーワード (カンマ区切り)",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Return キーで選択した写真に変更を適用し、Esc キーで取り消します。アスタリスクは一部の写真だけにあるキーワードを示します。",
|
||||
"Edit Set…": "セットを編集…",
|
||||
"Edit Keyword Set": "キーワードセットを編集",
|
||||
"Edit Keywords": "キーワードを編集",
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
"New Folder in “{name}”": "ახალი საქაღალდე „{name}“-ში",
|
||||
"Created folder “{name}” in “{parent}”": "საქაღალდე „{name}“ შეიქმნა „{parent}“-ში",
|
||||
"On {have} of {of} selected photos": "{of} მონიშნული ფოტოდან {have}-ზე",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "საკვანძო სიტყვის სახელი ვარსკვლავით ვერ დასრულდება: „{name}“",
|
||||
"Painting “{k}”: click photos to add or remove it · Esc stops": "„{k}“-ის მინიჭება: დაწკაპეთ ფოტოებზე მის დასამატებლად ან მოსახსნელად · Esc ასრულებს",
|
||||
"Paste into {n} photo{} — only settings that were copied are pasted": "ჩასმა ფოტოებში: {n}{:.0} — ჩაისმება მხოლოდ კოპირებული პარამეტრები",
|
||||
"Preset: {name}": "პრესეტი: {name}",
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
"#106): a DNG is checked against the raw data, written to a temp file, synced and read back before it gets its": "#106): DNG მოწმდება RAW მონაცემებთან, იწერება დროებით ფაილში, სინქრონიზდება და ხელახლა იკითხება, სანამ მიიღებს",
|
||||
"% of all commits": "ყველა კომიტის %",
|
||||
"& Containing": "და შემცველი",
|
||||
"Enter Keywords": "საკვანძო სიტყვების შეყვანა",
|
||||
"Keywords, separated by commas": "საკვანძო სიტყვები, მძიმეებით გამოყოფილი",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Return ცვლილებას მონიშნულ ფოტოებს ანიჭებს, Esc კი აუქმებს. ვარსკვლავი აღნიშნავს საკვანძო სიტყვას, რომელიც მხოლოდ ზოგიერთ მათგანს აქვს.",
|
||||
"(\"Failed to associate portal window with parent window\" in the portal's log): tiling compositors put it beside the": "(„Failed to associate portal window with parent window“ პორტალის ჟურნალში): ფილისებრი კომპოზიტორები მას",
|
||||
"(Esc keeps the old angle; a decimal comma works too), or click the Straighten value; hovering any slider's value now says it can be typed.": "(Esc ძველ კუთხეს ტოვებს; ათწილადი მძიმეც მუშაობს), ან დაწკაპეთ გასწორების მნიშვნელობაზე; ნებისმიერი სლაიდერის მნიშვნელობაზე მიტანისას ახლა ჩანს, რომ მისი აკრეფა შეიძლება.",
|
||||
"(Space, G, X, ⌫) and ⌘ shortcuts were not affected.": "(Space, G, X, ⌫) და ⌘ მალსახმობებზე ეს გავლენას არ ახდენდა.",
|
||||
|
||||
@@ -220,6 +220,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "Dodano „{keyword}” do zdjęć: {n}{:.0}",
|
||||
"Add Keyword “{keywords}”": "Dodaj słowo kluczowe „{keywords}”",
|
||||
"On {have} of {of} selected photos": "Na {have} z {of} zaznaczonych zdjęć",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Nazwa słowa kluczowego nie może kończyć się gwiazdką: „{name}”",
|
||||
"Remove “{name}”": "Usuń „{name}”",
|
||||
"There is a keyword set “{name}” already": "Istnieje już zestaw słów kluczowych „{name}”",
|
||||
"Added {n} keyword{}": "Dodane słowa kluczowe: {n}{:.0}",
|
||||
|
||||
@@ -1839,6 +1839,9 @@
|
||||
"Will Export": "Zostanie wyeksportowane",
|
||||
"No keywords are exported": "Nie zostaną wyeksportowane żadne słowa kluczowe",
|
||||
"& Containing": "i nadrzędne",
|
||||
"Enter Keywords": "Wprowadź słowa kluczowe",
|
||||
"Keywords, separated by commas": "Słowa kluczowe oddzielone przecinkami",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Return stosuje zmianę do zaznaczonych zdjęć, Esc ją odrzuca. Gwiazdka oznacza słowo kluczowe, które ma tylko część z nich.",
|
||||
"Edit Set…": "Edytuj zestaw…",
|
||||
"Edit Keyword Set": "Edytuj zestaw słów kluczowych",
|
||||
"Edit Keywords": "Edytuj słowa kluczowe",
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "“{keyword}” adicionada a {n} foto{}",
|
||||
"Add Keyword “{keywords}”": "Adicionar palavra-chave “{keywords}”",
|
||||
"On {have} of {of} selected photos": "Em {have} de {of} fotos selecionadas",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "O nome de uma palavra-chave não pode terminar com asterisco: “{name}”",
|
||||
"Remove “{name}”": "Remover “{name}”",
|
||||
"There is a keyword set “{name}” already": "Já existe um conjunto de palavras-chave “{name}”",
|
||||
"Added {n} keyword{}": "Palavras-chave adicionadas: {n}{:.0}",
|
||||
|
||||
@@ -1898,6 +1898,9 @@
|
||||
"Will Export": "Será exportado",
|
||||
"No keywords are exported": "Nenhuma palavra-chave é exportada",
|
||||
"& Containing": "e as que as contêm",
|
||||
"Enter Keywords": "Inserir palavras-chave",
|
||||
"Keywords, separated by commas": "Palavras-chave separadas por vírgulas",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Enter aplica a alteração às fotos selecionadas; Esc a descarta. Um asterisco marca uma palavra-chave que só algumas delas têm.",
|
||||
"Edit Set…": "Editar conjunto…",
|
||||
"Edit Keyword Set": "Editar conjunto de palavras-chave",
|
||||
"Edit Keywords": "Editar palavras-chave",
|
||||
|
||||
@@ -236,6 +236,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "«{keyword}» добавлено к фото ({n}){:.0}",
|
||||
"Add Keyword “{keywords}”": "Добавить ключевое слово «{keywords}»",
|
||||
"On {have} of {of} selected photos": "На {have} из {of} выбранных фото",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Имя ключевого слова не может заканчиваться звёздочкой: «{name}»",
|
||||
"Remove “{name}”": "Убрать «{name}»",
|
||||
"There is a keyword set “{name}” already": "Набор ключевых слов «{name}» уже есть",
|
||||
"Added {n} keyword{}": "Добавлено ключевых слов: {n}{:.0}",
|
||||
|
||||
@@ -1824,6 +1824,9 @@
|
||||
"Will Export": "Будет экспортировано",
|
||||
"No keywords are exported": "Ключевые слова не экспортируются",
|
||||
"& Containing": "и родительские",
|
||||
"Enter Keywords": "Ввод ключевых слов",
|
||||
"Keywords, separated by commas": "Ключевые слова через запятую",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Клавиша Enter применяет изменение к выбранным фото, Esc отменяет его. Звёздочка отмечает ключевое слово, которое есть только у некоторых из них.",
|
||||
"Edit Set…": "Изменить набор…",
|
||||
"Edit Keyword Set": "Изменить набор ключевых слов",
|
||||
"Edit Keywords": "Изменить ключевые слова",
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
"none (CPU rendering): {why}": "ingen (CPU-rendering): {why}",
|
||||
"not added to Apple Photos: {e}": "inte tillagt i Apple Photos: {e}",
|
||||
"On {have} of {of} selected photos": "På {have} av {of} markerade foton",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Ett nyckelordsnamn kan inte sluta med en asterisk: ”{name}”",
|
||||
"Painting “{k}”: click photos to add or remove it · Esc stops": "Målar ”{k}”: klicka på foton för att lägga till eller ta bort det · Esc avslutar",
|
||||
"Paste into {n} photo{} — only settings that were copied are pasted": "Klistra in i {n} foto{} – endast inställningar som kopierades klistras in",
|
||||
"Preset: {name}": "Förinställning: {name}",
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
"#106): a DNG is checked against the raw data, written to a temp file, synced and read back before it gets its": "#106): en DNG kontrolleras mot rådata, skrivs till en temporär fil, synkas och läses tillbaka innan den får sitt",
|
||||
"% of all commits": "% av alla commits",
|
||||
"& Containing": "& innehåller",
|
||||
"Enter Keywords": "Ange nyckelord",
|
||||
"Keywords, separated by commas": "Nyckelord, åtskilda med kommatecken",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Retur tillämpar ändringen på de markerade fotona, Esc ångrar den. En asterisk markerar ett nyckelord som bara några av dem har.",
|
||||
"(`gpuReason`, `gpuFallback`), Help ▸ System Info and Settings ▸ Performance say why the GPU isn't": "(`gpuReason`, `gpuFallback`), Hjälp → Systeminfo och Inställningar → Prestanda anger varför GPU:n inte",
|
||||
"(e.g. D750, D780, D850, D7500, Z 50) no longer render nearly black or with crushed shadows: their black level was": "(t.ex. D750, D780, D850, D7500, Z 50) renderas inte längre nästan svarta eller med klippta skuggor: deras svartnivå var",
|
||||
"(issue #94): an HTTP request from a web page can no longer carry a command in its body. Lines are capped at": "(ärende #94): en HTTP-begäran från en webbsida kan inte längre bära ett kommando i sin brödtext. Rader begränsas till",
|
||||
|
||||
@@ -236,6 +236,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "«{keyword}» додано до фото: {n}{:.0}",
|
||||
"Add Keyword “{keywords}”": "Додати ключове слово «{keywords}»",
|
||||
"On {have} of {of} selected photos": "На {have} з {of} вибраних фото",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Назва ключового слова не може закінчуватися зірочкою: «{name}»",
|
||||
"Remove “{name}”": "Вилучити «{name}»",
|
||||
"There is a keyword set “{name}” already": "Набір ключових слів «{name}» уже існує",
|
||||
"Added {n} keyword{}": "Додано ключових слів: {n}{:.0}",
|
||||
|
||||
@@ -2081,6 +2081,9 @@
|
||||
"Will Export": "Буде експортовано",
|
||||
"No keywords are exported": "Ключові слова не експортуються",
|
||||
"& Containing": "і батьківські",
|
||||
"Enter Keywords": "Введення ключових слів",
|
||||
"Keywords, separated by commas": "Ключові слова через кому",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Клавіша Enter застосовує зміну до вибраних фото, Esc скасовує її. Зірочка позначає ключове слово, яке є лише в деяких із них.",
|
||||
"Edit Set…": "Редагувати набір…",
|
||||
"Edit Keyword Set": "Редагувати набір ключових слів",
|
||||
"Edit Keywords": "Редагувати ключові слова",
|
||||
|
||||
@@ -140,6 +140,7 @@
|
||||
"New Folder in “{name}”": "Thư mục mới trong «{name}»",
|
||||
"Created folder “{name}” in “{parent}”": "Đã tạo thư mục «{name}» trong «{parent}»",
|
||||
"On {have} of {of} selected photos": "Trên {have} / {of} ảnh đã chọn",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "Tên từ khóa không thể kết thúc bằng dấu sao: «{name}»",
|
||||
"Painting “{k}”: click photos to add or remove it · Esc stops": "Gán «{k}»: nhấp ảnh để thêm hoặc gỡ · Esc dừng",
|
||||
"Paste into {n} photo{} — only settings that were copied are pasted": "Dán vào {n} ảnh{:.0} — chỉ dán các thiết lập đã sao chép",
|
||||
"Preset: {name}": "Thiết lập sẵn: {name}",
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
"#106): a DNG is checked against the raw data, written to a temp file, synced and read back before it gets its": "#106): một DNG được đối chiếu với dữ liệu raw, ghi vào tệp tạm, đồng bộ và đọc lại trước khi nhận",
|
||||
"% of all commits": "% tất cả commit",
|
||||
"& Containing": "& Chứa",
|
||||
"Enter Keywords": "Nhập từ khóa",
|
||||
"Keywords, separated by commas": "Từ khóa, cách nhau bằng dấu phẩy",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "Nhấn Return để áp dụng thay đổi cho các ảnh đã chọn, Esc để bỏ. Dấu sao đánh dấu từ khóa chỉ một số ảnh có.",
|
||||
"(`gpuReason`, `gpuFallback`), Help ▸ System Info and Settings ▸ Performance say why the GPU isn't": "(`gpuReason`, `gpuFallback`), Trợ giúp → Thông tin hệ thống và Cài đặt → Hiệu năng giải thích vì sao GPU không",
|
||||
"(e.g. D750, D780, D850, D7500, Z 50) no longer render nearly black or with crushed shadows: their black level was": "(ví dụ D750, D780, D850, D7500, Z 50) không còn hiển thị gần như đen hoặc vùng tối bị nén: mức đen của chúng đã được",
|
||||
"(issue #94): an HTTP request from a web page can no longer carry a command in its body. Lines are capped at": "(issue #94): yêu cầu HTTP từ trang web không còn mang lệnh trong phần thân. Số dòng được giới hạn ở",
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "已将“{keyword}”添加到 {n} 张照片{:.0}",
|
||||
"Add Keyword “{keywords}”": "添加关键字“{keywords}”",
|
||||
"On {have} of {of} selected photos": "所选 {of} 张照片中的 {have} 张",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "关键字名称不能以星号结尾:“{name}”",
|
||||
"Remove “{name}”": "移除“{name}”",
|
||||
"There is a keyword set “{name}” already": "已有关键字集“{name}”",
|
||||
"Added {n} keyword{}": "已添加 {n} 个关键字{:.0}",
|
||||
|
||||
@@ -1892,6 +1892,9 @@
|
||||
"Will Export": "将导出",
|
||||
"No keywords are exported": "没有要导出的关键字",
|
||||
"& Containing": "及上级",
|
||||
"Enter Keywords": "输入关键字",
|
||||
"Keywords, separated by commas": "关键字,用逗号分隔",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "按回车键将修改应用到所选照片,按 Esc 键放弃。星号表示只有部分照片带有的关键字。",
|
||||
"Edit Set…": "编辑关键字集…",
|
||||
"Edit Keyword Set": "编辑关键字集",
|
||||
"Edit Keywords": "编辑关键字",
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
"Added “{keyword}” to {n} photo{}": "已將「{keyword}」加入 {n} 張照片{:.0}",
|
||||
"Add Keyword “{keywords}”": "加入關鍵字「{keywords}」",
|
||||
"On {have} of {of} selected photos": "選取的 {of} 張照片中的 {have} 張",
|
||||
"A keyword name can't end with an asterisk: “{name}”": "關鍵字名稱不能以星號結尾:「{name}」",
|
||||
"Remove “{name}”": "移除「{name}」",
|
||||
"There is a keyword set “{name}” already": "已有關鍵字集「{name}」",
|
||||
"Added {n} keyword{}": "已加入 {n} 個關鍵字{:.0}",
|
||||
|
||||
@@ -1898,6 +1898,9 @@
|
||||
"Will Export": "將匯出",
|
||||
"No keywords are exported": "沒有要匯出的關鍵字",
|
||||
"& Containing": "及上層",
|
||||
"Enter Keywords": "輸入關鍵字",
|
||||
"Keywords, separated by commas": "關鍵字,以逗號分隔",
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.": "按 Return 鍵將修改套用到選取的照片,按 Esc 鍵放棄。星號表示只有部分照片帶有的關鍵字。",
|
||||
"Edit Set…": "編輯關鍵字集…",
|
||||
"Edit Keyword Set": "編輯關鍵字集",
|
||||
"Edit Keywords": "編輯關鍵字",
|
||||
|
||||
@@ -56,6 +56,7 @@ impl LightcraftApp {
|
||||
max_texture_side: MAX_TEXTURE_SIDE,
|
||||
clock: AppClock::new(),
|
||||
accesskit_language: None,
|
||||
selection_seen: (0, 0),
|
||||
slideshow_hidden_at: None,
|
||||
slideshow_auto_paused: false,
|
||||
dropped_files: vec![],
|
||||
@@ -203,6 +204,26 @@ impl LightcraftApp {
|
||||
/// [`LightcraftApp::run`], keeping what kind of error a refusal is: for code that decides on it
|
||||
/// (offer a model's download, treat a cancel as one) instead of reading the message.
|
||||
pub fn run_typed(&mut self, id: &str, params: Value) -> Result<Value, CommandError> {
|
||||
// (seen before and after each command, so a selection changed and changed back between two
|
||||
// UI passes still counts as changed)
|
||||
self.selection_changes();
|
||||
let r = self.run_command(id, params);
|
||||
self.selection_changes();
|
||||
r
|
||||
}
|
||||
|
||||
/// How many times the selection has been seen to change, counting a change to other photos and
|
||||
/// back as two. Each command and each finished UI pass looks at the selection.
|
||||
pub(crate) fn selection_changes(&mut self) -> u64 {
|
||||
let s = &self.session.selection;
|
||||
let key = if s.ids.is_empty() { crate::key_of(s.active.as_slice()) } else { crate::key_of(s.ids.as_slice()) };
|
||||
if key != self.selection_seen.0 {
|
||||
self.selection_seen = (key, self.selection_seen.1.wrapping_add(1));
|
||||
}
|
||||
self.selection_seen.1
|
||||
}
|
||||
|
||||
fn run_command(&mut self, id: &str, params: Value) -> Result<Value, CommandError> {
|
||||
if let Some(r) = menus::run_ui_command(self, id, ¶ms) {
|
||||
if r.is_ok() {
|
||||
docking::reveal_command(self, id)?;
|
||||
@@ -656,6 +677,7 @@ impl LightcraftApp {
|
||||
frame_rate::forget(ctx);
|
||||
}
|
||||
panels::edit::wheel_pointer_frame_end(ctx);
|
||||
panels::right::forget_stale_enter_keywords(self, ctx);
|
||||
ctx.output(|o| {
|
||||
for c in &o.commands {
|
||||
if let egui::OutputCommand::CopyText(text) = c {
|
||||
|
||||
@@ -204,6 +204,9 @@ pub struct LightcraftApp {
|
||||
/// The language already sent to `Context::set_language`, so a logic pass does not allocate a
|
||||
/// `String` just to compare it.
|
||||
accesskit_language: Option<String>,
|
||||
/// The selection last seen ([`LightcraftApp::selection_changes`]) and how many times it was
|
||||
/// seen to differ from the one before.
|
||||
selection_seen: (u64, u64),
|
||||
/// When playback was auto-paused because the window became hidden (`None`: it is running, or
|
||||
/// the user paused it). On unhide the pause is lifted and the slide keeps its remaining time.
|
||||
slideshow_hidden_at: Option<f64>,
|
||||
|
||||
@@ -9,14 +9,17 @@ use crate::LightcraftApp;
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets::register;
|
||||
|
||||
/// The Keywording box's view: the keywords (chips), them with the keywords containing them, or
|
||||
/// what exported files will carry.
|
||||
/// The Keywording box's view: the keywords as text (Enter Keywords), the keywords (chips), them
|
||||
/// with the keywords containing them, or what exported files will carry.
|
||||
pub fn view_switch(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
use crate::state::KeywordingView as V;
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for (view, id, label) in
|
||||
[(V::Keywords, "keywords", "Keywords"), (V::Containing, "containing", "& Containing"), (V::WillExport, "willExport", "Will Export")]
|
||||
{
|
||||
for (view, id, label) in [
|
||||
(V::Enter, "enter", "Enter Keywords"),
|
||||
(V::Keywords, "keywords", "Keywords"),
|
||||
(V::Containing, "containing", "& Containing"),
|
||||
(V::WillExport, "willExport", "Will Export"),
|
||||
] {
|
||||
let r = ui.selectable_label(app.ui.keywording_view == view, crate::i18n::tr(label));
|
||||
register(ui, format!("keywordView:{id}"), r.rect);
|
||||
if r.clicked() {
|
||||
@@ -374,20 +377,59 @@ pub(crate) fn typing(text: &str) -> &str {
|
||||
/// The keywords typed before the last comma, each where the library would put it.
|
||||
pub(crate) fn typed_before(catalog: &Catalog, text: &str) -> Vec<String> {
|
||||
let Some((before, _)) = text.rsplit_once(',') else { return Vec::new() };
|
||||
before.split(',').map(|s| catalog.typed_keyword(s)).filter(|s| !s.is_empty()).collect()
|
||||
typed_names(catalog, before)
|
||||
}
|
||||
|
||||
/// The keywords typed in the Add keyword box's `text`, split at commas, each where the library
|
||||
/// would put it. `>` and `<` mark a hierarchy as `|` does (see `typed_levels`).
|
||||
pub(crate) fn typed_names(catalog: &Catalog, text: &str) -> Vec<String> {
|
||||
text.split(',').map(|s| catalog.typed_keyword(&typed_levels(catalog, s).unwrap_or_else(|| s.to_string()))).filter(|s| !s.is_empty()).collect()
|
||||
}
|
||||
|
||||
/// `typed` with `>` and `<` read as hierarchy marks (see `levels`), cleaned, when that changes it
|
||||
/// and no keyword of the library holds the name as written as whole levels of its path (`a > b`,
|
||||
/// `Inbox|a > b` or `a > b|c` for `a > b`).
|
||||
fn typed_levels(catalog: &Catalog, typed: &str) -> Option<String> {
|
||||
typed_levels_among(catalog, typed, || catalog.photos().filter(|p| p.in_library()).flat_map(|p| p.meta.keywords.iter().map(String::as_str)))
|
||||
}
|
||||
|
||||
/// [`typed_levels`], with `on_photos` giving the in-library photos' keywords when they are needed.
|
||||
fn typed_levels_among<'a, I: Iterator<Item = &'a str>>(catalog: &'a Catalog, typed: &str, on_photos: impl FnOnce() -> I) -> Option<String> {
|
||||
use lightcraft_catalog::keywords::{SEP, clean, same};
|
||||
let written = clean(typed);
|
||||
let leveled = clean(&levels(typed));
|
||||
if leveled == written {
|
||||
return None;
|
||||
}
|
||||
// whole levels of a path, anywhere in it
|
||||
let levels_of = format!("{SEP}{}{SEP}", written.to_lowercase());
|
||||
let spelled = |p: &str| same(p, &written) || format!("{SEP}{}{SEP}", p.to_lowercase()).contains(&levels_of);
|
||||
// the listed keywords, then the photos' own, stopping at the first match
|
||||
let known = catalog.listed_keywords().any(|l| spelled(&l.path)) || on_photos().any(spelled);
|
||||
(!known).then_some(leveled)
|
||||
}
|
||||
|
||||
/// What the box offers for `typed`, for photos that all have the `current` keywords.
|
||||
pub(crate) fn offers(catalog: &Catalog, current: &[String], typed: &str) -> Offers {
|
||||
use lightcraft_catalog::keywords::{SEP, clean};
|
||||
let name = clean(typed);
|
||||
// the photos' keywords, gathered from the library once for the hierarchy check and the offers
|
||||
let on_photos = std::cell::OnceCell::new();
|
||||
// `>` and `<` read as hierarchy marks, as Return reads them (see `typed_names`)
|
||||
let as_written = clean(typed);
|
||||
let leveled = typed_levels_among(catalog, typed, || on_photos.get_or_init(|| catalog.keywords()).iter().map(|(k, _)| k.as_str()));
|
||||
let name = leveled.clone().unwrap_or(as_written);
|
||||
if name.is_empty() {
|
||||
return Offers::default();
|
||||
}
|
||||
let on_photos = on_photos.into_inner().unwrap_or_else(|| catalog.keywords());
|
||||
// (a keyword two photos spell differently is one offer, the first spelling)
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let mut keywords = catalog.keyword_suggestions(current, typed, OFFERS);
|
||||
// with `>` or `<` read as levels, the keywords for that first, then those for the text as
|
||||
// written (a keyword whose own name holds `>` or `<`)
|
||||
let mut keywords = leveled.as_deref().map(|l| catalog.keyword_suggestions_among(on_photos.clone(), current, l, OFFERS)).unwrap_or_default();
|
||||
keywords.extend(catalog.keyword_suggestions_among(on_photos, current, typed, OFFERS));
|
||||
keywords.retain(|k| seen.insert(k.to_lowercase()));
|
||||
keywords.truncate(OFFERS);
|
||||
// where Return would put a name the library lacks, as `Catalog::typed_keyword` does, without
|
||||
// looking through the library a second time
|
||||
let create = (!catalog.has_keyword(&name)).then(|| match catalog.default_keyword_parent() {
|
||||
@@ -708,6 +750,219 @@ pub(crate) fn chips(catalog: &Catalog, photos: &[PhotoId]) -> Vec<Chip> {
|
||||
have.into_values().map(|(k, n)| Chip { path: catalog.listed_path(&k).map(str::to_string).unwrap_or(k), have: n, of: photos.len() }).collect()
|
||||
}
|
||||
|
||||
/// The Enter Keywords text of the selection's keywords `chips`: each keyword's path, with commas
|
||||
/// between them and an asterisk after a keyword only some of the selected photos have. A keyword
|
||||
/// whose name holds a comma, a new line, a double quote, `>` or `<` is written in double quotes
|
||||
/// (before its asterisk), each double quote inside written twice, so that it reads as one name as
|
||||
/// written, in this selection or another one. A keyword every
|
||||
/// photo has whose name ends in an asterisk is also written in double quotes, so that it reads
|
||||
/// differently from a partial keyword marked with the asterisk.
|
||||
pub(crate) fn entered_text(chips: &[Chip]) -> String {
|
||||
chips
|
||||
.iter()
|
||||
.map(|c| {
|
||||
let in_quotes = || format!("\"{}\"", c.path.replace('"', "\"\""));
|
||||
let held = c.path.contains([',', '\n', '"', '>', '<']);
|
||||
if !c.on_all() && held {
|
||||
format!("{}*", in_quotes())
|
||||
} else if !c.on_all() {
|
||||
format!("{}*", c.path)
|
||||
} else if held || c.path.ends_with('*') {
|
||||
in_quotes()
|
||||
} else {
|
||||
c.path.clone()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
/// The name inside `token` when it is in double quotes, each double quote inside it written twice
|
||||
/// (a single one inside means it is not).
|
||||
fn quoted(token: &str) -> Option<String> {
|
||||
let inside = token.strip_prefix('"')?.strip_suffix('"')?;
|
||||
let mut name = String::with_capacity(inside.len());
|
||||
let mut chars = inside.chars();
|
||||
while let Some(ch) = chars.next() {
|
||||
if ch == '"' && chars.next() != Some('"') {
|
||||
return None;
|
||||
}
|
||||
name.push(ch);
|
||||
}
|
||||
Some(name)
|
||||
}
|
||||
|
||||
/// What an edit of the Enter Keywords text gives to and takes off the selected photos.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub(crate) struct Entered {
|
||||
/// Keywords for every selected photo.
|
||||
pub add: Vec<String>,
|
||||
/// Keywords taken off every selected photo.
|
||||
pub remove: Vec<String>,
|
||||
}
|
||||
|
||||
impl Entered {
|
||||
/// The edit changes no photo.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.add.is_empty() && self.remove.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
/// The names in the Enter Keywords `text`, trimmed: the text split at commas and new lines, except
|
||||
/// where a name opened with a double quote closes with one (the next piece holding a double quote
|
||||
/// not written twice ends with it, or with it and an asterisk), only commas lie between or the
|
||||
/// name spells a keyword of `start` the text has not named yet, and each double quote inside is
|
||||
/// written twice; or where pieces joined by their separators spell a keyword of `start` whose name
|
||||
/// holds a comma or a new line (with or without its asterisk or its quotes) that the text has not
|
||||
/// named yet, unless each of those pieces is a keyword of `start` by itself. Either stays one name.
|
||||
fn entered_names<'a>(start: &[Chip], text: &'a str) -> Vec<&'a str> {
|
||||
use lightcraft_catalog::keywords::{clean, same};
|
||||
let is_separator = |ch: char| ch == ',' || ch == '\n';
|
||||
let spells = |s: &str, c: &Chip| {
|
||||
let marked = s.strip_suffix('*');
|
||||
let inside = [quoted(s), marked.and_then(quoted)];
|
||||
// as written, and with `>` and `<` read as hierarchy marks (a name without them reads the same)
|
||||
let leveled: Vec<String> = [Some(s), marked].into_iter().flatten().filter(|n| n.contains(['>', '<'])).map(levels).collect();
|
||||
[Some(s), marked]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.chain(inside.iter().flatten().map(String::as_str))
|
||||
.chain(leveled.iter().map(String::as_str))
|
||||
.any(|n| same(&clean(n), &c.path))
|
||||
};
|
||||
// a piece holding a double quote that is not one written twice
|
||||
let unpaired = |s: &str| s.split(|ch| ch != '"').any(|run| run.len() % 2 == 1);
|
||||
// a piece that closes a name in double quotes: it ends with one (before an asterisk or not)
|
||||
// that is not one written twice
|
||||
let closes = |s: &str| s.strip_suffix('*').unwrap_or(s).chars().rev().take_while(|&ch| ch == '"').count() % 2 == 1;
|
||||
// the keywords of `start` the text has named so far
|
||||
let mut named = vec![false; start.len()];
|
||||
let unnamed = |s: &str, named: &[bool]| start.iter().zip(named).position(|(c, n)| !n && spells(s, c));
|
||||
// each piece's byte range in the text
|
||||
let mut pieces: Vec<std::ops::Range<usize>> = Vec::new();
|
||||
let mut from = 0;
|
||||
for piece in text.split(is_separator) {
|
||||
pieces.push(from..from + piece.len());
|
||||
from += piece.len() + 1;
|
||||
}
|
||||
let piece = |p: &std::ops::Range<usize>| text.get(p.clone()).unwrap_or_default().trim();
|
||||
// how many separators the names of `start` hold, each count once, the most first
|
||||
let mut counts: Vec<usize> = start.iter().map(|c| c.path.matches(is_separator).count()).filter(|&n| n > 0).collect();
|
||||
counts.sort_unstable_by(|a, b| b.cmp(a));
|
||||
counts.dedup();
|
||||
let mut names = Vec::new();
|
||||
let mut i = 0;
|
||||
while let Some(first) = pieces.get(i) {
|
||||
// a name in double quotes, up to the piece that closes it (an unclosed one is plain pieces)
|
||||
let opened = piece(first).strip_prefix('"').is_some_and(|rest| !closes(rest));
|
||||
let quoted_run = opened
|
||||
.then(|| {
|
||||
pieces
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(i + 1)
|
||||
.find(|(_, p)| unpaired(piece(p)))
|
||||
.filter(|(_, p)| closes(piece(p)))
|
||||
.and_then(|(j, p)| Some((j - i, text.get(first.start..p.end)?.trim())))
|
||||
.filter(|&(_, s)| quoted(s.strip_suffix('*').unwrap_or(s)).is_some())
|
||||
.filter(|&(_, s)| !s.contains('\n') || unnamed(s, &named).is_some())
|
||||
})
|
||||
.flatten();
|
||||
// else the most pieces that spell a keyword with separators not named yet, unless each
|
||||
// piece is a keyword by itself
|
||||
let one_each =
|
||||
|from: usize, to: usize| pieces.get(from..=to).is_some_and(|run| run.iter().all(|p| start.iter().any(|c| spells(piece(p), c))));
|
||||
let joined = quoted_run.or_else(|| {
|
||||
counts.iter().find_map(|&separators| {
|
||||
let last = pieces.get(i + separators)?;
|
||||
let s = text.get(first.start..last.end)?.trim();
|
||||
unnamed(s, &named).filter(|_| !one_each(i, i + separators)).map(|_| (separators, s))
|
||||
})
|
||||
});
|
||||
let (separators, name) = joined.unwrap_or((0, text.get(first.clone()).unwrap_or_default().trim()));
|
||||
if let Some(n) = unnamed(name, &named) {
|
||||
named[n] = true;
|
||||
}
|
||||
if !name.is_empty() {
|
||||
names.push(name);
|
||||
}
|
||||
i += separators + 1;
|
||||
}
|
||||
names
|
||||
}
|
||||
|
||||
/// `name` with `>` and `<` read as hierarchy marks, as `|` is: `animal > dog` and `dog < animal`
|
||||
/// are both `animal|dog`. The parts between `>` go in order, and the parts between `<` inside each
|
||||
/// of them go from the last.
|
||||
fn levels(name: &str) -> String {
|
||||
name.split('>').flat_map(|part| part.rsplit('<')).collect::<Vec<_>>().join("|")
|
||||
}
|
||||
|
||||
/// Reads the Enter Keywords `text` against `start`, the selection's keywords when the edit began.
|
||||
/// Keywords are separated by commas or new lines; a name in double quotes holding commas (or new
|
||||
/// lines, when it is a keyword of `start`), and a keyword of `start` whose name holds a comma
|
||||
/// written without its quotes, are each read as one name (see `entered_names`). A keyword of
|
||||
/// `start` left out of the text is taken off every selected photo. A name without an asterisk goes
|
||||
/// to every selected photo (a keyword of `start` keeps its spelling, and a new name goes where
|
||||
/// `Catalog::typed_keyword` puts it). A keyword only some photos have, still marked with its
|
||||
/// asterisk, stays on those photos only, the name in double quotes before the asterisk included. A
|
||||
/// name in double quotes is read as written, an asterisk at its end included, and a double quote
|
||||
/// written twice inside it is one double quote. A keyword every photo has whose own name ends in an
|
||||
/// asterisk is also kept when written without its quotes, unless a keyword only some photos have
|
||||
/// reads the same. An asterisk after any other name is refused: the error is the name as typed.
|
||||
/// Outside double quotes, `>` and `<` mark a hierarchy as `|` does (see `levels`), unless the name
|
||||
/// as written is a keyword of `start`.
|
||||
pub(crate) fn entered(catalog: &Catalog, start: &[Chip], text: &str) -> Result<Entered, String> {
|
||||
use lightcraft_catalog::keywords::{clean, same};
|
||||
let mut kept: Vec<String> = Vec::new();
|
||||
let mut add: Vec<String> = Vec::new();
|
||||
for token in entered_names(start, text) {
|
||||
let literal = quoted(token);
|
||||
if let Some(marked) = token.strip_suffix('*').filter(|_| literal.is_none()) {
|
||||
let (whole, name) = (clean(token), clean(marked));
|
||||
// the name inside the quotes of a marked name in double quotes
|
||||
let inner = quoted(marked).map(|n| clean(&n));
|
||||
// a marked name without quotes, with `>` and `<` read as hierarchy marks
|
||||
let leveled = inner.is_none().then(|| clean(&levels(marked)));
|
||||
// a partial keyword marked (as written, else inside its quotes, else as a hierarchy),
|
||||
// or else a keyword on every photo named with the asterisk; one not named yet first
|
||||
let on_all = |c: &Chip| c.on_all() && same(&c.path, &whole);
|
||||
let partial = |c: &Chip, name: &str| !c.on_all() && same(&c.path, name);
|
||||
let either = |c: &Chip| [Some(name.as_str()), inner.as_deref(), leveled.as_deref()].into_iter().flatten().any(|n| partial(c, n));
|
||||
let fresh = |c: &Chip| !kept.iter().any(|k| same(k, &c.path));
|
||||
let found = start
|
||||
.iter()
|
||||
.find(|c| fresh(c) && partial(c, &name))
|
||||
.or_else(|| inner.as_deref().and_then(|n| start.iter().find(|c| fresh(c) && partial(c, n))))
|
||||
.or_else(|| leveled.as_deref().and_then(|n| start.iter().find(|c| fresh(c) && partial(c, n))))
|
||||
.or_else(|| start.iter().find(|c| fresh(c) && on_all(c)))
|
||||
.or_else(|| start.iter().find(|c| either(c) || on_all(c)))
|
||||
.ok_or_else(|| token.to_string())?;
|
||||
kept.push(found.path.clone());
|
||||
continue;
|
||||
}
|
||||
let written = literal.as_deref().unwrap_or(token);
|
||||
let typed = clean(written);
|
||||
// a name without quotes, with `>` and `<` read as hierarchy marks
|
||||
let path = if literal.is_some() { written.to_string() } else { levels(written) };
|
||||
let leveled = clean(&path);
|
||||
let (name, on_all) = match start.iter().find(|c| same(&c.path, &typed)).or_else(|| start.iter().find(|c| same(&c.path, &leveled))) {
|
||||
Some(c) => (c.path.clone(), c.on_all()),
|
||||
None if typed.ends_with('*') => return Err(token.to_string()),
|
||||
None => (catalog.typed_keyword(&path), false),
|
||||
};
|
||||
if name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if !on_all && !add.iter().any(|a| same(a, &name)) {
|
||||
add.push(name.clone());
|
||||
}
|
||||
kept.push(name);
|
||||
}
|
||||
let remove = start.iter().filter(|c| !kept.iter().any(|k| same(k, &c.path))).map(|c| c.path.clone()).collect();
|
||||
Ok(Entered { add, remove })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use lightcraft_catalog::{Op, Photo, Source};
|
||||
@@ -991,6 +1246,29 @@ mod tests {
|
||||
assert!(typed_before(&c, "lis").is_empty());
|
||||
}
|
||||
|
||||
/// In the Add keyword box, `>` and `<` mark a hierarchy as `|` does, unless the name as written
|
||||
/// is a keyword the library has.
|
||||
#[test]
|
||||
fn the_add_keyword_box_reads_greater_and_less_than_as_levels() {
|
||||
let (c, _) = library(&[&["sea", "a > b"]]);
|
||||
assert_eq!(typed_names(&c, "animal > dog, cat < animal, x|y"), ["animal|dog", "animal|cat", "x|y"]);
|
||||
assert_eq!(typed_names(&c, "a > b, sea"), ["a > b", "sea"], "a keyword the library has is read as written");
|
||||
assert_eq!(typed_before(&c, "animal > dog, lis"), ["animal|dog"]);
|
||||
// the offers say what Return gives
|
||||
assert_eq!(offers(&c, &[], "animal > dog").create.as_deref(), Some("animal|dog"));
|
||||
assert_eq!(offers(&c, &[], "a > b").create, None, "the library has `a > b`");
|
||||
let (c, _) = library(&[&["animal|dog"]]);
|
||||
let got = offers(&c, &[], "dog < animal");
|
||||
assert_eq!((got.keywords, got.create), (vec!["animal|dog".to_string()], None), "the library has animal|dog");
|
||||
// a keyword inside another whose own name holds `>` is read as written too
|
||||
let (c, _) = library(&[&["Inbox|a > b"]]);
|
||||
assert_eq!(typed_names(&c, "a > b, x > y"), ["a > b", "x|y"]);
|
||||
assert_eq!(offers(&c, &[], "a > b").keywords, ["Inbox|a > b"]);
|
||||
// a part of such a name still offers it, after the keywords for the levels
|
||||
let (c, _) = library(&[&["a > boat", "a|bow"]]);
|
||||
assert_eq!(offers(&c, &[], "a > bo").keywords, ["a|bow", "a > boat"]);
|
||||
}
|
||||
|
||||
/// The grouped box's suggestions say a keyword's own name; two with the same name say their
|
||||
/// whole paths, so they can be told apart.
|
||||
#[test]
|
||||
@@ -1007,4 +1285,222 @@ mod tests {
|
||||
let (c, ids) = library(&[&["travel|Italy|Rome", "travel|Spain"], &["travel|Italy"]]);
|
||||
assert_eq!(shown(&with_containing(&c, &ids)), [("Italy", 2, 2), ("Rome", 1, 2), ("Spain", 1, 2), ("travel", 2, 2)]);
|
||||
}
|
||||
|
||||
fn edit(add: &[&str], remove: &[&str]) -> Entered {
|
||||
Entered { add: add.iter().map(|s| s.to_string()).collect(), remove: remove.iter().map(|s| s.to_string()).collect() }
|
||||
}
|
||||
|
||||
/// The Enter Keywords text is the selection's keywords with their paths, commas between them, and
|
||||
/// an asterisk after one only some of the selected photos have; left as it is, it changes nothing.
|
||||
#[test]
|
||||
fn the_entered_text_is_the_selections_keywords() {
|
||||
let (c, ids) = library(&[&["Places|Lisbon", "beach"], &["beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
let text = entered_text(&start);
|
||||
assert_eq!(text, "beach, Places|Lisbon*");
|
||||
assert_eq!(entered(&c, &start, &text), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, " beach ,\nPlaces | Lisbon * "), Ok(Entered::default()), "spaces and new lines");
|
||||
assert_eq!(entered(&c, &start, "BEACH, places|lisbon*"), Ok(Entered::default()), "another case is the same keyword");
|
||||
assert_eq!(entered_text(&[]), "");
|
||||
}
|
||||
|
||||
/// A keyword left out of the text is taken off every selected photo; a name typed goes to every
|
||||
/// one of them; a partial keyword without its asterisk goes to all of them.
|
||||
#[test]
|
||||
fn an_edit_adds_and_removes_for_every_selected_photo() {
|
||||
let (c, ids) = library(&[&["Places|Lisbon", "beach"], &["beach", "sea"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, "Places|Lisbon*, sea*"), Ok(edit(&[], &["beach"])));
|
||||
assert_eq!(entered(&c, &start, "beach, Places|Lisbon*, sea*, harbor, Places|Porto"), Ok(edit(&["harbor", "Places|Porto"], &[])));
|
||||
assert_eq!(entered(&c, &start, "beach, Places|Lisbon, sea*"), Ok(edit(&["Places|Lisbon"], &[])), "made common");
|
||||
assert_eq!(entered(&c, &start, "beach, harbor, HARBOR"), Ok(edit(&["harbor"], &["Places|Lisbon", "sea"])), "named once");
|
||||
assert_eq!(entered(&c, &start, ""), Ok(edit(&[], &["beach", "Places|Lisbon", "sea"])), "an empty box clears them");
|
||||
assert_eq!(entered(&c, &start, " , | ,"), Ok(edit(&[], &["beach", "Places|Lisbon", "sea"])), "nothing but separators");
|
||||
}
|
||||
|
||||
/// Containing keywords and synonyms are not part of the text: they stay derived, and an edit
|
||||
/// never assigns them.
|
||||
#[test]
|
||||
fn containing_keywords_and_synonyms_stay_out_of_the_text() {
|
||||
use lightcraft_catalog::keywords::KeywordInfo;
|
||||
let (mut c, ids) = library(&[&["Places|Lisbon"]]);
|
||||
c.apply(Op::SetKeyword {
|
||||
path: "Places|Lisbon".into(),
|
||||
info: Some(KeywordInfo { synonyms: vec!["Lisboa".into()], ..KeywordInfo::default() }),
|
||||
})
|
||||
.unwrap();
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered_text(&start), "Places|Lisbon");
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()));
|
||||
}
|
||||
|
||||
/// An asterisk marks a keyword only some photos have; after any other name it is refused, and the
|
||||
/// error names what was typed.
|
||||
#[test]
|
||||
fn an_asterisk_after_another_name_is_refused() {
|
||||
let (c, ids) = library(&[&["beach", "sea"], &["beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, "beach*, sea*"), Err("beach*".to_string()), "every photo has beach");
|
||||
assert_eq!(entered(&c, &start, "beach, sea*, harbor*"), Err("harbor*".to_string()), "a new name");
|
||||
assert_eq!(entered(&c, &start, "beach, *"), Err("*".to_string()));
|
||||
}
|
||||
|
||||
/// A keyword whose name holds a comma is one name in the text: left as it is, it changes
|
||||
/// nothing, and it can be marked, made common or taken off like any other.
|
||||
#[test]
|
||||
fn a_keyword_with_a_comma_is_one_name() {
|
||||
let (c, ids) = library(&[&["Places|Paris, France", "beach", "Lyon, Rhône, France"], &["beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
let text = entered_text(&start);
|
||||
assert_eq!(text, "beach, \"Lyon, Rhône, France\"*, \"Places|Paris, France\"*");
|
||||
assert_eq!(entered(&c, &start, &text), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "beach, \"Places|Paris, France\""), Ok(edit(&["Places|Paris, France"], &["Lyon, Rhône, France"])));
|
||||
assert_eq!(entered(&c, &start, "beach,\nPlaces | Paris, France * , Lyon, Rhône, France*"), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "beach, Places|Paris, France"), Ok(edit(&["Places|Paris, France"], &["Lyon, Rhône, France"])));
|
||||
assert_eq!(entered(&c, &start, "Paris, France"), Ok(edit(&["Paris", "France"], &["beach", "Lyon, Rhône, France", "Places|Paris, France"])));
|
||||
let (c, ids) = library(&[&["Paris, France"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()), "on every photo");
|
||||
// beside keywords named by its pieces, a name with a comma is the quoted one only
|
||||
let (c, ids) = library(&[&["a", "b", "a, b"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered_text(&start), "a, \"a, b\", b");
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "b, \"a, b\", a"), Ok(Entered::default()), "reordered");
|
||||
assert_eq!(entered(&c, &start, "a, b"), Ok(edit(&[], &["a, b"])), "its entry deleted");
|
||||
assert_eq!(entered(&c, &start, "a, b, a, b"), Ok(edit(&[], &["a, b"])));
|
||||
assert_eq!(entered(&c, &start, "\"a, b\", a"), Ok(edit(&[], &["b"])));
|
||||
// the same when it is a partial keyword
|
||||
let (c, ids) = library(&[&["a", "b", "a, b"], &["a", "b"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered_text(&start), "a, \"a, b\"*, b");
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "a, b"), Ok(edit(&[], &["a, b"])), "its entry deleted");
|
||||
assert_eq!(entered(&c, &start, "a, b, \"a, b\""), Ok(edit(&["a, b"], &[])), "made common");
|
||||
}
|
||||
|
||||
/// A name in double quotes holding a comma is read as one name, whether the selection, the
|
||||
/// library or neither has it; an unclosed quote leaves the pieces apart.
|
||||
#[test]
|
||||
fn a_quoted_name_with_a_comma_is_one_name() {
|
||||
let (c, ids) = library(&[&["beach"], &["beach"], &["Places|Rome, Italy"]]);
|
||||
let start = chips(&c, &ids[..2]);
|
||||
assert_eq!(entered(&c, &start, "beach, \"Paris, France\""), Ok(edit(&["Paris, France"], &[])), "a new name");
|
||||
assert_eq!(entered(&c, &start, " \"Places|Rome, Italy\" ,beach"), Ok(edit(&["Places|Rome, Italy"], &[])), "in the library");
|
||||
assert_eq!(entered(&c, &start, "\"a, b, c\""), Ok(edit(&["a, b, c"], &["beach"])));
|
||||
assert_eq!(entered(&c, &start, "beach, \"Paris, France"), Ok(edit(&["\"Paris", "France"], &[])), "unclosed");
|
||||
assert_eq!(entered(&c, &start, "\"Paris\nFrance\", beach"), Ok(edit(&["\"Paris", "France\""], &[])), "not across a new line");
|
||||
}
|
||||
|
||||
/// A keyword whose name holds a new line is read as one name, as one holding a comma is.
|
||||
#[test]
|
||||
fn a_keyword_with_a_line_break_is_one_name() {
|
||||
let (c, ids) = library(&[&["a\nb", "beach", "x,\ny"], &["beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
let text = entered_text(&start);
|
||||
assert_eq!(text, "\"a\nb\"*, beach, \"x,\ny\"*");
|
||||
assert_eq!(entered(&c, &start, &text), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "beach, a\nb"), Ok(edit(&["a\nb"], &["x,\ny"])));
|
||||
assert_eq!(entered(&c, &start, "beach\na"), Ok(edit(&["a"], &["a\nb", "x,\ny"])));
|
||||
let (c, ids) = library(&[&["a\nb"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()), "on every photo");
|
||||
}
|
||||
|
||||
/// A keyword on every photo whose own name ends in an asterisk is written in quotes and kept when
|
||||
/// the text is left as it is; one only some photos have is marked with a second asterisk.
|
||||
#[test]
|
||||
fn a_keyword_ending_in_an_asterisk_is_kept() {
|
||||
let (c, ids) = library(&[&["star*", "beach", "sea*"], &["star*", "beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
let text = entered_text(&start);
|
||||
assert_eq!(text, "beach, sea**, \"star*\"");
|
||||
assert_eq!(entered(&c, &start, &text), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "beach, star*"), Ok(edit(&[], &["sea*"])), "without its quotes");
|
||||
assert_eq!(entered(&c, &start, "beach, \"sea*\", \"star*\""), Ok(edit(&["sea*"], &[])), "a quoted partial goes to all");
|
||||
assert_eq!(entered(&c, &start, "beach, \"harbor*\""), Err("\"harbor*\"".to_string()), "a new name with an asterisk");
|
||||
// a partial `star` beside a common `star*`: each reads differently, and either can go
|
||||
let (c, ids) = library(&[&["star*", "star"], &["star*"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered_text(&start), "star*, \"star*\"");
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "\"star*\""), Ok(edit(&[], &["star"])));
|
||||
assert_eq!(entered(&c, &start, "star*"), Ok(edit(&[], &["star*"])));
|
||||
// a keyword every photo has that is itself in quotes keeps them
|
||||
let (c, ids) = library(&[&["\"quoted\""]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered_text(&start), "\"\"\"quoted\"\"\"");
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()));
|
||||
}
|
||||
|
||||
/// A keyword whose name holds a double quote is written in double quotes with that one written
|
||||
/// twice, so that the text left as it is changes nothing, beside keywords spelled like its pieces
|
||||
/// too.
|
||||
#[test]
|
||||
fn a_keyword_with_a_double_quote_reads_back() {
|
||||
let sets: [&[&str]; 6] = [
|
||||
&["a", "b\"", "a\", b"],
|
||||
&["a", "b\"", "a\"", "b"],
|
||||
&["a\", b"],
|
||||
&["\"b", "c\""],
|
||||
&["\"quoted\"", "say \"hi\", there", "\"a, b"],
|
||||
&["x", "a\"\"b"],
|
||||
];
|
||||
for set in sets {
|
||||
let (c, ids) = library(&[set]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()), "{set:?} on every photo: {}", entered_text(&start));
|
||||
// each one only some photos have
|
||||
let (c, ids) = library(&[set, &["x"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()), "{set:?} partial: {}", entered_text(&start));
|
||||
}
|
||||
let (c, ids) = library(&[&["a", "b\"", "a\", b"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered_text(&start), "a, \"a\"\", b\", \"b\"\"\"");
|
||||
assert_eq!(entered(&c, &start, "a, \"b\"\"\""), Ok(edit(&[], &["a\", b"])), "its entry deleted");
|
||||
assert_eq!(entered(&c, &start, "a, b\""), Ok(edit(&[], &["a\", b"])), "written without its quotes");
|
||||
}
|
||||
|
||||
/// A new name goes inside the default parent, as one typed in the Add keyword box does.
|
||||
#[test]
|
||||
fn a_new_name_goes_inside_the_default_parent() {
|
||||
use lightcraft_catalog::keywords::KeywordInfo;
|
||||
let (mut c, ids) = library(&[&["beach"]]);
|
||||
c.apply(Op::SetKeyword { path: "Inbox".into(), info: Some(KeywordInfo { new_keywords_inside: true, ..KeywordInfo::default() }) }).unwrap();
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, "beach, harbor"), Ok(edit(&["Inbox|harbor"], &[])));
|
||||
}
|
||||
|
||||
/// `>` and `<` mark a hierarchy as `|` does: `animal > dog` and `dog < animal` are both
|
||||
/// `animal|dog`, for a new name, a keyword of the selection and one marked with its asterisk. A
|
||||
/// keyword whose own name holds one of them, and a name in double quotes, are read as written.
|
||||
#[test]
|
||||
fn a_hierarchy_is_written_with_greater_or_less_than() {
|
||||
let (c, ids) = library(&[&["beach", "Places|Lisbon"], &["beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, "beach, Places|Lisbon*, animal > dog, cat < animal"), Ok(edit(&["animal|dog", "animal|cat"], &[])));
|
||||
assert_eq!(entered(&c, &start, "beach, Places > Lisbon*"), Ok(Entered::default()), "a partial keyword marked");
|
||||
assert_eq!(entered(&c, &start, "beach, Lisbon < Places*"), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "beach, Places > Lisbon"), Ok(edit(&["Places|Lisbon"], &[])), "made common");
|
||||
assert_eq!(entered(&c, &start, "beach, a > b > c, z < y < x"), Ok(edit(&["a|b|c", "x|y|z"], &["Places|Lisbon"])), "deeper levels");
|
||||
assert_eq!(entered(&c, &start, "beach, \"a > b\""), Ok(edit(&["a > b"], &["Places|Lisbon"])), "in quotes, as written");
|
||||
assert_eq!(entered(&c, &start, "beach, Places|Lisbon*, animal >"), Ok(edit(&["animal"], &[])), "an empty level after a mark");
|
||||
assert_eq!(entered(&c, &start, "beach, Places|Lisbon*, < animal"), Ok(edit(&["animal"], &[])), "an empty level before a mark");
|
||||
// a keyword whose name holds a comma is one name written with `>` too
|
||||
let (c, ids) = library(&[&["Places|Paris, France", "beach"], &["beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, "beach, Places > Paris, France*"), Ok(Entered::default()));
|
||||
assert_eq!(entered(&c, &start, "beach, Places > Paris, France"), Ok(edit(&["Places|Paris, France"], &[])));
|
||||
let (c, ids) = library(&[&["x>y"], &["beach"]]);
|
||||
let start = chips(&c, &ids);
|
||||
assert_eq!(entered(&c, &start, &entered_text(&start)), Ok(Entered::default()), "a name holding > reads back");
|
||||
assert_eq!(entered(&c, &start, "x>y, beach*"), Ok(edit(&["x>y"], &[])), "made common as written");
|
||||
// the text of a keyword holding `>` or `<`, pasted into the box of photos without it
|
||||
let (c, ids) = library(&[&["x>y", "y<z"], &["beach"]]);
|
||||
let text = entered_text(&chips(&c, &ids[..1]));
|
||||
assert_eq!(text, "\"x>y\", \"y<z\"");
|
||||
let other = chips(&c, &ids[1..]);
|
||||
assert_eq!(entered(&c, &other, &format!("beach, {text}")), Ok(edit(&["x>y", "y<z"], &[])), "read as written in another selection");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ use history::{activity, versions};
|
||||
use info::info;
|
||||
#[cfg(test)]
|
||||
pub(crate) use info::mixed_meta;
|
||||
pub(crate) use keywords::forget_stale_enter_keywords;
|
||||
use keywords::keywords;
|
||||
|
||||
pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
|
||||
@@ -8,6 +8,10 @@ pub(super) fn keywords(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId)
|
||||
let top = ui.cursor().top();
|
||||
if fold_header(app, ui, "keywording", "Keywords") {
|
||||
keywording(app, ui);
|
||||
} else if ui.data(|d| d.get_temp::<EnterEdit>(enter_id())).is_some_and(|e| !e.refused) {
|
||||
// a folded box applies the Enter Keywords edit it held, as leaving the box does
|
||||
let selection = app.session.selected();
|
||||
leave_enter_keywords(app, ui, &selection);
|
||||
}
|
||||
hold_list_in_place(ui, top);
|
||||
crate::panels::keyword_list::show(app, ui);
|
||||
@@ -106,9 +110,8 @@ fn keywording(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
// this edit (the shared field does)
|
||||
let returned = r.ending == Some(crate::text_field::Ending::Return) && !text.trim().is_empty();
|
||||
// a new name goes inside the default parent (Put New Keywords Inside This Keyword)
|
||||
let as_typed = |app: &LightcraftApp, text: &str| -> Vec<String> {
|
||||
text.split(',').map(|s| app.session.catalog.typed_keyword(s)).filter(|s| !s.is_empty()).collect()
|
||||
};
|
||||
// (`>` and `<` mark a hierarchy as `|` does)
|
||||
let as_typed = |app: &LightcraftApp, text: &str| -> Vec<String> { crate::panels::keywording::typed_names(&app.session.catalog, text) };
|
||||
let adding: Option<Vec<String>> = match picked {
|
||||
// an offer: it, and the keywords typed before the last comma
|
||||
Some(crate::panels::keywording::Picked::Keyword(k)) => {
|
||||
@@ -135,13 +138,17 @@ fn keywording(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
ui.data_mut(|d| d.insert_temp(kid, text));
|
||||
ui.add_space(8.0);
|
||||
let view = app.ui.keywording_view;
|
||||
crate::panels::keywording::view_switch(app, ui);
|
||||
if view == crate::state::KeywordingView::Enter && app.ui.keywording_view != view {
|
||||
leave_enter_keywords(app, ui, &selection);
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
crate::panels::keywording::scope(app, ui, &selection);
|
||||
if app.ui.keywording_view == crate::state::KeywordingView::Keywords {
|
||||
crate::panels::keywording::chip_row(app, ui, &selection);
|
||||
} else {
|
||||
crate::panels::keywording::names_row(app, ui);
|
||||
match app.ui.keywording_view {
|
||||
crate::state::KeywordingView::Enter => enter_keywords(app, ui, &selection),
|
||||
crate::state::KeywordingView::Keywords => crate::panels::keywording::chip_row(app, ui, &selection),
|
||||
_ => crate::panels::keywording::names_row(app, ui),
|
||||
}
|
||||
ui.add_space(10.0);
|
||||
keyword_set(app, ui);
|
||||
@@ -198,6 +205,199 @@ fn keywording(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
});
|
||||
}
|
||||
|
||||
/// An edit of the Enter Keywords box: its text, and the selection it was started on. It is made
|
||||
/// only once the box is edited, and the selection-sized parts are shared, so the box's data is not
|
||||
/// copied on every frame.
|
||||
#[derive(Clone)]
|
||||
struct EnterEdit {
|
||||
text: String,
|
||||
/// The selection's keywords when the edit started (shared with `Caches::keyword_chips`).
|
||||
start: std::sync::Arc<Vec<crate::panels::keywording::Chip>>,
|
||||
/// The photos the edit is for (`photo.setMeta` `ids`).
|
||||
ids: std::sync::Arc<[u64]>,
|
||||
/// The selection the edit was started on (`key_of`).
|
||||
selection: u64,
|
||||
/// [`LightcraftApp::selection_changes`] when the edit started: the same photos selected again
|
||||
/// after others are another selection.
|
||||
changes: u64,
|
||||
/// The library the edit was started in ([`lightcraft_engine::Session::library_generation`]):
|
||||
/// photo ids are a library's own, so the same ids in another library are other photos.
|
||||
library: u64,
|
||||
/// The last try to apply it was refused: the text stays to be put right.
|
||||
refused: bool,
|
||||
}
|
||||
|
||||
impl EnterEdit {
|
||||
fn new(
|
||||
text: String,
|
||||
chips: std::sync::Arc<Vec<crate::panels::keywording::Chip>>,
|
||||
selection: &[PhotoId],
|
||||
key: u64,
|
||||
changes: u64,
|
||||
library: u64,
|
||||
) -> Self {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
EnterEdit {
|
||||
text,
|
||||
start: chips,
|
||||
ids: selection.iter().filter(|id| seen.insert(**id)).map(|id| id.0).collect(),
|
||||
selection: key,
|
||||
changes,
|
||||
library,
|
||||
refused: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the edit was started on `selection` (`key_of`) in the open library, with no other
|
||||
/// selection since.
|
||||
fn is_for(&self, app: &mut LightcraftApp, selection: u64) -> bool {
|
||||
self.selection == selection && self.changes == app.selection_changes() && self.library == app.session.library_generation()
|
||||
}
|
||||
}
|
||||
|
||||
/// The Enter Keywords box's field.
|
||||
const ENTER_FIELD: &str = "field:enterKeywords";
|
||||
|
||||
/// Where the Enter Keywords box keeps its edit between frames.
|
||||
fn enter_id() -> egui::Id {
|
||||
egui::Id::unique("kw-enter")
|
||||
}
|
||||
|
||||
/// Applies the Enter Keywords `edit` to the photos it was started on, as one undo step. Returns
|
||||
/// whether it was applied (an edit that changes nothing is, and so is one saved in memory but not
|
||||
/// written to disk); a refusal or a failed write is said.
|
||||
fn apply_enter(app: &mut LightcraftApp, ctx: &egui::Context, edit: &EnterEdit) -> bool {
|
||||
match crate::panels::keywording::entered(&app.session.catalog, &edit.start, &edit.text) {
|
||||
Ok(change) if change.is_empty() => true,
|
||||
Ok(change) => match app.run_typed("photo.setMeta", json!({"ids": &*edit.ids, "addKeywords": change.add, "removeKeywords": change.remove})) {
|
||||
Ok(_) => true,
|
||||
Err(e) => {
|
||||
let applied = e.kind == crate::ErrorKind::NotSaved;
|
||||
app.toast_error(ctx, e.message);
|
||||
applied
|
||||
}
|
||||
},
|
||||
Err(name) => {
|
||||
app.toast_error(ctx, crate::i18n::tr_format!("A keyword name can't end with an asterisk: “{name}”", name = name));
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Another view chosen while the Enter Keywords box holds an edit: the edit is applied, as leaving
|
||||
/// the box applies it, and the box gives up the cursor. An edit of another selection, or of another
|
||||
/// library, is given up. A refused edit is kept, marked refused, and comes back when Enter Keywords
|
||||
/// is chosen again.
|
||||
fn leave_enter_keywords(app: &mut LightcraftApp, ui: &mut egui::Ui, selection: &[PhotoId]) {
|
||||
let id = enter_id();
|
||||
ui.memory_mut(|m| m.surrender_focus(crate::text_field::id(ENTER_FIELD)));
|
||||
let Some(mut edit) = ui.data(|d| d.get_temp::<EnterEdit>(id)) else { return };
|
||||
if edit.is_for(app, crate::key_of(selection)) && !apply_enter(app, ui.ctx(), &edit) {
|
||||
edit.refused = true;
|
||||
ui.data_mut(|d| d.insert_temp(id, edit));
|
||||
} else {
|
||||
ui.data_mut(|d| d.remove::<EnterEdit>(id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives up an Enter Keywords edit, applied or not, and the cursor in its box.
|
||||
fn give_up_enter_keywords(ctx: &egui::Context) {
|
||||
ctx.memory_mut(|m| m.surrender_focus(crate::text_field::id(ENTER_FIELD)));
|
||||
ctx.data_mut(|d| d.remove::<EnterEdit>(enter_id()));
|
||||
}
|
||||
|
||||
/// Gives up an Enter Keywords edit once the selection or the library differs from the one it was
|
||||
/// started on, whether its box is drawn or not: the same photos selected again later do not bring
|
||||
/// it back.
|
||||
pub(crate) fn forget_stale_enter_keywords(app: &mut LightcraftApp, ctx: &egui::Context) {
|
||||
let Some(edit) = ctx.data(|d| d.get_temp::<EnterEdit>(enter_id())) else { return };
|
||||
let selection = crate::key_of(app.session.selected());
|
||||
if !edit.is_for(app, selection) {
|
||||
give_up_enter_keywords(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/// Enter Keywords: the selection's keywords as text, separated by commas, one only some of the
|
||||
/// photos have marked with an asterisk. Return, leaving the box, choosing another view or folding
|
||||
/// the box applies the edit to the photos selected when it started, as one undo step; Esc gives it
|
||||
/// up. An edit whose box was hidden with its panel is applied when the box is next drawn. Another
|
||||
/// selection while the box is being edited, or another library opened, gives the edit up too. A
|
||||
/// refused edit keeps its text and says why.
|
||||
fn enter_keywords(app: &mut LightcraftApp, ui: &mut egui::Ui, selection: &[PhotoId]) {
|
||||
let id = enter_id();
|
||||
let key = crate::key_of(selection);
|
||||
let changes = app.selection_changes();
|
||||
let library = app.session.library_generation();
|
||||
let chips = app.caches.keyword_chips(&app.session.catalog, selection);
|
||||
let fid = crate::text_field::id(ENTER_FIELD);
|
||||
let focused = ui.memory(|m| m.has_focus(fid));
|
||||
let kept: Option<EnterEdit> = ui.data(|d| d.get_temp(id));
|
||||
// (an edit of another selection or library is given up, never applied to this one)
|
||||
if kept.as_ref().is_some_and(|e| !e.is_for(app, key)) && focused {
|
||||
ui.memory_mut(|m| m.surrender_focus(fid));
|
||||
}
|
||||
let kept = kept.filter(|e| e.is_for(app, key));
|
||||
// (an edit kept without the cursor lost it while the box was not drawn, its panel hidden)
|
||||
let left_undrawn = !focused && kept.as_ref().is_some_and(|e| !e.refused);
|
||||
// (no edit held: only the shown text is made, and the edit itself once the box is edited)
|
||||
let (kept, mut text) = match kept {
|
||||
Some(mut e) => {
|
||||
let text = std::mem::take(&mut e.text);
|
||||
(Some(e), text)
|
||||
}
|
||||
None => (None, crate::panels::keywording::entered_text(&chips)),
|
||||
};
|
||||
// Return applies the edit (Shift+Return or a pasted line break separates keywords as a comma does)
|
||||
let returned = focused
|
||||
&& ui.input_mut(|i| {
|
||||
let plain =
|
||||
|e: &egui::Event| matches!(e, egui::Event::Key { key: egui::Key::Enter, pressed: true, modifiers, .. } if modifiers.is_none());
|
||||
let found = i.events.iter().any(plain);
|
||||
i.events.retain(|e| !plain(e));
|
||||
found
|
||||
});
|
||||
let r = crate::text_field::TextField::multiline(ENTER_FIELD, &mut text)
|
||||
.hint(crate::i18n::tr("Keywords, separated by commas"))
|
||||
.label(crate::i18n::tr("Enter Keywords"))
|
||||
.rows(2)
|
||||
.width(f32::INFINITY)
|
||||
.show(ui);
|
||||
r.response.clone().on_hover_text(crate::i18n::tr(
|
||||
"Return applies the edit to the selected photos; Esc gives it up. An asterisk marks a keyword only some of them have.",
|
||||
));
|
||||
if r.cancelled() {
|
||||
ui.data_mut(|d| d.remove::<EnterEdit>(id));
|
||||
return;
|
||||
}
|
||||
// (applied as leaving the box applies it)
|
||||
let apply = returned || r.committed() || (left_undrawn && !r.editing);
|
||||
if !apply && !r.editing && !returned && !kept.as_ref().is_some_and(|e| e.refused) {
|
||||
ui.data_mut(|d| d.remove::<EnterEdit>(id));
|
||||
return;
|
||||
}
|
||||
let mut edit = match kept {
|
||||
Some(mut e) => {
|
||||
e.text = text;
|
||||
e
|
||||
}
|
||||
None => EnterEdit::new(text, chips, selection, key, changes, library),
|
||||
};
|
||||
let mut done = false;
|
||||
if apply {
|
||||
let applied = apply_enter(app, ui.ctx(), &edit);
|
||||
edit.refused = !applied;
|
||||
done = applied;
|
||||
if applied && returned {
|
||||
ui.memory_mut(|m| m.surrender_focus(fid));
|
||||
}
|
||||
}
|
||||
if !done && (r.editing || returned || edit.refused) {
|
||||
ui.data_mut(|d| d.insert_temp(id, edit));
|
||||
} else {
|
||||
ui.data_mut(|d| d.remove::<EnterEdit>(id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the Keyword List where it is on screen when the Keywords box above it (starting at
|
||||
/// `top`) grows or shrinks: a keyword ticked or unticked in the list, another selection. Without it
|
||||
/// a long tree slides away from under the pointer by a row of chips each time. It holds only while
|
||||
@@ -218,7 +418,7 @@ fn hold_list_in_place(ui: &mut egui::Ui, top: f32) {
|
||||
// (only the part of it in sight: the pointer on the top bar above a half-hidden box isn't on it)
|
||||
let old_box = Rect::from_x_y_ranges(ui.max_rect().x_range(), top..=top + before).intersect(ui.clip_rect());
|
||||
let on_box = ui.input(|i| i.pointer.latest_pos()).is_some_and(|p| old_box.contains(p));
|
||||
let typing = ui.memory(|m| m.has_focus(crate::text_field::id("field:keyword")));
|
||||
let typing = ui.memory(|m| ["field:keyword", ENTER_FIELD].iter().any(|f| m.has_focus(crate::text_field::id(f))));
|
||||
if on_box || typing {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -367,11 +367,13 @@ pub const RIGHT_WIDTH: PanelWidth = PanelWidth { min: 250.0, default: 270.0, max
|
||||
/// The photo area the side panels always leave free (as far as their minimum widths allow).
|
||||
pub const MIN_PHOTO_WIDTH: f32 = 360.0;
|
||||
|
||||
/// What the Keywording box shows: the keywords (chips to edit), them with the keywords containing
|
||||
/// them, or what exported files will carry (read only).
|
||||
/// What the Keywording box shows: the keywords as text to edit (Enter Keywords), the keywords
|
||||
/// (chips to edit), them with the keywords containing them, or what exported files will carry
|
||||
/// (read only).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum KeywordingView {
|
||||
Enter,
|
||||
#[default]
|
||||
Keywords,
|
||||
Containing,
|
||||
|
||||
@@ -14,7 +14,12 @@ const SETTLE: Duration = Duration::from_secs(120);
|
||||
/// The Library grid with the Keywords panel open and two photos selected: the first with beach and
|
||||
/// Weddings, the second with beach.
|
||||
fn two_selected() -> (Headless, Vec<u64>) {
|
||||
let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services { png: None, ..Default::default() });
|
||||
two_selected_in(lightcraft_engine::Session::with_demo())
|
||||
}
|
||||
|
||||
/// [`two_selected`] in `session`'s library.
|
||||
fn two_selected_in(session: lightcraft_engine::Session) -> (Headless, Vec<u64>) {
|
||||
let app = LightcraftApp::new(session, Services { png: None, ..Default::default() });
|
||||
let mut h = Headless::new(app, [1400.0, 1000.0], 1.0);
|
||||
let ids: Vec<u64> = h.app.session.visible_cloned().iter().take(2).map(|p| p.0).collect();
|
||||
for (method, params) in [
|
||||
@@ -949,3 +954,354 @@ fn open_dialogs_count_once_per_library_change() {
|
||||
}
|
||||
assert_eq!(h.app.caches.dialog_count_scans, before + 3, "another dialog counts its own photos, once");
|
||||
}
|
||||
|
||||
/// Enter Keywords, with everything in its box replaced by `text`.
|
||||
fn enter(h: &mut Headless, text: &str) {
|
||||
ask(h, "ui.clickWidget", json!({"id": "keywordView:enter"}));
|
||||
ask(h, "ui.clickWidget", json!({"id": "field:enterKeywords"}));
|
||||
ask(h, "ui.key", json!({"key": "A", "cmd": true}));
|
||||
ask(h, "ui.key", json!({"key": "Backspace"}));
|
||||
if !text.is_empty() {
|
||||
ask(h, "ui.text", json!({"text": text}));
|
||||
}
|
||||
}
|
||||
|
||||
fn enter_focused(h: &Headless) -> bool {
|
||||
h.view.ctx.memory(|m| m.has_focus(crate::text_field::id("field:enterKeywords")))
|
||||
}
|
||||
|
||||
/// Given two selected photos, when Enter Keywords is chosen, then the box shows their keywords as
|
||||
/// text in place of the chips; Return applies an edit to both photos as one undo step, and gives up
|
||||
/// the cursor.
|
||||
#[test]
|
||||
fn enter_keywords_edits_the_selections_keywords_as_text() {
|
||||
let (mut h, ids) = two_selected();
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "keywordView:enter"}));
|
||||
assert!(has(&h, "field:enterKeywords") && !has(&h, "keywordChip:beach"), "the text gives the chips way");
|
||||
enter(&mut h, "beach, Weddings*, harbor");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings", "harbor"]);
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach", "harbor"], "Weddings stays on the photo that had it");
|
||||
assert!(!enter_focused(&h), "Return gave up the cursor");
|
||||
ask(&mut h, "engine.execute", json!({"command": "edit.undo", "params": {}}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings"], "one undo takes the edit back");
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach"]);
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "keywordView:keywords"}));
|
||||
assert!(has(&h, "keywordChip:beach") && !has(&h, "field:enterKeywords"), "Keywords brings the chips back");
|
||||
}
|
||||
|
||||
/// A keyword left out of the text is taken off every selected photo, a partial one keeps its photos
|
||||
/// while its asterisk stays, and without its asterisk it goes to all of them.
|
||||
#[test]
|
||||
fn enter_keywords_removes_and_makes_a_partial_keyword_common() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "Weddings*");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["Weddings"]);
|
||||
assert!(keywords_of(&h, ids[1]).is_empty(), "beach went from both");
|
||||
enter(&mut h, "Weddings");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["Weddings"], "without its asterisk it goes to both");
|
||||
enter(&mut h, "");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(ids.iter().all(|id| keywords_of(&h, *id).is_empty()), "an empty box takes every keyword off");
|
||||
}
|
||||
|
||||
/// Esc gives the edit up; leaving the box applies it, as Return does.
|
||||
#[test]
|
||||
fn enter_keywords_escape_gives_up_and_leaving_applies() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "sea");
|
||||
ask(&mut h, "ui.key", json!({"key": "Escape"}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings"], "Esc changed nothing");
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach"]);
|
||||
enter(&mut h, "beach, Weddings*, sea");
|
||||
ask(&mut h, "ui.key", json!({"key": "Tab"}));
|
||||
assert!(all_have(&h, &ids, "sea"), "leaving the box applied it");
|
||||
}
|
||||
|
||||
/// Choosing another view while typing applies the edit, as leaving the box does; Enter Keywords
|
||||
/// chosen again shows the photos' keywords, not the old text. A refused edit comes back with it.
|
||||
#[test]
|
||||
fn enter_keywords_applies_an_edit_when_another_view_is_chosen() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, sea");
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "keywordView:containing"}));
|
||||
assert!(all_have(&h, &ids, "sea"), "choosing another view applied it");
|
||||
assert!(!enter_focused(&h));
|
||||
ask(&mut h, "engine.execute", json!({"command": "photo.setMeta", "params": {"ids": [ids[1]], "removeKeywords": ["sea"]}}));
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "keywordView:enter"}));
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "field:enterKeywords"}));
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach"], "the old text did not come back to give sea again");
|
||||
enter(&mut h, "beach, harbor*");
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "keywordView:keywords"}));
|
||||
assert!(h.app.ui.toast.as_ref().is_some_and(|(t, ..)| t.contains("harbor*")), "{:?}", h.app.ui.toast);
|
||||
assert!(none_has(&h, &ids, "harbor"));
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "keywordView:enter"}));
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "field:enterKeywords"}));
|
||||
ask(&mut h, "ui.key", json!({"key": "End", "cmd": true}));
|
||||
ask(&mut h, "ui.key", json!({"key": "Backspace"}));
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(all_have(&h, &ids, "harbor"), "the refused text came back to be put right");
|
||||
}
|
||||
|
||||
/// Folding the Keywords box while typing applies the edit, as leaving the box does; so does hiding
|
||||
/// its panel, once the box is shown again for the same photos.
|
||||
#[test]
|
||||
fn enter_keywords_applies_an_edit_when_the_box_is_folded_or_hidden() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, sea");
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "section:keywording"}));
|
||||
assert!(!has(&h, "field:enterKeywords"), "the box is folded");
|
||||
assert!(all_have(&h, &ids, "sea"), "folding the box applied it");
|
||||
ask(&mut h, "ui.clickWidget", json!({"id": "section:keywording"}));
|
||||
enter(&mut h, "beach, Weddings*, sea, harbor");
|
||||
h.app.ui.toggle_folded("keywording");
|
||||
h.step();
|
||||
assert!(all_have(&h, &ids, "harbor"), "folded without a click, it applied it");
|
||||
h.app.ui.toggle_folded("keywording");
|
||||
h.step();
|
||||
enter(&mut h, "beach, Weddings*, sea, harbor, pier");
|
||||
ask(&mut h, "ui.set", json!({"right": "info"}));
|
||||
h.step();
|
||||
ask(&mut h, "ui.set", json!({"right": "keywords"}));
|
||||
h.step();
|
||||
assert!(all_have(&h, &ids, "pier"), "hiding the box with its panel applied it when it came back");
|
||||
}
|
||||
|
||||
/// An edit kept while its box was hidden with its panel is given up when another library is open
|
||||
/// by the time the box is drawn or folded again: that library's photos with the same ids keep their
|
||||
/// keywords.
|
||||
#[test]
|
||||
fn enter_keywords_gives_up_an_edit_when_another_library_opens() {
|
||||
for folded in [false, true] {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, pier");
|
||||
ask(&mut h, "ui.set", json!({"right": "info"}));
|
||||
h.step();
|
||||
h.app.session = lightcraft_engine::Session::with_demo();
|
||||
ask(&mut h, "engine.execute", json!({"command": "library.select", "params": {"ids": ids}}));
|
||||
let before: Vec<Vec<String>> = ids.iter().map(|id| keywords_of(&h, *id)).collect();
|
||||
if folded {
|
||||
h.app.ui.toggle_folded("keywording");
|
||||
}
|
||||
ask(&mut h, "ui.set", json!({"right": "keywords"}));
|
||||
h.step();
|
||||
let after: Vec<Vec<String>> = ids.iter().map(|id| keywords_of(&h, *id)).collect();
|
||||
assert_eq!(after, before, "the other library's photos keep their keywords (box folded: {folded})");
|
||||
}
|
||||
}
|
||||
|
||||
/// An asterisk after a name that is not a keyword only some photos have is refused: the photos keep
|
||||
/// their keywords, the box keeps the cursor and its text, and the refusal is said.
|
||||
#[test]
|
||||
fn enter_keywords_refuses_a_name_ending_in_an_asterisk() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, sea*");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings"]);
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach"]);
|
||||
assert!(enter_focused(&h), "the box keeps the cursor to put it right");
|
||||
assert!(h.app.ui.toast.as_ref().is_some_and(|(t, ..)| t.contains("asterisk") && t.contains("sea*")), "{:?}", h.app.ui.toast);
|
||||
ask(&mut h, "ui.key", json!({"key": "Backspace"}));
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(all_have(&h, &ids, "sea"), "the text was kept and put right");
|
||||
}
|
||||
|
||||
/// An edit the library could not write to disk is still applied in memory: the box gives it up as
|
||||
/// applied. Retyping the photos' earlier keywords then takes it back, and another Return adds no
|
||||
/// second undo step, so one Undo takes it back.
|
||||
#[test]
|
||||
fn enter_keywords_treats_an_edit_saved_only_in_memory_as_applied() {
|
||||
use std::sync::atomic::Ordering;
|
||||
let store = super::unsaved::Flaky::default();
|
||||
let mut session = lightcraft_engine::Session::new();
|
||||
let stores = lightcraft_engine::library::LibraryStores {
|
||||
dir: "flaky".into(),
|
||||
catalog: Box::new(store.clone()),
|
||||
files: Box::new(lightcraft_catalog::MemStore::new()),
|
||||
on_disk: false,
|
||||
};
|
||||
session.open_library_in(stores, true).unwrap();
|
||||
let (mut h, ids) = two_selected_in(session);
|
||||
let undo = h.app.session.undo.len();
|
||||
|
||||
store.fail.store(true, Ordering::SeqCst);
|
||||
enter(&mut h, "beach, Weddings*, harbor");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(all_have(&h, &ids, "harbor"), "the edit is applied in memory");
|
||||
assert!(h.app.ui.toast.as_ref().is_some_and(|(t, ..)| t.contains("not written to disk")), "{:?}", h.app.ui.toast);
|
||||
assert!(!enter_focused(&h), "Return gave up the cursor, as for an applied edit");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(h.app.session.undo.len(), undo + 1, "another Return added no undo step");
|
||||
store.fail.store(false, Ordering::SeqCst);
|
||||
ask(&mut h, "engine.execute", json!({"command": "edit.undo", "params": {}}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings"], "one undo takes the edit back");
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach"]);
|
||||
|
||||
store.fail.store(true, Ordering::SeqCst);
|
||||
enter(&mut h, "beach, Weddings*, harbor");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(all_have(&h, &ids, "harbor"));
|
||||
enter(&mut h, "beach, Weddings*");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(none_has(&h, &ids, "harbor"), "retyping the earlier keywords took the edit back");
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings"]);
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach"]);
|
||||
store.fail.store(false, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// What the Enter Keywords box shows, read by copying all of it.
|
||||
fn enter_text(h: &mut Headless) -> String {
|
||||
ask(h, "ui.clickWidget", json!({"id": "keywordView:enter"}));
|
||||
ask(h, "ui.clickWidget", json!({"id": "field:enterKeywords"}));
|
||||
ask(h, "ui.key", json!({"key": "A", "cmd": true}));
|
||||
ask(h, "ui.clipboard", json!({"action": "copy"}));
|
||||
let r = h.request("ui.inspect", json!({}), T);
|
||||
r["result"]["copied"].as_str().unwrap_or_default().to_string()
|
||||
}
|
||||
|
||||
/// A plain list of names typed in the box goes to every selected photo as written; the names left
|
||||
/// out come off every one of them.
|
||||
#[test]
|
||||
fn enter_keywords_gives_a_plain_list_to_every_photo() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "harbor, sea, pier");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
for id in &ids {
|
||||
assert_eq!(keywords_of(&h, *id), ["harbor", "sea", "pier"], "photo {id}");
|
||||
}
|
||||
}
|
||||
|
||||
/// `>` and `<` in a typed name mark a hierarchy, as `|` does: `animal > dog` and `cat < animal`
|
||||
/// give both photos `animal|dog` and `animal|cat`.
|
||||
#[test]
|
||||
fn enter_keywords_reads_a_hierarchy_typed_with_greater_or_less_than() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, animal > dog, cat < animal");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(all_have(&h, &ids, "animal|dog") && all_have(&h, &ids, "animal|cat"), "{:?}", keywords_of(&h, ids[1]));
|
||||
assert!(none_has(&h, &ids, "animal > dog") && none_has(&h, &ids, "cat < animal"));
|
||||
assert_eq!(enter_text(&mut h), "animal|cat, animal|dog, beach, Weddings*", "the box shows them as paths");
|
||||
}
|
||||
|
||||
/// The Add keyword box reads `>` and `<` as Enter Keywords does: `animal > dog, cat < animal`
|
||||
/// gives both photos `animal|dog` and `animal|cat`, and so does an offer taken after them.
|
||||
#[test]
|
||||
fn the_add_keyword_box_reads_a_hierarchy_typed_with_greater_or_less_than() {
|
||||
let (mut h, ids) = with_places();
|
||||
typed(&mut h, "animal > dog, cat < animal");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(all_have(&h, &ids, "animal|dog") && all_have(&h, &ids, "animal|cat"), "{:?}", keywords_of(&h, ids[1]));
|
||||
assert!(none_has(&h, &ids, "animal > dog") && none_has(&h, &ids, "cat < animal"));
|
||||
typed(&mut h, "bird < animal, lis");
|
||||
ask(&mut h, "ui.key", json!({"key": "ArrowDown"}));
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert!(all_have(&h, &ids, "animal|bird") && all_have(&h, &ids, "Places|Portugal|Lisbon"), "{:?}", keywords_of(&h, ids[1]));
|
||||
}
|
||||
|
||||
/// A mixed selection shows each keyword only some photos have with an asterisk after it. Left
|
||||
/// marked, it stays on those photos only while the rest of the edit applies; it comes off only
|
||||
/// when its name is deleted from the text.
|
||||
#[test]
|
||||
fn enter_keywords_shows_and_keeps_a_mixed_selections_keywords() {
|
||||
let (mut h, ids) = two_selected();
|
||||
assert_eq!(enter_text(&mut h), "beach, Weddings*", "a keyword only some photos have is marked");
|
||||
ask(&mut h, "ui.key", json!({"key": "End", "cmd": true}));
|
||||
ask(&mut h, "ui.text", json!({"text": ", sea"}));
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings", "sea"]);
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["beach", "sea"], "Weddings did not go to the photo without it");
|
||||
enter(&mut h, "Weddings*, sea");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["Weddings", "sea"], "beach, deleted from the text, came off");
|
||||
assert_eq!(keywords_of(&h, ids[1]), ["sea"]);
|
||||
}
|
||||
|
||||
/// One edit that adds and removes keywords on three photos is one undo step for all of them, and
|
||||
/// one redo gives it back to all of them.
|
||||
#[test]
|
||||
fn enter_keywords_undoes_an_edit_of_every_photo_in_one_step() {
|
||||
let (mut h, mut ids) = two_selected();
|
||||
let third = h.app.session.visible_cloned().get(2).map(|p| p.0).unwrap();
|
||||
ask(&mut h, "engine.execute", json!({"command": "photo.setMeta", "params": {"ids": [third], "keywords": ["pier"]}}));
|
||||
ids.push(third);
|
||||
ask(&mut h, "engine.execute", json!({"command": "library.select", "params": {"ids": ids}}));
|
||||
let before: Vec<Vec<String>> = ids.iter().map(|id| keywords_of(&h, *id)).collect();
|
||||
let undo = h.app.session.undo.len();
|
||||
enter(&mut h, "Weddings*, sea, animal > dog");
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
let after: Vec<Vec<String>> = ids.iter().map(|id| keywords_of(&h, *id)).collect();
|
||||
assert_eq!(after, [vec!["Weddings", "sea", "animal|dog"], vec!["sea", "animal|dog"], vec!["sea", "animal|dog"]]);
|
||||
assert_eq!(h.app.session.undo.len(), undo + 1, "one undo step");
|
||||
ask(&mut h, "engine.execute", json!({"command": "edit.undo", "params": {}}));
|
||||
assert_eq!(ids.iter().map(|id| keywords_of(&h, *id)).collect::<Vec<_>>(), before, "one undo puts every photo back");
|
||||
ask(&mut h, "engine.execute", json!({"command": "edit.redo", "params": {}}));
|
||||
assert_eq!(ids.iter().map(|id| keywords_of(&h, *id)).collect::<Vec<_>>(), after, "one redo gives it back");
|
||||
}
|
||||
|
||||
/// Another selection while the box is being edited gives the edit up: what was typed goes neither to
|
||||
/// the photos it was typed for nor to the new selection.
|
||||
#[test]
|
||||
fn enter_keywords_gives_up_an_edit_when_the_selection_changes() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, harbor");
|
||||
ask(&mut h, "engine.execute", json!({"command": "library.select", "params": {"ids": [ids[1]]}}));
|
||||
ask(&mut h, "ui.key", json!({"key": "Enter"}));
|
||||
let every: Vec<u64> = h.app.session.visible_cloned().iter().map(|p| p.0).collect();
|
||||
assert!(every.iter().all(|id| !keywords_of(&h, *id).contains(&"harbor".to_string())), "nobody got harbor");
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings"]);
|
||||
}
|
||||
|
||||
/// A selection cleared while the box is being edited gives the edit up too: the same photos
|
||||
/// selected again keep their keywords.
|
||||
#[test]
|
||||
fn enter_keywords_gives_up_an_edit_when_the_selection_is_cleared() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, harbor");
|
||||
ask(&mut h, "engine.execute", json!({"command": "library.select", "params": {"ids": []}}));
|
||||
h.step();
|
||||
assert!(h.app.session.active().is_none(), "nothing selected");
|
||||
ask(&mut h, "engine.execute", json!({"command": "library.select", "params": {"ids": ids}}));
|
||||
h.step();
|
||||
assert_eq!(enter_text(&mut h), "beach, Weddings*", "the box shows the photos' keywords, not the old text");
|
||||
ask(&mut h, "ui.key", json!({"key": "Tab"}));
|
||||
assert!(none_has(&h, &ids, "harbor"), "the edit was not applied when the photos came back");
|
||||
assert_eq!(keywords_of(&h, ids[0]), ["beach", "Weddings"]);
|
||||
}
|
||||
|
||||
/// An edit kept while its box was hidden with its panel is given up when other photos are selected
|
||||
/// meanwhile, even when the first photos are selected again before the box comes back.
|
||||
#[test]
|
||||
fn enter_keywords_gives_up_a_hidden_edit_when_the_selection_changes_meanwhile() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, harbor");
|
||||
ask(&mut h, "ui.set", json!({"right": "info"}));
|
||||
h.step();
|
||||
ask(&mut h, "engine.execute", json!({"command": "library.select", "params": {"ids": [ids[1]]}}));
|
||||
h.step();
|
||||
ask(&mut h, "engine.execute", json!({"command": "library.select", "params": {"ids": ids}}));
|
||||
h.step();
|
||||
ask(&mut h, "ui.set", json!({"right": "keywords"}));
|
||||
h.step();
|
||||
assert!(none_has(&h, &ids, "harbor"), "the edit was not applied when the box came back");
|
||||
assert_eq!(enter_text(&mut h), "beach, Weddings*", "the box shows the photos' keywords");
|
||||
}
|
||||
|
||||
/// Two selection changes between UI passes give the hidden edit up too, even when the first photos
|
||||
/// are selected again before the next pass.
|
||||
#[test]
|
||||
fn enter_keywords_gives_up_a_hidden_edit_when_the_selection_round_trips_between_passes() {
|
||||
let (mut h, ids) = two_selected();
|
||||
enter(&mut h, "beach, Weddings*, harbor");
|
||||
ask(&mut h, "ui.set", json!({"right": "info"}));
|
||||
h.step();
|
||||
h.app.run("library.select", json!({"ids": [ids[1]]})).unwrap();
|
||||
h.app.run("library.select", json!({"ids": ids})).unwrap();
|
||||
h.step();
|
||||
ask(&mut h, "ui.set", json!({"right": "keywords"}));
|
||||
h.step();
|
||||
assert!(none_has(&h, &ids, "harbor"), "the edit was not applied when the box came back");
|
||||
assert_eq!(enter_text(&mut h), "beach, Weddings*", "the box shows the photos' keywords");
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ const T: Duration = Duration::from_secs(20);
|
||||
|
||||
/// Appends fail while `fail` is set.
|
||||
#[derive(Clone, Default)]
|
||||
struct Flaky {
|
||||
pub(super) struct Flaky {
|
||||
files: MemStore,
|
||||
fail: Arc<AtomicBool>,
|
||||
pub(super) fail: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl Store for Flaky {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user