diff -r 024ba1836a94 -r b26df0282953 PluginSelectionEncloser.py --- a/PluginSelectionEncloser.py Fri Apr 18 19:46:40 2014 +0200 +++ b/PluginSelectionEncloser.py Mon Apr 21 15:25:27 2014 +0200 @@ -98,10 +98,24 @@ self.__ui = ui # menu is a list of lists; each list consists of a string for the - # submenu title and a list of submenu entries. The title of the submenu - # entry is the enclosing string. + # submenu title and a list of submenu entries. Each submenu entry + # consists of another list giving the title and the enclosing string + # or formatting string. defaultMenu = [ - [self.tr("Quotes"), ['"', "'", '"""', "'''"]], + [self.tr("Quotes"), [ + ['"', '"'], + ["'", "'"], + ['"""', '"""'], + ["'''", "'''"] + ]], + [self.tr("HTML"), [ + ['<h1>', '<h1>{0}</h1>'], + ['<h2>', '<h2>{0}</h2>'], + ['<h3>', '<h3>{0}</h3>'], + ['<p>', '<p>{0}</p>'], + ['<div>', '<div>{0}</div>'], + ['<span>', '<span>{0}</span>'], + ]] ] self.__defaults = { "MenuHierarchy": json.dumps(defaultMenu), @@ -283,9 +297,9 @@ hierarchy = self.getPreferences("MenuHierarchy") for menuTitle, entries in hierarchy: submenu = QMenu(menuTitle, self.__menu) - for entry in entries: - act = submenu.addAction(entry, self.__encloseSelection) - act.setData(entry) + for title, encString in entries: + act = submenu.addAction(title, self.__encloseSelection) + act.setData(encString) self.__menu.addMenu(submenu) def __encloseSelection(self): @@ -307,7 +321,12 @@ if not string: return - newText = string + editor.selectedText() + string + if '%s' in string: + newText = string % editor.selectedText() + elif '{0}' in string: + newText = string.format(editor.selectedText()) + else: + newText = string + editor.selectedText() + string editor.beginUndoAction() editor.replaceSelectedText(newText) editor.endUndoAction()