mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Allow d'nd to the edit metadata action
This commit is contained in:
parent
c274ce5014
commit
6e03557e02
@ -27,6 +27,33 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
action_type = 'current'
|
action_type = 'current'
|
||||||
action_add_menu = True
|
action_add_menu = True
|
||||||
|
|
||||||
|
accepts_drops = True
|
||||||
|
|
||||||
|
def accept_enter_event(self, event, mime_data):
|
||||||
|
if mime_data.hasFormat("application/calibre+from_library"):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def accept_drag_move_event(self, event, mime_data):
|
||||||
|
if mime_data.hasFormat("application/calibre+from_library"):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def drop_event(self, event, mime_data):
|
||||||
|
mime = 'application/calibre+from_library'
|
||||||
|
if mime_data.hasFormat(mime):
|
||||||
|
self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split()))
|
||||||
|
QTimer.singleShot(1, self.do_drop)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def do_drop(self):
|
||||||
|
book_ids = self.dropped_ids
|
||||||
|
del self.dropped_ids
|
||||||
|
db = self.gui.library_view.model().db
|
||||||
|
rows = [db.row(i) for i in book_ids]
|
||||||
|
self.edit_metadata_for(rows, book_ids)
|
||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
md = self.qaction.menu()
|
md = self.qaction.menu()
|
||||||
cm = partial(self.create_menu_action, md)
|
cm = partial(self.create_menu_action, md)
|
||||||
@ -186,18 +213,23 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
Edit metadata of selected books in library.
|
Edit metadata of selected books in library.
|
||||||
'''
|
'''
|
||||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||||
previous = self.gui.library_view.currentIndex()
|
|
||||||
if not rows or len(rows) == 0:
|
if not rows or len(rows) == 0:
|
||||||
d = error_dialog(self.gui, _('Cannot edit metadata'),
|
d = error_dialog(self.gui, _('Cannot edit metadata'),
|
||||||
_('No books selected'))
|
_('No books selected'))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
return
|
return
|
||||||
|
|
||||||
if bulk or (bulk is None and len(rows) > 1):
|
|
||||||
return self.edit_bulk_metadata(checked)
|
|
||||||
|
|
||||||
row_list = [r.row() for r in rows]
|
row_list = [r.row() for r in rows]
|
||||||
|
m = self.gui.library_view.model()
|
||||||
|
ids = [m.id(r) for r in rows]
|
||||||
|
self.edit_metadata_for(row_list, ids, bulk=bulk)
|
||||||
|
|
||||||
|
def edit_metadata_for(self, rows, book_ids, bulk=None):
|
||||||
|
previous = self.gui.library_view.currentIndex()
|
||||||
|
if bulk or (bulk is None and len(rows) > 1):
|
||||||
|
return self.do_edit_bulk_metadata(rows, book_ids)
|
||||||
|
|
||||||
current_row = 0
|
current_row = 0
|
||||||
|
row_list = rows
|
||||||
|
|
||||||
if len(row_list) == 1:
|
if len(row_list) == 1:
|
||||||
cr = row_list[0]
|
cr = row_list[0]
|
||||||
@ -242,7 +274,6 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
db = self.gui.library_view.model().db
|
db = self.gui.library_view.model().db
|
||||||
view.view_format(db.row(id_), fmt)
|
view.view_format(db.row(id_), fmt)
|
||||||
|
|
||||||
|
|
||||||
def edit_bulk_metadata(self, checked):
|
def edit_bulk_metadata(self, checked):
|
||||||
'''
|
'''
|
||||||
Edit metadata of selected books in library in bulk.
|
Edit metadata of selected books in library in bulk.
|
||||||
@ -256,6 +287,9 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
_('No books selected'))
|
_('No books selected'))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
return
|
return
|
||||||
|
self.do_edit_bulk_metadata(rows, ids)
|
||||||
|
|
||||||
|
def do_edit_bulk_metadata(self, rows, book_ids):
|
||||||
# Prevent the TagView from updating due to signals from the database
|
# Prevent the TagView from updating due to signals from the database
|
||||||
self.gui.tags_view.blockSignals(True)
|
self.gui.tags_view.blockSignals(True)
|
||||||
changed = False
|
changed = False
|
||||||
@ -278,7 +312,7 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
self.gui.tags_view.recount()
|
self.gui.tags_view.recount()
|
||||||
if self.gui.cover_flow:
|
if self.gui.cover_flow:
|
||||||
self.gui.cover_flow.dataChanged()
|
self.gui.cover_flow.dataChanged()
|
||||||
self.gui.library_view.select_rows(ids)
|
self.gui.library_view.select_rows(book_ids)
|
||||||
|
|
||||||
# Merge books {{{
|
# Merge books {{{
|
||||||
def merge_books(self, safe_merge=False, merge_only_formats=False):
|
def merge_books(self, safe_merge=False, merge_only_formats=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user