Commit Graph

81 Commits

Author SHA1 Message Date
Damien Elmes
9b6a21126d drag&drop support, and paste refactor
- insert resulting html directly into fields instead of relying on
fragile clipboard rewriting
- catch paste events in js and send them back to python so we cover
all possible ways of pasting
- use checksum in pasted image filenames instead of .cacheKey(),
which was not unique across runs
- try each _processX() in turn instead of having special cases inside
them
- rewrite the HTML filtering:
 - img rewriting and stripping of certain tags handled in bs4; other
 processing handled in js for easier sharing with other clients
 - use a whitelist of HTML tags and properties instead of focusing
 mainly on webkit cruft
 - don't run filter when focus lost, as it no longer seems to
 be necessary
 - the "strip html" option is currently ignored
2016-12-15 18:14:47 +10:00
noobie
1a665cc185 Suppress the BeautifulSoup filename warning
Bs4 will raise a warning if the markup (field input) starts with '/'. Suppressing the warning is probably the easiest solution, as Bs4 will still process it (no disadvantages?).
2016-10-20 04:00:34 +02:00
Damien Elmes
8e71554ac4 saveNow() now requires a callback
the current code was freezing when clicking on 'cards' in the
browser - it looks like like the javascript callback was never
being called despite calling processEvents(). so we need to
refactor the code to call saveNow() with a callback that does the
subsequent processing.

a lot of the browser code was implicitly calling saveNow() via
beginReset(), so we've had to change all that code to save
immediately before it begins any processing. found a probable bug in
the process - it doesn't look like onRowChange() was saving before
overwriting the note, so theoretically edits could be lost if the
user switched to another card very quickly after typing something.

onSearch() has been split into a GUI-activated onSearchActivated()
that takes care of saving, and a lower level search() that refreshes
the current search. it keeps track of the last search via an instance
variable so that it refreshes properly if a user accidentally adds
some characters to their search without activating the search, then
does something like reverse the sort order.
2016-07-14 20:23:44 +10:00
Damien Elmes
3fa597ed1a wait until saveNow() is done
fixes content missing if typed right before save, and add window
complaining that fields aren't empty when they appear so
2016-07-12 13:30:10 +10:00
Damien Elmes
a8e2f992c8 image support 2016-07-07 23:39:48 +10:00
Damien Elmes
eddef71f75 prevent field from collapsing 2016-07-07 17:41:47 +10:00
Damien Elmes
258a10edc7 add titles to various webviews to make them easy to locate 2016-07-07 17:23:13 +10:00
Damien Elmes
d94c011c88 fix clayout preview, js errors
.exec_() and webengineview don't seem to play nicely together
2016-07-07 12:32:27 +10:00
Damien Elmes
a001553f66 move the editor buttons into the webview
use new icons, which scale with dpi changes
2016-06-22 14:52:17 +10:00
Damien Elmes
d7339d9a27 update editor, key handling in webview
keyPressEvent/etc no longer work with qwebengineview, so we need to
install an event filter to catch things like ctrl+c. drag & drop
doesn't seem to be supported until 5.7
2016-06-06 17:54:39 +10:00
Damien Elmes
15b349e3a8 start port to python 3
unit tests pass and main screens of GUI load
2016-05-12 14:45:35 +10:00
Damien Elmes
80e45fee85 Revert "Deal with Internationalized Domain Name in URI"
This reverts commit a68af5f199.

Patch does not fix the issue on my machine, so reverting for now.
2016-04-27 20:43:11 +10:00
Roman Franchuk
a68af5f199 Deal with Internationalized Domain Name in URI
This fixes https://anki.tenderapp.com/discussions/ankidesktop/17132-anki-reports-an-error-when-pasting-an-image-from-non-ascii-url

The problem is that urllib2 can't work with IDN. However, it's perfectly valid
to have such URIs in HTML, and Firefox, when copying image, generates exactly
this kind of HTML.
2016-04-17 15:49:28 +03:00
Damien Elmes
6f95527758 use the larger arrow only on windows, and in other screens 2015-09-28 23:09:30 +10:00
Jonathan Hall
6f77eed9bf Recognize a couple new media formats.
Adding 'webp' was necessary for Anki to recognize WebP images
(https://developers.google.com/speed/webp/?csw=1) as images rather than
audio.  The addition of the audio formats was incidental, as it appears Anki
assumes audio files if a file is not an image file.
2015-03-15 17:33:48 -05:00
Thomas TEMPÉ
3d81ef2c68 Avoid calling checkValid on an empty note
Fix error message when editFocusLost is called after editor destruction

https://anki.tenderapp.com/discussions/ankidesktop/11175-bug-in-browser-revealed-by-add-on?unresolve=true
To reproduce:
1. Install the attached add-on. (All it does is register a function on the editFocusLost hook, and set the flag to 1 to signify that a field has been updated).
2. Run Anki. Enter the Browse window. Press Enter to display your deck.
3. Select one card.
4. Click inside one of the fields for that card. Now, when you leave that field, the editFocusLost hook will be called.
5. Now, select 2 notes from the browser, with your mouse, without clicking anywhere else before.

You will observe this error message:

Traceback (most recent call last):
File "aqt/progress.pyc", line 69, in handler 
File "aqt/editor.pyc", line 467, in onUpdate 
File "aqt/editor.pyc", line 572, in checkValid AttributeError: 'NoneType' object has no attribute 'fields'
2014-12-31 22:36:12 +08:00
Damien Elmes
ece78a7d11 allow all ankiwebview instances to take focus
the canFocus/canCopy separate variables was silly, as we ended up
with text that could be copied from the context menu but not with
a shortcut key. also we default to allowing focus now, since that's
the more sensible default. fixes copy issues with card info dialog and
some addons
2014-09-15 15:04:14 +09:00
Damien Elmes
d53346d783 limit url unquoting to image tags
this prevents random text like %20 in a field from being converted
when note is saved
2014-08-01 09:42:28 +09:00
Damien Elmes
f8bf8afe4a Revert "remove urllib.unquote() step in editor"
This reverts commit 23cec2d5e9.

without other changes, this causes double escaping when editing
2014-08-01 09:37:23 +09:00
Soren I. Bjornstad
23cec2d5e9 remove urllib.unquote() step in editor
Fixes bug #950. We need to keep an eye out for media filename problems,
as this line is probably not necessary anymore with changes to the way
Anki handles encoding but could potentially introduce issues.
2014-07-22 10:36:08 -05:00
dae
8dd88c5f30 add m4a to usable formats 2014-05-25 20:02:24 +09:00
Julien Baley
69a19b58c2 Fixes creation of Cloze when having a chained modifier on the left of cloze 2014-03-09 18:12:39 +00:00
Damien Elmes
96cc486528 editor needs to accept focus; rename cardViewer to canFocus 2014-02-18 15:13:59 +09:00
Damien Elmes
76ed611bc0 workaround for google images+safari 2014-01-14 14:59:16 +09:00
Damien Elmes
0372f30220 adjust media regexp to not trigger on mce_src
otherwise pasting the following will cause an error:

<img src="..." mce_src="/foo.png">
2013-11-27 19:24:41 +09:00
Damien Elmes
dc2fd097d8 if unrecognized url pasted in, paste as text
this fixes pasting a url copied from the location bar in chrome
2013-11-26 17:57:14 +09:00
Damien Elmes
927e618f53 disable plastique theme on osx as possible crash fix 2013-11-13 14:56:37 +09:00
Damien Elmes
4a9c08014e return of the evil bytestring windows exceptions 2013-10-20 11:01:57 +09:00
Damien Elmes
2fff30db2f prioritize urls over text; fixes linux fm drop (#945) 2013-09-20 14:41:56 +09:00
Damien Elmes
36e877fe12 work around crash on close when card layout opened on windows (#940) 2013-07-23 22:35:00 +09:00
Damien Elmes
402ec3a0b8 don't try to download local image urls 2013-07-18 20:44:33 +09:00
Damien Elmes
9ccb21fe09 fix incorrect code that was not restoring clipboard 2013-07-18 19:56:47 +09:00
Damien Elmes
6f66f11572 Merge pull request #40 from steveaw/add-hooks3
Add hooks for context menus
2013-07-16 19:08:59 -07:00
Damien Elmes
4c671b3676 work around linux crash on paste
https://anki.tenderapp.com/discussions/ankidesktop/2019-inaccessible-firewall-blocked-media-url-paste-hangs-anki-for-a-minute-until-a-network-is-unreachable-like-message-appears
2013-07-17 10:19:09 +09:00
steveaw
e5bc1650f9 Add hooks for context menus 2013-07-16 17:42:50 +10:00
Damien Elmes
ffff271362 make sure we strip <!--anki--> 2013-07-11 21:22:51 +09:00
Damien Elmes
3007d884b8 if there's no html and we have an image, use that (#915) 2013-07-11 17:43:18 +09:00
Damien Elmes
e2d2b759a4 refactor media downloading on paste/drop
- use html as the first choice for incoming drops/pastes
- when filtering incoming html, automatically localize any remote image
  references
- add a special case for pasting/dropping from google images when html
  stripping is on
- move filtering code into editor
2013-07-11 17:21:16 +09:00
Damien Elmes
077d6b8187 Revert "force webkit to output <br> when enter pressed, instead of div"
This reverts commit e63c8e5619.
2013-06-14 13:11:48 +09:00
Damien Elmes
24995de437 Revert "need to strip trailing <br /> when saving fields"
This reverts commit f10b336fb9.
2013-06-14 13:11:26 +09:00
Damien Elmes
49ea66bca9 Revert "add a hack to prevent double newlines when deleting formatting"
This reverts commit ecf9776f90.
2013-06-14 13:11:04 +09:00
Damien Elmes
426eff4cff prioritize images over html for now
when a user copies an image from the browser to the clipboard, we need to do
this so the image pastes, as we currently don't support images derived from
html pastes (issue 92)
2013-06-10 16:04:58 +09:00
Damien Elmes
78155afb09 we shouldn't be quoting sound tags 2013-05-27 12:15:21 +09:00
Damien Elmes
9c24c41b90 we do need to quote when adding media
contrary to commit 3576475, we do need to quote when adding media on windows
as well, as it seems webkit can not handle all representations variants when
passed unicode

as we're stripping # and % when adding characters, hopefully that's the last
of it!
2013-05-27 11:26:02 +09:00
Damien Elmes
48f40c4884 ignore sticky fields when checking if blank (#843) 2013-05-24 12:04:28 +09:00
Damien Elmes
cc73a3bb42 work around broken images when pasting/attaching on linux 2013-05-24 10:50:15 +09:00
Damien Elmes
ecf9776f90 add a hack to prevent double newlines when deleting formatting
prior to this change, if you entered an empty field, turned on bold,
typed some text, and then backspaced over the text, it would expand
to two lines and the formatting would not go away
2013-05-23 12:31:49 +09:00
Damien Elmes
34b7eaf4c9 replace implicit styling at the top, and catch style missing case 2013-05-23 12:00:28 +09:00
Damien Elmes
b1ae088042 can't assign tuple to bs attrs without breaking later code 2013-05-23 11:37:14 +09:00
Damien Elmes
04b010a6d1 make sure we focus first field when adding next note (#605) 2013-05-22 12:54:29 +09:00