mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fix close & selectfacts, only update field on change, remove yellow
This commit is contained in:
parent
e16fa4c259
commit
9c720452b9
3 changed files with 40 additions and 51 deletions
|
@ -192,32 +192,6 @@ class DeckModel(QAbstractTableModel):
|
||||||
else:
|
else:
|
||||||
return _("in %s") % fmtTimeSpan(secs, pad=0)
|
return _("in %s") % fmtTimeSpan(secs, pad=0)
|
||||||
|
|
||||||
class StatusDelegate(QItemDelegate):
|
|
||||||
|
|
||||||
def __init__(self, parent, model):
|
|
||||||
QItemDelegate.__init__(self, parent)
|
|
||||||
self.model = model
|
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
|
||||||
row = self.model.cards[index.row()]
|
|
||||||
standard = True
|
|
||||||
# tagged
|
|
||||||
if row[1] == 0:
|
|
||||||
brush = QBrush(QColor("#ffffaa"))
|
|
||||||
standard = False
|
|
||||||
if self.model.isDeleted(row[0]):
|
|
||||||
brush = QBrush(QColor("#ffaaaa"))
|
|
||||||
standard = False
|
|
||||||
if standard:
|
|
||||||
QItemDelegate.paint(self, painter, option, index)
|
|
||||||
return
|
|
||||||
# custom render
|
|
||||||
painter.save()
|
|
||||||
painter.fillRect(option.rect, brush)
|
|
||||||
data = self.model.data(index, Qt.DisplayRole)
|
|
||||||
self.drawDisplay(painter, option, option.rect, data.toString())
|
|
||||||
painter.restore()
|
|
||||||
|
|
||||||
class EditDeck(QMainWindow):
|
class EditDeck(QMainWindow):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
@ -233,7 +207,6 @@ class EditDeck(QMainWindow):
|
||||||
self.model = DeckModel(self.parent, self.parent.deck)
|
self.model = DeckModel(self.parent, self.parent.deck)
|
||||||
self.dialog.tableView.setSortingEnabled(False)
|
self.dialog.tableView.setSortingEnabled(False)
|
||||||
self.dialog.tableView.setModel(self.model)
|
self.dialog.tableView.setModel(self.model)
|
||||||
self.dialog.tableView.setItemDelegate(StatusDelegate(self, self.model))
|
|
||||||
self.dialog.tableView.selectionModel()
|
self.dialog.tableView.selectionModel()
|
||||||
self.dialog.tableView.setFont(QFont(
|
self.dialog.tableView.setFont(QFont(
|
||||||
self.config['editFontFamily'],
|
self.config['editFontFamily'],
|
||||||
|
@ -252,8 +225,8 @@ class EditDeck(QMainWindow):
|
||||||
self.show()
|
self.show()
|
||||||
self.selectLastCard()
|
self.selectLastCard()
|
||||||
|
|
||||||
def findCardInDeckModel( self, model, card ):
|
def findCardInDeckModel(self, model, card):
|
||||||
for i, thisCard in enumerate( model.cards ):
|
for i, thisCard in enumerate(model.cards):
|
||||||
if thisCard.id == card.id:
|
if thisCard.id == card.id:
|
||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
@ -263,12 +236,12 @@ class EditDeck(QMainWindow):
|
||||||
self.updateSearch()
|
self.updateSearch()
|
||||||
if self.parent.currentCard:
|
if self.parent.currentCard:
|
||||||
currentCardIndex = self.findCardInDeckModel(
|
currentCardIndex = self.findCardInDeckModel(
|
||||||
self.model, self.parent.currentCard )
|
self.model, self.parent.currentCard)
|
||||||
if currentCardIndex >= 0:
|
if currentCardIndex >= 0:
|
||||||
self.dialog.tableView.selectRow( currentCardIndex )
|
self.dialog.tableView.selectRow(currentCardIndex)
|
||||||
self.dialog.tableView.scrollTo(
|
self.dialog.tableView.scrollTo(
|
||||||
self.model.index(currentCardIndex,0),
|
self.model.index(currentCardIndex,0),
|
||||||
self.dialog.tableView.PositionAtTop )
|
self.dialog.tableView.PositionAtTop)
|
||||||
|
|
||||||
def setupFilter(self):
|
def setupFilter(self):
|
||||||
self.filterTimer = None
|
self.filterTimer = None
|
||||||
|
@ -411,24 +384,18 @@ class EditDeck(QMainWindow):
|
||||||
self.connect(self.dialog.actionDeleteTag, SIGNAL("triggered()"), self.deleteTags)
|
self.connect(self.dialog.actionDeleteTag, SIGNAL("triggered()"), self.deleteTags)
|
||||||
self.connect(self.dialog.actionAddCards, SIGNAL("triggered()"), self.addCards)
|
self.connect(self.dialog.actionAddCards, SIGNAL("triggered()"), self.addCards)
|
||||||
self.connect(self.dialog.actionResetProgress, SIGNAL("triggered()"), self.resetProgress)
|
self.connect(self.dialog.actionResetProgress, SIGNAL("triggered()"), self.resetProgress)
|
||||||
self.connect(self.dialog.actionSelectAll, SIGNAL("triggered()"), self.selectAll)
|
|
||||||
self.connect(self.dialog.actionSelectFacts, SIGNAL("triggered()"), self.selectFacts)
|
self.connect(self.dialog.actionSelectFacts, SIGNAL("triggered()"), self.selectFacts)
|
||||||
self.parent.runHook('editor.setupMenus', self)
|
self.parent.runHook('editor.setupMenus', self)
|
||||||
|
|
||||||
def onClose(self):
|
def onClose(self):
|
||||||
saveGeom(self, "editor")
|
|
||||||
self.editor.saveFieldsNow()
|
self.editor.saveFieldsNow()
|
||||||
if not self.factValid:
|
if not self.factValid:
|
||||||
ui.utils.showInfo(_(
|
ui.utils.showInfo(_(
|
||||||
"Some fields are missing or not unique."),
|
"Some fields are missing or not unique."),
|
||||||
parent=self, help="AddItems#AddError")
|
parent=self, help="AddItems#AddError")
|
||||||
return
|
return
|
||||||
|
saveGeom(self, "editor")
|
||||||
self.hide()
|
self.hide()
|
||||||
self.deck.deleteCards(self.model.deleted.keys())
|
|
||||||
if len(self.model.deleted):
|
|
||||||
self.parent.setStatus(
|
|
||||||
_("%(del)d deleted.") %
|
|
||||||
{"del": len(self.model.deleted)})
|
|
||||||
if self.origModTime != self.deck.modified:
|
if self.origModTime != self.deck.modified:
|
||||||
self.parent.reset()
|
self.parent.reset()
|
||||||
ui.dialogs.close("CardList")
|
ui.dialogs.close("CardList")
|
||||||
|
@ -539,18 +506,20 @@ where id in (%s)""" % ",".join([
|
||||||
if tags: self.deck.deleteTags(self.selectedFacts(), tags)
|
if tags: self.deck.deleteTags(self.selectedFacts(), tags)
|
||||||
self.updateAfterCardChange()
|
self.updateAfterCardChange()
|
||||||
|
|
||||||
|
def resetProgress(self):
|
||||||
|
self.deck.resetCards(self.selectedCards())
|
||||||
|
self.updateAfterCardChange(reset=True)
|
||||||
|
|
||||||
def addCards(self):
|
def addCards(self):
|
||||||
raise
|
raise
|
||||||
# for id in self.selectedFacts():
|
# for id in self.selectedFacts():
|
||||||
# self.deck.addMissingCards(self.deck.s.query(Fact).get(id))
|
# self.deck.addMissingCards(self.deck.s.query(Fact).get(id))
|
||||||
# self.updateSearch()
|
# self.updateSearch()
|
||||||
|
|
||||||
def resetProgress(self):
|
|
||||||
self.deck.resetCards(self.selectedCards())
|
|
||||||
self.updateAfterCardChange(reset=True)
|
|
||||||
|
|
||||||
def selectAll(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def selectFacts(self):
|
def selectFacts(self):
|
||||||
pass
|
sm = self.dialog.tableView.selectionModel()
|
||||||
|
cardIds = dict([(x, 1) for x in self.selectedFactsAsCards()])
|
||||||
|
for i, card in enumerate(self.model.cards):
|
||||||
|
if card.id in cardIds:
|
||||||
|
sm.select(self.model.index(i, 0),
|
||||||
|
QItemSelectionModel.Select | QItemSelectionModel.Rows)
|
||||||
|
|
|
@ -302,9 +302,13 @@ class FactEditor(object):
|
||||||
|
|
||||||
def saveFields(self):
|
def saveFields(self):
|
||||||
"Save field text into fact."
|
"Save field text into fact."
|
||||||
|
modified = False
|
||||||
for (w, f) in self.widgets.items():
|
for (w, f) in self.widgets.items():
|
||||||
v = tidyHTML(unicode(w.toHtml()))
|
v = tidyHTML(unicode(w.toHtml())).strip()
|
||||||
self.fact[f.name] = v.strip()
|
if self.fact[f.name] != v:
|
||||||
|
self.fact[f.name] = v
|
||||||
|
modified = True
|
||||||
|
if modified:
|
||||||
self.fact.setModified(textChanged=True)
|
self.fact.setModified(textChanged=True)
|
||||||
self.deck.setModified()
|
self.deck.setModified()
|
||||||
|
|
||||||
|
|
|
@ -314,5 +314,21 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>actionClose</sender>
|
||||||
|
<signal>triggered()</signal>
|
||||||
|
<receiver>MainWindow</receiver>
|
||||||
|
<slot>close()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>299</x>
|
||||||
|
<y>300</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Loading…
Reference in a new issue