342 editor.beginUndoAction() |
343 editor.beginUndoAction() |
343 editor.insert(markup) |
344 editor.insert(markup) |
344 cline, cindex = editor.getCursorPosition() |
345 cline, cindex = editor.getCursorPosition() |
345 editor.setCursorPosition(cline + lines, 0) |
346 editor.setCursorPosition(cline + lines, 0) |
346 editor.endUndoAction() |
347 editor.endUndoAction() |
|
348 |
|
349 def hasBulletedList(self): |
|
350 """ |
|
351 Public method to indicate the availability of bulleted list markup. |
|
352 |
|
353 @return flag indicating the availability of bulleted list markup |
|
354 @rtype bool |
|
355 """ |
|
356 return True |
|
357 |
|
358 def bulletedList(self, editor): |
|
359 """ |
|
360 Public method to generate bulleted list text. |
|
361 |
|
362 @param editor reference to the editor to work on |
|
363 @type Editor |
|
364 """ |
|
365 self.__makeList(editor, False) |
|
366 |
|
367 def hasNumberedList(self): |
|
368 """ |
|
369 Public method to indicate the availability of numbered list markup. |
|
370 |
|
371 @return flag indicating the availability of numbered list markup |
|
372 @rtype bool |
|
373 """ |
|
374 return True |
|
375 |
|
376 def numberedList(self, editor): |
|
377 """ |
|
378 Public method to generate numbered list text. |
|
379 |
|
380 @param editor reference to the editor to work on |
|
381 @type Editor |
|
382 """ |
|
383 self.__makeList(editor, True) |
|
384 |
|
385 def __makeList(self, editor, numberedList): |
|
386 """ |
|
387 Private method to generate the desired list markup. |
|
388 |
|
389 @param editor reference to the editor to work on |
|
390 @type Editor |
|
391 @param numberedList flag indicating the generation of a numbered list |
|
392 @type bool |
|
393 """ |
|
394 if editor is None: |
|
395 return |
|
396 |
|
397 if numberedList: |
|
398 markup = " #. " |
|
399 else: |
|
400 markup = " * " |
|
401 lineSeparator = editor.getLineSeparator() |
|
402 editor.beginUndoAction() |
|
403 if editor.hasSelectedText(): |
|
404 startLine, startIndex, endLine, endIndex = \ |
|
405 editor.getSelection() |
|
406 if endIndex == 0: |
|
407 endLine -= 1 |
|
408 for line in range(startLine, endLine + 1): |
|
409 editor.insertAt(markup, line, 0) |
|
410 editor.setCursorPosition(endLine + 1, 0) |
|
411 else: |
|
412 listElements, ok = QInputDialog.getInt( |
|
413 None, |
|
414 QCoreApplication.translate( |
|
415 "RestructuredTextProvider", "Create List"), |
|
416 QCoreApplication.translate( |
|
417 "RestructuredTextProvider", |
|
418 "Enter desired number of list elements:"), |
|
419 0, 0, 99, 1) |
|
420 if ok: |
|
421 if listElements == 0: |
|
422 listElements = 1 |
|
423 cline, cindex = editor.getCursorPosition() |
|
424 listBody = \ |
|
425 listElements * "{1}{0}".format(lineSeparator, markup) |
|
426 if cindex == 0: |
|
427 editor.insertAt(listBody, cline, cindex) |
|
428 editor.setCursorPosition(cline, len(markup)) |
|
429 else: |
|
430 if cline == editor.lines() - 1: |
|
431 editor.insertAt(lineSeparator, cline, 1000) |
|
432 editor.insertAt(listBody, cline + 1, 0) |
|
433 editor.setCursorPosition(cline + 1, len(markup)) |
|
434 editor.endUndoAction() |