remember last selected card wherever possible

This commit is contained in:
Damien Elmes 2009-05-16 05:00:05 +09:00
parent b3aaf31f8a
commit bb43ed18b0

View file

@ -319,10 +319,9 @@ class EditDeck(QMainWindow):
self.drawTags() self.drawTags()
self.updateFilterLabel() self.updateFilterLabel()
self.show() self.show()
self.updateSearch()
if self.parent.currentCard: if self.parent.currentCard:
self.currentCard = self.parent.currentCard self.currentCard = self.parent.currentCard
self.focusCurrentCard() self.updateSearch()
if sys.platform.startswith("darwin"): if sys.platform.startswith("darwin"):
self.macCloseShortcut = QShortcut(QKeySequence("Ctrl+w"), self) self.macCloseShortcut = QShortcut(QKeySequence("Ctrl+w"), self)
self.connect(self.macCloseShortcut, SIGNAL("activated()"), self.connect(self.macCloseShortcut, SIGNAL("activated()"),
@ -556,23 +555,20 @@ class EditDeck(QMainWindow):
def updateSearch(self, force=True): def updateSearch(self, force=True):
if self.parent.inDbHandler: if self.parent.inDbHandler:
return return
idx = self.dialog.tableView.currentIndex()
row = idx.row()
self.model.searchStr = unicode(self.dialog.filterEdit.text()) self.model.searchStr = unicode(self.dialog.filterEdit.text())
self.model.showMatching(force) self.model.showMatching(force)
self.updateFilterLabel() self.updateFilterLabel()
self.onEvent() self.onEvent()
self.filterTimer = None self.filterTimer = None
if self.model.cards: if self.model.cards:
if row == -1:
row = 0
self.dialog.cardInfoGroup.show() self.dialog.cardInfoGroup.show()
self.dialog.fieldsArea.show() self.dialog.fieldsArea.show()
else: else:
self.dialog.cardInfoGroup.hide() self.dialog.cardInfoGroup.hide()
self.dialog.fieldsArea.hide() self.dialog.fieldsArea.hide()
self.dialog.tableView.selectRow(row) if not self.focusCurrentCard():
self.dialog.tableView.scrollTo(idx, QAbstractItemView.PositionAtCenter) if self.model.cards:
self.dialog.tableView.selectRow(0)
if not self.model.cards: if not self.model.cards:
self.editor.setFact(None) self.editor.setFact(None)
@ -587,6 +583,8 @@ class EditDeck(QMainWindow):
self.dialog.tableView.scrollTo( self.dialog.tableView.scrollTo(
self.model.index(currentCardIndex,0), self.model.index(currentCardIndex,0),
self.dialog.tableView.PositionAtCenter) self.dialog.tableView.PositionAtCenter)
return True
return False
def setupHeaders(self): def setupHeaders(self):
if not sys.platform.startswith("win32"): if not sys.platform.startswith("win32"):