From 795fdf83760fe1ff167fae53b9aa18ebc858826d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 23 Apr 2015 09:17:28 +0530 Subject: [PATCH] Properly display names of libraries containing the ampersand character. Fixes #1447188 [ampersand does not show in library name](https://bugs.launchpad.net/calibre/+bug/1447188) --- src/calibre/gui2/actions/choose_library.py | 11 +++++++---- src/calibre/gui2/actions/copy_to_library.py | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index fedf4742d4..caa47ddf01 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -303,7 +303,7 @@ class ChooseLibraryAction(InterfaceAction): if len(lname) > 16: lname = lname[:16] + u'…' a = self.qaction - a.setText(lname) + a.setText(lname.replace('&', '&&&')) # I have no idea why this requires a triple ampersand self.update_tooltip(db.count()) self.build_menus() state = self.view_state_map.get(self.stats.canonicalize_path( @@ -331,6 +331,7 @@ class ChooseLibraryAction(InterfaceAction): self.delete_menu.clear() quick_actions, rename_actions, delete_actions = [], [], [] for name, loc in locations: + name = name.replace('&', '&&') ac = self.quick_menu.addAction(name, Dispatcher(partial(self.switch_requested, loc))) ac.setStatusTip(_('Switch to: %s') % loc) @@ -347,6 +348,7 @@ class ChooseLibraryAction(InterfaceAction): qs_actions = [] for i, x in enumerate(locations[:len(self.switch_actions)]): name, loc = x + name = name.replace('&', '&&') ac = self.switch_actions[i] ac.setText(name) ac.setStatusTip(_('Switch to: %s') % loc) @@ -371,12 +373,13 @@ class ChooseLibraryAction(InterfaceAction): LibraryDatabase = db_class() loc = location.replace('/', os.sep) base = os.path.dirname(loc) - newname, ok = QInputDialog.getText(self.gui, _('Rename') + ' ' + name, + old_name = name.replace('&&', '&') + newname, ok = QInputDialog.getText(self.gui, _('Rename') + ' ' + old_name, '

'+_('Choose a new name for the library %s. ')%name + '

'+_('Note that the actual library folder will be renamed.'), - text=name) + text=old_name) newname = sanitize_file_name_unicode(unicode(newname)) - if not ok or not newname or newname == name: + if not ok or not newname or newname == old_name: return newloc = os.path.join(base, newname) if os.path.exists(newloc): diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index 305f5848d6..c9b01193e5 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -351,6 +351,7 @@ class CopyToLibraryAction(InterfaceAction): self.menu.addAction(_('Choose library by path...'), self.choose_library) self.menu.addSeparator() for name, loc in locations: + name = name.replace('&', '&&') self.menu.addAction(name, partial(self.copy_to_library, loc)) self.menu.addAction(name + ' ' + _('(delete after copy)'),