mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Merge pull request #914 from hgiesel/previewineditor
Preview Button in Editor instead of Browser
This commit is contained in:
commit
5f02be4943
5 changed files with 79 additions and 40 deletions
|
@ -624,12 +624,6 @@ class Browser(QMainWindow):
|
|||
# pylint: disable=unnecessary-lambda
|
||||
# actions
|
||||
f = self.form
|
||||
qconnect(f.previewButton.clicked, self.onTogglePreview)
|
||||
f.previewButton.setToolTip(
|
||||
tr(TR.BROWSING_PREVIEW_SELECTED_CARD, val=shortcut("Ctrl+Shift+P"))
|
||||
)
|
||||
f.previewButton.setShortcut("Ctrl+Shift+P")
|
||||
|
||||
qconnect(f.filter.clicked, self.onFilterButton)
|
||||
# edit
|
||||
qconnect(f.actionUndo.triggered, self.mw.onUndo)
|
||||
|
@ -874,7 +868,30 @@ QTableView {{ gridline-color: {grid} }}
|
|||
self.singleCard = False
|
||||
|
||||
def setupEditor(self):
|
||||
def add_preview_button(leftbuttons, editor):
|
||||
preview_shortcut = "Ctrl+Shift+P"
|
||||
leftbuttons.insert(
|
||||
0,
|
||||
editor.addButton(
|
||||
None,
|
||||
"preview",
|
||||
lambda _editor: self.onTogglePreview(),
|
||||
tr(
|
||||
TR.BROWSING_PREVIEW_SELECTED_CARD,
|
||||
val=shortcut(preview_shortcut),
|
||||
),
|
||||
tr(TR.ACTIONS_PREVIEW),
|
||||
id="previewButton",
|
||||
keys=preview_shortcut,
|
||||
disables=False,
|
||||
rightside=False,
|
||||
toggleable=True,
|
||||
),
|
||||
)
|
||||
|
||||
gui_hooks.editor_did_init_left_buttons.append(add_preview_button)
|
||||
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self)
|
||||
gui_hooks.editor_did_init_left_buttons.remove(add_preview_button)
|
||||
|
||||
def onRowChanged(self, current, previous):
|
||||
"Update current note and hide/show editor."
|
||||
|
@ -1567,7 +1584,10 @@ where id in %s"""
|
|||
|
||||
def _renderPreview(self):
|
||||
if self._previewer:
|
||||
if self.singleCard:
|
||||
self._previewer.render_card()
|
||||
else:
|
||||
self.onTogglePreview()
|
||||
|
||||
def _cleanup_preview(self):
|
||||
if self._previewer:
|
||||
|
@ -1575,6 +1595,8 @@ where id in %s"""
|
|||
self._previewer.close()
|
||||
|
||||
def _on_preview_closed(self):
|
||||
if self.editor.web:
|
||||
self.editor.web.eval("$('#previewButton').removeClass('highlighted')")
|
||||
self._previewer = None
|
||||
|
||||
# Card deletion
|
||||
|
|
|
@ -65,15 +65,33 @@ button.linkb {
|
|||
box-shadow: none;
|
||||
padding: 0px 2px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
button.linkb:disabled {
|
||||
&:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.nightMode & > img {
|
||||
filter: invert(180);
|
||||
}
|
||||
}
|
||||
|
||||
button:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button.highlighted {
|
||||
.nightMode #topbutsleft & {
|
||||
background: linear-gradient(0deg, #333333 0%, #434343 100%);
|
||||
}
|
||||
|
||||
#topbutsleft & {
|
||||
background-color: lightgrey;
|
||||
}
|
||||
|
||||
#topbutsright & {
|
||||
border-bottom: 3px solid #000;
|
||||
}
|
||||
}
|
||||
|
||||
#fields {
|
||||
|
@ -88,12 +106,6 @@ button.highlighted {
|
|||
color: var(--link);
|
||||
}
|
||||
|
||||
.nightMode {
|
||||
button.linkb > img {
|
||||
filter: invert(180);
|
||||
}
|
||||
}
|
||||
|
||||
.drawing {
|
||||
zoom: 50%;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import urllib.error
|
|||
import urllib.parse
|
||||
import urllib.request
|
||||
import warnings
|
||||
from random import randrange
|
||||
from typing import Callable, List, Optional, Tuple
|
||||
|
||||
import bs4
|
||||
|
@ -251,12 +252,29 @@ class Editor:
|
|||
"""Assign func to bridge cmd, register shortcut, return button"""
|
||||
if func:
|
||||
self._links[cmd] = func
|
||||
|
||||
if keys:
|
||||
|
||||
def on_activated():
|
||||
func(self)
|
||||
|
||||
if toggleable:
|
||||
# generate a random id for triggering toggle
|
||||
id = id or str(randrange(1_000_000))
|
||||
|
||||
def on_hotkey():
|
||||
on_activated()
|
||||
self.web.eval(f'toggleEditorButton("#{id}");')
|
||||
|
||||
else:
|
||||
on_hotkey = on_activated
|
||||
|
||||
QShortcut( # type: ignore
|
||||
QKeySequence(keys),
|
||||
self.widget,
|
||||
activated=lambda s=self: func(s),
|
||||
activated=on_hotkey,
|
||||
)
|
||||
|
||||
btn = self._addButton(
|
||||
icon,
|
||||
cmd,
|
||||
|
|
|
@ -114,19 +114,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="previewButton">
|
||||
<property name="text">
|
||||
<string>ACTIONS_PREVIEW</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string notr="true">Ctrl+Shift+P</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="filter">
|
||||
<property name="text">
|
||||
|
|
|
@ -16,6 +16,7 @@ from aqt.qt import (
|
|||
QIcon,
|
||||
QKeySequence,
|
||||
QPixmap,
|
||||
QShortcut,
|
||||
Qt,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
|
@ -63,6 +64,9 @@ class Previewer(QDialog):
|
|||
def _create_gui(self):
|
||||
self.setWindowTitle(tr(TR.ACTIONS_PREVIEW))
|
||||
|
||||
self.close_shortcut = QShortcut(QKeySequence("Ctrl+Shift+P"), self)
|
||||
qconnect(self.close_shortcut.activated, self.close)
|
||||
|
||||
qconnect(self.finished, self._on_finished)
|
||||
self.silentlyClose = True
|
||||
self.vbox = QVBoxLayout()
|
||||
|
@ -305,10 +309,6 @@ class BrowserPreviewer(MultiCardPreviewer):
|
|||
self._last_card_id = c.id
|
||||
return changed
|
||||
|
||||
def _on_finished(self, ok):
|
||||
super()._on_finished(ok)
|
||||
self._parent.form.previewButton.setChecked(False)
|
||||
|
||||
def _on_prev_card(self):
|
||||
self._parent.editor.saveNow(
|
||||
lambda: self._parent._moveCur(QAbstractItemView.MoveUp)
|
||||
|
|
Loading…
Reference in a new issue