mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enhancement 1961639: Option to disable editing composite templates if edited with the Tab key
This commit is contained in:
parent
e3fb3ce015
commit
ab1d49d3f1
@ -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
|
||||
|
@ -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']
|
||||
# }}}
|
||||
|
@ -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):
|
||||
|
@ -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'])
|
||||
|
@ -1060,6 +1060,15 @@ will be elided, otherwise they will be word wrapped.</string>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_1023">
|
||||
<property name="text">
|
||||
<string> </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_102">
|
||||
<property name="text">
|
||||
<string>Elision point:</string>
|
||||
@ -1069,7 +1078,7 @@ will be elided, otherwise they will be word wrapped.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item>
|
||||
<widget class="QComboBox" name="opt_edit_metadata_elision_point">
|
||||
<property name="toolTip">
|
||||
<string>Choose where in the label to put the...</string>
|
||||
@ -1078,6 +1087,20 @@ will be elided, otherwise they will be word wrapped.</string>
|
||||
</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>&Tab key doesn't edit column templates on the book list</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
|
Loading…
x
Reference in New Issue
Block a user