mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Manage categories dialog: When editing a value with multiple values selected, change them all
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
986aff2890
@ -4,10 +4,13 @@
|
|||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
from PyQt5.Qt import (Qt, QDialog, QTableWidgetItem, QIcon, QByteArray, QSize,
|
from PyQt5.Qt import (Qt, QDialog, QTableWidgetItem, QIcon, QByteArray, QSize,
|
||||||
QDialogButtonBox, QTableWidget, QItemDelegate, QApplication)
|
QDialogButtonBox, QTableWidget, QItemDelegate, QApplication,
|
||||||
|
pyqtSignal)
|
||||||
|
|
||||||
from calibre.gui2.dialogs.tag_list_editor_ui import Ui_TagListEditor
|
from calibre.gui2.dialogs.tag_list_editor_ui import Ui_TagListEditor
|
||||||
|
from calibre.gui2.complete2 import EditWithComplete
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
|
from calibre.gui2.widgets import EnLineEdit
|
||||||
from calibre.gui2 import question_dialog, error_dialog, gprefs
|
from calibre.gui2 import question_dialog, error_dialog, gprefs
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
@ -20,6 +23,7 @@ class NameTableWidgetItem(QTableWidgetItem):
|
|||||||
self.initial_value = ''
|
self.initial_value = ''
|
||||||
self.current_value = ''
|
self.current_value = ''
|
||||||
self.is_deleted = False
|
self.is_deleted = False
|
||||||
|
self.is_placeholder = False
|
||||||
|
|
||||||
def data(self, role):
|
def data(self, role):
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
@ -54,9 +58,23 @@ class NameTableWidgetItem(QTableWidgetItem):
|
|||||||
return self.current_value
|
return self.current_value
|
||||||
|
|
||||||
def setText(self, txt):
|
def setText(self, txt):
|
||||||
|
self.is_placeholder = False
|
||||||
self.current_value = txt
|
self.current_value = txt
|
||||||
QTableWidgetItem.setText(self, txt)
|
QTableWidgetItem.setText(self, txt)
|
||||||
|
|
||||||
|
# Before this method is called, signals should be blocked for the
|
||||||
|
# table containing this item
|
||||||
|
def set_placeholder(self, txt):
|
||||||
|
self.text_before_placeholder = self.current_value
|
||||||
|
self.setText(txt)
|
||||||
|
self.is_placeholder = True
|
||||||
|
|
||||||
|
# Before this method is called, signals should be blocked for the
|
||||||
|
# table containing this item
|
||||||
|
def reset_placeholder(self):
|
||||||
|
if self.is_placeholder:
|
||||||
|
self.setText(self.text_before_placeholder)
|
||||||
|
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
return sort_key(unicode_type(self.text())) >= sort_key(unicode_type(other.text()))
|
return sort_key(unicode_type(self.text())) >= sort_key(unicode_type(other.text()))
|
||||||
|
|
||||||
@ -78,6 +96,8 @@ class CountTableWidgetItem(QTableWidgetItem):
|
|||||||
|
|
||||||
|
|
||||||
class EditColumnDelegate(QItemDelegate):
|
class EditColumnDelegate(QItemDelegate):
|
||||||
|
editing_finished = pyqtSignal(int)
|
||||||
|
editing_started = pyqtSignal(int)
|
||||||
|
|
||||||
def __init__(self, table):
|
def __init__(self, table):
|
||||||
QItemDelegate.__init__(self)
|
QItemDelegate.__init__(self)
|
||||||
@ -88,21 +108,24 @@ class EditColumnDelegate(QItemDelegate):
|
|||||||
self.completion_data = data
|
self.completion_data = data
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
|
self.editing_started.emit(index.row())
|
||||||
if index.column() == 0:
|
if index.column() == 0:
|
||||||
item = self.table.item(index.row(), 0)
|
self.item = self.table.itemFromIndex(index)
|
||||||
if item.is_deleted:
|
if self.item.is_deleted:
|
||||||
return None
|
return None
|
||||||
if self.completion_data:
|
if self.completion_data:
|
||||||
from calibre.gui2.complete2 import EditWithComplete
|
|
||||||
editor = EditWithComplete(parent)
|
editor = EditWithComplete(parent)
|
||||||
editor.set_separator(None)
|
editor.set_separator(None)
|
||||||
editor.update_items_cache(self.completion_data)
|
editor.update_items_cache(self.completion_data)
|
||||||
else:
|
else:
|
||||||
from calibre.gui2.widgets import EnLineEdit
|
|
||||||
editor = EnLineEdit(parent)
|
editor = EnLineEdit(parent)
|
||||||
return editor
|
return editor
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def destroyEditor(self, editor, index):
|
||||||
|
self.editing_finished.emit(index.row())
|
||||||
|
QItemDelegate.destroyEditor(self, editor, index)
|
||||||
|
|
||||||
|
|
||||||
class TagListEditor(QDialog, Ui_TagListEditor):
|
class TagListEditor(QDialog, Ui_TagListEditor):
|
||||||
|
|
||||||
@ -136,6 +159,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
self.ordered_tags = []
|
self.ordered_tags = []
|
||||||
self.sorter = sorter
|
self.sorter = sorter
|
||||||
self.get_book_ids = get_book_ids
|
self.get_book_ids = get_book_ids
|
||||||
|
self.text_before_editing = ''
|
||||||
|
|
||||||
# Set up the column headings
|
# Set up the column headings
|
||||||
self.down_arrow_icon = QIcon(I('arrow-down.png'))
|
self.down_arrow_icon = QIcon(I('arrow-down.png'))
|
||||||
@ -152,6 +176,8 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
self.was_order = 1
|
self.was_order = 1
|
||||||
|
|
||||||
self.edit_delegate = EditColumnDelegate(self.table)
|
self.edit_delegate = EditColumnDelegate(self.table)
|
||||||
|
self.edit_delegate.editing_finished.connect(self.stop_editing)
|
||||||
|
self.edit_delegate.editing_started.connect(self.start_editing)
|
||||||
self.table.setItemDelegateForColumn(0, self.edit_delegate)
|
self.table.setItemDelegateForColumn(0, self.edit_delegate)
|
||||||
|
|
||||||
# Add the data
|
# Add the data
|
||||||
@ -290,17 +316,39 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
gprefs['tag_list_editor_table_widths'] = self.table_column_widths
|
gprefs['tag_list_editor_table_widths'] = self.table_column_widths
|
||||||
gprefs['tag_list_editor_dialog_geometry'] = bytearray(self.saveGeometry())
|
gprefs['tag_list_editor_dialog_geometry'] = bytearray(self.saveGeometry())
|
||||||
|
|
||||||
def finish_editing(self, item):
|
def start_editing(self, on_row):
|
||||||
if not item.text():
|
items = self.table.selectedItems()
|
||||||
|
self.table.blockSignals(True)
|
||||||
|
for item in items:
|
||||||
|
if item.row() != on_row:
|
||||||
|
item.set_placeholder(_('Editing...'))
|
||||||
|
else:
|
||||||
|
self.text_before_editing = item.text()
|
||||||
|
self.table.blockSignals(False)
|
||||||
|
|
||||||
|
def stop_editing(self, on_row):
|
||||||
|
items = self.table.selectedItems()
|
||||||
|
self.table.blockSignals(True)
|
||||||
|
for item in items:
|
||||||
|
if item.row() != on_row and item.is_placeholder:
|
||||||
|
item.reset_placeholder()
|
||||||
|
self.table.blockSignals(False)
|
||||||
|
|
||||||
|
def finish_editing(self, edited_item):
|
||||||
|
if not edited_item.text():
|
||||||
error_dialog(self, _('Item is blank'), _(
|
error_dialog(self, _('Item is blank'), _(
|
||||||
'An item cannot be set to nothing. Delete it instead.'), show=True)
|
'An item cannot be set to nothing. Delete it instead.'), show=True)
|
||||||
item.setText(item.initial_text())
|
|
||||||
return
|
|
||||||
if item.text() != item.initial_text():
|
|
||||||
id_ = int(item.data(Qt.UserRole))
|
|
||||||
self.to_rename[id_] = unicode_type(item.text())
|
|
||||||
orig = self.table.item(item.row(), 2)
|
|
||||||
self.table.blockSignals(True)
|
self.table.blockSignals(True)
|
||||||
|
edited_item.setText(self.text_before_editing)
|
||||||
|
self.table.blockSignals(False)
|
||||||
|
return
|
||||||
|
items = self.table.selectedItems()
|
||||||
|
self.table.blockSignals(True)
|
||||||
|
for item in items:
|
||||||
|
id_ = int(item.data(Qt.UserRole))
|
||||||
|
self.to_rename[id_] = unicode_type(edited_item.text())
|
||||||
|
orig = self.table.item(item.row(), 2)
|
||||||
|
item.setText(edited_item.text())
|
||||||
orig.setData(Qt.DisplayRole, item.initial_text())
|
orig.setData(Qt.DisplayRole, item.initial_text())
|
||||||
self.table.blockSignals(False)
|
self.table.blockSignals(False)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user