diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py
index 6094b6c5c0..90a75974b6 100644
--- a/src/calibre/gui2/__init__.py
+++ b/src/calibre/gui2/__init__.py
@@ -210,6 +210,7 @@ def create_defs():
defs['edit_metadata_elision_point'] = "right"
defs['edit_metadata_bulk_cc_label_length'] = 25
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):
# If the tweak has been changed then leave the tweak in the file so
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index cd79789ac9..5e5c02f25a 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -13,7 +13,7 @@ from qt.core import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox, QStyleOpt
QStyleOptionComboBox, QStyleOptionSpinBox, QLocale, QSize, QLineEdit, QDialog, QPalette)
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.gui2.widgets import EnLineEdit
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.
'''
QStyledItemDelegate.__init__(self, parent)
+ self.disallow_edit = gprefs['edit_metadata_templates_only_F2_on_booklist']
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
m = index.model()
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)
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']
# }}}
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index f28c89936f..689a32857b 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -866,6 +866,9 @@ class BooksView(QTableView): # {{{
self.was_restored = True
+ def refresh_composite_edit(self):
+ self.cc_template_delegate.refresh()
+
def refresh_row_sizing(self):
self.row_sizing_done = False
self.do_row_sizing()
@@ -1225,6 +1228,10 @@ class BooksView(QTableView): # {{{
def keyPressEvent(self, ev):
if handle_enter_press(self, ev):
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)
def ids_to_rows(self, ids):
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index 571dacf8b0..aa6e54639b 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -546,6 +546,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('edit_metadata_single_use_2_cols_for_custom_fields', gprefs)
r('edit_metadata_bulk_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.change_font_button.clicked.connect(self.change_font)
@@ -892,6 +893,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
gui.tags_view.reread_collapse_parameters()
gui.library_view.refresh_book_details(force=True)
gui.library_view.refresh_grid()
+ gui.library_view.refresh_composite_edit()
gui.library_view.set_row_header_visibility()
gui.cover_flow.setShowReflections(gprefs['cover_browser_reflections'])
gui.cover_flow.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio'])
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index 3038e0b225..5e501dac70 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -1060,19 +1060,42 @@ will be elided, otherwise they will be word wrapped.
-
-
+
- Elision point:
-
-
- opt_edit_metadata_elision_point
+
-
-
+
+
-
+
+
+ Elision point:
+
+
+ opt_edit_metadata_elision_point
+
+
+
+ -
+
+
+ Choose where in the label to put the...
+
+
+
+
+
+ -
+
+
+ &Tab key doesn't edit column templates on the book list
+
- Choose where in the label to put the...
+ <p>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.</p>