Commit Graph

2920 Commits

Author SHA1 Message Date
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
Abdo
a99253b990
Allow passing args to anki-console.bat (#1785) 2022-04-09 14:40:26 +10:00
roxgib
77d14ddf1e
Add minimumContentsLength property to templatesBox (#1781)
Addresses #1777 by adding the `minimumContentsLength` property to the comboBox, which causes the size policy to not require expanding beyond that amount while still expanding if the user stretches the window manually.

Note that users who were previously experiencing large window widths due to the previous behaviour might see the same size again due the geometry being restored.
2022-04-09 13:55:03 +10:00
Aristotelis
8100e81789
Fix a number of bugs with add-on conflict resolution (#1780)
* Always enable manually installed add-ons

Ensures that manually installed add-ons are enabled after the installation, even if previously disabled.

Prevents scenarios where users could end up with no active add-on build (e.g. when switching between stable add-on builds distributed via AnkiWeb and betas distributed via GitHub).

* Improve type annotations

* Also enable disabled AnkiWeb add-ons upon interactive installation

Applies to add-ons that users actively install via their AnkiWeb ID. Updates are exempt, preserving whatever status add-ons were in.

* Prevent disabled add-ons from triggering conflicts

* Fix download_addons() not passing on force_enable argument (dae)
2022-04-09 13:51:59 +10:00
Damien Elmes
f2bffaa185 Tweaks to video driver handling
- Use a separate `gldriver6` file for configuring Qt6 so we don't
pick up old settings, or cause problems when switching back and forth.
- Default to OpenGL/auto instead of software, as that was what we
were using throughout the beta period.
- Try to detect driver failure on startup. Untested.
- Hide the selector in the preferences again, as if Anki is unable
to automatically switch drivers, the user could change the setting
and then not be able to get back into Anki.
2022-04-06 11:35:49 +10:00
Damien Elmes
bb940cad82 Match editor background to widget background in day mode 2022-04-05 10:55:25 +10:00
Damien Elmes
e4f46463f2 Expose video driver settings on Qt6, sans ANGLE 2022-04-03 19:57:58 +10:00
Damien Elmes
04f508d664 Add link to Wayland issues page 2022-04-03 16:50:00 +10:00
Damien Elmes
9ed12bb9d0 Call browser show hook prior to initiating search
https://github.com/ankipalace/advanced-browser/issues/141
2022-04-02 21:42:49 +10:00
Henrik Giesel
5b1fcccf33
Add extra button group for cloze commands (#1756)
* First attempt at adding a directory for icons under //ts

* Fix image import

* Fix import order

* Add cloze button group

* Fix issue with toolbar.toolbar dynamically slottable

* Change tooltip for repeating cloze deletion

* Fix repeat cloze button not working on macOS (dae)
2022-03-31 13:30:00 +10:00
Damien Elmes
39c3a8e104 Add Daniel to about screen
As always, anyone who has contributed and is missing, please let me
know, or send through a PR.
2022-03-30 13:49:07 +10:00
RumovZ
f1488b5983
Card type error (#1749)
* TemplateSaveError -> CardTypeError

* Don't show success tooltip if export fails

* Attach help page to error

Show help link if export fails due to card type error.

* Add type (dae)

* Add shared show_exception() (dae)

- Use a shared routine for printing standard backend errors, so that
we can take advantage of the help links in eg. the card layout screen
as well.
- The truthiness check on help in showInfo() would have ignored the
enum 0 value.
- Close the exporting dialog on a documented failure as well

* Fix local variable help_page
2022-03-28 22:17:50 +10:00
RumovZ
dd16890c11
Add Deleted error and disable all bad browser rows (#1742)
* Add Deleted error and disable all bad browser rows

* Avoid error when opening the browse screen to a card with a missing note (dae)

* In cards mode, a missing note is NotFound, not Deleted (dae)

So we distinguish between referential integrity error, and explicit
deletion.

* Remove redundant try block
2022-03-28 19:06:19 +10:00
Damien Elmes
45970fd0d2 Stop directing users to the old add-ons support site 2022-03-28 18:54:18 +10:00
Damien Elmes
7506d5f06c Fall back on regular deletion when trash folder unavailable
aa0cac1ed3 (commitcomment-69668166)
2022-03-28 14:40:31 +10:00
Damien Elmes
d2caab6d5a Update Python deps for Waitress fix
b28c9e8bda

Closes #1731
2022-03-23 22:22:23 +10:00
Damien Elmes
4515c41d2c
Backup improvements (#1728)
* Collection needs to be closed prior to backup even when not downgrading

* Backups -> BackupLimits

* Some improvements to backup_task

- backup_inner now returns the error instead of logging it, so that
the frontend can discover the issue when they await a backup (or create
another one)
- start_backup() was acquiring backup_task twice, and if another thread
started a backup between the two locks, the task could have been accidentally
overwritten without awaiting it

* Backups no longer require a collection close

- Instead of closing the collection, we ensure there is no active
transaction, and flush the WAL to disk. This means the undo history
is no longer lost on backup, which will be particularly useful if we
add a periodic backup in the future.
- Because a close is no longer required, backups are now achieved with
a separate command, instead of being included in CloseCollection().
- Full sync no longer requires an extra close+reopen step, and we now
wait for the backup to complete before proceeding.
- Create a backup before 'check db'

* Add File>Create Backup

https://forums.ankiweb.net/t/anki-mac-os-no-backup-on-sync/6157

* Defer checkpoint until we know we need it

When running periodic backups on a timer, we don't want to be fsync()ing
unnecessarily.

* Skip backup if modification time has not changed

We don't want the user leaving Anki open overnight, and coming back
to lots of identical backups.

* Periodic backups

Creates an automatic backup every 30 minutes if the collection has been
modified.

If there's a legacy checkpoint active, tries again 5 minutes later.

* Switch to a user-configurable backup duration

CreateBackup() now uses a simple force argument to determine whether
the user's limits should be respected or not, and only potentially
destructive ops (full download, check DB) override the user's configured
limit.

I considered having a separate limit for collection close and automatic
backups (eg keeping the previous 5 minute limit for collection close),
but that had two downsides:

- When the user closes their collection at the end of the day, they'd
get a recent backup. When they open the collection the next day, it
would get backed up again within 5 minutes, even though not much had
changed.
- Multiple limits are harder to communicate to users in the UI

Some remaining decisions I wasn't 100% sure about:

- If force is true but the collection has not been modified, the backup
will be skipped. If the user manually deleted their backups without
closing Anki, they wouldn't get a new one if the mtime hadn't changed.
- Force takes preference over the configured backup interval - should
we be ignored the user here, or take no backups at all?

Did a sneaky edit of the existing ftl string, as it hasn't been live
long.

* Move maybe_backup() into Collection

* Use a single method for manual and periodic backups

When manually creating a backup via the File menu, we no longer make
the user wait until the backup completes. As we continue waiting for
the backup in the background, if any errors occur, the user will get
notified about it fairly quickly.

* Show message to user if backup was skipped due to no changes

+ Don't incorrectly assert a backup will be created on force

* Add "automatic" to description

* Ensure we backup prior to importing colpkg if collection open

The backup doesn't happen when invoked from 'open backup' in the profile
screen, which matches Anki's previous behaviour. The user could
potentially clobber up to 30 minutes of their work if they exited to
the profile screen and restored a backup, but the alternative is we
create backups every time a backup is restored, which may happen a number
of times if the user is trying various ones. Or we could go back to a
separate throttle amount for this case, at the cost of more complexity.

* Remove the 0 special case on backup interval; minimum of 5 minutes

https://github.com/ankitects/anki/pull/1728#discussion_r830876833
2022-03-21 19:40:42 +10:00
Hikaru Y
704fb918c3
Fix NotFoundError when opening browser after switching profiles (#1725) 2022-03-21 14:45:22 +10:00
RumovZ
16fe18d033
Refactor export-import code and resolve fixmes (#1723)
* Write media files in chunks

* Test media file writing

* Add iter `ReadDirFiles`

* Remove ImportMediaError, fail fatally instead

Partially reverts commit f8ed4d89ba.

* Compare hashes of media files to be restored

* Improve `MediaCopier::copy()`

* Restore media files atomically with tempfile

* Make downgrade flag an enum

* Remove SchemaVersion::Latest in favour of Option

* Remove sha1 comparison again

* Remove unnecessary repr(u8) (dae)
2022-03-18 19:31:55 +10:00
Damien Elmes
f8ed4d89ba Add new error variant to frontend; ensure errors are mapped appropriately 2022-03-17 20:58:35 +10:00