Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fonol committed Sep 20, 2020
2 parents 593880b + 51fd715 commit b320edf
Show file tree
Hide file tree
Showing 28 changed files with 525 additions and 160 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ addon-packed.zip
build.bat
.vscode/*
user_files/siac-notes.db
user_files/siac_backups/*
user_files/data.json
web/node_modules/*
src/rs/siacrs/target/*
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"results.showIDButton": false,
"results.showCIDButton": false,
"results.hide_cloze_brackets": false,
"styles.night.tagBackgroundColor": "DarkOrange",
"styles.night.tagBackgroundColor": "Coral",
"styles.night.tagForegroundColor": "Black",
"styles.tagBackgroundColor": "#f0506e",
"styles.tagForegroundColor": "white",
Expand Down
37 changes: 33 additions & 4 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ def init_addon():
setup_hooks()

# add shortcuts
aqt.editor._html += """
<script>
document.addEventListener("keydown", function (e) {globalKeydown(e); }, false);
</script>"""
aqt.editor._html += """ <script> document.addEventListener("keydown", function (e) {globalKeydown(e); }, false); </script>"""

#this inserts all the javascript functions in scripts.js into the editor webview
aqt.editor._html += getScriptPlatformSpecific()
Expand All @@ -114,6 +111,13 @@ def init_addon():
#when a note is loaded (i.e. the add cards dialog is opened), we have to insert our html for the search ui
gui_hooks.editor_did_load_note.append(on_load_note)

# IO add note wrapping
if mw.addonManager.isEnabled("1374772155"):
try:
register_io_add_hook()
except:
pass

def webview_on_drop(web: aqt.editor.EditorWebView, evt: QDropEvent, _old: Callable):
""" If a pdf file is dropped, intercept and open Create Note dialog. """

Expand Down Expand Up @@ -454,6 +458,31 @@ def cb(can_load):
ix.ui.reading_modal.display(dialog.chosen_id)
ix.ui.js_with_cb("beforeNoteQuickOpen();", cb)


def register_io_add_hook():
""" Monkey patch IO note generation to save links to PDF page. """

io = __import__("1374772155")
old = io.ngen.ImgOccNoteGenerator._saveMaskAndReturnNote

def snew(gen, omask_path, qmask, amask, img, note_id, nid=None):
old(gen, omask_path, qmask, amask, img, note_id, nid)
index = get_index()
if index and index.ui.reading_modal.note_id and index.ui.reading_modal.note.is_pdf() and not nid:
stamp = utility.misc.get_milisec_stamp() - 1000
res = mw.col.db.list(f"select * from notes where id > {stamp}")
if res and len(res) > 0:
nid = index.ui.reading_modal.note_id
def cb(page: int):
if page is not None and page >= 0:
for anid in res:
link_note_and_page(nid, anid, page)
# update sidebar if shown
index.ui.js("updatePageSidebarIfShown()")
index.ui.reading_modal.page_displayed(cb)

io.ngen.ImgOccNoteGenerator._saveMaskAndReturnNote = snew

def setup_tagedit_timer():
global tagEditTimer
tagEditTimer = QTimer()
Expand Down
Loading

0 comments on commit b320edf

Please sign in to comment.