From c97c6c6e98ba8df9bb684357daf5caede8fb548a Mon Sep 17 00:00:00 2001 From: RumovZ Date: Mon, 31 May 2021 12:03:30 +0200 Subject: [PATCH 1/3] Add violet, turquoise and purple flags --- ftl/core/actions.ftl | 11 ++++--- ftl/core/search.ftl | 2 +- pylib/anki/cards.py | 2 +- qt/aqt/browser/table/__init__.py | 6 ++++ qt/aqt/data/web/js/reviewer.ts | 5 ++- qt/aqt/flags.py | 21 ++++++++++++ qt/aqt/forms/browser.ui | 44 ++++++++++++++++++++++--- rslib/backend.proto | 6 ++++ rslib/src/backend/search/search_node.rs | 3 ++ rslib/src/browser_table.rs | 3 ++ rslib/src/card/mod.rs | 9 ++--- rslib/src/search/parser.rs | 6 ++-- ts/sass/_vars.scss | 12 +++++++ 13 files changed, 110 insertions(+), 20 deletions(-) diff --git a/ftl/core/actions.ftl b/ftl/core/actions.ftl index 57d7d188f..263c9d897 100644 --- a/ftl/core/actions.ftl +++ b/ftl/core/actions.ftl @@ -1,7 +1,6 @@ actions-add = Add actions-all-selected = All selected actions-any-selected = Any selected -actions-blue-flag = Blue Flag actions-cancel = Cancel actions-choose = Choose actions-close = Close @@ -11,7 +10,6 @@ actions-decks = Decks actions-delete = Delete actions-export = Export actions-filter = Filter -actions-green-flag = Green Flag actions-help = Help actions-import = Import actions-manage = Manage... @@ -20,10 +18,8 @@ actions-new = New actions-new-name = New name: actions-options = Options actions-options-for = Options for { $val } -actions-orange-flag = Orange Flag actions-preview = Preview actions-rebuild = Rebuild -actions-red-flag = Red Flag actions-rename = Rename actions-rename-deck = Rename Deck actions-rename-tag = Rename Tag @@ -53,3 +49,10 @@ actions-add-notetype = Add Notetype actions-remove-notetype = Remove Notetype actions-update-notetype = Update Notetype actions-update-config = Update Config +actions-red-flag = Red Flag +actions-orange-flag = Orange Flag +actions-green-flag = Green Flag +actions-blue-flag = Blue Flag +actions-violet-flag = Violet Flag +actions-turquoise-flag = Turquoise Flag +actions-purple-flag = Purple Flag diff --git a/ftl/core/search.ftl b/ftl/core/search.ftl index 768d77109..e26ce4a9c 100644 --- a/ftl/core/search.ftl +++ b/ftl/core/search.ftl @@ -16,7 +16,7 @@ search-unclosed-quote = an opening double quote `"` was found, but there was no search-missing-key = a colon `:` was found, but there was no keyword preceding it. If you want to search for a literal `:`, prepend a backslash: `\:`. search-unknown-escape = the escape sequence `{ $val }` is not defined. If you want to search for a literal backslash `\`, prepend another one: `\\`. search-invalid-argument = `{ $term }` was given an invalid argument '`{ $argument }`'. -search-invalid-flag = `flag:` must be followed by a valid flag number: `1` (red), `2` (orange), `3` (green), `4` (blue) or `0` (no flag). +search-invalid-flag = `flag:` must be followed by a valid flag number: `1` (red), `2` (orange), `3` (green), `4` (blue), `5` (violet), `6` (turquoise), `7` (purple) or `0` (no flag). search-invalid-prop-operator = `prop:{ $val }` must be followed by one of the following comparison operators: `=`, `!=`, `<`, `>`, `<=` or `>=`. search-invalid-other = please check for typing mistakes. diff --git a/pylib/anki/cards.py b/pylib/anki/cards.py index eb4b43d17..809efd577 100644 --- a/pylib/anki/cards.py +++ b/pylib/anki/cards.py @@ -215,7 +215,7 @@ class Card: def set_user_flag(self, flag: int) -> None: print("use col.set_user_flag_for_cards() instead") - assert 0 <= flag <= 4 + assert 0 <= flag <= 7 self.flags = (self.flags & ~0b111) | flag # legacy diff --git a/qt/aqt/browser/table/__init__.py b/qt/aqt/browser/table/__init__.py index 6f9bfa110..03d6a0952 100644 --- a/qt/aqt/browser/table/__init__.py +++ b/qt/aqt/browser/table/__init__.py @@ -88,6 +88,12 @@ def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> Optional[Tuple[str, return colors.FLAG3_BG if color == BrowserRow.COLOR_FLAG_BLUE: return colors.FLAG4_BG + if color == BrowserRow.COLOR_FLAG_VIOLET: + return colors.FLAG5_BG + if color == BrowserRow.COLOR_FLAG_TURQUOISE: + return colors.FLAG6_BG + if color == BrowserRow.COLOR_FLAG_PURPLE: + return colors.FLAG7_BG return None diff --git a/qt/aqt/data/web/js/reviewer.ts b/qt/aqt/data/web/js/reviewer.ts index d56d09fe7..650c710ff 100644 --- a/qt/aqt/data/web/js/reviewer.ts +++ b/qt/aqt/data/web/js/reviewer.ts @@ -150,9 +150,12 @@ const _flagColours = { 2: "#ff9900", 3: "#77ff77", 4: "#77aaff", + 5: "#fc68e8", + 6: "#00d3b7", + 7: "#9e3bfa", }; -function _drawFlag(flag: 0 | 1 | 2 | 3 | 4): void { +function _drawFlag(flag: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7): void { const elem = document.getElementById("_flag"); if (flag === 0) { elem.setAttribute("hidden", ""); diff --git a/qt/aqt/flags.py b/qt/aqt/flags.py index 46587d316..a2baa8bc3 100644 --- a/qt/aqt/flags.py +++ b/qt/aqt/flags.py @@ -65,4 +65,25 @@ def load_flags(col: Collection) -> List[Flag]: SearchNode(flag=SearchNode.FLAG_BLUE), "actionBlue_Flag", ), + Flag( + 5, + labels["5"] if "5" in labels else tr.actions_violet_flag(), + icon.with_color(colors.FLAG5_FG), + SearchNode(flag=SearchNode.FLAG_VIOLET), + "actionViolet_Flag", + ), + Flag( + 6, + labels["6"] if "6" in labels else tr.actions_turquoise_flag(), + icon.with_color(colors.FLAG6_FG), + SearchNode(flag=SearchNode.FLAG_TURQUOISE), + "actionTurquoise_Flag", + ), + Flag( + 7, + labels["7"] if "7" in labels else tr.actions_purple_flag(), + icon.with_color(colors.FLAG7_FG), + SearchNode(flag=SearchNode.FLAG_PURPLE), + "actionPurple_Flag", + ), ] diff --git a/qt/aqt/forms/browser.ui b/qt/aqt/forms/browser.ui index eb5528d9a..ded81567a 100644 --- a/qt/aqt/forms/browser.ui +++ b/qt/aqt/forms/browser.ui @@ -144,12 +144,12 @@ false - - 20 - false + + 20 + true @@ -209,7 +209,7 @@ 0 0 750 - 24 + 21 @@ -262,6 +262,9 @@ + + + @@ -622,6 +625,39 @@ Ctrl+Shift+Z + + + true + + + actions_violet_flag + + + Ctrl+5 + + + + + true + + + actions_turquoise_flag + + + Ctrl+6 + + + + + true + + + actions_purple_flag + + + Ctrl+7 + + diff --git a/rslib/backend.proto b/rslib/backend.proto index 0b8e33631..12d4698e9 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -858,6 +858,9 @@ message SearchNode { FLAG_ORANGE = 3; FLAG_GREEN = 4; FLAG_BLUE = 5; + FLAG_VIOLET = 6; + FLAG_TURQUOISE = 7; + FLAG_PURPLE = 8; } enum Rating { RATING_ANY = 0; @@ -1130,6 +1133,9 @@ message BrowserRow { COLOR_FLAG_ORANGE = 4; COLOR_FLAG_GREEN = 5; COLOR_FLAG_BLUE = 6; + COLOR_FLAG_VIOLET = 7; + COLOR_FLAG_TURQUOISE = 8; + COLOR_FLAG_PURPLE = 9; } repeated Cell cells = 1; Color color = 2; diff --git a/rslib/src/backend/search/search_node.rs b/rslib/src/backend/search/search_node.rs index c095a90d0..c3d321551 100644 --- a/rslib/src/backend/search/search_node.rs +++ b/rslib/src/backend/search/search_node.rs @@ -70,6 +70,9 @@ impl TryFrom for Node { Flag::Orange => Node::Search(SearchNode::Flag(2)), Flag::Green => Node::Search(SearchNode::Flag(3)), Flag::Blue => Node::Search(SearchNode::Flag(4)), + Flag::Violet => Node::Search(SearchNode::Flag(5)), + Flag::Turquoise => Node::Search(SearchNode::Flag(6)), + Flag::Purple => Node::Search(SearchNode::Flag(7)), }, Filter::Negated(term) => Node::try_from(*term)?.negated(), Filter::Group(mut group) => { diff --git a/rslib/src/browser_table.rs b/rslib/src/browser_table.rs index 1e988b79a..5fc8a9b1f 100644 --- a/rslib/src/browser_table.rs +++ b/rslib/src/browser_table.rs @@ -527,6 +527,9 @@ impl RowContext { 2 => Color::FlagOrange, 3 => Color::FlagGreen, 4 => Color::FlagBlue, + 5 => Color::FlagViolet, + 6 => Color::FlagTurquoise, + 7 => Color::FlagPurple, _ => { if self.note.is_marked() { Color::Marked diff --git a/rslib/src/card/mod.rs b/rslib/src/card/mod.rs index e45f9458c..26486754b 100644 --- a/rslib/src/card/mod.rs +++ b/rslib/src/card/mod.rs @@ -119,11 +119,8 @@ impl Card { /// True if flag changed. fn set_flag(&mut self, flag: u8) -> bool { - // we currently only allow 4 flags - assert!(flag < 5); - - // but reserve space for 7, preserving the rest of - // the flags (up to a byte) + // The first 3 bits represent one of the 7 supported flags, the rest of + // the flag byte is preserved. let updated_flags = (self.flags & !0b111) | flag; if self.flags != updated_flags { self.flags = updated_flags; @@ -268,7 +265,7 @@ impl Collection { } pub fn set_card_flag(&mut self, cards: &[CardId], flag: u32) -> Result> { - if flag > 4 { + if flag > 7 { return Err(AnkiError::invalid_input("invalid flag")); } let flag = flag as u8; diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 8b4dd355d..22ca55db9 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -414,10 +414,10 @@ fn parse_template(s: &str) -> ParseResult { })) } -/// flag:0-4 +/// flag:0-7 fn parse_flag(s: &str) -> ParseResult { if let Ok(flag) = s.parse::() { - if flag > 4 { + if flag > 7 { Err(parse_failure(s, FailKind::InvalidFlag)) } else { Ok(SearchNode::Flag(flag)) @@ -999,7 +999,7 @@ mod test { assert_err_kind(r#""flag: ""#, InvalidFlag); assert_err_kind("flag:-0", InvalidFlag); assert_err_kind("flag:", InvalidFlag); - assert_err_kind("flag:5", InvalidFlag); + assert_err_kind("flag:8", InvalidFlag); assert_err_kind("flag:1.1", InvalidFlag); for term in &["added", "edited", "rated", "resched"] { diff --git a/ts/sass/_vars.scss b/ts/sass/_vars.scss index 949307835..45573e354 100644 --- a/ts/sass/_vars.scss +++ b/ts/sass/_vars.scss @@ -21,10 +21,16 @@ --flag2-fg: #ffb347; --flag3-fg: #0a0; --flag4-fg: #77ccff; + --flag5-fg: #fc68e8; + --flag6-fg: #00d3b7; + --flag7-fg: #9e3bfa; --flag1-bg: #ffaaaa; --flag2-bg: #ffb347; --flag3-bg: #82e0aa; --flag4-bg: #85c1e9; + --flag5-bg: #ffafeb; + --flag6-bg: #4bd3cc; + --flag7-bg: #c07dff; --buried-fg: #aaaa33; --suspended-fg: #dd0; --suspended-bg: #ffffb2; @@ -52,10 +58,16 @@ --flag2-fg: #ffb347; --flag3-fg: #82e0aa; --flag4-fg: #85c1e9; + --flag5-fg: #ffafeb; + --flag6-fg: #3fccc5; + --flag7-fg: #c07dff; --flag1-bg: #aa5555; --flag2-bg: #aa6337; --flag3-bg: #33a055; --flag4-bg: #3581a9; + --flag5-bg: #be64b2; + --flag6-bg: #11a591; + --flag7-bg: #904fce; --buried-fg: #777733; --suspended-fg: #ffffb2; --suspended-bg: #aaaa33; From 5e7a47fdc76610fbcbb83d80d5ebc5ed11263be9 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 1 Jun 2021 18:14:43 +0200 Subject: [PATCH 2/3] Rename violet to pink --- ftl/core/actions.ftl | 2 +- ftl/core/search.ftl | 2 +- qt/aqt/browser/table/__init__.py | 2 +- qt/aqt/flags.py | 6 +++--- qt/aqt/forms/browser.ui | 6 +++--- rslib/backend.proto | 4 ++-- rslib/src/backend/search/search_node.rs | 2 +- rslib/src/browser_table.rs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ftl/core/actions.ftl b/ftl/core/actions.ftl index 263c9d897..b6d04bfc0 100644 --- a/ftl/core/actions.ftl +++ b/ftl/core/actions.ftl @@ -53,6 +53,6 @@ actions-red-flag = Red Flag actions-orange-flag = Orange Flag actions-green-flag = Green Flag actions-blue-flag = Blue Flag -actions-violet-flag = Violet Flag +actions-pink-flag = Pink Flag actions-turquoise-flag = Turquoise Flag actions-purple-flag = Purple Flag diff --git a/ftl/core/search.ftl b/ftl/core/search.ftl index e26ce4a9c..f18fa73c3 100644 --- a/ftl/core/search.ftl +++ b/ftl/core/search.ftl @@ -16,7 +16,7 @@ search-unclosed-quote = an opening double quote `"` was found, but there was no search-missing-key = a colon `:` was found, but there was no keyword preceding it. If you want to search for a literal `:`, prepend a backslash: `\:`. search-unknown-escape = the escape sequence `{ $val }` is not defined. If you want to search for a literal backslash `\`, prepend another one: `\\`. search-invalid-argument = `{ $term }` was given an invalid argument '`{ $argument }`'. -search-invalid-flag = `flag:` must be followed by a valid flag number: `1` (red), `2` (orange), `3` (green), `4` (blue), `5` (violet), `6` (turquoise), `7` (purple) or `0` (no flag). +search-invalid-flag = `flag:` must be followed by a valid flag number: `1` (red), `2` (orange), `3` (green), `4` (blue), `5` (pink), `6` (turquoise), `7` (purple) or `0` (no flag). search-invalid-prop-operator = `prop:{ $val }` must be followed by one of the following comparison operators: `=`, `!=`, `<`, `>`, `<=` or `>=`. search-invalid-other = please check for typing mistakes. diff --git a/qt/aqt/browser/table/__init__.py b/qt/aqt/browser/table/__init__.py index 03d6a0952..4d19ba618 100644 --- a/qt/aqt/browser/table/__init__.py +++ b/qt/aqt/browser/table/__init__.py @@ -88,7 +88,7 @@ def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> Optional[Tuple[str, return colors.FLAG3_BG if color == BrowserRow.COLOR_FLAG_BLUE: return colors.FLAG4_BG - if color == BrowserRow.COLOR_FLAG_VIOLET: + if color == BrowserRow.COLOR_FLAG_PINK: return colors.FLAG5_BG if color == BrowserRow.COLOR_FLAG_TURQUOISE: return colors.FLAG6_BG diff --git a/qt/aqt/flags.py b/qt/aqt/flags.py index a2baa8bc3..af01570d4 100644 --- a/qt/aqt/flags.py +++ b/qt/aqt/flags.py @@ -67,10 +67,10 @@ def load_flags(col: Collection) -> List[Flag]: ), Flag( 5, - labels["5"] if "5" in labels else tr.actions_violet_flag(), + labels["5"] if "5" in labels else tr.actions_pink_flag(), icon.with_color(colors.FLAG5_FG), - SearchNode(flag=SearchNode.FLAG_VIOLET), - "actionViolet_Flag", + SearchNode(flag=SearchNode.FLAG_PINK), + "actionPink_Flag", ), Flag( 6, diff --git a/qt/aqt/forms/browser.ui b/qt/aqt/forms/browser.ui index ded81567a..eda2155e6 100644 --- a/qt/aqt/forms/browser.ui +++ b/qt/aqt/forms/browser.ui @@ -262,7 +262,7 @@ - + @@ -625,12 +625,12 @@ Ctrl+Shift+Z - + true - actions_violet_flag + actions_pink_flag Ctrl+5 diff --git a/rslib/backend.proto b/rslib/backend.proto index 12d4698e9..87f5e1aee 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -858,7 +858,7 @@ message SearchNode { FLAG_ORANGE = 3; FLAG_GREEN = 4; FLAG_BLUE = 5; - FLAG_VIOLET = 6; + FLAG_PINK = 6; FLAG_TURQUOISE = 7; FLAG_PURPLE = 8; } @@ -1133,7 +1133,7 @@ message BrowserRow { COLOR_FLAG_ORANGE = 4; COLOR_FLAG_GREEN = 5; COLOR_FLAG_BLUE = 6; - COLOR_FLAG_VIOLET = 7; + COLOR_FLAG_PINK = 7; COLOR_FLAG_TURQUOISE = 8; COLOR_FLAG_PURPLE = 9; } diff --git a/rslib/src/backend/search/search_node.rs b/rslib/src/backend/search/search_node.rs index c3d321551..d1f9da9ab 100644 --- a/rslib/src/backend/search/search_node.rs +++ b/rslib/src/backend/search/search_node.rs @@ -70,7 +70,7 @@ impl TryFrom for Node { Flag::Orange => Node::Search(SearchNode::Flag(2)), Flag::Green => Node::Search(SearchNode::Flag(3)), Flag::Blue => Node::Search(SearchNode::Flag(4)), - Flag::Violet => Node::Search(SearchNode::Flag(5)), + Flag::Pink => Node::Search(SearchNode::Flag(5)), Flag::Turquoise => Node::Search(SearchNode::Flag(6)), Flag::Purple => Node::Search(SearchNode::Flag(7)), }, diff --git a/rslib/src/browser_table.rs b/rslib/src/browser_table.rs index 5fc8a9b1f..634729db5 100644 --- a/rslib/src/browser_table.rs +++ b/rslib/src/browser_table.rs @@ -527,7 +527,7 @@ impl RowContext { 2 => Color::FlagOrange, 3 => Color::FlagGreen, 4 => Color::FlagBlue, - 5 => Color::FlagViolet, + 5 => Color::FlagPink, 6 => Color::FlagTurquoise, 7 => Color::FlagPurple, _ => { From daa696e703f0bbd2749e5a75c4c4f1e1888d3567 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 1 Jun 2021 18:14:54 +0200 Subject: [PATCH 3/3] Tweak flag colors --- qt/aqt/data/web/js/reviewer.ts | 14 +++++----- ts/sass/_vars.scss | 50 +++++++++++++++++----------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/qt/aqt/data/web/js/reviewer.ts b/qt/aqt/data/web/js/reviewer.ts index 650c710ff..c56b07638 100644 --- a/qt/aqt/data/web/js/reviewer.ts +++ b/qt/aqt/data/web/js/reviewer.ts @@ -146,13 +146,13 @@ function _showAnswer(a: string, bodyclass: string): void { } const _flagColours = { - 1: "#ff6666", - 2: "#ff9900", - 3: "#77ff77", - 4: "#77aaff", - 5: "#fc68e8", - 6: "#00d3b7", - 7: "#9e3bfa", + 1: "#e25252", + 2: "#ffb347", + 3: "#54c414", + 4: "#578cff", + 5: "#ff82ee", + 6: "#00d1b5", + 7: "#9649dd", }; function _drawFlag(flag: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7): void { diff --git a/ts/sass/_vars.scss b/ts/sass/_vars.scss index 45573e354..ec8b2d1bb 100644 --- a/ts/sass/_vars.scss +++ b/ts/sass/_vars.scss @@ -17,20 +17,20 @@ --highlight-bg: #77ccff; --highlight-fg: black; --disabled: #777; - --flag1-fg: #c35617; + --flag1-fg: #e25252; --flag2-fg: #ffb347; - --flag3-fg: #0a0; - --flag4-fg: #77ccff; - --flag5-fg: #fc68e8; - --flag6-fg: #00d3b7; - --flag7-fg: #9e3bfa; - --flag1-bg: #ffaaaa; + --flag3-fg: #54c414; + --flag4-fg: #578cff; + --flag5-fg: #ff82ee; + --flag6-fg: #00d1b5; + --flag7-fg: #9649dd; + --flag1-bg: #ff9b9b; --flag2-bg: #ffb347; - --flag3-bg: #82e0aa; - --flag4-bg: #85c1e9; - --flag5-bg: #ffafeb; - --flag6-bg: #4bd3cc; - --flag7-bg: #c07dff; + --flag3-bg: #93e066; + --flag4-bg: #9dbcff; + --flag5-bg: #f5a8eb; + --flag6-bg: #7edbd7; + --flag7-bg: #cca3f1; --buried-fg: #aaaa33; --suspended-fg: #dd0; --suspended-bg: #ffffb2; @@ -54,20 +54,20 @@ --highlight-bg: #77ccff; --highlight-fg: white; --disabled: #777; - --flag1-fg: #ffaaaa; - --flag2-fg: #ffb347; - --flag3-fg: #82e0aa; - --flag4-fg: #85c1e9; - --flag5-fg: #ffafeb; - --flag6-fg: #3fccc5; - --flag7-fg: #c07dff; + --flag1-fg: #ff7b7b; + --flag2-fg: #f5aa41; + --flag3-fg: #86ce5d; + --flag4-fg: #6f9dff; + --flag5-fg: #f097e4; + --flag6-fg: #5ccfca; + --flag7-fg: #9f63d3; --flag1-bg: #aa5555; - --flag2-bg: #aa6337; - --flag3-bg: #33a055; - --flag4-bg: #3581a9; - --flag5-bg: #be64b2; - --flag6-bg: #11a591; - --flag7-bg: #904fce; + --flag2-bg: #ac653a; + --flag3-bg: #559238; + --flag4-bg: #506aa3; + --flag5-bg: #975d8f; + --flag6-bg: #399185; + --flag7-bg: #624b77; --buried-fg: #777733; --suspended-fg: #ffffb2; --suspended-bg: #aaaa33;