--- a/PluginProjectWeb.py Thu Jan 01 13:27:03 2015 +0100 +++ b/PluginProjectWeb.py Thu Jan 01 17:14:39 2015 +0100 @@ -180,6 +180,9 @@ "HTML5 to CSS3"), self.__htm5ToCss3) self.__html5ToJsAct = self.__menu.addAction(self.tr( "HTML5 to JavaScript"), self.__htm5ToJs) + self.__menu.addSeparator() + self.__html5PrettifyAct = self.__menu.addAction(self.tr( + "Prettify HTML"), self.__html5Prettify) self.__menu.aboutToShow.connect(self.__menuAboutToShow) @@ -189,11 +192,14 @@ """ editor = e5App().getObject("ViewManager").activeWindow() selectionAvailable = bool(editor and editor.selectedText() != "") + isHtml = editor.getLanguage().lower().startswith("html") self.__html5ToCss3Act.setEnabled( - selectionAvailable and BeautifulSoupAvailable) + selectionAvailable and BeautifulSoupAvailable and isHtml) self.__html5ToJsAct.setEnabled( - selectionAvailable and BeautifulSoupAvailable) + selectionAvailable and BeautifulSoupAvailable and isHtml) + self.__html5PrettifyAct.setEnabled( + BeautifulSoupAvailable and isHtml) def __populateMenu(self, name, menu): """ @@ -264,7 +270,6 @@ html = editor.selectedText() converter = Html5ToCss3Converter(html) - css3 = converter.getCss3() if css3: @@ -283,7 +288,6 @@ html = editor.selectedText() converter = Html5ToJsConverter(html) - js = converter.getJavaScript() if js: @@ -291,3 +295,24 @@ newEditor = vm.activeWindow() newEditor.setText(js) newEditor.setLanguage("dummy.js") + + def __html5Prettify(self): + """ + Private slot handling the Prettify HTML action. + """ + from ProjectWeb.Html5Prettifier import Html5Prettifier + editor = e5App().getObject("ViewManager").activeWindow() + html = editor.text() + + prettifier = Html5Prettifier(html) + newHtml = prettifier.getPrettifiedHtml() + + if newHtml and newHtml != html: + cursorLine, cursorIndex = editor.getCursorPosition() + + editor.beginUndoAction() + editor.selectAll() + editor.replaceSelectedText(newHtml) + editor.endUndoAction() + + editor.setCursorPosition(cursorLine, cursorIndex)