314 editor.beginUndoAction() |
315 editor.beginUndoAction() |
315 editor.insert(markup) |
316 editor.insert(markup) |
316 cline, cindex = editor.getCursorPosition() |
317 cline, cindex = editor.getCursorPosition() |
317 editor.setCursorPosition(cline, cindex + len(markup)) |
318 editor.setCursorPosition(cline, cindex + len(markup)) |
318 editor.endUndoAction() |
319 editor.endUndoAction() |
|
320 |
|
321 def hasBulletedList(self): |
|
322 """ |
|
323 Public method to indicate the availability of bulleted list markup. |
|
324 |
|
325 @return flag indicating the availability of bulleted list markup |
|
326 @rtype bool |
|
327 """ |
|
328 return True |
|
329 |
|
330 def bulletedList(self, editor): |
|
331 """ |
|
332 Public method to generate bulleted list text. |
|
333 |
|
334 @param editor reference to the editor to work on |
|
335 @type Editor |
|
336 """ |
|
337 self.__makeList(editor, "ul") |
|
338 |
|
339 def hasNumberedList(self): |
|
340 """ |
|
341 Public method to indicate the availability of numbered list markup. |
|
342 |
|
343 @return flag indicating the availability of numbered list markup |
|
344 @rtype bool |
|
345 """ |
|
346 return True |
|
347 |
|
348 def numberedList(self, editor): |
|
349 """ |
|
350 Public method to generate numbered list text. |
|
351 |
|
352 @param editor reference to the editor to work on |
|
353 @type Editor |
|
354 """ |
|
355 self.__makeList(editor, "ol") |
|
356 |
|
357 def __makeList(self, editor, listType): |
|
358 """ |
|
359 Private method to generate the desired list markup. |
|
360 |
|
361 @param editor reference to the editor to work on |
|
362 @type Editor |
|
363 @param listType type of the desired list (should be ul or ol) |
|
364 @type str |
|
365 """ |
|
366 if editor is None: |
|
367 return |
|
368 |
|
369 lineSeparator = editor.getLineSeparator() |
|
370 editor.beginUndoAction() |
|
371 if editor.hasSelectedText(): |
|
372 startLine, startIndex, endLine, endIndex = \ |
|
373 editor.getSelection() |
|
374 if endIndex == 0: |
|
375 endLine -= 1 |
|
376 for line in range(startLine, endLine + 1): |
|
377 editor.insertAt("</li>", line, len(editor.text(line).rstrip())) |
|
378 editor.insertAt(" <li>", line, 0) |
|
379 if line == editor.lines() - 1: |
|
380 editor.insertAt(lineSeparator, line, 1000) |
|
381 editor.insertAt("</{1}>{0}".format(lineSeparator, listType), |
|
382 endLine + 1, 0) |
|
383 editor.insertAt("<{1}>{0}".format(lineSeparator, listType), |
|
384 startLine, 0) |
|
385 editor.setCursorPosition(endLine + 3, 0) |
|
386 else: |
|
387 listElements, ok = QInputDialog.getInt( |
|
388 None, |
|
389 QCoreApplication.translate( |
|
390 "HtmlProvider", "Create List"), |
|
391 QCoreApplication.translate( |
|
392 "HtmlProvider", "Enter desired number of list elements:"), |
|
393 0, 0, 99, 1) |
|
394 if ok: |
|
395 if listElements == 0: |
|
396 listElements = 1 |
|
397 cline, cindex = editor.getCursorPosition() |
|
398 listBody = \ |
|
399 listElements * " <li></li>{0}".format(lineSeparator) |
|
400 markup = "<{1}>{0}{2}</{1}>{0}".format( |
|
401 lineSeparator, listType, listBody) |
|
402 if cindex == 0: |
|
403 editor.insertAt(markup, cline, cindex) |
|
404 editor.setCursorPosition(cline + 1, 6) |
|
405 else: |
|
406 if cline == editor.lines() - 1: |
|
407 editor.insertAt(lineSeparator, cline, 1000) |
|
408 editor.insertAt(markup, cline + 1, 0) |
|
409 editor.setCursorPosition(cline + 2, 6) |
|
410 editor.endUndoAction() |