92 if editor is None or level > self.headerLevels(): |
92 if editor is None or level > self.headerLevels(): |
93 return |
93 return |
94 |
94 |
95 editor.beginUndoAction() |
95 editor.beginUndoAction() |
96 cline, cindex = editor.getCursorPosition() |
96 cline, cindex = editor.getCursorPosition() |
|
97 if editor.hasSelection() and cindex == 0: |
|
98 cline -= 1 |
97 lineSeparator = editor.getLineSeparator() |
99 lineSeparator = editor.getLineSeparator() |
98 if not editor.text(cline).endswith(lineSeparator): |
100 if not editor.text(cline).endswith(lineSeparator): |
99 editor.insertAt(lineSeparator, cline, len(editor.text(cline))) |
101 editor.insertAt(lineSeparator, cline, len(editor.text(cline))) |
100 lineLength = len(editor.text(cline)) - len(lineSeparator) |
102 lineLength = len(editor.text(cline)) - len(lineSeparator) |
101 editor.insertAt( |
103 editor.insertAt( |
198 Public method to generate hyperlink text. |
200 Public method to generate hyperlink text. |
199 |
201 |
200 @param editor reference to the editor to work on |
202 @param editor reference to the editor to work on |
201 @type Editor |
203 @type Editor |
202 """ |
204 """ |
|
205 if editor is None: |
|
206 return |
|
207 |
203 from .HyperlinkMarkupDialog import HyperlinkMarkupDialog |
208 from .HyperlinkMarkupDialog import HyperlinkMarkupDialog |
204 dlg = HyperlinkMarkupDialog(False, True, noTitle=True) |
209 dlg = HyperlinkMarkupDialog(False, True, noTitle=True) |
205 if dlg.exec_() == QDialog.Accepted: |
210 if dlg.exec_() == QDialog.Accepted: |
206 text, target, _ = dlg.getData() |
211 text, target, _ = dlg.getData() |
207 |
212 |
266 markup = "{0}-----{0}{0}".format(lineSeparator) |
271 markup = "{0}-----{0}{0}".format(lineSeparator) |
267 editor.insert(markup) |
272 editor.insert(markup) |
268 cline, cindex = editor.getCursorPosition() |
273 cline, cindex = editor.getCursorPosition() |
269 editor.setCursorPosition(cline + 3, 0) |
274 editor.setCursorPosition(cline + 3, 0) |
270 editor.endUndoAction() |
275 editor.endUndoAction() |
|
276 |
|
277 def hasQuote(self): |
|
278 """ |
|
279 Public method to indicate the availability of block quote markup. |
|
280 |
|
281 @return flag indicating the availability of block quote markup |
|
282 @rtype bool |
|
283 """ |
|
284 return True |
|
285 |
|
286 def quote(self, editor): |
|
287 """ |
|
288 Public method to generate block quote text. |
|
289 |
|
290 @param editor reference to the editor to work on |
|
291 @type Editor |
|
292 """ |
|
293 if editor is None: |
|
294 return |
|
295 |
|
296 lineSeparator = editor.getLineSeparator() |
|
297 editor.beginUndoAction() |
|
298 markup = "> " |
|
299 sline, sindex, eline, eindex = editor.getSelection() |
|
300 for line in range(sline, eline + 1 if eindex > 0 else eline): |
|
301 editor.insertAt(markup, line, 0) |
|
302 editor.insertAt("::{0}{0}".format(lineSeparator), sline, 0) |
|
303 editor.setCursorPosition(eline + 2, eindex) |
|
304 editor.endUndoAction() |
|
305 |
|
306 def hasImage(self): |
|
307 """ |
|
308 Public method to indicate the availability of image markup. |
|
309 |
|
310 @return flag indicating the availability of image markup |
|
311 @rtype bool |
|
312 """ |
|
313 return True |
|
314 |
|
315 def image(self, editor): |
|
316 """ |
|
317 Public method to generate image text. |
|
318 |
|
319 @param editor reference to the editor to work on |
|
320 @type Editor |
|
321 """ |
|
322 if editor is None: |
|
323 return |
|
324 |
|
325 from .ImageMarkupDialog import ImageMarkupDialog |
|
326 dlg = ImageMarkupDialog(ImageMarkupDialog.RestMode) |
|
327 if dlg.exec_() == QDialog.Accepted: |
|
328 address, altText, title, originalSize, width, height = \ |
|
329 dlg.getData() |
|
330 |
|
331 lineSeparator = editor.getLineSeparator() |
|
332 markup = ".. image:: {0}{1}".format(address, lineSeparator) |
|
333 lines = 1 |
|
334 if altText: |
|
335 markup += " :alt: {0}{1}".format(altText, lineSeparator) |
|
336 lines += 1 |
|
337 if not originalSize: |
|
338 markup += " :height: {0}px{1}".format(height, lineSeparator) |
|
339 markup += " :width: {0}px{1}".format(width, lineSeparator) |
|
340 lines += 2 |
|
341 |
|
342 editor.beginUndoAction() |
|
343 editor.insert(markup) |
|
344 cline, cindex = editor.getCursorPosition() |
|
345 editor.setCursorPosition(cline + lines, 0) |
|
346 editor.endUndoAction() |