mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
rename support, titlebar, recent decks
- use libanki's new .rename(); don't need to close any deck windows anymore - titlebar updated only on app load now. No longer shows card count or due count, as computing it is expensive, and drops the deck name as it's more effective to use groups than separate decks now
This commit is contained in:
parent
0b95bab30b
commit
60001e41e4
1 changed files with 20 additions and 56 deletions
76
aqt/main.py
76
aqt/main.py
|
@ -85,6 +85,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.setupUpgrade()
|
self.setupUpgrade()
|
||||||
self.setupCardStats()
|
self.setupCardStats()
|
||||||
self.setupSchema()
|
self.setupSchema()
|
||||||
|
self.updateTitleBar()
|
||||||
# screens
|
# screens
|
||||||
self.setupDeckBrowser()
|
self.setupDeckBrowser()
|
||||||
self.setupOverview()
|
self.setupOverview()
|
||||||
|
@ -107,7 +108,6 @@ class AnkiQt(QMainWindow):
|
||||||
self.disableDeckMenuItems()
|
self.disableDeckMenuItems()
|
||||||
self.closeAllDeckWindows()
|
self.closeAllDeckWindows()
|
||||||
self.deckBrowser.show()
|
self.deckBrowser.show()
|
||||||
self.updateTitleBar()
|
|
||||||
|
|
||||||
def _deckLoadingState(self, oldState):
|
def _deckLoadingState(self, oldState):
|
||||||
"Run once, when deck is loaded."
|
"Run once, when deck is loaded."
|
||||||
|
@ -329,9 +329,6 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
if not ret:
|
if not ret:
|
||||||
showWarning(_("Unable to load file."))
|
showWarning(_("Unable to load file."))
|
||||||
self.deck = None
|
self.deck = None
|
||||||
else:
|
|
||||||
self.updateRecentFiles(file)
|
|
||||||
self.browserLastRefreshed = 0
|
|
||||||
getFile(self, _("Open deck"), accept, filter, dir)
|
getFile(self, _("Open deck"), accept, filter, dir)
|
||||||
|
|
||||||
def maybeLoadLastDeck(self, args):
|
def maybeLoadLastDeck(self, args):
|
||||||
|
@ -347,14 +344,6 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
if r:
|
if r:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def updateRecentFiles(self, path):
|
|
||||||
"Add the current deck to the list of recent files."
|
|
||||||
path = os.path.normpath(path)
|
|
||||||
if path in self.config['recentDeckPaths']:
|
|
||||||
self.config['recentDeckPaths'].remove(path)
|
|
||||||
self.config['recentDeckPaths'].insert(0, path)
|
|
||||||
self.config.save()
|
|
||||||
|
|
||||||
# Open recent
|
# Open recent
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -429,7 +418,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
return
|
return
|
||||||
self.loadDeck(path)
|
self.loadDeck(path)
|
||||||
if register:
|
if register:
|
||||||
self.updateRecentFiles(self.deck.path)
|
self.config.addRecentDeck(self.deck.path)
|
||||||
|
|
||||||
# Closing
|
# Closing
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -517,39 +506,28 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
|
|
||||||
def onRename(self):
|
def onRename(self):
|
||||||
"Rename deck."
|
"Rename deck."
|
||||||
return showInfo("now yet implemented")
|
dir = os.path.dirname(self.deck.path)
|
||||||
print "rename"
|
path = QFileDialog.getSaveFileName(self, _("Rename Deck"),
|
||||||
return
|
|
||||||
title = _("Rename Deck")
|
|
||||||
if self.deck.path:
|
|
||||||
dir = os.path.dirname(self.deck.path)
|
|
||||||
else:
|
|
||||||
dir = self.config['documentDir']
|
|
||||||
file = QFileDialog.getSaveFileName(self, title,
|
|
||||||
dir,
|
dir,
|
||||||
_("Deck files (*.anki)"),
|
_("Deck files (*.anki)"),
|
||||||
None,
|
None,
|
||||||
QFileDialog.DontConfirmOverwrite)
|
QFileDialog.DontConfirmOverwrite)
|
||||||
file = unicode(file)
|
path = unicode(path)
|
||||||
if not file:
|
if not path:
|
||||||
return
|
return
|
||||||
if not file.lower().endswith(".anki"):
|
if not path.lower().endswith(".anki"):
|
||||||
file += ".anki"
|
path += ".anki"
|
||||||
if self.deck.path:
|
if os.path.abspath(path) == os.path.abspath(self.deck.path):
|
||||||
if os.path.abspath(file) == os.path.abspath(self.deck.path):
|
return
|
||||||
return self.onSave()
|
if os.path.exists(path):
|
||||||
if os.path.exists(file):
|
|
||||||
# check for existence after extension
|
|
||||||
if not askUser(
|
if not askUser(
|
||||||
"This file exists. Are you sure you want to overwrite it?"):
|
"Selected file exists. Overwrite it?"):
|
||||||
return
|
return
|
||||||
self.closeAllDeckWindows()
|
old = self.deck.path
|
||||||
self.deck = self.deck.saveAs(file)
|
self.deck.rename(path)
|
||||||
self.updateTitleBar()
|
self.config.addRecentDeck(path)
|
||||||
self.updateRecentFiles(self.deck.path)
|
self.config.delRecentDeck(old)
|
||||||
self.browserLastRefreshed = 0
|
return path
|
||||||
self.moveToState("initial")
|
|
||||||
return file
|
|
||||||
|
|
||||||
# App exit
|
# App exit
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -814,6 +792,8 @@ Please choose a new deck name:"""))
|
||||||
"Cstats",
|
"Cstats",
|
||||||
"StudyOptions",
|
"StudyOptions",
|
||||||
"Overview",
|
"Overview",
|
||||||
|
"Groups",
|
||||||
|
"Models",
|
||||||
)
|
)
|
||||||
|
|
||||||
def setupMenus(self):
|
def setupMenus(self):
|
||||||
|
@ -872,23 +852,7 @@ Please choose a new deck name:"""))
|
||||||
self.enableDeckMenuItems(enabled=False)
|
self.enableDeckMenuItems(enabled=False)
|
||||||
|
|
||||||
def updateTitleBar(self):
|
def updateTitleBar(self):
|
||||||
"Display the current deck and card count in the titlebar."
|
self.setWindowTitle(aqt.appName)
|
||||||
title=aqt.appName
|
|
||||||
if self.deck:
|
|
||||||
deckpath = self.deck.name()
|
|
||||||
if not self.config['showProgress']:
|
|
||||||
title = deckpath + " - " + title
|
|
||||||
else:
|
|
||||||
title = _("%(path)s (%(due)d of %(cards)d due)"
|
|
||||||
" - %(title)s") % {
|
|
||||||
"path": deckpath,
|
|
||||||
"title": title,
|
|
||||||
"cards": self.deck.cardCount,
|
|
||||||
"due": self.deck.failedSoonCount + self.deck.revCount
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
title += " - " + _("Decks")
|
|
||||||
self.setWindowTitle(title)
|
|
||||||
|
|
||||||
def disableCardMenuItems(self):
|
def disableCardMenuItems(self):
|
||||||
self.maybeEnableUndo()
|
self.maybeEnableUndo()
|
||||||
|
|
Loading…
Reference in a new issue