mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-26 12:13:05 +02:00
Make Open with context menu creation code re-useable
This commit is contained in:
parent
1c9db87492
commit
37d050f356
1 changed files with 34 additions and 21 deletions
|
|
@ -188,7 +188,40 @@ def paint(self, painter, option, index):
|
|||
# }}}
|
||||
|
||||
|
||||
class FileList(QTreeWidget):
|
||||
class OpenWithHandler(object): # {{{
|
||||
|
||||
def add_open_with_actions(self, menu, file_name):
|
||||
from calibre.gui2.open_with import populate_menu, edit_programs
|
||||
fmt = file_name.rpartition('.')[-1].lower()
|
||||
if not fmt:
|
||||
return
|
||||
m = QMenu(_('Open %s with...') % file_name)
|
||||
|
||||
def connect_action(ac, entry):
|
||||
connect_lambda(ac.triggered, self, lambda self: self.open_with(file_name, fmt, entry))
|
||||
|
||||
populate_menu(m, connect_action, fmt)
|
||||
if len(m.actions()) == 0:
|
||||
menu.addAction(_('Open %s with...') % file_name, partial(self.choose_open_with, file_name, fmt))
|
||||
else:
|
||||
m.addSeparator()
|
||||
m.addAction(_('Add other application for %s files...') % fmt.upper(), partial(self.choose_open_with, file_name, fmt))
|
||||
m.addAction(_('Edit Open With applications...'), partial(edit_programs, fmt, file_name))
|
||||
menu.addMenu(m)
|
||||
menu.ow = m
|
||||
|
||||
def choose_open_with(self, file_name, fmt):
|
||||
from calibre.gui2.open_with import choose_program
|
||||
entry = choose_program(fmt, self)
|
||||
if entry is not None:
|
||||
self.open_with(file_name, fmt, entry)
|
||||
|
||||
def open_with(self, file_name, fmt, entry):
|
||||
raise NotImplementedError()
|
||||
# }}}
|
||||
|
||||
|
||||
class FileList(QTreeWidget, OpenWithHandler):
|
||||
|
||||
delete_requested = pyqtSignal(object, object)
|
||||
reorder_spine = pyqtSignal(object)
|
||||
|
|
@ -586,26 +619,6 @@ def show_context_menu(self, point):
|
|||
if len(list(m.actions())) > 0:
|
||||
m.popup(self.mapToGlobal(point))
|
||||
|
||||
def add_open_with_actions(self, menu, file_name):
|
||||
from calibre.gui2.open_with import populate_menu, edit_programs
|
||||
fmt = file_name.rpartition('.')[-1].lower()
|
||||
if not fmt:
|
||||
return
|
||||
m = QMenu(_('Open %s with...') % file_name)
|
||||
|
||||
def connect_action(ac, entry):
|
||||
connect_lambda(ac.triggered, self, lambda self: self.open_with(file_name, fmt, entry))
|
||||
|
||||
populate_menu(m, connect_action, fmt)
|
||||
if len(m.actions()) == 0:
|
||||
menu.addAction(_('Open %s with...') % file_name, partial(self.choose_open_with, file_name, fmt))
|
||||
else:
|
||||
m.addSeparator()
|
||||
m.addAction(_('Add other application for %s files...') % fmt.upper(), partial(self.choose_open_with, file_name, fmt))
|
||||
m.addAction(_('Edit Open With applications...'), partial(edit_programs, fmt, file_name))
|
||||
menu.addMenu(m)
|
||||
menu.ow = m
|
||||
|
||||
def choose_open_with(self, file_name, fmt):
|
||||
from calibre.gui2.open_with import choose_program
|
||||
entry = choose_program(fmt, self)
|
||||
|
|
|
|||
Loading…
Reference in a new issue