From dc67ed99524366c9b41c54a22198d03289aec633 Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Wed, 12 Oct 2022 06:29:06 +0200 Subject: [PATCH 01/11] Add stylesheet for QMenu (#2122) * Give QMenu cursor: pointer * Darken border colors in dark theme * Refactor cursor: pointer event filter * Add QMenu stylesheet * Remove min-width for QMenu item * Add QMenuBar styles with increased height for touchscreen users and more visible highlight color. * Fix type * Revert "Add QMenuBar styles" This reverts commit 6ae405a073b15389b7926ef8aa91c3b228a7889e. * Remove strong border from QMenu checkbox style * Keep highlight color consistent * Adjust highlight-bg * Increase horizontal padding and adjust checkbox margin * Introduce border-faint var and make default border brighter in dark mode * Fix 1px move on hover and make highlight color more subtle * Remove win10 styles because the properties are set in the other stylesheets anyway. * Fix bottom border of QMenuBar not showing underneath entries * Remove unused import * Make border-faint one shade darker in light theme --- qt/aqt/__init__.py | 33 ++++------ qt/aqt/data/web/css/deckbrowser.scss | 2 +- qt/aqt/stylesheets.py | 92 ++++++++++++++++++---------- qt/aqt/theme.py | 9 +-- sass/_vars.scss | 22 ++++--- 5 files changed, 89 insertions(+), 69 deletions(-) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 767975982..378f058e3 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -345,26 +345,19 @@ class AnkiApp(QApplication): ################################################## def eventFilter(self, src: Any, evt: QEvent) -> bool: - if evt.type() == QEvent.Type.HoverEnter: - if ( - ( - isinstance( - src, - ( - QPushButton, - QCheckBox, - QRadioButton, - # classes with PyQt5 compatibility proxy - without_qt5_compat_wrapper(QToolButton), - without_qt5_compat_wrapper(QTabBar), - ), - ) - ) - and src.isEnabled() - or ( - isinstance(src, without_qt5_compat_wrapper(QComboBox)) - and not src.isEditable() - ) + pointer_classes = ( + QPushButton, + QCheckBox, + QRadioButton, + QMenu, + # classes with PyQt5 compatibility proxy + without_qt5_compat_wrapper(QToolButton), + without_qt5_compat_wrapper(QTabBar), + ) + if evt.type() in [QEvent.Type.Enter, QEvent.Type.HoverEnter]: + if (isinstance(src, pointer_classes) and src.isEnabled()) or ( + isinstance(src, without_qt5_compat_wrapper(QComboBox)) + and not src.isEditable() ): self.setOverrideCursor(QCursor(Qt.CursorShape.PointingHandCursor)) else: diff --git a/qt/aqt/data/web/css/deckbrowser.scss b/qt/aqt/data/web/css/deckbrowser.scss index 4d424eddf..764fda0cb 100644 --- a/qt/aqt/data/web/css/deckbrowser.scss +++ b/qt/aqt/data/web/css/deckbrowser.scss @@ -16,7 +16,7 @@ a.deck:hover { } tr.deck td { - border-bottom: 1px solid var(--border-subtle); + border-bottom: 1px solid var(--border-faint); } tr.top-level-drag-row td { diff --git a/qt/aqt/stylesheets.py b/qt/aqt/stylesheets.py index 98bebf6d3..b55fb3637 100644 --- a/qt/aqt/stylesheets.py +++ b/qt/aqt/stylesheets.py @@ -28,7 +28,8 @@ qlineargradient( def general_styles(tm: ThemeManager) -> str: return f""" -QFrame {{ +QFrame, +QWidget {{ background: none; }} QPushButton, @@ -38,7 +39,7 @@ QLineEdit, QListWidget, QTreeWidget, QListView {{ - border: 1px solid {tm.var(colors.BORDER)}; + border: 1px solid {tm.var(colors.BORDER_SUBTLE)}; border-radius: {tm.var(props.BORDER_RADIUS)}; }} QLineEdit {{ @@ -58,6 +59,47 @@ QSpinBox {{ """ +def menu_styles(tm: ThemeManager) -> str: + return f""" +QMenuBar {{ + border-bottom: 1px solid {tm.var(colors.BORDER_FAINT)}; +}} +QMenuBar::item {{ + background-color: transparent; + padding: 2px 4px; + border-radius: {tm.var(props.BORDER_RADIUS)}; +}} +QMenuBar::item:selected {{ + background-color: {tm.var(colors.CANVAS_ELEVATED)}; +}} +QMenu {{ + background-color: {tm.var(colors.CANVAS_OVERLAY)}; + border: 1px solid {tm.var(colors.BORDER_SUBTLE)}; + padding: 4px; +}} +QMenu::item {{ + background-color: transparent; + padding: 3px 14px; + margin-bottom: 4px; +}} +QMenu::item:selected {{ + background-color: {tm.var(colors.CANVAS_INSET)}; + color: {tm.var(colors.HIGHLIGHT_FG)}; + border-radius: {tm.var(props.BORDER_RADIUS)}; +}} +QMenu::separator {{ + height: 1px; + background: {tm.var(colors.BORDER_SUBTLE)}; + margin: 0 8px 4px 8px; +}} +QMenu::indicator {{ + border: 1px solid {tm.var(colors.BORDER)}; + margin-left: 6px; + margin-right: -6px; +}} + """ + + def button_styles(tm: ThemeManager) -> str: return f""" QPushButton {{ @@ -184,7 +226,7 @@ QTabWidget::pane {{ top: -15px; padding-top: 1em; background: {tm.var(colors.CANVAS_ELEVATED)}; - border: 1px solid {tm.var(colors.BORDER)}; + border: 1px solid {tm.var(colors.BORDER_SUBTLE)}; border-radius: {tm.var(props.BORDER_RADIUS)}; }} QTabWidget::tab-bar {{ @@ -196,7 +238,7 @@ QTabBar::tab {{ min-width: 8ex; }} QTabBar::tab {{ - border: 1px solid {tm.var(colors.BORDER)}; + border: 1px solid {tm.var(colors.BORDER_SUBTLE)}; }} QTabBar::tab:first {{ border-top-{tm.left()}-radius: {tm.var(props.BORDER_RADIUS)}; @@ -225,7 +267,7 @@ def table_styles(tm: ThemeManager) -> str: return f""" QTableView {{ border-radius: {tm.var(props.BORDER_RADIUS)}; - gridline-color: {tm.var(colors.BORDER)}; + gridline-color: {tm.var(colors.BORDER_SUBTLE)}; selection-background-color: {tm.var(colors.SELECTION_BG)}; selection-color: {tm.var(colors.SELECTION_FG)}; }} @@ -233,7 +275,7 @@ QHeaderView {{ background: {tm.var(colors.CANVAS)}; }} QHeaderView::section {{ - border: 1px solid {tm.var(colors.BORDER)}; + border: 1px solid {tm.var(colors.BORDER_SUBTLE)}; background: { button_gradient( tm.var(colors.BUTTON_GRADIENT_START), @@ -261,19 +303,19 @@ QHeaderView::section:hover {{ }; }} QHeaderView::section:first {{ - border-left: 1px solid {tm.var(colors.BORDER)}; + border-left: 1px solid {tm.var(colors.BORDER_SUBTLE)}; border-top-left-radius: {tm.var(props.BORDER_RADIUS)}; }} QHeaderView::section:!first {{ border-left: none; }} QHeaderView::section:last {{ - border-right: 1px solid {tm.var(colors.BORDER)}; + border-right: 1px solid {tm.var(colors.BORDER_SUBTLE)}; border-top-right-radius: {tm.var(props.BORDER_RADIUS)}; }} QHeaderView::section:only-one {{ - border-left: 1px solid {tm.var(colors.BORDER)}; - border-right: 1px solid {tm.var(colors.BORDER)}; + border-left: 1px solid {tm.var(colors.BORDER_SUBTLE)}; + border-right: 1px solid {tm.var(colors.BORDER_SUBTLE)}; border-top-left-radius: {tm.var(props.BORDER_RADIUS)}; border-top-right-radius: {tm.var(props.BORDER_RADIUS)}; }} @@ -374,16 +416,16 @@ QRadioButton {{ margin: 2px 0; }} QCheckBox::indicator, -QRadioButton::indicator {{ +QRadioButton::indicator, +QMenu::indicator {{ border: 1px solid {tm.var(colors.BUTTON_BORDER)}; + border-radius: {tm.var(props.BORDER_RADIUS)}; background: {tm.var(colors.CANVAS_INSET)}; width: 16px; height: 16px; }} -QCheckBox::indicator {{ - border-radius: {tm.var(props.BORDER_RADIUS)}; -}} -QRadioButton::indicator {{ +QRadioButton::indicator, +QMenu::indicator:exclusive {{ border-radius: 8px; }} QCheckBox::indicator:hover, @@ -395,7 +437,8 @@ QRadioButton::indicator:checked:hover {{ height: 14px; }} QCheckBox::indicator:checked, -QRadioButton::indicator:checked {{ +QRadioButton::indicator:checked, +QMenu::indicator:checked {{ image: url({tm.themed_icon("mdi:check")}); }} QCheckBox::indicator:indeterminate {{ @@ -445,20 +488,3 @@ QScrollBar::sub-line {{ background: none; }} """ - - -def win10_styles(tm: ThemeManager) -> str: - return f""" -/* day mode is missing a bottom border; background must be - also set for border to apply */ -QMenuBar {{ - border-bottom: 1px solid {tm.var(colors.BORDER)}; - background: {tm.var(colors.CANVAS) if tm.night_mode else "white"}; -}} - -/* qt bug? setting the above changes the browser sidebar - to white as well, so set it back */ -QTreeWidget {{ - background: {tm.var(colors.CANVAS)}; -}} - """ diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py index d1e03572b..3e935cdf8 100644 --- a/qt/aqt/theme.py +++ b/qt/aqt/theme.py @@ -5,7 +5,6 @@ from __future__ import annotations import enum import os -import platform import re import subprocess from dataclasses import dataclass @@ -229,29 +228,27 @@ class ThemeManager: checkbox_styles, combobox_styles, general_styles, + menu_styles, scrollbar_styles, spinbox_styles, table_styles, tabwidget_styles, - win10_styles, ) buf += "".join( [ general_styles(self), button_styles(self), + checkbox_styles(self), + menu_styles(self), combobox_styles(self), tabwidget_styles(self), table_styles(self), spinbox_styles(self), - checkbox_styles(self), scrollbar_styles(self), ] ) - if is_win and platform.release() == "10": - buf += win10_styles(self) - # allow addons to modify the styling buf = gui_hooks.style_did_init(buf) diff --git a/sass/_vars.scss b/sass/_vars.scss index 5e4c8f2a1..5a773d1a1 100644 --- a/sass/_vars.scss +++ b/sass/_vars.scss @@ -56,8 +56,8 @@ $vars: ( dark: palette(darkgray, 6), ), overlay: ( - light: white, - dark: black, + light: palette(lightgray, 0), + dark: palette(darkgray, 5), ), code: ( light: white, @@ -67,16 +67,20 @@ $vars: ( border: ( default: ( light: palette(lightgray, 6), - dark: palette(darkgray, 7), - ), - subtle: ( - light: palette(lightgray, 5), - dark: palette(darkgray, 6), + dark: palette(darkgray, 4), ), strong: ( light: palette(lightgray, 9), dark: palette(darkgray, 1), ), + subtle: ( + light: palette(lightgray, 5), + dark: palette(darkgray, 7), + ), + faint: ( + light: palette(lightgray, 4), + dark: palette(darkgray, 6), + ), focus: ( light: palette(blue, 5), dark: palette(blue, 5), @@ -269,8 +273,8 @@ $vars: ( ), highlight: ( bg: ( - light: palette(blue, 3), - dark: palette(blue, 4), + light: color.scale(palette(blue, 3), $alpha: -33%), + dark: color.scale(palette(blue, 4), $alpha: -33%), ), fg: ( light: black, From 5c240e8561f34474fe43b56ccc0a010504cc4135 Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Wed, 12 Oct 2022 06:31:54 +0200 Subject: [PATCH 02/11] Fix SpinBox initially neglecting passed value (#2125) --- ts/components/SpinBox.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ts/components/SpinBox.svelte b/ts/components/SpinBox.svelte index 52c483096..076d874a2 100644 --- a/ts/components/SpinBox.svelte +++ b/ts/components/SpinBox.svelte @@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import IconConstrain from "./IconConstrain.svelte"; import { chevronLeft, chevronRight } from "./icons"; - export let value = 1; + export let value: number; export let step = 1; export let min = 1; export let max = 9999; @@ -22,7 +22,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } let stringValue: string; - $: stringValue = value.toFixed(decimalPlaces(step)); + $: if (value) stringValue = value.toFixed(decimalPlaces(step)); function update(this: HTMLInputElement): void { value = Math.min(max, Math.max(min, parseFloat(this.value))); From d7deb5fafccb764c6492eca48472d237382e1e3a Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Wed, 12 Oct 2022 06:34:25 +0200 Subject: [PATCH 03/11] Move MathJax toggle to OptionsButton and fix two bugs (#2126) * Rename MathJax toggle and move it to OptionsButton * Apply MathJax setting to newly added blocks * Actually remove MathJax element on delete --- ftl/core/editing.ftl | 2 +- ts/editor/editor-toolbar/LatexButton.svelte | 28 ++++++++++--------- ts/editor/editor-toolbar/OptionsButton.svelte | 10 +++++++ .../mathjax-overlay/MathjaxOverlay.svelte | 14 ++++++---- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/ftl/core/editing.ftl b/ftl/core/editing.ftl index 75b915f11..b91dcb390 100644 --- a/ftl/core/editing.ftl +++ b/ftl/core/editing.ftl @@ -60,7 +60,7 @@ editing-collapse-field = Collapse field editing-underline-text = Underline text editing-unordered-list = Unordered list editing-warning-cloze-deletions-will-not-work = Warning, cloze deletions will not work until you switch the type at the top to Cloze. -editing-toggle-mathjax-rendering = Toggle MathJax Rendering +editing-mathjax-preview = MathJax Preview editing-shrink-images = Shrink Images editing-close-html-tags = Auto-close HTML tags diff --git a/ts/editor/editor-toolbar/LatexButton.svelte b/ts/editor/editor-toolbar/LatexButton.svelte index ba5a6b81d..adfbb5610 100644 --- a/ts/editor/editor-toolbar/LatexButton.svelte +++ b/ts/editor/editor-toolbar/LatexButton.svelte @@ -9,7 +9,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import Shortcut from "../../components/Shortcut.svelte"; import WithFloating from "../../components/WithFloating.svelte"; import { mathjaxConfig } from "../../editable/mathjax-element"; - import { bridgeCommand } from "../../lib/bridgecommand"; import * as tr from "../../lib/ftl"; import { getPlatformString } from "../../lib/shortcuts"; import { wrapInternal } from "../../lib/wrap"; @@ -27,15 +26,27 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } function onMathjaxInline(): void { - surround("", ""); + if (mathjaxConfig.enabled) { + surround("", ""); + } else { + surround("\\(", "\\)"); + } } function onMathjaxBlock(): void { - surround('', ""); + if (mathjaxConfig.enabled) { + surround('', ""); + } else { + surround("\\[", "\\]"); + } } function onMathjaxChemistry(): void { - surround('\\ce{', "}"); + if (mathjaxConfig.enabled) { + surround('\\ce{', "}"); + } else { + surround("\\(\\ce{", "}\\)"); + } } function onLatex(): void { @@ -50,11 +61,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html surround("[$$]", "[/$$]"); } - function toggleShowMathjax(): void { - mathjaxConfig.enabled = !mathjaxConfig.enabled; - bridgeCommand("toggleMathjax"); - } - type LatexItem = [() => void, string, string]; const dropdownItems: LatexItem[] = [ @@ -94,10 +100,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html > {/each} - - - {tr.editingToggleMathjaxRendering()} - diff --git a/ts/editor/editor-toolbar/OptionsButton.svelte b/ts/editor/editor-toolbar/OptionsButton.svelte index a871b3a95..4386aae92 100644 --- a/ts/editor/editor-toolbar/OptionsButton.svelte +++ b/ts/editor/editor-toolbar/OptionsButton.svelte @@ -8,6 +8,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import IconButton from "../../components/IconButton.svelte"; import Popover from "../../components/Popover.svelte"; import WithFloating from "../../components/WithFloating.svelte"; + import { mathjaxConfig } from "../../editable/mathjax-element"; import { bridgeCommand } from "../../lib/bridgecommand"; import * as tr from "../../lib/ftl"; import { shrinkImagesByDefault } from "../image-overlay/ImageOverlay.svelte"; @@ -22,6 +23,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html showFloating = false; } + function toggleShowMathjax(_evt: MouseEvent): void { + mathjaxConfig.enabled = !mathjaxConfig.enabled; + bridgeCommand("toggleMathjax"); + } + function toggleCloseHTMLTags(_evt: MouseEvent): void { $closeHTMLTags = !$closeHTMLTags; bridgeCommand("toggleCloseHTMLTags"); @@ -50,6 +56,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {tr.editingShrinkImages()} + + + {tr.editingMathjaxPreview()} + {tr.editingCloseHtmlTags()} diff --git a/ts/editor/mathjax-overlay/MathjaxOverlay.svelte b/ts/editor/mathjax-overlay/MathjaxOverlay.svelte index 967fc8883..677bc9095 100644 --- a/ts/editor/mathjax-overlay/MathjaxOverlay.svelte +++ b/ts/editor/mathjax-overlay/MathjaxOverlay.svelte @@ -65,14 +65,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } } + function clear(): void { + unsubscribe(); + activeImage = null; + mathjaxElement = null; + } + async function resetHandle(): Promise { selectAll = false; position = undefined; if (activeImage && mathjaxElement) { - unsubscribe(); - activeImage = null; - mathjaxElement = null; + clear(); } allow(); @@ -220,8 +224,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html }} on:delete={async () => { placeCaretAfter(activeImage); - activeImage.remove(); - await resetHandle(); + mathjaxElement?.remove(); + clear(); }} on:surround={async ({ detail }) => { const editor = await mathjaxEditor.editor; From 29b2a2b35c641e09f49b9424f745ceedd3a564d9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 12 Oct 2022 14:48:26 +1000 Subject: [PATCH 04/11] Update translations --- repos.bzl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/repos.bzl b/repos.bzl index b9250d337..3a51186c8 100644 --- a/repos.bzl +++ b/repos.bzl @@ -115,12 +115,12 @@ def register_repos(): ################ core_i18n_repo = "anki-core-i18n" - core_i18n_commit = "71bfeda9ef7667f3454e7341969835168768bd54" - core_i18n_zip_csum = "4b4203d862aa1d90c0c391fac00bdf8ba0a8bffe00e4ba5fd36b2c7b288613c9" + core_i18n_commit = "b9d5c896f22fe6e79810194f41222d8638c13e16" + core_i18n_zip_csum = "8ef7888373cacf682c17f41056dc1f5348f60a15e1809c8db0f66f4072e7d5fb" qtftl_i18n_repo = "anki-desktop-ftl" - qtftl_i18n_commit = "aa0e656fa4b0b9c926fc7436cb62418d8995e666" - qtftl_i18n_zip_csum = "5949b0e19b92f8699e9f1a3ca17abf9249103232aa408b4bb21bb6c5d1ff28bc" + qtftl_i18n_commit = "a8bd0e284e2785421180af2ce10dd1d534b0033d" + qtftl_i18n_zip_csum = "f88398324a64be99521bd5cd7e79e7dda64c31a2cd4e568328a211c7765b23ac" i18n_build_content = """ filegroup( From e14f87ba99a0bd81a45701dda0b05ae437fe2478 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 12 Oct 2022 14:56:38 +1000 Subject: [PATCH 05/11] Switch back to clearing MathJax preview on blur This means two clicks are required again, but that's the lesser of two evils: https://forums.ankiweb.net/t/anki-2-1-55-beta-mathjax-preview/23529/8 Better fixes welcome :-) --- ts/editor/mathjax-overlay/MathjaxEditor.svelte | 2 +- ts/editor/mathjax-overlay/MathjaxOverlay.svelte | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ts/editor/mathjax-overlay/MathjaxEditor.svelte b/ts/editor/mathjax-overlay/MathjaxEditor.svelte index 142985405..ec90c0c65 100644 --- a/ts/editor/mathjax-overlay/MathjaxEditor.svelte +++ b/ts/editor/mathjax-overlay/MathjaxEditor.svelte @@ -99,7 +99,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {configuration} bind:api={codeMirror} on:change={({ detail: mathjaxText }) => code.set(mathjaxText)} - on:tab + on:blur /> diff --git a/ts/editor/mathjax-overlay/MathjaxOverlay.svelte b/ts/editor/mathjax-overlay/MathjaxOverlay.svelte index 677bc9095..281b6752d 100644 --- a/ts/editor/mathjax-overlay/MathjaxOverlay.svelte +++ b/ts/editor/mathjax-overlay/MathjaxOverlay.svelte @@ -192,10 +192,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html placeHandle(true); await resetHandle(); }} - on:tab={async () => { - // Instead of resetting on blur, we reset on tab - // Otherwise, when clicking from Mathjax element to another, - // the user has to click twice (focus is called before blur?) + on:blur={async () => { await resetHandle(); }} let:editor={mathjaxEditor} From 0a3d38125da56790e46f5909fbfa515dcc9e385f Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Thu, 13 Oct 2022 02:08:30 +0200 Subject: [PATCH 06/11] Add background to tag editor and improve autocomplete items (#2130) --- ts/tag-editor/AutocompleteItem.svelte | 16 +++++++++++----- ts/tag-editor/TagEditor.svelte | 3 +++ ts/tag-editor/WithAutocomplete.svelte | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ts/tag-editor/AutocompleteItem.svelte b/ts/tag-editor/AutocompleteItem.svelte index 3e9bf5982..cfec171a3 100644 --- a/ts/tag-editor/AutocompleteItem.svelte +++ b/ts/tag-editor/AutocompleteItem.svelte @@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let selected = false; export let active = false; - let buttonRef: HTMLButtonElement; + let buttonRef: HTMLElement; $: if (selected && buttonRef) { /* buttonRef.scrollIntoView({ behavior: "smooth", block: "start" }); */ @@ -18,7 +18,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } - + diff --git a/ts/components/Pane.svelte b/ts/components/Pane.svelte index c291947ee..54d111cb0 100644 --- a/ts/components/Pane.svelte +++ b/ts/components/Pane.svelte @@ -59,5 +59,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html .pane { @include panes.resizable(column, true, true); + opacity: var(--opacity, 1); } diff --git a/ts/editor/NoteEditor.svelte b/ts/editor/NoteEditor.svelte index fe5f6f2e3..40ee1fdee 100644 --- a/ts/editor/NoteEditor.svelte +++ b/ts/editor/NoteEditor.svelte @@ -355,12 +355,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html $: tagAmount = $tags.length; + let snapTags = $tagsCollapsed; + function collapseTags(): void { lowerResizer.move([tagsPane, fieldsPane], tagsPane.minHeight); + $tagsCollapsed = snapTags = true; } function expandTags(): void { lowerResizer.move([tagsPane, fieldsPane], tagsPane.maxHeight); + $tagsCollapsed = snapTags = false; + } + + window.addEventListener("resize", () => snapResizer(snapTags)); + + function snapResizer(collapse: boolean): void { + if (collapse) { + collapseTags(); + bridgeCommand("collapseTags"); + } else { + expandTags(); + bridgeCommand("expandTags"); + } } @@ -390,7 +406,9 @@ the AddCards dialog) should be implemented in the user of this component. (fieldsPane.height = e.detail.height)} + on:resize={(e) => { + fieldsPane.height = e.detail.height; + }} > @@ -553,7 +571,17 @@ the AddCards dialog) should be implemented in the user of this component. - {#if $tagsCollapsed} + snapResizer(!$tagsCollapsed)} + on:release={() => { + snapResizer(snapTags); + }} + >
{ @@ -564,36 +592,28 @@ the AddCards dialog) should be implemented in the user of this component. {@html tagAmount > 0 ? `${tagAmount} Tags` : ""}
- {/if} - - { - if ($tagsCollapsed) { - expandTags(); - bridgeCommand("expandTags"); - $tagsCollapsed = false; - } else { - collapseTags(); - bridgeCommand("collapseTags"); - $tagsCollapsed = true; - } - }} - /> + { tagsPane.height = e.detail.height; - $tagsCollapsed = tagsPane.height == 0; + if (tagsPane.maxHeight > 0) { + snapTags = tagsPane.height < tagsPane.maxHeight / 2; + } }} + --opacity={(() => { + if (!$tagsCollapsed) { + return 1; + } else { + return snapTags ? tagsPane.height / tagsPane.maxHeight : 1; + } + })()} > { @@ -617,7 +637,4 @@ the AddCards dialog) should be implemented in the user of this component. flex-direction: column; height: 100%; } - .tags-expander { - margin-top: 0.5rem; - } diff --git a/ts/tag-editor/tag-options-button/TagOptionsButton.svelte b/ts/tag-editor/tag-options-button/TagOptionsButton.svelte index b6f39040b..69ad34ee6 100644 --- a/ts/tag-editor/tag-options-button/TagOptionsButton.svelte +++ b/ts/tag-editor/tag-options-button/TagOptionsButton.svelte @@ -25,6 +25,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html From e0e45c55b51982796ae0947c8af90f0d0b4786e7 Mon Sep 17 00:00:00 2001 From: Hikaru Y Date: Fri, 14 Oct 2022 09:19:20 +0900 Subject: [PATCH 08/11] Fix maximized browser window not being restored (#2132) --- qt/aqt/browser/browser.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index 22a354747..1afe0ae67 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -126,19 +126,22 @@ class Browser(QMainWindow): self._closeEventHasCleanedUp = False self.form = aqt.forms.browser.Ui_Dialog() self.form.setupUi(self) - restoreGeom(self, "editor", 0) - restoreSplitter(self.form.splitter, "editor3") self.form.splitter.setChildrenCollapsible(False) # set if exactly 1 row is selected; used by the previewer self.card: Card | None = None self.current_card: Card | None = None self.setupSidebar() - # make sure to call restoreState() after QDockWidget is attached to QMainWindow - restoreState(self, "editor") self.setup_table() self.setupMenus() self.setupHooks() self.setupEditor() + + # restoreXXX() should be called after all child widgets have been created + # and attached to QMainWindow + restoreGeom(self, "editor", 0) + restoreSplitter(self.form.splitter, "editor3") + restoreState(self, "editor") + # responsive layout self.aspect_ratio = self.width() / self.height() self.set_layout(self.mw.pm.browser_layout(), True) From c22f6022fc59182d89079e4772c9083714969778 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 15 Oct 2022 10:58:43 +1000 Subject: [PATCH 09/11] Add Christos to about --- qt/aqt/about.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qt/aqt/about.py b/qt/aqt/about.py index 9197d7caa..643317304 100644 --- a/qt/aqt/about.py +++ b/qt/aqt/about.py @@ -226,6 +226,7 @@ def show(mw: aqt.AnkiQt) -> QDialog: "Nicholas Flint", "Daniel Vieira Memoria10X", "Luka Warren", + "Christos Longros", ) ) From fb9c934ef2009572526f9e25d8497af5125aae16 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 17 Oct 2022 09:57:36 +1000 Subject: [PATCH 10/11] Use protoc from Bazel if missing from path Closes #2134 --- Cargo.lock | 1 + cargo/BUILD.bazel | 9 +++++++++ pylib/rsbridge/cargo/BUILD.bazel | 9 +++++++++ rslib/BUILD.bazel | 1 + rslib/Cargo.toml | 1 + rslib/build/protobuf.rs | 28 +++++++++++++++++++++++++++- rslib/cargo/BUILD.bazel | 9 +++++++++ rslib/i18n/cargo/BUILD.bazel | 9 +++++++++ rslib/i18n_helpers/cargo/BUILD.bazel | 9 +++++++++ rslib/linkchecker/cargo/BUILD.bazel | 9 +++++++++ 10 files changed, 84 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 068f85711..da19d3704 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,6 +118,7 @@ dependencies = [ "unicase", "unicode-normalization", "utime", + "which", "zip", "zstd", ] diff --git a/cargo/BUILD.bazel b/cargo/BUILD.bazel index 2b529535e..42a561ba5 100644 --- a/cargo/BUILD.bazel +++ b/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/pylib/rsbridge/cargo/BUILD.bazel b/pylib/rsbridge/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/pylib/rsbridge/cargo/BUILD.bazel +++ b/pylib/rsbridge/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/BUILD.bazel b/rslib/BUILD.bazel index 2c027a0b8..7dfb7abfb 100644 --- a/rslib/BUILD.bazel +++ b/rslib/BUILD.bazel @@ -31,6 +31,7 @@ cargo_build_script( ], deps = [ "//rslib/cargo:prost_build", + "//rslib/cargo:which", ], ) diff --git a/rslib/Cargo.toml b/rslib/Cargo.toml index 3bc06a78c..efc87b693 100644 --- a/rslib/Cargo.toml +++ b/rslib/Cargo.toml @@ -23,6 +23,7 @@ required-features = ["bench"] [build-dependencies] prost-build = "0.11.1" +which = "4.3.0" [dev-dependencies] env_logger = "0.9.1" diff --git a/rslib/build/protobuf.rs b/rslib/build/protobuf.rs index 4535be3e1..a51dfd097 100644 --- a/rslib/build/protobuf.rs +++ b/rslib/build/protobuf.rs @@ -1,7 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use std::{env, fmt::Write, path::PathBuf}; +use std::{ + env, + fmt::Write, + path::{Path, PathBuf}, +}; struct CustomGenerator {} @@ -71,6 +75,7 @@ fn service_generator() -> Box { } pub fn write_backend_proto_rs() { + maybe_add_protobuf_to_path(); let proto_dir = if let Ok(proto) = env::var("PROTO_TOP") { PathBuf::from(proto).parent().unwrap().to_owned() } else { @@ -122,3 +127,24 @@ pub fn write_backend_proto_rs() { .compile_protos(paths.as_slice(), &[proto_dir]) .unwrap(); } + +/// If PROTOC is not defined, and protoc is not on path, use the protoc +/// fetched by Bazel so that Rust Analyzer does not fail. +fn maybe_add_protobuf_to_path() { + if std::env::var("PROTOC").is_ok() { + return; + } + if which::which("protoc").is_ok() { + return; + } + let base = Path::new("../.bazel/out/../external"); + let subpath = if cfg!(target_os = "windows") { + "protoc_bin_windows/bin/protoc.exe" + } else if cfg!(target_os = "macos") { + "protoc_bin_macos/bin/protoc" + } else { + "protoc_bin_linux_x86_64/bin/protoc" + }; + let path = base.join(subpath); + std::env::set_var("PROTOC", path.to_str().unwrap()); +} diff --git a/rslib/cargo/BUILD.bazel b/rslib/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/cargo/BUILD.bazel +++ b/rslib/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/i18n/cargo/BUILD.bazel b/rslib/i18n/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/i18n/cargo/BUILD.bazel +++ b/rslib/i18n/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/i18n_helpers/cargo/BUILD.bazel b/rslib/i18n_helpers/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/i18n_helpers/cargo/BUILD.bazel +++ b/rslib/i18n_helpers/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/linkchecker/cargo/BUILD.bazel b/rslib/linkchecker/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/linkchecker/cargo/BUILD.bazel +++ b/rslib/linkchecker/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", From b8c294bf4d1e3f0ac1de3abeb7cf4b54c02011a2 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Wed, 19 Oct 2022 12:08:58 +0200 Subject: [PATCH 11/11] Explicitly evaluate symlink on Windows (#2135) --- rslib/build/protobuf.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/rslib/build/protobuf.rs b/rslib/build/protobuf.rs index a51dfd097..c8f85b131 100644 --- a/rslib/build/protobuf.rs +++ b/rslib/build/protobuf.rs @@ -137,14 +137,17 @@ fn maybe_add_protobuf_to_path() { if which::which("protoc").is_ok() { return; } - let base = Path::new("../.bazel/out/../external"); - let subpath = if cfg!(target_os = "windows") { - "protoc_bin_windows/bin/protoc.exe" - } else if cfg!(target_os = "macos") { - "protoc_bin_macos/bin/protoc" + let path = if cfg!(target_os = "windows") { + let base = std::fs::read_link("../.bazel/out").unwrap(); + base.join("../external/protoc_bin_windows/bin/protoc.exe") } else { - "protoc_bin_linux_x86_64/bin/protoc" + let base = Path::new("../.bazel/out/../external"); + let subpath = if cfg!(target_os = "macos") { + "protoc_bin_macos/bin/protoc" + } else { + "protoc_bin_linux_x86_64/bin/protoc" + }; + base.join(subpath) }; - let path = base.join(subpath); std::env::set_var("PROTOC", path.to_str().unwrap()); }