mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Add revert to backup option to file menu (#3434)
* Add revert to backup context item * Fix contributors a new way * Change relative time to filename * Update ftl/qt/qt-accel.ftl (dae)
This commit is contained in:
parent
dc5fa60c8b
commit
df127b1af7
6 changed files with 53 additions and 17 deletions
|
@ -191,7 +191,7 @@ Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
|
|||
Themis Demetriades <themis100@outlook.com>
|
||||
Luke Bartholomew <lukesbart@icloud.com>
|
||||
Gregory Abrasaldo <degeemon@gmail.com>
|
||||
Taylor Obyen <https://github.com/taylorobyen>
|
||||
Taylor Obyen <taylorobyen@gmail.com>
|
||||
Kris Cherven <krischerven@gmail.com>
|
||||
twwn <github.com/twwn>
|
||||
|
||||
|
|
|
@ -43,3 +43,4 @@ qt-accel-reset-zoom = &Reset Zoom
|
|||
qt-accel-zoom-editor-in = Zoom Editor &In
|
||||
qt-accel-zoom-editor-out = Zoom Editor &Out
|
||||
qt-accel-create-backup = Create &Backup
|
||||
qt-accel-load-backup = &Revert to Backup
|
||||
|
|
|
@ -38,7 +38,7 @@ qt-misc-please-select-1-card = (please select 1 card)
|
|||
qt-misc-please-select-a-deck = Please select a deck.
|
||||
qt-misc-please-use-fileimport-to-import-this = Please use File>Import to import this file.
|
||||
qt-misc-processing = Processing...
|
||||
qt-misc-replace-your-collection-with-an-earlier = Replace your collection with an earlier backup?
|
||||
qt-misc-replace-your-collection-with-an-earlier = Replace your collection with an earlier backup from { $val }?
|
||||
qt-misc-revert-to-backup = Revert to backup
|
||||
# please do not change the quote character, and please only change the font name if you have confirmed the new name is a valid Windows font
|
||||
qt-misc-segoe-ui = "Segoe UI"
|
||||
|
|
|
@ -147,6 +147,7 @@ def show(mw: aqt.AnkiQt) -> QDialog:
|
|||
"Susanna Björverud",
|
||||
"Sylvain Durand",
|
||||
"Tacutu",
|
||||
"Taylor Obyen",
|
||||
"Timm Preetz",
|
||||
"Timo Paulssen",
|
||||
"Ursus",
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
<addaction name="actionExport"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="action_create_backup"/>
|
||||
<addaction name="action_open_backup"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
|
@ -277,6 +278,11 @@
|
|||
<string>qt_accel_create_backup</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_open_backup">
|
||||
<property name="text">
|
||||
<string>qt_accel_load_backup</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="icons.qrc"/>
|
||||
|
|
|
@ -424,32 +424,59 @@ class AnkiQt(QMainWindow):
|
|||
self.pm.remove(self.pm.name)
|
||||
self.refreshProfilesList()
|
||||
|
||||
def onOpenBackup(self) -> None:
|
||||
if not askUser(
|
||||
tr.qt_misc_replace_your_collection_with_an_earlier(),
|
||||
msgfunc=QMessageBox.warning,
|
||||
defaultno=True,
|
||||
):
|
||||
return
|
||||
def _handle_load_backup_success(self) -> None:
|
||||
"""
|
||||
Actions that occur when profile backup has been loaded successfully
|
||||
"""
|
||||
if self.state == "profileManager":
|
||||
self.profileDiag.closeWithoutQuitting()
|
||||
|
||||
def doOpen(path: str) -> None:
|
||||
self._openBackup(path)
|
||||
self.loadProfile()
|
||||
|
||||
def _handle_load_backup_failure(self, error: Exception) -> None:
|
||||
"""
|
||||
Actions that occur when a profile has loaded unsuccessfully
|
||||
"""
|
||||
showWarning(str(error))
|
||||
if self.state != "profileManager":
|
||||
self.loadProfile()
|
||||
|
||||
def onOpenBackup(self) -> None:
|
||||
|
||||
def do_open(path: str) -> None:
|
||||
if not askUser(
|
||||
tr.qt_misc_replace_your_collection_with_an_earlier(
|
||||
os.path.basename(path)
|
||||
),
|
||||
msgfunc=QMessageBox.warning,
|
||||
defaultno=True,
|
||||
):
|
||||
return
|
||||
|
||||
showInfo(tr.qt_misc_automatic_syncing_and_backups_have_been())
|
||||
|
||||
# Collection is still loaded if called from main window, so we unload. This is already
|
||||
# unloaded if called from the ProfileManager window.
|
||||
if self.col:
|
||||
self.unloadProfile(lambda: self._start_restore_backup(path))
|
||||
return
|
||||
|
||||
self._start_restore_backup(path)
|
||||
|
||||
getFile(
|
||||
self.profileDiag,
|
||||
self.profileDiag if self.state == "profileManager" else self,
|
||||
tr.qt_misc_revert_to_backup(),
|
||||
cb=doOpen, # type: ignore
|
||||
cb=do_open, # type: ignore
|
||||
filter="*.colpkg",
|
||||
dir=self.pm.backupFolder(),
|
||||
)
|
||||
|
||||
def _openBackup(self, path: str) -> None:
|
||||
def _start_restore_backup(self, path: str):
|
||||
self.restoring_backup = True
|
||||
showInfo(tr.qt_misc_automatic_syncing_and_backups_have_been())
|
||||
|
||||
import_collection_package_op(
|
||||
self, path, success=self.onOpenProfile
|
||||
).run_in_background()
|
||||
self, path, success=self._handle_load_backup_success
|
||||
).failure(self._handle_load_backup_failure).run_in_background()
|
||||
|
||||
def _on_downgrade(self) -> None:
|
||||
self.progress.start()
|
||||
|
@ -1349,6 +1376,7 @@ title="{}" {}>{}</button>""".format(
|
|||
qconnect(m.actionImport.triggered, self.onImport)
|
||||
qconnect(m.actionExport.triggered, self.onExport)
|
||||
qconnect(m.action_create_backup.triggered, self.on_create_backup_now)
|
||||
qconnect(m.action_open_backup.triggered, self.onOpenBackup)
|
||||
qconnect(m.actionExit.triggered, self.close)
|
||||
|
||||
# Help
|
||||
|
|
Loading…
Reference in a new issue