Implemented: config file, default open/close state, default split ratio, toolbar icon
This commit is contained in:
parent
30394c02d5
commit
ef413c20ee
@ -6,6 +6,7 @@ from aqt.utils import *
|
|||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
from aqt.webview import AnkiWebView
|
from aqt.webview import AnkiWebView
|
||||||
|
|
||||||
|
config = mw.addonManager.getConfig(__name__)
|
||||||
|
|
||||||
class EditorPreview(object):
|
class EditorPreview(object):
|
||||||
js=[
|
js=[
|
||||||
@ -37,6 +38,9 @@ class EditorPreview(object):
|
|||||||
context=ed,
|
context=ed,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not config['showPreviewAutomatically']:
|
||||||
|
ed.webview.hide()
|
||||||
|
|
||||||
self._inject_splitter(ed)
|
self._inject_splitter(ed)
|
||||||
gui_hooks.editor_did_fire_typing_timer.append(lambda o: self.onedit_hook(ed, o))
|
gui_hooks.editor_did_fire_typing_timer.append(lambda o: self.onedit_hook(ed, o))
|
||||||
gui_hooks.editor_did_load_note.append(lambda o: None if o != ed else self.editor_note_hook(o))
|
gui_hooks.editor_did_load_note.append(lambda o: None if o != ed else self.editor_note_hook(o))
|
||||||
@ -49,9 +53,10 @@ class EditorPreview(object):
|
|||||||
layout.removeWidget(editor.web)
|
layout.removeWidget(editor.web)
|
||||||
split.addWidget(editor.web)
|
split.addWidget(editor.web)
|
||||||
split.addWidget(editor.webview)
|
split.addWidget(editor.webview)
|
||||||
split.setStretchFactor(0, 0)
|
splitRatio = config['splitRatio']
|
||||||
split.setStretchFactor(1, 1)
|
upperR, lowerR = [int(r) for r in splitRatio.split(":")]
|
||||||
split.setStretchFactor(2, 1)
|
split.setStretchFactor(0, upperR)
|
||||||
|
split.setStretchFactor(1, lowerR)
|
||||||
layout.insertWidget(web_index, split)
|
layout.insertWidget(web_index, split)
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +64,9 @@ class EditorPreview(object):
|
|||||||
self.onedit_hook(editor, editor.note)
|
self.onedit_hook(editor, editor.note)
|
||||||
|
|
||||||
def editor_init_button_hook(self, buttons, editor):
|
def editor_init_button_hook(self, buttons, editor):
|
||||||
b = editor.addButton(icon=None, cmd="_editor_toggle_preview", label='P', tip='Toggle Live Preview',
|
addon_path = os.path.dirname(__file__)
|
||||||
|
icons_dir = os.path.join(addon_path, 'icons')
|
||||||
|
b = editor.addButton(icon=os.path.join(icons_dir, 'file.svg'), cmd="_editor_toggle_preview", tip='Toggle Live Preview',
|
||||||
func=lambda o=editor: self.onEditorPreviewButton(o), disables=False
|
func=lambda o=editor: self.onEditorPreviewButton(o), disables=False
|
||||||
)
|
)
|
||||||
buttons.append(b)
|
buttons.append(b)
|
||||||
|
1
src/config.json
Normal file
1
src/config.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"showPreviewAutomatically": true, "splitRatio": "4:1"}
|
6
src/config.md
Normal file
6
src/config.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
### Config
|
||||||
|
\- `showPreviewAutomatically` [boolean (true | false)]:<br/>
|
||||||
|
Defines if the preview window should show up automatically as you enter the Editor (default: true)<br/><br/>
|
||||||
|
\- `splitRatio` [int:int]:<br/>
|
||||||
|
Defines the default split ratio of the main view and preview view (default: 4:1)
|
||||||
|
<br/>
|
BIN
src/icons/.DS_Store
vendored
Normal file
BIN
src/icons/.DS_Store
vendored
Normal file
Binary file not shown.
19
src/icons/file.svg
Normal file
19
src/icons/file.svg
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 26.4.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve">
|
||||||
|
<style type="text/css">
|
||||||
|
.st0{stroke:#000000;stroke-width:0.5;stroke-miterlimit:10;}
|
||||||
|
</style>
|
||||||
|
<g>
|
||||||
|
<path class="st0" d="M8.7,14.1H2.2c-0.2,0-0.4-0.2-0.4-0.4V2.4c0-0.2,0.2-0.4,0.4-0.4h9.3c0.2,0,0.4,0.2,0.4,0.4v2.8
|
||||||
|
c0,0.2,0.2,0.4,0.4,0.4c0.2,0,0.4-0.2,0.4-0.4V2.4c0-0.7-0.6-1.3-1.3-1.3H2.2c-0.7,0-1.3,0.6-1.3,1.3v11.3c0,0.7,0.6,1.3,1.3,1.3
|
||||||
|
h6.5c0.2,0,0.4-0.2,0.4-0.4S9,14.1,8.7,14.1z"/>
|
||||||
|
<path class="st0" d="M15.4,14.2l-1.9-2c0.5-0.6,0.8-1.4,0.8-2.3c0-2-1.6-3.6-3.6-3.6S7.1,8,7.1,10s1.6,3.6,3.6,3.6
|
||||||
|
c0.8,0,1.6-0.3,2.2-0.7l1.9,2c0.1,0.1,0.2,0.1,0.3,0.1c0.1,0,0.2,0,0.3-0.1C15.6,14.7,15.6,14.4,15.4,14.2L15.4,14.2z M10.7,12.7
|
||||||
|
C9.2,12.7,8,11.5,8,10s1.2-2.7,2.7-2.7s2.7,1.2,2.7,2.7S12.2,12.7,10.7,12.7z M9.1,5.2c0-0.2-0.2-0.4-0.4-0.4H3.6
|
||||||
|
C3.4,4.8,3.2,5,3.2,5.2c0,0.2,0.2,0.4,0.4,0.4h5.1C9,5.6,9.1,5.4,9.1,5.2z M6.5,7.6c0-0.2-0.2-0.4-0.4-0.4H3.6
|
||||||
|
c-0.2,0-0.4,0.2-0.4,0.4S3.4,8,3.6,8h2.5C6.3,8,6.5,7.8,6.5,7.6z M3.6,9.6c-0.2,0-0.4,0.2-0.4,0.4c0,0.2,0.2,0.4,0.4,0.4h1.3
|
||||||
|
c0.2,0,0.4-0.2,0.4-0.4c0-0.2-0.2-0.4-0.4-0.4H3.6z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in New Issue
Block a user