mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement file deletion in data files manager
This commit is contained in:
parent
cbacc7c343
commit
380cdee85b
@ -16,8 +16,10 @@ from calibre.db.constants import DATA_DIR_NAME, DATA_FILE_PATTERN
|
|||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
choose_files, error_dialog, file_icon_provider, gprefs, question_dialog,
|
choose_files, error_dialog, file_icon_provider, gprefs, question_dialog,
|
||||||
)
|
)
|
||||||
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
from calibre.utils.icu import primary_sort_key
|
from calibre.utils.icu import primary_sort_key
|
||||||
|
from calibre.utils.recycle_bin import delete_file
|
||||||
|
|
||||||
|
|
||||||
class Files(QAbstractListModel):
|
class Files(QAbstractListModel):
|
||||||
@ -125,6 +127,9 @@ class DataFilesManager(Dialog):
|
|||||||
self.add_button = b = QPushButton(QIcon.ic('plus.png'), _('&Add files'), self)
|
self.add_button = b = QPushButton(QIcon.ic('plus.png'), _('&Add files'), self)
|
||||||
b.clicked.connect(self.add_files)
|
b.clicked.connect(self.add_files)
|
||||||
self.bb.addButton(b, QDialogButtonBox.ButtonRole.ActionRole)
|
self.bb.addButton(b, QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
|
self.remove_button = b = QPushButton(QIcon.ic('minus.png'), _('&Remove files'), self)
|
||||||
|
b.clicked.connect(self.remove_files)
|
||||||
|
self.bb.addButton(b, QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
|
|
||||||
self.current_changed()
|
self.current_changed()
|
||||||
self.resize(self.sizeHint())
|
self.resize(self.sizeHint())
|
||||||
@ -204,6 +209,23 @@ class DataFilesManager(Dialog):
|
|||||||
with self.preserve_state():
|
with self.preserve_state():
|
||||||
self.files.refresh()
|
self.files.refresh()
|
||||||
|
|
||||||
|
def remove_files(self):
|
||||||
|
files = []
|
||||||
|
for idx in self.fview.selectionModel().selectedRows():
|
||||||
|
files.append(self.files.item_at(idx.row()))
|
||||||
|
if not files:
|
||||||
|
return error_dialog(self, _('Cannot delete'), _('No files selected to remove'), show=True)
|
||||||
|
if len(files) == 1:
|
||||||
|
msg = _('Send the file "{}" to the Recycle Bin?').format(files[0].relpath.replace('/', os.sep))
|
||||||
|
else:
|
||||||
|
msg = _('Send the {} selected filed to the Recycle Bin?').format(len(files))
|
||||||
|
if not confirm(msg, 'manage-data-files-confirm-delete'):
|
||||||
|
return
|
||||||
|
for f in files:
|
||||||
|
delete_file(f.file_path, permanent=False)
|
||||||
|
with self.preserve_state():
|
||||||
|
self.files.refresh()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from calibre.gui2 import Application
|
from calibre.gui2 import Application
|
||||||
|
Loading…
x
Reference in New Issue
Block a user