From 9f46e89649c99dd7b71d364beafe2bdf47f03bae Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 1 May 2015 12:05:53 +0530 Subject: [PATCH] Avoid unnecessary sub-menu for open with button in view specific format dialog --- src/calibre/gui2/dialogs/choose_format.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/dialogs/choose_format.py b/src/calibre/gui2/dialogs/choose_format.py index d6390ec8d5..86c4cf76a1 100644 --- a/src/calibre/gui2/dialogs/choose_format.py +++ b/src/calibre/gui2/dialogs/choose_format.py @@ -28,6 +28,7 @@ class ChooseFormatDialog(QDialog): l.addLayout(h) if show_open_with: self.owb = QPushButton(_('&Open With...'), self) + self.formats.currentRowChanged.connect(self.update_open_with_button) h.addWidget(self.owb) self.own = QMenu(self.owb.text()) self.owb.setMenu(self.own) @@ -45,21 +46,24 @@ class ChooseFormatDialog(QDialog): self._format = self.open_with_format = None if show_open_with: self.populate_open_with() + self.update_open_with_button() def populate_open_with(self): from calibre.gui2.open_with import populate_menu, edit_programs menu = self.own menu.clear() fmt = self._formats[self.formats.currentRow()] - m = QMenu(_('Open %s with...') % fmt.upper(), menu) - populate_menu(m, self.open_with, fmt) - if len(m.actions()) == 0: + populate_menu(menu, self.open_with, fmt) + if len(menu.actions()) == 0: menu.addAction(_('Open %s with...') % fmt.upper(), self.choose_open_with) else: - m.addSeparator() - m.addAction(_('Add other application for %s files...') % fmt.upper(), self.choose_open_with) - m.addAction(_('Edit Open With applications...'), partial(edit_programs, fmt, self)) - menu.addMenu(m) + menu.addSeparator() + menu.addAction(_('Add other application for %s files...') % fmt.upper(), self.choose_open_with) + menu.addAction(_('Edit Open With applications...'), partial(edit_programs, fmt, self)) + + def update_open_with_button(self): + fmt = self._formats[self.formats.currentRow()] + self.owb.setText(_('Open %s With...') % fmt) def open_with(self, entry): self.open_with_format = (self._formats[self.formats.currentRow()], entry)