mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
Fixes #2062434 [[Enhancement] Book list header menu](https://bugs.launchpad.net/calibre/+bug/2062434)
This commit is contained in:
commit
ad8cddce40
@ -42,7 +42,8 @@ from qt.core import (
|
|||||||
|
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
from calibre.constants import filesystem_encoding, islinux
|
from calibre.constants import filesystem_encoding, islinux
|
||||||
from calibre.gui2 import BOOK_DETAILS_DISPLAY_DEBOUNCE_DELAY, FunctionDispatcher, error_dialog, gprefs
|
from calibre.gui2 import (BOOK_DETAILS_DISPLAY_DEBOUNCE_DELAY, FunctionDispatcher,
|
||||||
|
error_dialog, gprefs, show_restart_warning)
|
||||||
from calibre.gui2.dialogs.enum_values_edit import EnumValuesEdit
|
from calibre.gui2.dialogs.enum_values_edit import EnumValuesEdit
|
||||||
from calibre.gui2.gestures import GestureManager
|
from calibre.gui2.gestures import GestureManager
|
||||||
from calibre.gui2.library import DEFAULT_SORT
|
from calibre.gui2.library import DEFAULT_SORT
|
||||||
@ -68,6 +69,7 @@ from calibre.gui2.library.delegates import (
|
|||||||
)
|
)
|
||||||
from calibre.gui2.library.models import BooksModel, DeviceBooksModel
|
from calibre.gui2.library.models import BooksModel, DeviceBooksModel
|
||||||
from calibre.gui2.pin_columns import PinTableView
|
from calibre.gui2.pin_columns import PinTableView
|
||||||
|
from calibre.gui2.preferences.create_custom_column import CreateNewCustomColumn
|
||||||
from calibre.utils.config import prefs, tweaks
|
from calibre.utils.config import prefs, tweaks
|
||||||
from calibre.utils.icu import primary_sort_key
|
from calibre.utils.icu import primary_sort_key
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
@ -567,6 +569,18 @@ class BooksView(QTableView): # {{{
|
|||||||
view.apply_state(view.get_default_state())
|
view.apply_state(view.get_default_state())
|
||||||
elif action == 'addcustcol':
|
elif action == 'addcustcol':
|
||||||
self.add_column_signal.emit()
|
self.add_column_signal.emit()
|
||||||
|
elif action == 'editcustcol':
|
||||||
|
def show_restart_dialog():
|
||||||
|
from calibre.gui2.preferences.main import must_restart_message
|
||||||
|
if show_restart_warning(must_restart_message):
|
||||||
|
self.gui.quit(restart=True)
|
||||||
|
col_manager = CreateNewCustomColumn(self.gui)
|
||||||
|
if col_manager.must_restart():
|
||||||
|
show_restart_dialog()
|
||||||
|
else:
|
||||||
|
res = col_manager.edit_existing_column(column)
|
||||||
|
if res[0] == CreateNewCustomColumn.Result.COLUMN_EDITED:
|
||||||
|
show_restart_dialog()
|
||||||
elif action.startswith('align_'):
|
elif action.startswith('align_'):
|
||||||
alignment = action.partition('_')[-1]
|
alignment = action.partition('_')[-1]
|
||||||
self._model.change_alignment(column, alignment)
|
self._model.change_alignment(column, alignment)
|
||||||
@ -631,6 +645,13 @@ class BooksView(QTableView): # {{{
|
|||||||
ans.addAction(QIcon.ic('width.png'), _('Adjust width of column {0}').format(name),
|
ans.addAction(QIcon.ic('width.png'), _('Adjust width of column {0}').format(name),
|
||||||
partial(self.manually_adjust_column_size, view, col, name))
|
partial(self.manually_adjust_column_size, view, col, name))
|
||||||
|
|
||||||
|
if not isinstance(view, DeviceBooksView):
|
||||||
|
col_manager = CreateNewCustomColumn(self.gui)
|
||||||
|
if self.can_add_columns and self.model().is_custom_column(col):
|
||||||
|
act = ans.addAction(QIcon.ic('edit_input.png'), _('Edit column definition for %s') % name,
|
||||||
|
partial(handler, action='editcustcol'))
|
||||||
|
if col_manager.must_restart():
|
||||||
|
act.setEnabled(False)
|
||||||
if self.is_library_view:
|
if self.is_library_view:
|
||||||
if self._model.db.field_metadata[col]['is_category']:
|
if self._model.db.field_metadata[col]['is_category']:
|
||||||
act = ans.addAction(QIcon.ic('quickview.png'), _('Quickview column %s') % name,
|
act = ans.addAction(QIcon.ic('quickview.png'), _('Quickview column %s') % name,
|
||||||
@ -664,8 +685,10 @@ class BooksView(QTableView): # {{{
|
|||||||
partial(handler, action='reset_ondevice_width'))
|
partial(handler, action='reset_ondevice_width'))
|
||||||
ans.addAction(_('Restore default layout'), partial(handler, action='defaults'))
|
ans.addAction(_('Restore default layout'), partial(handler, action='defaults'))
|
||||||
if self.can_add_columns:
|
if self.can_add_columns:
|
||||||
ans.addAction(
|
act = ans.addAction(QIcon.ic('column.png'), _('Add your own columns'),
|
||||||
QIcon.ic('column.png'), _('Add your own columns'), partial(handler, action='addcustcol'))
|
partial(handler, action='addcustcol'))
|
||||||
|
col_manager = CreateNewCustomColumn(self.gui)
|
||||||
|
act.setEnabled(not col_manager.must_restart())
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def show_row_header_context_menu(self, pos):
|
def show_row_header_context_menu(self, pos):
|
||||||
|
@ -292,9 +292,15 @@ class CreateCustomColumn(QDialog):
|
|||||||
self.g = g = QGridLayout()
|
self.g = g = QGridLayout()
|
||||||
l.addLayout(g)
|
l.addLayout(g)
|
||||||
l.addStretch(10)
|
l.addStretch(10)
|
||||||
|
bbl = QHBoxLayout()
|
||||||
|
txt = QLabel(_('Pressing OK will require restarting calibre even if nothing was changed'))
|
||||||
|
txt.setWordWrap(True)
|
||||||
|
bbl.addWidget(txt)
|
||||||
|
bbl.addStretch(1)
|
||||||
self.button_box = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel, self)
|
self.button_box = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel, self)
|
||||||
bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
|
bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
|
||||||
l.addWidget(bb)
|
bbl.addWidget(bb)
|
||||||
|
l.addLayout(bbl)
|
||||||
|
|
||||||
def add_row(text, widget):
|
def add_row(text, widget):
|
||||||
if text is None:
|
if text is None:
|
||||||
@ -932,6 +938,7 @@ class CreateNewCustomColumn:
|
|||||||
INVALID_DISPLAY = 7
|
INVALID_DISPLAY = 7
|
||||||
EXCEPTION_RAISED = 8
|
EXCEPTION_RAISED = 8
|
||||||
MUST_RESTART = 9
|
MUST_RESTART = 9
|
||||||
|
COLUMN_EDITED = 11
|
||||||
|
|
||||||
def __init__(self, gui):
|
def __init__(self, gui):
|
||||||
self.gui = gui
|
self.gui = gui
|
||||||
@ -991,20 +998,40 @@ class CreateNewCustomColumn:
|
|||||||
'colnum': self.created_count,
|
'colnum': self.created_count,
|
||||||
'is_multiple': is_multiple,
|
'is_multiple': is_multiple,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return self._create_or_edit_column(lookup_name, freeze_lookup_name=freeze_lookup_name,
|
||||||
|
operation='create')
|
||||||
|
|
||||||
|
def edit_existing_column(self, lookup_name):
|
||||||
|
if lookup_name not in self.custcols:
|
||||||
|
return self.Result.INVALID_KEY
|
||||||
|
return self._create_or_edit_column(lookup_name, freeze_lookup_name=False, operation='edit')
|
||||||
|
|
||||||
|
def _create_or_edit_column(self, lookup_name, freeze_lookup_name, operation=None):
|
||||||
try:
|
try:
|
||||||
dialog = CreateCustomColumn(self.gui, self, lookup_name,
|
dialog = CreateCustomColumn(self.gui, self, lookup_name,
|
||||||
self.gui.library_view.model().orig_headers,
|
self.gui.library_view.model().orig_headers,
|
||||||
freeze_lookup_name=freeze_lookup_name)
|
freeze_lookup_name=freeze_lookup_name)
|
||||||
if dialog.result() == QDialog.DialogCode.Accepted and self.cc_column_key is not None:
|
if dialog.result() == QDialog.DialogCode.Accepted and self.cc_column_key is not None:
|
||||||
cc = self.custcols[lookup_name]
|
cc = self.custcols[lookup_name]
|
||||||
|
if operation == 'create':
|
||||||
self.db.create_custom_column(
|
self.db.create_custom_column(
|
||||||
label=cc['label'],
|
label=cc['label'],
|
||||||
name=cc['name'],
|
name=cc['name'],
|
||||||
datatype=cc['datatype'],
|
datatype=cc['datatype'],
|
||||||
is_multiple=cc['is_multiple'],
|
is_multiple=bool(cc['is_multiple']),
|
||||||
display=cc['display'])
|
display=cc['display'])
|
||||||
self.gui.must_restart_before_config = True
|
self.gui.must_restart_before_config = True
|
||||||
return (self.Result.COLUMN_ADDED, self.cc_column_key)
|
return (self.Result.COLUMN_ADDED, self.cc_column_key)
|
||||||
|
# editing/viewing
|
||||||
|
if operation == 'edit':
|
||||||
|
self.db.set_custom_column_metadata(cc['colnum'], name=cc['name'],
|
||||||
|
label=cc['label'], display=cc['display'],
|
||||||
|
notify=False)
|
||||||
|
if '*must_restart' in cc:
|
||||||
|
self.gui.must_restart_before_config = True
|
||||||
|
return (self.Result.COLUMN_EDITED, self.cc_column_key)
|
||||||
|
return (self.Result.CANCELED, self.cc_column_key)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -218,6 +218,12 @@ class Browser(QScrollArea): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
must_restart_message = _('The changes you have made require calibre be '
|
||||||
|
'restarted immediately. You will not be allowed to '
|
||||||
|
'set any more preferences, until you restart.')
|
||||||
|
|
||||||
|
|
||||||
class Preferences(QDialog):
|
class Preferences(QDialog):
|
||||||
|
|
||||||
run_wizard_requested = pyqtSignal()
|
run_wizard_requested = pyqtSignal()
|
||||||
@ -394,13 +400,11 @@ class Preferences(QDialog):
|
|||||||
do_restart = False
|
do_restart = False
|
||||||
if must_restart:
|
if must_restart:
|
||||||
self.must_restart = True
|
self.must_restart = True
|
||||||
|
if rc:
|
||||||
|
msg = must_restart_message
|
||||||
|
else:
|
||||||
msg = _('Some of the changes you made require a restart.'
|
msg = _('Some of the changes you made require a restart.'
|
||||||
' Please restart calibre as soon as possible.')
|
' Please restart calibre as soon as possible.')
|
||||||
if rc:
|
|
||||||
msg = _('The changes you have made require calibre be '
|
|
||||||
'restarted immediately. You will not be allowed to '
|
|
||||||
'set any more preferences, until you restart.')
|
|
||||||
|
|
||||||
do_restart = show_restart_warning(msg, parent=self)
|
do_restart = show_restart_warning(msg, parent=self)
|
||||||
|
|
||||||
self.showing_widget.refresh_gui(self.gui)
|
self.showing_widget.refresh_gui(self.gui)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user