Commit Graph

3139 Commits

Author SHA1 Message Date
Damien Elmes
2ccc8ca436 Fix sync spinner not showing
Regressed in #2137

Closes #2270
2022-12-15 19:10:05 +10:00
Damien Elmes
1ed2cce648 Use 6 digit hex codes for default colors
The color selector prints a warning otherwise.
2022-12-13 11:35:21 +10:00
Damien Elmes
c5da911f24 Another attempt at fixing reversed toolbar on first startup
May close https://github.com/ankitects/anki/issues/2269
2022-12-13 10:51:13 +10:00
Damien Elmes
449338d7ec Revert "Avoid setting RTL on first run"
This reverts commit 5dc79e22cd.

I appear to have been confused in my earlier testing, as reverting
this change seems to make no difference the top bar on first startup,
and fixes a bunch of other regressions that the original change introduced.

https://github.com/ankitects/anki/issues/2269
2022-12-13 10:45:36 +10:00
Matthias Metelka
ec4c1b1a20
Do not append description button for filtered deck (#2266) 2022-12-11 15:03:11 +10:00
Damien Elmes
01f6d618bc Increase initial add-on dialog size
I can't reproduce the reported issue, but this will probably help.

https://forums.ankiweb.net/t/anki-2-1-55-beta-7/25130/10
2022-12-09 12:36:28 +10:00
Matthias Metelka
6481899454
Fix some more RTL issues (#2244)
* Swap flag and mark indicator position in RTL mode

* Make buttons of bottom toolbar align to edge of screen in RTL mode

* Use start instead of left and end instead of right
2022-12-08 22:29:56 +10:00
Damien Elmes
1215ee7849 Deck options: hide webview after showing dialog
This seems to reduce flicker, presumably because the webview doesn't pick
up the correct geometry until the dialog is shown.
2022-12-08 22:18:28 +10:00
Damien Elmes
93d14de95c Set night-mode class on web page initialization
Ensures the background is the correct color by the time the webview
is shown. We keep the #night check for now, as it's useful when testing
in an external browser.
2022-12-08 22:02:12 +10:00
Damien Elmes
1870253589 Add default_size argument to restoreGeom(); fix missing dialogs
The starting size of a webview seems to be 640x480, but if it is hidden
without retainSizeWhenHidden being set, the dialog it contains can end
up with a height of 0, which prevents the dialog from being shown.

By being explicit about our desired starting size, we can use a more
useful default, and avoid the issue of missing dialogs.
2022-12-08 22:02:12 +10:00
Yoshi
ef3cfc561c
Facilitate hook updating/replacement (#2213)
* Facilitate updating of hooks

- Add instructions in contributing.md
- Change addon_config_editor_will_update_json hook to work with the new
  hookslib code

* Fix typo in docs

* Always run replaced hook

* Use lowercase list for typing

* Forbid defining both a replaced and a legacy hook
2022-12-07 15:39:57 +10:00
Matthias Metelka
d2fa50dd9f
Persist field states with SessionOptions object (#2241)
* Persist collapsed- and field states with SessionOptions object

* Format types.ts

* Replace format function with f-string

* Give setters more descriptive parameter names

* Do not use default prefix for descriptions and fonts

since they are not meant to be changed via Svelte.
2022-12-07 15:37:46 +10:00
Damien Elmes
9dc6e41153 Switch back to winrt to see if it fixes slow TTS
https://forums.ankiweb.net/t/slow-tts-and-duplicated-voices/25157/7

winrt blocks an upgrade from Python 3.9, so this will be a temporary
solution at best.
2022-12-06 20:30:54 +10:00
Abdo
f0c3256e39
Fix Esc not closing TS pages (#2240) 2022-12-06 20:03:34 +10:00
Abdo
6ef460e74a
Close MathJax editor when Esc is pressed (#2237) 2022-12-05 15:08:38 +10:00
Damien Elmes
6095b01301 Avoid hiding webview when refreshing
When opening the graphs screen in dark mode, we want to load the
page first and then reveal the webview, to prevent a flash of white
that can appear as the page loads. Previously we did this for any
call to load_ts_page(), but this results in flicker when refreshing
an existing webview, such as the move from deck list to congrats screen.
In those cases, at least on the machines I have to test with here, the
refresh is smoother without the hide and show step.

The new window case is still not ideal - while the hide+show prevents a
flash of white, there is a flash of black instead, presumably as the
webview draws the initially-blank framebuffer with the contents of the
webview.
2022-12-04 21:17:57 +10:00
Matthias Metelka
627313666e
Add profile manager setting to force custom qt stylesheets (#2233) 2022-12-04 12:54:39 +10:00
Matthias Metelka
fdaa65e064
Make button color and hover gradient fit together (#2232)
* Fix QMenu item not having different color on hover

due to the color changes in #2220.

* Remove strong border on pressed Qt widgets

* Make button gradient more subtle

by changing gradient-start on hover instead of gradient-end.

* Apply QPushButton style to QSpinBox buttons

* Improve margin of QComboBox arrow

* Make button-bg same color as button-gradient-end

This makes the hover gradient more subtle.
2022-12-04 11:48:09 +10:00
Matthias Metelka
430f5613d6
Decrease block padding for deck browser rows (#2231) 2022-12-04 11:45:59 +10:00
Damien Elmes
f2ca87b1d8 Ensure certifi refresh repeats 2022-12-03 23:31:08 +10:00
Damien Elmes
d98912ca6b Revert "Probable workaround for mpv failing after a few days on macOS"
This reverts commit fa4fc3e15a.

Issue turned out to be a packaging problem, and this should not be
required as the socket should be held open even if removed.
2022-12-03 23:30:19 +10:00
Damien Elmes
2068c2424d Fix mpv being placed in incorrect bundle location on macOS 2022-12-03 23:29:26 +10:00
Damien Elmes
c253445c4a Revert "Reset zoom on page transition"
This reverts commit ee70006ec4.

There have been a number of people complaining that the current
behaviour is not intuitive, and they have a point - it's not the
way browsers behave when you navigate between pages.
2022-12-03 23:14:45 +10:00
Damien Elmes
41b329aa05 Fix alternate table row color on macOS
https://forums.ankiweb.net/t/anki-2-1-55-beta-3/24295/102
2022-12-03 22:21:22 +10:00
Damien Elmes
fa4fc3e15a Probable workaround for mpv failing after a few days on macOS
Also fix the certifi bumper: it was supposed to repeat
2022-12-03 22:11:39 +10:00
Damien Elmes
509e0a9811 Try to address crashes on shutdown
I was able to reproduce the crashes fairly reliably by opening the
prefs screen on startup and shutting down the app after 600ms; after
this change the crashes no longer seem to occur.
2022-12-03 19:33:51 +10:00
Damien Elmes
5dc79e22cd Avoid setting RTL on first run
I'm not sure why, but this seems to address the first issue mentioned on
https://forums.ankiweb.net/t/anki-2-1-55-beta-5/24870/58
2022-11-30 19:19:22 +10:00
Damien Elmes
e3167c4e3c Update incompatible crates 2022-11-30 12:38:10 +10:00
Damien Elmes
b4f4df0030 Pin chrono; update compatible Rust crates
Also pin reqwest in our other crates
2022-11-30 12:38:10 +10:00
Damien Elmes
0ac7969e2a Use workspace package info in more crates; mark private for cargo-deny 2022-11-30 12:19:56 +10:00
Damien Elmes
50992972d8 Remove unused cargo config in qt/bundle 2022-11-30 11:37:20 +10:00
Matthias Metelka
43ce4cacc6
Give containers brighter color than canvas (#2220)
* Give deck browser table an elevated container look

* Tweak colors of elevated containers (e.g. in deck options)

* Prepare editor fields for custom backgrounds

* Tweak field margin and add explanatory comment
2022-11-29 17:54:42 +10:00
Damien Elmes
65b8b8c69b Fix typechecking error on Windows 2022-11-29 13:28:57 +10:00
Damien Elmes
a70f8d4dd5 Fix TTS handling on Windows
Also update to winsdk, which unblocks Python updates on Windows
2022-11-29 13:04:51 +10:00
BlueGreenMagick
dd2549564a
use BUTTON_BG for button background (#2217) 2022-11-28 20:53:07 +10:00
Damien Elmes
b2049209ff Re-enable formatting for .ts files
There are some style differences compared to prettier, and not all are
necessarily an improvement, but it's much faster now.
2022-11-28 09:33:04 +10:00
Damien Elmes
e497a56f54 Re-enable formatting for .toml files 2022-11-28 09:16:28 +10:00
Damien Elmes
5e0a761b87
Move away from Bazel (#2202)
(for upgrading users, please see the notes at the bottom)

Bazel brought a lot of nice things to the table, such as rebuilds based on
content changes instead of modification times, caching of build products,
detection of incorrect build rules via a sandbox, and so on. Rewriting the build
in Bazel was also an opportunity to improve on the Makefile-based build we had
prior, which was pretty poor: most dependencies were external or not pinned, and
the build graph was poorly defined and mostly serialized. It was not uncommon
for fresh checkouts to fail due to floating dependencies, or for things to break
when trying to switch to an older commit.

For day-to-day development, I think Bazel served us reasonably well - we could
generally switch between branches while being confident that builds would be
correct and reasonably fast, and not require full rebuilds (except on Windows,
where the lack of a sandbox and the TS rules would cause build breakages when TS
files were renamed/removed).

Bazel achieves that reliability by defining rules for each programming language
that define how source files should be turned into outputs. For the rules to
work with Bazel's sandboxing approach, they often have to reimplement or
partially bypass the standard tools that each programming language provides. The
Rust rules call Rust's compiler directly for example, instead of using Cargo,
and the Python rules extract each PyPi package into a separate folder that gets
added to sys.path.

These separate language rules allow proper declaration of inputs and outputs,
and offer some advantages such as caching of build products and fine-grained
dependency installation. But they also bring some downsides:

- The rules don't always support use-cases/platforms that the standard language
tools do, meaning they need to be patched to be used. I've had to contribute a
number of patches to the Rust, Python and JS rules to unblock various issues.
- The dependencies we use with each language sometimes make assumptions that do
not hold in Bazel, meaning they either need to be pinned or patched, or the
language rules need to be adjusted to accommodate them.

I was hopeful that after the initial setup work, things would be relatively
smooth-sailing. Unfortunately, that has not proved to be the case. Things
frequently broke when dependencies or the language rules were updated, and I
began to get frustrated at the amount of Anki development time I was instead
spending on build system upkeep. It's now about 2 years since switching to
Bazel, and I think it's time to cut losses, and switch to something else that's
a better fit.

The new build system is based on a small build tool called Ninja, and some
custom Rust code in build/. This means that to build Anki, Bazel is no longer
required, but Ninja and Rust need to be installed on your system. Python and
Node toolchains are automatically downloaded like in Bazel.

This new build system should result in faster builds in some cases:

- Because we're using cargo to build now, Rust builds are able to take advantage
of pipelining and incremental debug builds, which we didn't have with Bazel.
It's also easier to override the default linker on Linux/macOS, which can
further improve speeds.
- External Rust crates are now built with opt=1, which improves performance
of debug builds.
- Esbuild is now used to transpile TypeScript, instead of invoking the TypeScript
compiler. This results in faster builds, by deferring typechecking to test/check
time, and by allowing more work to happen in parallel.

As an example of the differences, when testing with the mold linker on Linux,
adding a new message to tags.proto (which triggers a recompile of the bulk of
the Rust and TypeScript code) results in a compile that goes from about 22s on
Bazel to about 7s in the new system. With the standard linker, it's about 9s.

Some other changes of note:

- Our Rust workspace now uses cargo-hakari to ensure all packages agree on
available features, preventing unnecessary rebuilds.
- pylib/anki is now a PEP420 implicit namespace, avoiding the need to merge
source files and generated files into a single folder for running. By telling
VSCode about the extra search path, code completion now works with generated
files without needing to symlink them into the source folder.
- qt/aqt can't use PEP420 as it's difficult to get rid of aqt/__init__.py.
Instead, the generated files are now placed in a separate _aqt package that's
added to the path.
- ts/lib is now exposed as @tslib, so the source code and generated code can be
provided under the same namespace without a merging step.
- MyPy and PyLint are now invoked once for the entire codebase.
- dprint will be used to format TypeScript/json files in the future instead of
the slower prettier (currently turned off to avoid causing conflicts). It can
automatically defer to prettier when formatting Svelte files.
- svelte-check is now used for typechecking our Svelte code, which revealed a
few typing issues that went undetected with the old system.
- The Jest unit tests now work on Windows as well.

If you're upgrading from Bazel, updated usage instructions are in docs/development.md and docs/build.md. A summary of the changes:

- please remove node_modules and .bazel
- install rustup (https://rustup.rs/)
- install rsync if not already installed  (on windows, use pacman - see docs/windows.md)
- install Ninja (unzip from https://github.com/ninja-build/ninja/releases/tag/v1.11.1 and
  place on your path, or from your distro/homebrew if it's 1.10+)
- update .vscode/settings.json from .vscode.dist
2022-11-27 15:24:20 +10:00
Matthias Metelka
0d541563a0
Add platform-specific classes to body of ts pages (#2211) 2022-11-24 20:37:01 +10:00
Stefan Kangas
5551a37f03
Fix typos (#2210) 2022-11-24 20:18:57 +10:00
Damien Elmes
b7e3d9fbfc Probable fix for "unknown error"
(cherry picked from commit b56835511865cb0e76be012e6aeff721d68fb203)
2022-11-23 18:51:56 +10:00
Yoshi
80598f12ed
Pass addon name to config edit hook (#2205)
* Pass addon name to config edit hook

* Deprecate old hook instead of replacing it
2022-11-23 18:00:28 +10:00
Matthias Metelka
365c5e1fb2
UI size tweaks (#2184)
* Reduce font size of answer button indicators

* Increase padding of browser rows with ResizeToContents on vertical header

* Remove 0.8 scale factor for dropdown item font-size

* Remove font-size prop entirely from DropdownItem

* Revert "Remove font-size prop entirely from DropdownItem"

This reverts commit bb0a158f96183cca74e198867070c2f99af04dc4.

* Remove hard-coded Python font sizes

* Move font size and scrollbar into _root-vars.scss

* Revert editor size variable to 1.6

* Fix icon alignment

* Fix checkbox alignment for dropdown items

* Remove unused classes from Tag.svelte

* Revert "Increase padding of browser rows with ResizeToContents on vertical header"

This reverts commit 77bfc854ba140dd99aae98efcdd4af7052615fa6.

* Remove option to set font size of browser entries

* Add setting for browser row padding to preferences

* Revert "Add setting for browser row padding to preferences"

This reverts commit 75c59da65a1028e2caa3c48b247f99825c1b0b6c.

* Revert "Remove option to set font size of browser entries"

This reverts commit a543783d8ea079f39b7ae445152573c96be29841.
2022-11-23 16:50:15 +10:00
Matthias Metelka
7768262086
Remove unneeded spacers (#2208) 2022-11-23 16:35:23 +10:00
BlueGreenMagick
79f94d5a71
fix body classes changes when changing theme (#2199) 2022-11-21 10:20:00 +10:00
Abdo
05b5abb856
Call browser_will_show before restoring state (#2198)
This is to fix a recent issue that started to appear in the Fastbar
add-on where the layout of the toolbar is broken.
2022-11-21 10:18:59 +10:00
Hikaru Y
dc4ac1da66
Add tooltip to 'More' button to show keyboard shortcut (#2193)
* Add tooltip to 'More' button to show keyboard shortcut

* Remove unused 'rem' key
2022-11-17 10:03:38 +10:00
Damien Elmes
063623af3c Format .toml files with dprint 2022-11-09 20:03:49 +10:00
Damien Elmes
7437ce41ec Add another contributor at their request 2022-11-09 12:44:13 +10:00
Matthias Metelka
dbd9e71d44
Adjust QTableWidget stylesheet (#2183)
* Center table headers

by giving the arrow a negative margin equal to its width.

* Prevent overlap with arrow for small headers (largely)

I didn't want to go all out and make the right padding equal to the width of the arrow, because it would cut off the text too early on sections that aren't active.

* Hide vertical table header on Windows too

* Remove margin between toolbars in main view

Didn't want to create a separate PR for such a minor change.

* Create better borders for QTableWidget

* Remove unused import

* Improve RTL appearance of table
2022-11-05 11:11:32 +10:00
Damien Elmes
2504ad0b99 Fix mypy not picking up on missing attributes
Behaviour changed in recent releases:
https://github.com/python/mypy/issues/13319
2022-11-04 14:56:36 +10:00
Aristotelis
dba4925aba
Hide note/card switch label during animation (#2177)
* Hide note/card switch label during animation

* Satisfy mypy
2022-11-03 13:24:52 +10:00
Abdo
e64784f093
Fix RTL arrangement of browser views (#2176) 2022-11-03 12:14:52 +10:00
Aristotelis
20d2a0f33b
Equalize browser panes on splitter double-click (#2175) 2022-11-03 12:13:48 +10:00
Damien Elmes
c9a9f38ea9 Remove untranslated 'see old deck options' notice
It was intended to be a temporary message, and it's been about 15 months.

https://forums.ankiweb.net/t/anki-2-1-55-beta-3/24295/42
2022-11-03 12:05:19 +10:00
Matthias Metelka
27eff12235
Fix various RTL issues (#2172)
* Fix RTL issues in deck browser

* Fix RTL issues in deck options

* Fix QMenu indicator being cutoff in RTL mode
2022-11-02 21:47:07 +10:00
Matthias Metelka
0a3ac591e6
Flatten buttons to match macOS style (#2159)
* Use button gradient only on hover

* Apply hover effect to main window buttons

* Apply arbitrary change to force recreation of colors.py

* Undo arbitrary change to fix props not being created

* Remember that the comments are used for regex matching

* Yet another try

* Revert "Yet another try"

This reverts commit eaef4805c1618cf93ac2f93bc14ada900dc6d155.

* Update _root-vars.scss
2022-11-02 20:39:30 +10:00
Matthias Metelka
7b0236551e
Use circle icon for QRadioButton (#2162) 2022-11-02 18:28:58 +10:00
Matthias Metelka
d44a99885e
Use shallow copy to isolate browser row color adjustments (#2158)
This stops flag and card state colors from getting increasingly lighter/darker and also makes the effect exclusive to the cell rows.
2022-11-02 18:25:36 +10:00
Matthias Metelka
1478801e4a
Fix indicator positioning of Reviewer bottom toolbar (#2157)
* Prevent interval indicators from wrapping

* Move indicators inside and relative to their buttons

* Move due indicators into answer buttons
2022-11-02 18:18:21 +10:00
Matthias Metelka
6514ec5796
Fix CSS vars not being included in reviewer (#2155) 2022-11-01 11:38:03 +10:00
Damien Elmes
e5c4ccf08c If a backup fails before close, ensure collection closed
Otherwise when user returns to profiles screen, they'll be unable to
open a different profile, as the collection is still open.

Encountered when opening the collection that triggered
https://github.com/ankitects/anki/issues/2123
2022-10-29 11:08:58 +10:00
Matthias Metelka
0c340c4f74
Add comments to Sass variables and tweak main window (#2137)
* Prevent multiple inclusion of variables in CSS files

* Use dict instead of tuple for variables

* Add comments to variables

* Improve appearance of main window

* Tweak main window styles

* Use json.dumps over pprint.format

* Make study button primary

* Improve header margin

* Make bottom toolbar slimmer

* Make congrats page more balanced

* Fix type issue

* Replace day/night with light/dark

* Exclude top-level-drag-row from hover effect

* Create dataclass for variables

* Run formatter

* Apply CSS variables from Python side

Why go full-circle with the Sass variables? This way we only need one interface for add-on authors to interact with. It also makes it easier for us to apply additional themes in the future.

* Fix typing

* Fix rgba values in Qt

* Darken button background

* Fix palette not being applied in light theme

For some odd reason this problem arose much later than #2016.

* Tweak default button look

* Reformat

* Apply CSS vars to ts pages

* Include elevation in button_mixins_lib

* Cast opacity to int

* Add some margin to studiedToday info

* Tweak light theme button gradient

* Tweak highlight-bg for light theme

* Add back default button color

as it made the browser sidebar tool icons dark in light theme.

* Reformat

* Tweak light theme buttons once more

Sorry for the back-and-forth. Sass only compiles when there are changes in user files, not when I only change the vars.

* Fix bottom toolbar button indicators

* Make buttons more clicky

* Fix button padding

* Handle macOS separately again

* Decrease elevation effect for main window buttons to 1

* Imitate box-shadow for Qt elements

* Adjust shadow vars

* Adjust primary border color

because the save button in the deck options had a lighter color than its background gradient.

* Boost box-shadow color of primary buttons

* Format

* Adjust Qt box-shadow imitation and shadow colors

* Use more subtle default shadow color

* Add some more padding to top toolbar

* Revert "Apply CSS vars to ts pages"

This reverts commit 5d8e7f6b7ffc8894b6517ecbb8cfba35407fc69a.

* Revert "Apply CSS variables from Python side"

This reverts commit 87db774412fd2bfd75e2630d2c5e782daef96b5f.

* Better match the standard macOS buttons

In the dark theme the standard color is a lighter grey, but at least
the size/shape is similar again.

This doesn't work for the editor buttons.

* Reduce the top margin of the congrats screen

* Fix illegible buttons when changing theme on macOS; match dark button style
2022-10-29 10:48:53 +10:00
Abdo
9fb3eb86d5
Add aqt.operations helper for col.update_notes() (#2145) 2022-10-28 20:52:04 +10:00
Damien Elmes
22f54c2c01 Protobuf now ships with a macOS arm64 wheel 2022-10-21 21:13:28 +10:00
Damien Elmes
f9aff548b7 Update protoc for new Python codegen
Pylint is no longer able to detect available members in the generated
protobuf files, so we need to exclude them from processing. This should
not be a problem as we get these checks from mypy already, and as a
bonus we no longer need to exclude protobuf classes manually.

The fact that anki.sync_pb2 needs to be added after the wildcard appears
to be a bug.
2022-10-21 20:23:31 +10:00
RumovZ
c521753057
Refactor error handling (#2136)
* Add crate snafu

* Replace all inline structs in AnkiError

* Derive Snafu on AnkiError

* Use snafu for card type errors

* Use snafu whatever error for InvalidInput

* Use snafu for NotFoundError and improve message

* Use snafu for FileIoError to attach context

Remove IoError.
Add some context-attaching helpers to replace code returning bare
io::Errors.

* Add more context-attaching io helpers

* Add message, context and backtrace to new snafus

* Utilize error context and backtrace on frontend

* Rename LocalizedError -> BackendError.
* Remove DocumentedError.
* Have all backend exceptions inherit BackendError.

* Rename localized(_description) -> message

* Remove accidentally committed experimental trait

* invalid_input_context -> ok_or_invalid

* ensure_valid_input! -> require!

* Always return `Err` from `invalid_input!`

Instead of a Result to unwrap, the macro accepts a source error now.

* new_tempfile_in_parent -> new_tempfile_in_parent_of

* ok_or_not_found -> or_not_found

* ok_or_invalid -> or_invalid

* Add crate convert_case

* Use unqualified lowercase type name

* Remove uses of snafu::ensure

* Allow public construction of InvalidInputErrors (dae)

Needed to port the AnkiDroid changes.

* Make into_protobuf() public (dae)

Also required for AnkiDroid. Not sure why it worked previously - possible
bug in older Rust version?
2022-10-21 18:02:12 +10:00
Damien Elmes
c22f6022fc Add Christos to about 2022-10-15 10:58:43 +10:00
Hikaru Y
e0e45c55b5
Fix maximized browser window not being restored (#2132) 2022-10-14 10:19:20 +10:00
Matthias Metelka
dc67ed9952
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
2022-10-12 14:29:06 +10:00
Matthias Metelka
3d47c9547a
Experiment with labelled note view switch (#2117)
* Swap initial letter for full label on switch.py

* Tweak note/card accent colors

* Decrease knob radius by 1px

* Make label font smaller, but bold
2022-10-10 18:36:11 +10:00
Matthias Metelka
4750962098
Fix QToolTip styling issue on Windows (#2120)
* Fix QToolTip styling issue on Windows

* Remove QToolTip styling entirely
2022-10-10 18:32:45 +10:00
Matthias Metelka
df03c172db
Add min-width to QPushButton stylesheet (#2115)
to improve look on windows systems
2022-10-10 13:50:24 +10:00
Matthias Metelka
b97fabb677
Make Qt stylesheets fully responsive to RTL (#2114)
* Make Qt stylesheets fully responsive to RTL

* Fix typing
2022-10-10 13:29:09 +10:00
Damien Elmes
f855fc67ad Update macOS bundle to Qt 6.4.0
This bumps the minimum OS version to 10.14
2022-10-10 12:56:47 +10:00
Abdo
9d6cd4cd76
Use showText to show add-on import errors (#2103)
* Use showText to show add-on import errors

Long error messages can be completely unreadable as QMessageBox doesn't
show a scrollbar and the text can't be selected and copied by default (on Windows at least).

* HTML-escape error
2022-10-06 18:15:56 +10:00
Matthias Metelka
9b878a2229
Make auto-closing of HTML tags default but optional (#2101) 2022-10-03 13:14:57 +10:00
Hikaru Y
76065e843b
Fix scrolling with keys / keyboard event listeners not working on answer side (#2099)
* Revert "Fix reviewer shortcuts being inaccessible due to IME"

This reverts commit 5bf031f1e3.

* Work around WebEngine/IME bug in Qt6
2022-10-03 12:53:09 +10:00
Aristotelis
da4d80da2a
Add API shim for webview.get_window_bg_color (#2095)
* Maintain shim for webview.get_window_bg_color

Used by the AMBOSS add-on

* Fix deprecation message
2022-10-03 12:50:22 +10:00
Damien Elmes
4bf243d0af Fix type answer warning making text bold 2022-09-30 14:08:03 +10:00
Damien Elmes
6944210fbe Fix theming on Windows
- Use Unix path separator
- Strip off UNC prefix when running under Bazel
2022-09-28 15:12:14 +10:00
Matthias Metelka
f72570c604
Make tags editor resizable using Henrik's components (#2046)
* Make tags editor resizable using Henrik's components

All credit for the components goes to Henrik. I just tweaked the design a bit and implemented them in NoteEditor.

Co-Authored-By: Henrik Giesel <hengiesel@gmail.com>

* Remove PaneContent padding

Co-Authored-By: Henrik Giesel <hengiesel@gmail.com>

* Add responsive box-shadows on scroll/resize

only shown when content overflows in the respective direction.

* Remove comment

* Fix overflow calculations and shadow mix-up

This happened when I switched from using scrolledToX to overflowX booleans.

* Simplify overflow calculations

* Make drag handles 0 height/width

The remaining height requirement comes from a margin set on NoteEditor.

* Run eslint on components

* Split editor into three panes: Toolbar, Fields, Tags

* Remove upper split for now

to unblock 2.1.55 beta

* Move panes.scss to sass folder

* Use single type for resizable panes

* Implement collapsed state toggled with click on resizer

* Add button to uncollapse tags pane and focus input

* Add indicator for # of tags

* Use dbclick to prevent interference with resize state

* Add utility functions for expand/collapse

* Meddle around with types and formatting

* Fix collapsed state being forgotten on second browser open (dae)

* Fix typecheck (dae)

Our tooling generates .d.ts files from the Svelte files, but it doesn't
expect variables to be exported. By changing them into functions, they
get included in .bazel/bin/ts/components/Pane.svelte.d.ts

* Remove an unnecessary bridgeCommand (dae)

* Fix the bottom of tags getting cut off (dae)

Not sure why offsetHeight is inaccurate in this case.

* Add missing header (dae)

Co-authored-by: Henrik Giesel <hengiesel@gmail.com>
2022-09-28 14:02:32 +10:00
Matthias Metelka
23e6b2123e
Redesign deck options inputs (#2082)
* Create _input-mixins.scss

* Use button-mixins on more elements

* Replace <select> tag with custom Select component

* Fix RevertButton causing cursor: pointer when hidden

* Increase SaveButton chevron width

* Hide floating component box-shadow when inactive

* Rework SpinBox and move it into components

* Run eslint and prettier

* Remove leftover options prop

* Pass disabled array to EnumSelector again

* Update MapperRow.svelte

* Darken QHeaderView border color

Slipping this in without an extra PR.

* Adjust disabled color, border and cursor

* Remove redundant icon definition from stylesheets

* Fix deck options initial config

* Fix z-index issues in change notetype screen

It might be best to handle z-index locally in each user component instead of hard-coded component values.

* Give web SpinBox a horizontal design

* Give QRadioButton the same treatment as QCheckBox in #2079

* Fix unused CSS selector warning with base button-mixin

* Remove redundant import

* Fix deck options save button

* Delete input-mixins and remove unused down-arrow

* Run eslint on change-notetype

* Run eslint on components
2022-09-27 12:16:45 +10:00
Abdo
73035819a9
Fix pm.night_mode() (#2091)
* Fix pm.night_mode()

* Add deprecation notice (dae)
2022-09-26 11:06:21 +10:00
Damien Elmes
4089e76800
Add option to shrink editor images by default (#2071)
+ Don't persist shrinking toggle

Closes #1894
2022-09-26 09:47:50 +10:00
Matthias Metelka
c1176a2e6c
Fix custom webview scrollbar not showing (#2085)
* Fix custom scrollbar not showing

* Move body selector out of scrollbar mixin

* Apply custom scrollbar to child elements too

* Remove some duplicate definitions

* Run prettier
2022-09-26 09:13:06 +10:00
Matthias Metelka
abb018b507
Fix Qt stylesheets getting duplicated over and over again (#2083) 2022-09-24 15:57:10 +10:00
Damien Elmes
9abc73360e Update Python deps
Addresses a protobuf CVE. Required some other patches due to changes
in latest mypy and pylint.
2022-09-24 09:46:43 +10:00
Damien Elmes
66178edd5a Compile _vars.scss in //sass
Saves an extra copy, and allows use by mobile clients
2022-09-23 13:48:18 +10:00
Damien Elmes
192dfe8185 Get the runtime Qt version instead of the compile-time version
PyQt sometimes bumps the Qt libraries without changing the Python side
2022-09-21 12:21:10 +10:00
Matthias Metelka
bff76727fe
Make mdi icons for Qt themeable (#2078)
* Fix create_vars_from_map not creating vars with default definition

* Add white and black to vars

* Replace some hard-coded SVGs with mdi equivalents

* Implement function to dynamically adjust SVG icon color

* Use new svg function to make Qt stylesheet icons respond to theme changes

* Use svg function for sidebar tool icons

* Create copy for each new color instead of modifying source file

* Fix check fails

* Add custom checkbox style for #2079

* Add example of how to generate svgs during build (dae)

* Create arbitrary color variants for each icon with Bazel

* Remove unused label (dae)
2022-09-21 12:02:30 +10:00
Matthias Metelka
e109c62aa9
Improve hover feedback on various widgets (#2079)
* Use cursor: pointer on QCheckBoxes too and exclude disabled widgets

* Left-align all QCheckBoxes to make hover-area and clickable area the same

Altough the clickable area has always been restricted to the label, the widget itself stretched all the way. This became a problem with the new cursor-pointer for checkboxes.

* Remove Switch duplicate from deck-options

* Add cursor: pointer to Switch and RevertButton

* Add cursor: pointer to bottom toolbar buttons

* Add cursor: pointer to gears

* Add cursor: pointer to radio and checkbox inputs of graphs page

* Improve button appearance in stats screen

* Add cursor: pointer to QTabBar and QToolButton

* Add cursor: pointer to non-editable QComboBox

* Center settings-will-take-effect-after notice in preferences screen

* Use public without_qt5_compat_wrapper() function

* Run prettier
2022-09-20 16:34:15 +10:00
Matthias Metelka
52f52724fa
Add orientation toggle to browser view menu (#2074)
* Use horizontal orientation on browser splitter by default

* Add View menu action to toggle browser orientation

* Add shortcut for toggleOrientation action

based on the most popular add-on.

* Try to fix typing issue

* Make orientation respond to aspect ratio

aspect ratio < 1 means vertical orientation, >= 1 horizontal

* Implement three-way switch for browser orientation

* Fix typing

* Add separator before QWidgetAction

* Use submenu instead of widget and adjust enum

* Add accelerators; move non-accelerator strings into separate .ftl (dae)

* Move BrowserLayout to its own file (dae)
2022-09-20 12:56:59 +10:00
Matthias Metelka
24abb06cee
Color Palette Patch 1 (#2073)
* Make several colors more faint

* Move selection-color definition out of table.py and adjust colors

* Use functions for repetitive border-gradient definitions

* Tweak QTableView and QScrollBar styles

* Use mdi icon for Qt drag handles and adjust padding in browser.ui

* Apply appropriate drag-handle icon depending on orientation

* Fix formatting

* Remove unused import

* Add right margin to browser layout

* Apply splitter styling on macOS as well (dae)

+ Remove the styling from sliders, as it was presumably not intentional.
2022-09-19 10:58:05 +10:00
Damien Elmes
5bf031f1e3 Fix reviewer shortcuts being inaccessible due to IME
Only tested on Windows, but hopefully resolves the Linux issue as well.

Closes #1952
2022-09-17 14:15:07 +10:00
Damien Elmes
39d59caa48 Possible fix for error when copying text in editor
https://forums.ankiweb.net/t/error-copying-data-when-editing-a-note-field-anki-2-1-54/23147
https://forums.ankiweb.net/t/error-during-performing-an-ahk-script/23070
2022-09-17 11:47:41 +10:00
Matthias Metelka
8142176f84
Introduce new color palette using Sass maps (#2016)
* Remove --medium-border variable

* Implement color palette using Sass maps

I hand-picked the gray tones, the other colors are from the Tailwind CSS v3 palette.

Significant changes:
- light theme is brighter
- dark theme is darker
- borders are softer

I also deleted some platform- and night-mode-specific code.

* Use custom colors for note view switch

* Use same placeholder color for all inputs

* Skew color palette for more dark values

by removing gray[3], which wasn't used anywhere. Slight adjustments were made to the darker tones.

* Adjust frame- window- and border colors

* Give deck browser entries --frame-bg as background color

* Define styling for QComboBox and QLineEdit globally

* Experiment with CSS filter for inline-colors

Inside darker inputs, some colors like dark blue will be hard to read, so we could try to improve text-color contrast with global adjustments depending on the theme.

* Use different map structure for _vars.scss

after @hgiesel's idea: https://github.com/ankitects/anki/pull/2016#discussion_r947087871

* Move custom QLineEdit styles out of searchbar.py

* Merge branch 'main' into color-palette

* Revert QComboBox stylesheet override

* Align gray color palette more with macOS

* Adjust light theme

* Use --slightly-grey-text for options tab color

* Replace gray tones with more neutral values

* Improve categorization of global colors

by renaming almost all of them and sorting them into separate maps.

* Saturate highlight-bg in light theme

* Tweak gray tones

* Adjust box-shadow of EditingArea to make fields look inset

* Add Sass functions to access color palette and semantic variables

in response to https://github.com/ankitects/anki/pull/2016#issuecomment-1220571076

* Showcase use of access functions in several locations

@hgiesel in buttons.scss I access the color palette directly. Is this what you meant by "... keep it local to the component, and possibly make it global at a later time ..."?

* Fix focus box shadow transition and remove default shadow for a cleaner look

I couldn't quite get the inset look the way I wanted, because inset box-shadows do not respect the border radius, therefore causing aliasing.

* Tweak light theme border and shadow colors

* Add functions and colors to base_lib

* Add vars_lib as dependency to base_lib and button_mixins_lib

* Improve uses of default-themed variables

* Use old --frame-bg color and use darker tone for canvas-default

* Return CSS var by default and add palette-of function for raw value

* Showcase use of palette-of function

The #{...} syntax is required only because the use cases are CSS var definitions. In other cases a simple palette-of(keyword, theme) would suffice.

* Light theme: decrease brightness of canvas-default and adjust fg-default

* Use canvas-inset variable for switch knob

* Adjust light theme

* Add back box-shadow to EditingArea

* Light theme: darken background and flatten transition

also set hue and saturation of gray-8 to 0 (like all the other grays).

* Reduce flag colors to single default value

* Tweak card/note accent colors

* Experiment with inset look for fields again

Is this too dark in night mode? It's the same color used for all other text inputs.

* Dark theme: make border-default one shade darker

* Tweak inset shadow color

* Dark theme: make border-faint darker than canvas-default

meaning two shades darker than it currently was.

* Fix PlainTextInput not expanding

* Dark theme: use less saturated flag colors

* Adjust gray tones

* Fix nested variables not getting extracted correctly

* Rename canvas-outset to canvas-elevated

* Light theme: darken canvas-default

* Make canvas-elevated a bit darker

* Rename variables and use them in various components

* Refactor button mixins

* Remove fusion vars from Anki

* Adjust button gradients

* Refactor button mixins

* Fix deck browser table td background color

* Use color function in buttons.scss

* Rework QTabWidget stylesheet

* Fix crash on browser open

* Perfect QTableView header

* Fix bottom toolbar button gradient

* Fix focus outline of bottom toolbar buttons

* Fix custom webview scrollbar

* Fix uses of vars in various webviews

The command @use vars as * lead to repeated inclusion of the CSS vars.

* Enable primary button color with mixin

* Run prettier

* Fix Python code style issues

* Tweak colors

* Lighten scrollbar shades in light theme

* Fix code style issues caused by merge

* Fix harsh border color in editor

caused by leftover --medium-border variables, probably introduced with a merge commit.

* Compile Sass before extracting Python colors/props

This means the Python side doesn't need to worry about the map structure and Sass functions, just copy the output CSS values.

* Desaturate primary button colors by 10%

* Convert accidentally capitalized variable names to lowercase

* Simplify color definitions with qcolor function

* Remove default border-focus variable

* Remove redundant colon

* Apply custom scrollbar CSS only on Windows and Linux

* Make border-subtle color brighter than background in dark theme

* Make border-subtle color a shade brighter in light theme

* Use border-subtle for NoteEditor and EditorToolbar border

* Small patches
2022-09-16 14:11:18 +10:00
Zoom
3ec7e23d7c
Fix Windows dark mode detection: OpenKey can fail (#2068)
* Fix Windows dark mode detection: OpenKey can fail

#1497 introduced reading hardcoded Windows Registry key, which assumes key exists. This is not true on Windows 7. Later addition of `try-except` block missed that OpenKey might fail.

This fix allows launching current version of Anki on Windows 7 when installed with Pip with the modified Python 3.9 installation.

* Update CONTRIBUTORS

CI req: Add myself to the contributor list
2022-09-15 12:04:19 +10:00
Abdo
497b246b66
Add MainWindowState hints to more signatures (#2064) 2022-09-12 19:31:22 +10:00
Henrik Giesel
8f8f3bd465
Insert symbols overlay (#2051)
* Add flag for enabling insert symbols feature

* Add symbols overlay directory

* Detect if :xy is inserted into editable

* Allow naive updating of overlay, and special handling of ':'

* First step towards better Virtual Element support

* Update floating to reference range on insert text

* Position SymbolsOverlay always on top or bottom

* Add a data-provider to emulate API

* Show correct suggestions in symbols overlay

* Rename to replacementLength

* Allow replacing via clicking in menu

* Optionally remove inline padding of Popover

* Hide Symbols overlay on blur of content editable

* Add specialKey to inputHandler and generalize how arrow movement is detected

- This way macOS users can use Ctrl-N to mean down, etc.

* Detect special key from within SymbolsOverlay

* Implement full backwards search while typing

* Allow navigating symbol menu and accepting with enter

* Add some entries to data-provider

* Satisfy eslint

* Generate symbolsTable from sources

* Use other github source, allow multiple names

In return, symbol must be unique

* Automatically scroll in symbols dropdown

* Use from npm packages rather than downloading from URL

* Remove console.log

* Remove print

* Add pointerDown event to input-handler

- so that SymbolsOverlay can reset on field click

* Make tab do the same as enter

* Make font a bit smaller but increase relative icon size

* Satisfy type requirement of handlerlist

* Revert changing default size of DropdownItems

* Remove some now unused code for bootstrap dropdowns
2022-09-10 18:46:59 +10:00
Matthias Metelka
414ff5db1c
Redesign Qt widgets with stylesheets (#2050)
* Remove --medium-border variable

* Implement color palette using Sass maps

I hand-picked the gray tones, the other colors are from the Tailwind CSS v3 palette.

Significant changes:
- light theme is brighter
- dark theme is darker
- borders are softer

I also deleted some platform- and night-mode-specific code.

* Use custom colors for note view switch

* Use same placeholder color for all inputs

* Skew color palette for more dark values

by removing gray[3], which wasn't used anywhere. Slight adjustments were made to the darker tones.

* Adjust frame- window- and border colors

* Give deck browser entries --frame-bg as background color

* Define styling for QComboBox and QLineEdit globally

* Experiment with CSS filter for inline-colors

Inside darker inputs, some colors like dark blue will be hard to read, so we could try to improve text-color contrast with global adjustments depending on the theme.

* Use different map structure for _vars.scss

after @hgiesel's idea: https://github.com/ankitects/anki/pull/2016#discussion_r947087871

* Move custom QLineEdit styles out of searchbar.py

* Merge branch 'main' into color-palette

* Revert QComboBox stylesheet override

* Align gray color palette more with macOS

* Adjust light theme

* Add custom styling for Qt controls

* Use --slightly-grey-text for options tab color

* Replace gray tones with more neutral values

* Improve categorization of global colors

by renaming almost all of them and sorting them into separate maps.

* Saturate highlight-bg in light theme

* Tweak gray tones

* Adjust box-shadow of EditingArea to make fields look inset

* Add Sass functions to access color palette and semantic variables

in response to https://github.com/ankitects/anki/pull/2016#issuecomment-1220571076

* Showcase use of access functions in several locations

@hgiesel in buttons.scss I access the color palette directly. Is this what you meant by "... keep it local to the component, and possibly make it global at a later time ..."?

* Fix focus box shadow transition and remove default shadow for a cleaner look

I couldn't quite get the inset look the way I wanted, because inset box-shadows do not respect the border radius, therefore causing aliasing.

* Tweak light theme border and shadow colors

* Add functions and colors to base_lib

* Add vars_lib as dependency to base_lib and button_mixins_lib

* Improve uses of default-themed variables

* Use old --frame-bg color and use darker tone for canvas-default

* Return CSS var by default and add palette-of function for raw value

* Showcase use of palette-of function

The #{...} syntax is required only because the use cases are CSS var definitions. In other cases a simple palette-of(keyword, theme) would suffice.

* Light theme: decrease brightness of canvas-default and adjust fg-default

* Use canvas-inset variable for switch knob

* Adjust light theme

* Add back box-shadow to EditingArea

* Light theme: darken background and flatten transition

also set hue and saturation of gray-8 to 0 (like all the other grays).

* Reduce flag colors to single default value

* Tweak card/note accent colors

* Experiment with inset look for fields again

Is this too dark in night mode? It's the same color used for all other text inputs.

* Dark theme: make border-default one shade darker

* Tweak inset shadow color

* Dark theme: make border-faint darker than canvas-default

meaning two shades darker than it currently was.

* Fix PlainTextInput not expanding

* Dark theme: use less saturated flag colors

* Adjust gray tones

* Create stylesheet overrides for various Qt widgets

Including QPushButton, QComboBox, QSpinBox, QLineEdit, QListWidget, QTabWidget, QTreeWidget, QToolTip, QTableView, QScrollBar and sub-widgets.

* Make webview scrollbar look identical to Qt one

* Add blue colors for primary buttons

* Tweak disabled state of SpinBox button

* Apply styles to all platforms

mainly so people like @hgiesel can easily test the widget style overrides, but maybe you actually prefer them over the native ones, who knows :)

* Tweak webview button borders

* Add type annotations to eventFilter

* Adjust padding of QComboBox and its drop-down arrow

* Use isinstance for comparison

* Remove reimport of Any

* Revert "Merge branch 'redesign-test' into custom-qt-controls"

This reverts commit ff36297456b693a0d4b4b69f5f487ac1a01c1861, reversing
changes made to 6bb45355d143aa081d2d643933bd02ddc43206de.

* Add missing copyright header

* Left-align QTabWidget headers

* Exclude macOS from stylesheet overrides

* Fix failure to start on macOS (dae)

* Use standard macOS theme in dark mode (dae)

I believe this was originally behind a feature flag because the user
had to use a hack to get it to work
(https://forums.ankiweb.net/t/title-bar-dark-mode-fix-broken/1189),
and it did not work correctly when the system theme was changed.

Since the introduction of libankihelper and the app automatically
updating as the system theme changes, these issues no longer seem to
exist, and switching between light and dark appears to work consistently.

Pushed into this PR because it addresses the background color issue
mentioned in code review.

Closes #2054
2022-09-08 20:44:38 +10:00
RumovZ
e7af0febb1
More template checks (#2032)
* Show warning if multiple type boxes are used

* Report templates referencing media in Media Check

* Apply suggestions from code review

* Fix media-check.ftl

* Only report media references with fields

Like `<img src={{Front}}>`.
Also report Anki sound tags and latex.

* Loop existing media regexes
2022-09-05 16:52:25 +10:00
RumovZ
e39fb74e82
Enable state-dependent custom scheduling data (#2049)
* Enable state-dependent custom scheduling data

* Next(Card)States -> SchedulingStates

The fact that `current` was included in `next` always bothered me,
and custom data is part of the card state, so that was a bit confusing
too.

* Store custom_data in SchedulingState

* Make custom_data optional when answering

Avoids having to send it 4 extra times to the frontend, and avoids the
legacy answerCard() API clobbering the stored data.

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2022-09-05 16:48:01 +10:00
Matthias Metelka
e2193950a9
Add animation toggle to preferences (#2041)
* Add animation toggle to preferences

and move settings affecting appearance together.

* Add class to body if animations unchecked

* Fix formatting in preferences.ftl

* Update duration(height) function for Collapsible transition

and add explanation.

* Fix formatting

* Increase duration baseline to 10 and decrease factor to 20

* Restore initial layout and rename option to "Reduce motion"

* Move checkboxes together and fix tab order (dae)

+ Remove separation of UI size
2022-09-03 12:14:47 +10:00
RumovZ
31b7464c67
Add card meta for persisting custom scheduling state (#2040)
* Add card meta for persisting custom scheduling state

* Rename meta -> custom_data

* Enforce limits on size of custom data

Large values will slow down table scans of the cards table, and it's
easier to be strict now and possibly relax things in the future than
the opposite.

* Pack card states and customData into a single message

+ default customData to empty if it can't be parsed

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2022-09-02 11:22:49 +10:00
Matthias Metelka
d110c4916c
Introduce setting to collapse field by default (#1990)
* Introduce setting to collapse field by default

* Fix schema order

* Change wording from adjective to imperative

sounds a bit less clunky

* Update rslib/src/notetype/schema11.rs (dae)

* Keep settings in single column

* Add back Toggle Visual Editor string

* Add RichTextBadge component and show it conditionally

* Reverse input order depending on default setting

* Make PlainTextInput border-radius responsive to toggle states

* Prevent first Collapsible transition differently

* Focus inputs after Collapsible transition

The double tick calls are just a temporary solution until I find the exact moment an input is focusable again.

* Use requestAnimationFrame to await focusable state

Note: Svelte tick doesn't seem to work in this scenario.
2022-08-31 23:34:39 +10:00
Sam Penny
65601196ee
add shortcut to close addcards window (#2031) 2022-08-31 20:09:09 +10:00
wallgrenen
0eaa80dd28
change update link to point to download section (#2034) 2022-08-31 18:35:53 +10:00
Damien Elmes
966d7f3760 Experimentally remove webview recycling
It was originally introduced for WebKit, and may no longer be pertinent
for Chromium.WebEngine.

https://forums.ankiweb.net/t/anki-glitch-showing-previous-card-answer-instead-of-new-card/12482/13
2022-08-30 21:52:22 +10:00
Damien Elmes
89c4441837 Fix scheduler change not reflected after normal sync 2022-08-24 18:37:58 +10:00
Sam Penny
45f2502e5b
fix line break in sync link in the toolbar (#2022) 2022-08-22 11:26:57 +10:00
Damien Elmes
fc93ea3ecc Show a pop-up when the user tries to study with V1
Closes #1991
2022-08-19 12:43:17 +10:00
Sam Bradshaw
92171e25e6
Add MessageBox class and associated funcs to aqt.utils and update the first few callers (#2010)
* Add MessageBox class and associated funcs to aqt.utils and update some callers in aqt.sync and aqt.addons

* Cleanup imports in aqt.sync

* Fix return values for ask_user and ask_user_dialog

* Fix wrong argument name in aqt.utils.ask_user

* Add type annotations to **kwargs in utils.py

* Type annotation for callback in aqt.sync.full_sync

* MessageBox accepts StandardButton in addition to str, fix linting issues

* Assess default buttons in correct order and return correct button name in MessageBox

* Add explicit Optionals in aqt.utils

* Pass button index to callback in MessageBox

* Update type hints for aqt.utils.MessageBox

* Use Sequence for aqt.utils.MessageBox buttons arg

* default_button > default_yes in aqt.utils.ask_user

* Dark mode question icon  in aqt.utils.MessageBox
2022-08-19 10:04:58 +10:00
Damien Elmes
19deb7ad25 Access certificates periodically
Tentatively closes #1965
2022-08-19 10:00:38 +10:00
Matthias Metelka
7517af4942
Fix not being able to scroll when mouse hovers PlainTextInput (#2019)
* Remove overscroll-behavior: none for * (all elements)

* Revert "Remove overscroll-behavior: none for * (all elements)"

This reverts commit 189358908cecd03027e19d8fe47822735319ec17.

* Use body instead of *, but keep CSS rule

* Unify two CSS rules
2022-08-18 12:48:28 +10:00
Matthias Metelka
d1cbb86178
Default input setting in fields dialog (#1987)
* Introduce field setting to use plain text editor by default

* Remove leftover function from #1476

* Use boolean instead of string

* Simplify clear_other_field_duplicates

* Convert plain text key to camelCase

* Move HTML item below the existing checkbox, instead of to the right (dae)

Showing it on the right is more space efficient, but feels a bit
cluttered IMHO.
2022-08-18 12:30:18 +10:00
Damien Elmes
75723d7c9c
Add option in math dropdown to toggle MathJax rendering (#2014)
* Add option in math dropdown to toggle MathJax rendering

Closes #1942

* Hackily redraw the page when toggling MathJax

* Add Fluent string
2022-08-18 12:06:06 +10:00
Matthias Metelka
d5945a213a
Make sidebar search input more pleasant to look at (#2009)
* Improve margins

* Remove right border on non-macOS systems

Would be interesting to know why this was implemented in the first place. Looks quite ugly on Linux.

* Add focus border

* Align height of toolbar icons with search bar

* Remove leftover f-strings
2022-08-15 13:08:44 +10:00
Matthias Metelka
99f4f68aca
Make switch knob smaller than path (#2008)
to ensure contrast when we move to a lighter window-bg color.
2022-08-15 13:05:20 +10:00
Sam Penny
21812556a6
Serialize modal popups at startup (#2000)
* call_add-on_update_after_initial_sync

* Add safeMode restriction

* check for anki update after other modal dialogs

* fix failing test

* make changes suggested in review
2022-08-09 13:40:52 +10:00
Sam Bradshaw
c4d71eae2f
Use platform.platform() in supportText() (#1999)
From [the documentation](https://docs.python.org/3.9/library/platform.html#platform.platform):
> Returns a single string identifying the underlying platform with as much useful information as possible.
The output is intended to be human readable rather than machine parseable. It may look different on different platforms and this is intended.
Changed in version 3.8: On macOS, the function now uses mac_ver(), if it returns a non-empty release string, to get the macOS version rather than the darwin version.

The main advantage of this change is that it provides the architecture of the platform, which is increasingly relevant as ARM systems are becoming more common.
2022-08-02 19:49:02 +10:00
BlueGreenMagick
a7208601fe
fix progress.update(value=0) to not increment progress (#1998) 2022-08-01 20:16:42 +10:00
Henrik Giesel
3e28605638
Use wavy flags (flag-alternative) (#1995) 2022-08-01 20:15:22 +10:00
Damien Elmes
8a62e9c95e Ensure only the first fatal error is shown
https://forums.ankiweb.net/t/a-fatal-error-occurred-and-anki-must-close-please-report-this-message-on-the-forums/21913
2022-08-01 19:38:46 +10:00
Sam Penny
56f806146c
added editor hook: add_cards_might_add_note (#1992)
* added hook add_cards_might_add_note

* fix failing test
2022-07-30 20:41:42 +10:00
Damien Elmes
d699bc1252 Handle missing attributes in win32 tts code
https://forums.ankiweb.net/t/trouble-adding-tts-to-my-cards/21792/4
2022-07-30 19:08:37 +10:00
Hikaru Y
e6cc12ca7a
Fix sidebar not being restored properly in some cases (#1982)
The sidebar (QDockWidget) was not restored properly in some environments
when re-opening the browser if the browser was closed while maximized
under the condition that the window size in the normal window state was
very small.
2022-07-23 16:12:02 +10:00
Damien Elmes
340da23104 Wrap type answer output in code tag; remove extra div
This would make more sense as a class on the outer div, but existing
templates reference code#typeans, so avoid breaking things for now.
2022-07-22 20:37:56 +10:00
Aristotelis
a584ef1f50
Introduce exporters_list_created hook to new export code (#1978)
* Introduce exporters_list_created hook for new export code

* Fix hook and argument name
2022-07-22 19:33:07 +10:00
Damien Elmes
1e0be26b7e Partially migrate type answer to backend
Partially completes #1068, and will allow mobile clients to drop
their separate diff-match-patch imports. Does not yet try to handle
case folding or combining-char stripping, and leaves some of the outer
HTML wrapping up to the frontend for now.

The logic for rendering the provided string has changed: missing chars
are now only inserted if they follow a correct section, and the original
text is shown instead of hyphens. This is an experiment, and can be
changed if it's not well received.
2022-07-22 19:28:34 +10:00
Aristotelis
070c8ac735
Add deck/collection export hooks (#1971)
* Add ExportFormat enum and use it in Exporter classes

* Add exporter hooks and call them from new exporters

* Fix filter argument order and add example to docstring

* Refactor: Avoid repeating ExportFormat

* Rename Options to ExportOptions for better namespacing in add-ons

* Add simplified legacy exporter hooks

Allows add-ons to be notified of exports when legacy handlers are enabled, without the need for monkey-patches.

* Switch away from ExportFormat, opting to pass exporter class/instance instead

* Consistently use exporter instances rather than classes

* Revert Exportdialog.exporters rename

* Revert "Revert Exportdialog.exporters rename"

This reverts commit 357a3aa85928cce702f06b88da5187d2b45cd22b.
2022-07-22 12:45:47 +10:00
Sam Penny
e0368a3858
modify type hint in aqt/qt/profiles (#1972) 2022-07-19 17:29:46 +10:00
Aristotelis
704ff7ab99
Fix legacy import switch (#1970) 2022-07-19 04:23:21 +10:00
Damien Elmes
d482e90c6b Turn new import/export code on by default
Closes #1966
2022-07-18 13:31:24 +10:00
Sam Penny
662586765b
Load previously loaded profile (#1960)
* added option to load the last loaded profile

* add formatting changes for tests

* fix comments - integrate as new functionality rather than as an option, fix type hinting and remove bug if profile is deleted
2022-07-18 13:01:36 +10:00
Mateus Etto
d7d9f51b68
Add reviewer suspend and bury hooks (#1967)
* Add reviewer suspend and bury hooks

* Empty commit

* Change my name in CONTRIBUTORS
2022-07-18 12:59:56 +10:00
Damien Elmes
2625388e8d Ensure files are world readable in macOS dist
Closes #1934
2022-07-12 13:04:48 +10:00
RumovZ
cff04a288a
Fix card info not updating (#1957)
Update was not triggered if card id didn't change.
2022-07-12 10:34:48 +10:00
Damien Elmes
ca69198097 Tweak type-answer example so users don't think the spelling is a mistake
https://github.com/ankitects/anki/pull/1954
2022-07-09 12:24:43 +10:00
Sam Penny
9dcceff4af
Remember previous choices in reposition dialog (#1950)
* remember previous choices in reposition dialog

* remember previous choice for randomize option as well

* fix failing test
2022-07-08 11:28:38 +10:00
Mateus Etto
fbbd3e678c
Add hook: overview_will_render_bottom (#1946) 2022-07-05 08:28:47 +10:00
Abdo
fe302a5d1b
Use portable filter to match all files in getFile (#1943)
`*.*` matches files with no extensions on Windows, while it doesn't do so on
macOS.

Reference: https://doc.qt.io/qt-6/qfiledialog.html#setNameFilters
2022-07-04 09:33:20 +10:00
Sam Penny
1e8ea0cade
fixed hook description (browser_will_search) (#1937)
* fixed hook description

* added name to CONTRIBUTORS
2022-07-01 10:12:27 +10:00
Mateus Etto
af8ae69837
Fix Study Deck in Sway spawning tiled window instead of floating window (#1935)
* Fix Study Deck in sway spawning tiled window instead of floating window

* Update CONTRIBUTORS

* Fix format error
2022-06-27 17:27:56 +10:00
RumovZ
dd0e56afb3
Handle note without cards in browser (#1929)
Change the IndexError to a NotFoundError which is picked up by the table
model.
2022-06-24 13:57:42 +10:00
RumovZ
cd3f9ff646
Workaround broken alignment flags in PyQt 6.3.1 (#1922)
Closes #1921
2022-06-22 09:44:50 +10:00
Damien Elmes
05adb50153 Prevent error when double-tapping delete key in browser
on_all_or_selected_rows_changed() unsets the editor note, but it is
called too late - by that time the note has already been deleted, and
the editor sometimes tries to save the deleted note due to an unfocus/
key timeout.

https://forums.ankiweb.net/t/two-suppr-lead-to-an-empty-warning/20860

Will need to check that this does not regression when #1691 is merged.
2022-06-20 11:07:38 +10:00
Damien Elmes
e5a74838c9 Remove redundant suffix in header key
We're already appending "Qt6"
2022-06-20 10:26:42 +10:00
Damien Elmes
32b9d34749 Add ellipsis to Forget action
https://forums.ankiweb.net/t/bug-card-browser-rmb-forget-label-should-end-with-ellipsis-because-it-displays-a-dialog/20851
2022-06-20 10:25:50 +10:00
Damien Elmes
48c7bb031e Work around broken headers in Qt 6.3.1
https://forums.ankiweb.net/t/anki-2-1-54-release-candidate/20861/2
2022-06-19 10:44:10 +10:00
Damien Elmes
595c92730f Remove CF_HTML header workaround 2022-06-18 09:56:06 +10:00
Abdo
67f64740c4
Accept .zip as an alias for .ankiaddon too (#1914) 2022-06-17 11:10:29 +10:00
Abdo
1bab947c9c
Fix JS drop event not firing in the reviewer (#1906)
* Allow webviews to opt in to default D&D handling

* Remove redundant webview.js include

* Block default drag & drop behavior in reviewing screens

* Fix mypy error
2022-06-10 23:33:53 +10:00
Damien Elmes
940f1dea06 Clear cached flag names on sync
Closes #1907
2022-06-09 12:08:16 +10:00
RumovZ
3816020085
Add legacy importers to new import screen (#1908) 2022-06-09 10:57:29 +10:00
RumovZ
6da5e5b042
CSV import/export fixes and features (#1898)
* Fix footer moving upwards

* Fix column detection

Was broken because escaped line breaks were not considered.
Also removes delimiter detection on `#columns:` line. User must use tabs
or set delimiter beforehand.

* Add CSV preview

* Parse `#tags column:`

* Optionally export deck and notetype with CSV

* Avoid clones in CSV export

* Prevent bottom of page appearing under footer (dae)

* Increase padding to 1em (dae)

With 0.5em, when a vertical scrollbar is shown, it sits right next to
the right edge of the content, making it look like there's no right
margin.

* Experimental changes to make table fit+scroll (dae)

- limit individual cells to 15em, and show ellipses when truncated
- limit total table width to body width, so that inner table is shown
with scrollbar
- use class rather than id - ids are bad practice in Svelte components,
as more than one may be displayed on a single page

* Skip importing foreign notes with filtered decks

Were implicitly imported into the default deck before.
Also some refactoring to fetch deck ids and names beforehand.

* Hide spacer below hidden field mapping

* Fix guid being replaced when updating note

* Fix dupe identity check

Canonify tags before checking if dupe is identical, but only add update
tags later if appropriate.

* Fix deck export for notes with missing card 1

* Fix note lines starting with `#`

csv crate doesn't support escaping a leading comment char. :(

* Support import/export of guids

* Strip HTML from preview rows

* Fix initially set deck if current is filtered

* Make isHtml toggle reactive

* Fix `html_to_text_line()` stripping sound names

* Tweak export option labels

* Switch to patched rust-csv fork

Fixes writing lines starting with `#`, so revert 5ece10ad05f331.

* List column options with first column field

* Fix flag for exports with HTML stripped
2022-06-09 10:28:01 +10:00
Bart Louwers
d6b8520d03
Update get_linux_dark_mode to use freedesktop.org standard (#1905)
* update get_linux_dark_mode to use freedesktop.org standard

* Update CONTRIBUTORS

* run formatter

* Update CONTRIBUTORS

* allow for multiple dark mode detection strategies on Linux

* string -> str

* update docstring

* Update CONTRIBUTORS
2022-06-07 09:30:42 +10:00
Damien Elmes
311d0342a0 Update regex in qt/bundle as well 2022-06-07 08:50:10 +10:00
Damien Elmes
a9884a1b78 Fix kwin hanging when adding new notetype
https://forums.ankiweb.net/t/bug-anki-2-1-52-crashes-after-adding-new-note-type/20284
2022-06-03 11:23:41 +10:00
Damien Elmes
9e5fef00d8 Expose new import/export code via prefs checkbox 2022-06-02 16:50:32 +10:00
RumovZ
42cbe42f06
Plaintext import/export (#1850)
* Add crate csv

* Add start of csv importing on backend

* Add Menomosyne serializer

* Add csv and json importing on backend

* Add plaintext importing on frontend

* Add csv metadata extraction on backend

* Add csv importing with GUI

* Fix missing dfa file in build

Added compile_data_attr, then re-ran cargo/update.py.

* Don't use doubly buffered reader in csv

* Escape HTML entities if CSV is not HTML

Also use name 'is_html' consistently.

* Use decimal number as foreign ease (like '2.5')

* ForeignCard.ivl → ForeignCard.interval

* Only allow fixed set of CSV delimiters

* Map timestamp of ForeignCard to native due time

* Don't trim CSV records

* Document use of empty strings for defaults

* Avoid creating CardGenContexts for every note

This requires CardGenContext to be generic, so it works both with an
owned and borrowed notetype.

* Show all accepted file types  in import file picker

* Add import_json_file()

* factor → ease_factor

* delimter_from_value → delimiter_from_value

* Map columns to fields, not the other way around

* Fallback to current config for csv metadata

* Add start of new import csv screen

* Temporary fix for compilation issue on Linux/Mac

* Disable jest bazel action for import-csv

Jest fails with an error code if no tests are available, but this would
not be noticable on Windows as Jest is not run there.

* Fix field mapping issue

* Revert "Temporary fix for compilation issue on Linux/Mac"

This reverts commit 21f8a261408cdae49ec031aa21a1b659c4f66d82.

* Add HtmlSwitch and move Switch to components

* Fix spacing and make selectors consistent

* Fix shortcut tooltip

* Place import button at the top with path

* Fix meta column indices

* Remove NotetypeForString

* Fix queue and type of foreign cards

* Support different dupe resolution strategies

* Allow dupe resolution selection when importing CSV

* Test import of unnormalized text

Close  #1863.

* Fix logging of foreign notes

* Implement CSV exports

* Use db_scalar() in notes_table_len()

* Rework CSV metadata

- Notetypes and decks are either defined by a global id or by a column.
- If a notetype id is provided, its field map must also be specified.
- If a notetype column is provided, fields are now mapped by index
instead of name at import time. So the first non-meta column is used for
the first field of every note, regardless of notetype. This makes
importing easier and should improve compatiblity with files without a
notetype column.
- Ensure first field can be mapped to a column.
- Meta columns must be defined as `#[meta name]:[column index]` instead
of in the `#columns` tag.
- Column labels contain the raw names defined by the file and must be
prettified by the frontend.

* Adjust frontend to new backend column mapping

* Add force flags for is_html and delimiter

* Detect if CSV is HTML by field content

* Update dupe resolution labels

* Simplify selectors

* Fix coalescence of oneofs in TS

* Disable meta columns from selection

Plus a lot of refactoring.

* Make import button stick to the bottom

* Write delimiter and html flag into csv

* Refetch field map after notetype change

* Fix log labels for csv import

* Log notes whose deck/notetype was missing

* Fix hiding of empty log queues

* Implement adding tags to all notes of a csv

* Fix dupe resolution not being set in log

* Implement adding tags to updated notes of a csv

* Check first note field is not empty

* Temporary fix for build on Linux/Mac

* Fix inverted html check (dae)

* Remove unused ftl string

* Delimiter → Separator

* Remove commented-out line

* Don't accept .json files

* Tweak tag ftl strings

* Remove redundant blur call

* Strip sound and add spaces in csv export

* Export HTML by default

* Fix unset deck in Mnemosyne import

Also accept both numbers and strings for notetypes and decks in JSON.

* Make DupeResolution::Update the default

* Fix missing dot in extension

* Make column indices 1-based

* Remove StickContainer from TagEditor

Fixes line breaking, border and z index on ImportCsvPage.

* Assign different key combos to tag editors

* Log all updated duplicates

Add a log field for the true number of found notes.

* Show identical notes as skipped

* Split tag-editor into separate ts module (dae)

* Add progress for CSV export

* Add progress for text import

* Tidy-ups after tag-editor split (dae)

- import-csv no longer depends on editor
- remove some commented lines
2022-06-01 20:26:16 +10:00
Abdo
5fe9447dcc
Add the media_check_did_finish hook (#1889) 2022-05-27 16:25:34 +10:00
Damien Elmes
2a9a6c5242 Avoid progress window pop-up when application not focused
A 10ms delay was chosen as it tends to result in the progress window
appearing immediately when clicking into the unfocused window, preventing
another action from being started before the progress window appears.

Closes #1873
2022-05-26 12:35:39 +10:00
Damien Elmes
383c890b0d Fix duplicate Anki icons appearing in dock
MPV was previously stored in the MacOS/ folder, which made macOS think
it should have a dock icon.

Fixes #1812
2022-05-26 11:05:36 +10:00
Damien Elmes
e50d40cedf Make editor.cleanup() idempotent
Hammering the esc key as a dialog loads can cause it to be run more
than once, leading to an error message.
2022-05-25 22:04:50 +10:00
Damien Elmes
496e074f29 Possible fix for Qt 6.3 crashes
As mentioned on #1879, the dialog.deleteLater() call appears to be
causing crashes on some systems on Qt 6.3. Explicitly destroying the page
prior to the containing webview appears to work around the issue.
2022-05-25 21:46:47 +10:00
Damien Elmes
82196753ec Rework display of available cards in custom study
In v3, it's more informative to show the count of child decks separately,
since increasing the limit of the current deck does not increase the limits
of child decks. When we rework the decks list in the future, a tooltip
will hopefully provide an easier way for users to see where cards are
available, and where limits are being applied.

Closes #1868
2022-05-20 17:52:02 +10:00
Abdo
515e77b0f4
Add the previewer_did_init hook (#1882) 2022-05-19 11:10:12 +10:00
Abdo
638286a3fc
Add the reviewer_will_replay_recording hook (#1877) 2022-05-18 13:44:56 +10:00
RumovZ
58370d6757
Fix #1874 (#1875)
Probably a race condition. `.get_row()` is not a reliable check for card
or note existence, because it returns from an outdated cache,
if the backend is currently blocked.
2022-05-18 13:34:51 +10:00
Henrik Giesel
3b8aa97396
Use same config for editor and reviewer Mathjax (#1865)
* Remove custom config and use tex-chtml-full for editor Mathjax

* Add mathjax package in /ts

* Share mathjax config between tex-svg and tex-chtml

* Use "[+]" in Mathjax config again

* Remove mention of MathJaxReady

* Satisfy eslint
2022-05-13 13:23:35 +10:00
Abdo
f22d8015a6
Add some helper functions to AVPlayer (#1864) 2022-05-13 13:08:05 +10:00
Abdo
7c543eeb2f
Add the av_player_will_play_tags hook (#1842)
A general version of the reviewer_will_play_question_sounds and reviewer_will_play_answer_sounds hooks
2022-05-09 11:08:34 +10:00
Henrik Giesel
df1f7ff96c
Replace sequences of whitespace into single space in AddTags (#1840) 2022-05-07 09:16:57 +10:00
Damien Elmes
c8a4e5ea22 Add more progress + abort points to export code
The old `media_files_did_export` hook has been kept around for use with
the legacy apkg exporter (an add-on uses it), and a new 
`legacy_export_progress` hook has been added so we can get progress
from the new colpkg exporter until we move over fully to the new code.
2022-05-06 15:32:23 +10:00
Damien Elmes
6a95141fd9 Accept .zip as an alias for .apkg
The legacy importer does this already, because some web servers and
clients sniff the content type of .apkg files, and "helpfully" rename
them to .zip
2022-05-05 21:25:59 +10:00
Damien Elmes
72389b97be Show a user-facing message instead of a traceback on invalid file type
While our importing dialog limits the types of files that can be selected,
users can also import by providing a filename on the command line.
2022-05-05 21:24:12 +10:00
Damien Elmes
fdbe211539 Support new import code in drag/drop + file double-click cases
https://forums.ankiweb.net/t/anki-2-1-52-release-candidate/19412/24
2022-05-03 14:09:40 +10:00
Matthias Metelka
567b05b731
Fix scrollbars showing on bottom bar (#1833) 2022-05-03 13:57:33 +10:00
RumovZ
5f9451f547
Add apkg import/export on backend (#1743)
* Add apkg export on backend

* Filter out missing media-paths at write time

* Make TagMatcher::new() infallible

* Gather export data instead of copying directly

* Revert changes to rslib/src/tags/

* Reuse filename_is_safe/check_filename_safe()

* Accept func to produce MediaIter in export_apkg()

* Only store file folder once in MediaIter

* Use temporary tables for gathering

export_apkg() now accepts a search instead of a deck id. Decks are
gathered according to the matched notes' cards.

* Use schedule_as_new() to reset cards

* ExportData → ExchangeData

* Ignore ascii case when filtering system tags

* search_notes_cards_into_table →

search_cards_of_notes_into_table

* Start on apkg importing on backend

* Fix due dates in days for apkg export

* Refactor import-export/package

- Move media and meta code into appropriate modules.
- Normalize/check for normalization when deserializing media entries.

* Add SafeMediaEntry for deserialized MediaEntries

* Prepare media based on checksums

- Ensure all existing media files are hashed.
- Hash incoming files during preparation to detect conflicts.
- Uniquify names of conflicting files with hash (not notetype id).
- Mark media files as used while importing notes.
- Finally copy used media.

* Handle encoding in `replace_media_refs()`

* Add trait to keep down cow boilerplate

* Add notetypes immediately instaed of preparing

* Move target_col into Context

* Add notes immediately instaed of preparing

* Note id, not guid of conflicting notes

* Add import_decks()

* decks_configs → deck_configs

* Add import_deck_configs()

* Add import_cards(), import_revlog()

* Use dyn instead of generic for media_fn

Otherwise, would have to pass None with type annotation in the default
case.

* Fix signature of import_apkg()

* Fix search_cards_of_notes_into_table()

* Test new functions in text.rs

* Add roundtrip test for apkg (stub)

* Keep source id of imported cards (or skip)

* Keep source ids of imported revlog (or skip)

* Try to keep source ids of imported notes

* Make adding notetype with id undoable

* Wrap apkg import in transaction

* Keep source ids of imported deck configs (or skip)

* Handle card due dates and original due/did

* Fix importing cards/revlog

Card ids are manually uniquified.

* Factor out card importing

* Refactor card and revlog importing

* Factor out card importing

Also handle missing parents .

* Factor out note importing

* Factor out media importing

* Maybe upgrade scheduler of apkg

* Fix parent deck gathering

* Unconditionally import static media

* Fix deck importing edge cases

Test those edge cases, and add some global test helpers.

* Test note importing

* Let import_apkg() take a progress func

* Expand roundtrip apkg test

* Use fat pointer to avoid propogating generics

* Fix progress_fn type

* Expose apkg export/import on backend

* Return note log when importing apkg

* Fix archived collection name on apkg import

* Add CollectionOpWithBackendProgress

* Fix wrong Interrupted Exception being checked

* Add ClosedCollectionOp

* Add note ids to log and strip HTML

* Update progress when checking incoming media too

* Conditionally enable new importing in GUI

* Fix all_checksums() for media import

Entries of deleted files are nulled, not removed.

* Make apkg exporting on backend abortable

* Return number of notes imported from apkg

* Fix exception printing for QueryOp as well

* Add QueryOpWithBackendProgress

Also support backend exporting progress.

* Expose new apkg and colpkg exporting

* Open transaction in insert_data()

Was slowing down exporting by several orders of magnitude.

* Handle zstd-compressed apkg

* Add legacy arg to ExportAnkiPackage

Currently not exposed on the frontend

* Remove unused import in proto file

* Add symlink for typechecking of import_export_pb2

* Avoid kwargs in pb message creation, so typechecking is not lost

Protobuf's behaviour is rather subtle and I had to dig through the docs
to figure it out: set a field on a submessage to automatically assign 
the submessage to the parent, or call SetInParent() to persist a default
version of the field you specified.

* Avoid re-exporting protobuf msgs we only use internally

* Stop after one test failure

mypy often fails much faster than pylint

* Avoid an extra allocation when extracting media checksums

* Update progress after prepare_media() finishes

Otherwise the bulk of the import ends up being shown as "Checked: 0"
in the progress window.

* Show progress of note imports

Note import is the slowest part, so showing progress here makes the UI
feel more responsive.

* Reset filtered decks at import time

Before this change, filtered decks exported with scheduling remained
filtered on import, and maybe_remove_from_filtered_deck() moved cards
into them as their home deck, leading to errors during review.

We may still want to provide a way to preserve filtered decks on import,
but to do that we'll need to ensure we don't rewrite the home decks of
cards, and we'll need to ensure the home decks are included as part of
the import (or give an error if they're not).

https://github.com/ankitects/anki/pull/1743/files#r839346423

* Fix a corner-case where due dates were shifted by a day

This issue existed in the old Python code as well. We need to include
the user's UTC offset in the exported file, or days_elapsed falls back
on the v1 cutoff calculation, which may be a day earlier or later than
the v2 calculation.

* Log conflicting note in remapped nt case

* take_fields() → into_fields()

* Alias `[u8; 20]` with `Sha1Hash`

* Truncate logged fields

* Rework apkg note import tests

- Use macros for more helpful errors.
- Split monolith into unit tests.
- Fix some unknown error with the previous test along the way.
(Was failing after 969484de4388d225c9f17d94534b3ba0094c3568.)

* Fix sorting of imported decks

Also adjust the test, so it fails without the patch. It was only passing
before, because the parent deck happened to come before the
inconsistently capitalised child alphabetically. But we want all parent
decks to be imported before their child decks, so their children can
adopt their capitalisation.

* target[_id]s → existing_card[_id]s

* export_collection_extracting_media() → ...

export_into_collection_file()

* target_already_exists→card_ordinal_already_exists

* Add search_cards_of_notes_into_table.sql

* Imrove type of apkg export selector/limit

* Remove redundant call to mod_schema()

* Parent tooltips to mw

* Fix a crash when truncating note text

String::truncate() is a bit of a footgun, and I've hit this before
too :-)

* Remove ExportLimit in favour of separate classes

* Remove OpWithBackendProgress and ClosedCollectionOp

Backend progress logic is now in ProgressManager. QueryOp can be used
for running on closed collection.

Also fix aborting of colpkg exports, which slipped through in #1817.

* Tidy up import log

* Avoid QDialog.exec()

* Default to excluding scheuling for deck list deck

* Use IncrementalProgress in whole import_export code

* Compare checksums when importing colpkgs

* Avoid registering changes if hashes are not needed

* ImportProgress::Collection → ImportProgress::File

* Make downgrading apkgs depend on meta version

* Generalise IncrementableProgress

And use it in entire import_export code instead.

* Fix type complexity lint

* Take count_map for IncrementableProgress::get_inner

* Replace import/export env with Shift click

* Accept all args from update() for backend progress

* Pass fields of ProgressUpdate explicitly

* Move update_interval into IncrementableProgress

* Outsource incrementing into Incrementor

* Mutate ProgressUpdate in progress_update callback

* Switch import/export legacy toggle to profile setting

Shift would have been nice, but the existing shortcuts complicate things.
If the user triggers an import with ctrl+shift+i, shift is unlikely to
have been released by the time our code runs, meaning the user accidentally
triggers the new code. We could potentially wait a while before bringing
up the dialog, but then we're forced to guess at how long it will take the
user to release the key.

One alternative would be to use alt instead of shift, but then we need to
trigger our shortcut when that key is pressed as well, and it could
potentially cause a conflict with an add-on that already uses that
combination.

* Show extension in export dialog

* Continue to provide separate options for schema 11+18 colpkg export

* Default to colpkg export when using File>Export

* Improve appearance of combo boxes when switching between apkg/colpkg

+ Deal with long deck names

* Convert newlines to spaces when showing fields from import

Ensures each imported note appears on a separate line

* Don't separate total note count from the other summary lines

This may come down to personal preference, but I feel the other counts
are equally as important, and separating them feels like it makes it
a bit easier to ignore them.

* Fix 'deck not normal' error when importing a filtered deck for the 2nd time

* Fix [Identical] being shown on first import

* Revert "Continue to provide separate options for schema 11+18 colpkg export"

This reverts commit 8f0b2c175f4794d642823b60414d142a12768441.

Will use a different approach

* Move legacy support into a separate exporter option; add to apkg export

* Adjust 'too new' message to also apply to .apkg import case

* Show a better message when attempting to import new apkg into old code

Previously the user could end seeing a message like:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 1: invalid start byte

Unfortunately we can't retroactively fix this for older clients.

* Hide legacy support option in older exporting screen

* Reflect change from paths to fnames in type & name

* Make imported decks normal at once

Then skip special casing in update_deck(). Also skip updating
description if new one is empty.

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2022-05-02 21:12:46 +10:00
RumovZ
1e02980133
Fix previewer runtime error "deleted" (#1830) 2022-05-02 10:40:44 +10:00
Damien Elmes
27f2e39ff9
Drop default Show Answer/Good highlight (#1820)
Feedback welcome. Discussion at
https://forums.ankiweb.net/t/2-1-5-border-around-good/19175

Partially reverts 301c9587d1
2022-04-27 19:26:16 +10:00
Damien Elmes
ee70006ec4 Reset zoom on page transition
https://forums.ankiweb.net/t/2-1-50-zooming-in-while-reviewing-results-in-an-unusably-huge-deck-list/19283
2022-04-22 15:45:50 +10:00
RumovZ
aea7eb667e
Fix progress of chained operations (#1817)
* Fix progress of chained operations

Especially aborting colpkg import.

* Notify about missing progress dialog
2022-04-22 14:47:17 +10:00
Damien Elmes
280c06425d Increase compression on zstd packages 2022-04-22 13:52:24 +10:00
Abdo
6ea75df292
Fix pasting of local links to unsupported types that contain spaces (#1813)
This change causes local links to unsupported formats like PDF to be
handled by _processUrls() instead of _processText, converting them to
correct hyperlinks in case they contain spaces.
2022-04-21 14:10:53 +10:00
Damien Elmes
6f764aeda4 Fix custom browser font not being honored
https://forums.ankiweb.net/t/on-anki-2-1-50-browser-table-font-override-is-not-respected/19259
2022-04-21 13:28:22 +10:00
Damien Elmes
031fc625fd Update Mac build to Qt 6.3 2022-04-20 21:33:31 +10:00
Damien Elmes
30d55aa553 Only require ANKI_WAYLAND if frozen
Accidentally changed `and` to `or` while testing 7115caab13.
2022-04-20 19:41:41 +10:00
Damien Elmes
da0cbfec32 Add workaround for unwanted CF_HTML header when pasting on Windows
Fixes #1751 for now; hopefully we can roll this change back once 6.3.1
is out in 3-4 weeks.
2022-04-20 17:23:11 +10:00
Damien Elmes
3031219a34 Add workaround to ensure internal pastes flagged on Windows/Qt6
Fixes #1793
2022-04-20 17:05:24 +10:00
Damien Elmes
7115caab13 Default to X11 on Qt6 builds as well
Qt6 no longer appears to require QT_QPA_PLATFORM to be set.

https://forums.ankiweb.net/t/blury-interface-with-gnome-wayland-and-fractional-scaling/19196/4
2022-04-20 14:41:01 +10:00
Damien Elmes
adbe96ca00
Load page script after body created (#1802)
document.body must exist by the time the top level Svelte component
initializes.

https://forums.ankiweb.net/t/2-1-50-editor-wont-show-when-addons-load-many-js-files/19036
2022-04-19 17:16:56 +10:00
Damien Elmes
a7cb5e210e Close browser before full sync or colpkg import/export
Closes #1797
2022-04-19 17:10:34 +10:00
Luka Warren
0835129a00
Fix issue #1114 by scrolling the user to the top of the page (#1810)
* Scroll stats to top when exporting (#1114)

It's obviously a bit of a "hacky" solution, since it's slightly jarring for users to scroll down, click export, then find themselves all the way at the top again, but it's somewhat less confusing than wondering why your PDF is broken :-)

* Clarified comment in stats.py (#1114)

* Apply scrolling fix to new stats screen, not legacy stats (dae)

Also wait for JS callback before saving the PDF, as JS is executed
asynchronously.
2022-04-19 15:39:32 +10:00
Damien Elmes
a9769813ba Add back support for custom mountpoint in card stats
The move to separate .html files broke our legacy card stats routine.

Related: d1d71ffdbb
2022-04-15 15:30:05 +10:00
Damien Elmes
24ab8ac423 Fix copying text to external apps when running on Gnome
Mutter seems to get confused if we mutate the keyboard in dataChanged().

Closes #1799
2022-04-15 12:09:56 +10:00
RumovZ
e29a5f779b
Fix selector index after programatic search (#1796) 2022-04-14 18:46:40 +10:00
Damien Elmes
29c48a60e0 Fix illegible calendar buttons in dark mode on Mac/Linux
https://forums.ankiweb.net/t/macos-apple-silicon-2-1-50-dark-mode-statistics-heatmap-buttons-dont-have-icons/18951

This button code is in need of a cleanup.
2022-04-13 13:53:45 +10:00
Damien Elmes
0b2a226dc8 Add mock stdout/stderr for console=False case on Windows
PyInstaller provided a NulWriter when running in GUI mode, but stdout/
stderr now default to None with PyOxidizer.

Fixes #1786
2022-04-09 16:48:32 +10:00