Enhancement 1961639: Option to disable editing composite templates if edited with the Tab key

This commit is contained in:
Charles Haley 2022-02-22 15:32:41 +00:00
parent e3fb3ce015
commit ab1d49d3f1
5 changed files with 59 additions and 8 deletions

View File

@ -210,6 +210,7 @@ def create_defs():
defs['edit_metadata_elision_point'] = "right" defs['edit_metadata_elision_point'] = "right"
defs['edit_metadata_bulk_cc_label_length'] = 25 defs['edit_metadata_bulk_cc_label_length'] = 25
defs['edit_metadata_single_cc_label_length'] = 12 defs['edit_metadata_single_cc_label_length'] = 12
defs['edit_metadata_edit_templates_only_F2_on_booklist'] = False
def migrate_tweak(tweak_name, pref_name): def migrate_tweak(tweak_name, pref_name):
# If the tweak has been changed then leave the tweak in the file so # If the tweak has been changed then leave the tweak in the file so

View File

@ -13,7 +13,7 @@ from qt.core import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox, QStyleOpt
QStyleOptionComboBox, QStyleOptionSpinBox, QLocale, QSize, QLineEdit, QDialog, QPalette) QStyleOptionComboBox, QStyleOptionSpinBox, QLocale, QSize, QLineEdit, QDialog, QPalette)
from calibre.ebooks.metadata import rating_to_stars from calibre.ebooks.metadata import rating_to_stars
from calibre.gui2 import UNDEFINED_QDATETIME, rating_font from calibre.gui2 import UNDEFINED_QDATETIME, rating_font, gprefs
from calibre.constants import iswindows from calibre.constants import iswindows
from calibre.gui2.widgets import EnLineEdit from calibre.gui2.widgets import EnLineEdit
from calibre.gui2.widgets2 import populate_standard_spinbox_context_menu, RatingEditor, DateTimeEdit as DateTimeEditBase from calibre.gui2.widgets2 import populate_standard_spinbox_context_menu, RatingEditor, DateTimeEdit as DateTimeEditBase
@ -744,8 +744,14 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{
Delegate for custom_column bool data. Delegate for custom_column bool data.
''' '''
QStyledItemDelegate.__init__(self, parent) QStyledItemDelegate.__init__(self, parent)
self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']
def createEditor(self, parent, option, index): def createEditor(self, parent, option, index):
if self.disallow_edit:
editor = QLineEdit(parent)
editor.setText(_('Template editing disabled'))
return editor
self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']
from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.dialogs.template_dialog import TemplateDialog
m = index.model() m = index.model()
mi = m.db.get_metadata(index.row(), index_is_id=False) mi = m.db.get_metadata(index.row(), index_is_id=False)
@ -762,4 +768,16 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{
m.setData(index, (editor.rule[1]), Qt.ItemDataRole.EditRole) m.setData(index, (editor.rule[1]), Qt.ItemDataRole.EditRole)
return None return None
def setEditorData(self, editor, index):
editor.setText('editing templates disabled')
editor.setReadOnly(True)
def setModelData(self, editor, model, index):
pass
def allow_one_edit(self):
self.disallow_edit = False
def refresh(self):
self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']
# }}} # }}}

View File

@ -866,6 +866,9 @@ class BooksView(QTableView): # {{{
self.was_restored = True self.was_restored = True
def refresh_composite_edit(self):
self.cc_template_delegate.refresh()
def refresh_row_sizing(self): def refresh_row_sizing(self):
self.row_sizing_done = False self.row_sizing_done = False
self.do_row_sizing() self.do_row_sizing()
@ -1225,6 +1228,10 @@ class BooksView(QTableView): # {{{
def keyPressEvent(self, ev): def keyPressEvent(self, ev):
if handle_enter_press(self, ev): if handle_enter_press(self, ev):
return return
if ev.key() == Qt.Key.Key_F2:
key = self.column_map[self.currentIndex().column()]
if self._model.db.field_metadata[key]['datatype'] == 'composite':
self.cc_template_delegate.allow_one_edit()
return QTableView.keyPressEvent(self, ev) return QTableView.keyPressEvent(self, ev)
def ids_to_rows(self, ids): def ids_to_rows(self, ids):

View File

@ -546,6 +546,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('edit_metadata_single_use_2_cols_for_custom_fields', gprefs) r('edit_metadata_single_use_2_cols_for_custom_fields', gprefs)
r('edit_metadata_bulk_cc_label_length', gprefs) r('edit_metadata_bulk_cc_label_length', gprefs)
r('edit_metadata_single_cc_label_length', gprefs) r('edit_metadata_single_cc_label_length', gprefs)
r('edit_metadata_templates_only_F2_on_booklist', gprefs)
self.current_font = self.initial_font = None self.current_font = self.initial_font = None
self.change_font_button.clicked.connect(self.change_font) self.change_font_button.clicked.connect(self.change_font)
@ -892,6 +893,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
gui.tags_view.reread_collapse_parameters() gui.tags_view.reread_collapse_parameters()
gui.library_view.refresh_book_details(force=True) gui.library_view.refresh_book_details(force=True)
gui.library_view.refresh_grid() gui.library_view.refresh_grid()
gui.library_view.refresh_composite_edit()
gui.library_view.set_row_header_visibility() gui.library_view.set_row_header_visibility()
gui.cover_flow.setShowReflections(gprefs['cover_browser_reflections']) gui.cover_flow.setShowReflections(gprefs['cover_browser_reflections'])
gui.cover_flow.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio']) gui.cover_flow.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio'])

View File

@ -1060,19 +1060,42 @@ will be elided, otherwise they will be word wrapped.</string>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_102"> <widget class="QLabel" name="label_1023">
<property name="text"> <property name="text">
<string>Elision point:</string> <string> </string>
</property>
<property name="buddy">
<cstring>opt_edit_metadata_elision_point</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QComboBox" name="opt_edit_metadata_elision_point"> <layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label_102">
<property name="text">
<string>Elision point:</string>
</property>
<property name="buddy">
<cstring>opt_edit_metadata_elision_point</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="opt_edit_metadata_elision_point">
<property name="toolTip">
<string>Choose where in the label to put the...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="opt_edit_metadata_templates_only_F2_on_booklist">
<property name="text">
<string>&amp;Tab key doesn't edit column templates on the book list</string>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Choose where in the label to put the...</string> <string>&lt;p&gt;Check this box to disable editing the template for
a "Column made from other columns" on the book list when the column is entered
using the Tab key. The F2 (Edit) key will still open the template editor.&lt;/p&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>