PluginProjectWeb.py

changeset 5
31bc1ef6f624
parent 4
6438afaad632
child 6
a1600fa29542
equal deleted inserted replaced
4:6438afaad632 5:31bc1ef6f624
178 # TODO: add our actions here 178 # TODO: add our actions here
179 self.__html5ToCss3Act = self.__menu.addAction(self.tr( 179 self.__html5ToCss3Act = self.__menu.addAction(self.tr(
180 "HTML5 to CSS3"), self.__htm5ToCss3) 180 "HTML5 to CSS3"), self.__htm5ToCss3)
181 self.__html5ToJsAct = self.__menu.addAction(self.tr( 181 self.__html5ToJsAct = self.__menu.addAction(self.tr(
182 "HTML5 to JavaScript"), self.__htm5ToJs) 182 "HTML5 to JavaScript"), self.__htm5ToJs)
183 self.__menu.addSeparator()
184 self.__html5PrettifyAct = self.__menu.addAction(self.tr(
185 "Prettify HTML"), self.__html5Prettify)
183 186
184 self.__menu.aboutToShow.connect(self.__menuAboutToShow) 187 self.__menu.aboutToShow.connect(self.__menuAboutToShow)
185 188
186 def __menuAboutToShow(self): 189 def __menuAboutToShow(self):
187 """ 190 """
188 Private slot to prepare the menu before it is shown. 191 Private slot to prepare the menu before it is shown.
189 """ 192 """
190 editor = e5App().getObject("ViewManager").activeWindow() 193 editor = e5App().getObject("ViewManager").activeWindow()
191 selectionAvailable = bool(editor and editor.selectedText() != "") 194 selectionAvailable = bool(editor and editor.selectedText() != "")
195 isHtml = editor.getLanguage().lower().startswith("html")
192 196
193 self.__html5ToCss3Act.setEnabled( 197 self.__html5ToCss3Act.setEnabled(
194 selectionAvailable and BeautifulSoupAvailable) 198 selectionAvailable and BeautifulSoupAvailable and isHtml)
195 self.__html5ToJsAct.setEnabled( 199 self.__html5ToJsAct.setEnabled(
196 selectionAvailable and BeautifulSoupAvailable) 200 selectionAvailable and BeautifulSoupAvailable and isHtml)
201 self.__html5PrettifyAct.setEnabled(
202 BeautifulSoupAvailable and isHtml)
197 203
198 def __populateMenu(self, name, menu): 204 def __populateMenu(self, name, menu):
199 """ 205 """
200 Private slot to populate the tools menu with our entries. 206 Private slot to populate the tools menu with our entries.
201 207
262 vm = e5App().getObject("ViewManager") 268 vm = e5App().getObject("ViewManager")
263 editor = vm.activeWindow() 269 editor = vm.activeWindow()
264 html = editor.selectedText() 270 html = editor.selectedText()
265 271
266 converter = Html5ToCss3Converter(html) 272 converter = Html5ToCss3Converter(html)
267
268 css3 = converter.getCss3() 273 css3 = converter.getCss3()
269 274
270 if css3: 275 if css3:
271 vm.newEditor() 276 vm.newEditor()
272 newEditor = vm.activeWindow() 277 newEditor = vm.activeWindow()
281 vm = e5App().getObject("ViewManager") 286 vm = e5App().getObject("ViewManager")
282 editor = vm.activeWindow() 287 editor = vm.activeWindow()
283 html = editor.selectedText() 288 html = editor.selectedText()
284 289
285 converter = Html5ToJsConverter(html) 290 converter = Html5ToJsConverter(html)
286
287 js = converter.getJavaScript() 291 js = converter.getJavaScript()
288 292
289 if js: 293 if js:
290 vm.newEditor() 294 vm.newEditor()
291 newEditor = vm.activeWindow() 295 newEditor = vm.activeWindow()
292 newEditor.setText(js) 296 newEditor.setText(js)
293 newEditor.setLanguage("dummy.js") 297 newEditor.setLanguage("dummy.js")
298
299 def __html5Prettify(self):
300 """
301 Private slot handling the Prettify HTML action.
302 """
303 from ProjectWeb.Html5Prettifier import Html5Prettifier
304 editor = e5App().getObject("ViewManager").activeWindow()
305 html = editor.text()
306
307 prettifier = Html5Prettifier(html)
308 newHtml = prettifier.getPrettifiedHtml()
309
310 if newHtml and newHtml != html:
311 cursorLine, cursorIndex = editor.getCursorPosition()
312
313 editor.beginUndoAction()
314 editor.selectAll()
315 editor.replaceSelectedText(newHtml)
316 editor.endUndoAction()
317
318 editor.setCursorPosition(cursorLine, cursorIndex)

eric ide

mercurial