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