eric6/QScintilla/MarkupProviders/MarkdownProvider.py

Sun, 29 Nov 2020 14:10:18 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Nov 2020 14:10:18 +0100
changeset 7844
cb108454eda7
parent 7781
607a6098cb44
child 7923
91e843545d9a
permissions
-rw-r--r--

WebBrowserWindow: removed the use of QTextCodec to prepare the Qt6 migration.

5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7267
diff changeset
3 # Copyright (c) 2017 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5397
fee5485e67f4 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5394
diff changeset
7 Module implementing the Markdown markup provider.
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
5411
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
10 from PyQt5.QtCore import QCoreApplication
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
11 from PyQt5.QtWidgets import QDialog, QInputDialog
5404
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
12
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .MarkupBase import MarkupBase
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 class MarkdownProvider(MarkupBase):
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
5397
fee5485e67f4 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5394
diff changeset
18 Class implementing the Markdown markup provider.
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 def __init__(self):
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Constructor
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 super(MarkdownProvider, self).__init__()
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
5398
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
26 def kind(self):
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
27 """
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
28 Public method to get the markup kind.
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
29
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
30 @return string with markup kind
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
31 @rtype str
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
32 """
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
33 return "markdown"
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
34
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 def hasBold(self):
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Public method to indicate the availability of bold markup.
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @return flag indicating the availability of bold markup
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @rtype bool
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 return True
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
5402
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
44 def bold(self, editor):
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
45 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
46 Public method to generate bold text.
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
47
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
48 @param editor reference to the editor to work on
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
49 @type Editor
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
50 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
51 self.__insertMarkup("**", editor)
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
52
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def hasItalic(self):
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Public method to indicate the availability of italic markup.
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @return flag indicating the availability of italic markup
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @rtype bool
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 return True
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
5402
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
62 def italic(self, editor):
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
63 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
64 Public method to generate italic text.
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
65
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
66 @param editor reference to the editor to work on
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
67 @type Editor
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
68 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
69 self.__insertMarkup("_", editor)
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
70
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 def hasStrikethrough(self):
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 Public method to indicate the availability of strikethrough markup.
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @return flag indicating the availability of strikethrough markup
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @rtype bool
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 return True
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
5402
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
80 def strikethrough(self, editor):
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
81 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
82 Public method to generate strikethrough text.
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
83
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
84 @param editor reference to the editor to work on
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
85 @type Editor
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
86 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
87 self.__insertMarkup("~~", editor)
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
88
5398
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
89 def headerLevels(self):
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
90 """
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
91 Public method to determine the available header levels.
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
92
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
93 @return supported header levels
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
94 @rtype int
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
95 """
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
96 return 6
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
97
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
98 def header(self, editor, level):
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
99 """
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
100 Public method to generate a header.
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
101
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
102 @param editor reference to the editor to work on
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
103 @type Editor
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
104 @param level header level
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
105 @type int
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
106 """
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
107 if editor is None or level > self.headerLevels():
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
108 return
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
109
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
110 editor.beginUndoAction()
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
111 cline, cindex = editor.getCursorPosition()
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
112 editor.insertAt(level * "#" + " ", cline, 0)
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
113 editor.setCursorPosition(cline, level + 1)
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
114 editor.endUndoAction()
1f4509cf8f35 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5397
diff changeset
115
5402
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
116 def hasCode(self):
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
117 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
118 Public method to indicate the availability of inline code markup.
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
119
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
120 @return flag indicating the availability of inline code markup
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
121 @rtype bool
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
122 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
123 return True
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
124
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
125 def code(self, editor):
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
126 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
127 Public method to generate inline code text.
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
128
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
129 @param editor reference to the editor to work on
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
130 @type Editor
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
131 """
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
132 self.__insertMarkup("`", editor)
ce21a78a5fcf Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5398
diff changeset
133
5404
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
134 def hasCodeBlock(self):
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
135 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
136 Public method to indicate the availability of code block markup.
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
137
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
138 @return flag indicating the availability of code block markup
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
139 @rtype bool
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
140 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
141 return True
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
142
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
143 def codeBlock(self, editor):
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
144 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
145 Public method to generate code block text.
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
146
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
147 @param editor reference to the editor to work on
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
148 @type Editor
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
149 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
150 if editor is None:
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
151 return
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
152
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
153 lineSeparator = editor.getLineSeparator()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
154 editor.beginUndoAction()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
155 if editor.hasSelectedText():
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
156 newText = "```{0}{1}```{0}".format(
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
157 lineSeparator, editor.selectedText())
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
158 editor.replaceSelectedText(newText)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
159 else:
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
160 editor.insert("```{0}{0}```{0}".format(lineSeparator))
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
161 cline, cindex = editor.getCursorPosition()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
162 editor.setCursorPosition(cline + 1, 0)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
163 editor.endUndoAction()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
164
5394
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 def __insertMarkup(self, markup, editor):
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 Private method to insert the specified markup.
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 If the editor has selected text, this text is enclosed by the given
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 markup. If no text is selected, the markup is inserted at the cursor
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 position and the cursor is positioned in between.
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 @param markup markup string to be inserted
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 @type str
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 @param editor reference to the editor to work on
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 @type Editor
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 """
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 if editor is None:
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 return
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 editor.beginUndoAction()
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if editor.hasSelectedText():
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 newText = "{0}{1}{0}".format(markup, editor.selectedText())
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 editor.replaceSelectedText(newText)
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 else:
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 editor.insert(2 * markup)
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 cline, cindex = editor.getCursorPosition()
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 editor.setCursorPosition(cline, cindex + len(markup))
b2c6179184f6 Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 editor.endUndoAction()
5404
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
190
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
191 def hasHyperlink(self):
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
192 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
193 Public method to indicate the availability of hyperlink markup.
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
194
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
195 @return flag indicating the availability of hyperlink markup
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
196 @rtype bool
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
197 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
198 return True
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
199
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
200 def hyperlink(self, editor):
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
201 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
202 Public method to generate hyperlink text.
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
203
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
204 @param editor reference to the editor to work on
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
205 @type Editor
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
206 """
5407
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
207 if editor is None:
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
208 return
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
209
5404
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
210 from .HyperlinkMarkupDialog import HyperlinkMarkupDialog
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
211 dlg = HyperlinkMarkupDialog(False, True)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
212 if dlg.exec() == QDialog.Accepted:
5407
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
213 text, target, title = dlg.getData()
5404
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
214
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
215 link = "[{0}]".format(text)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
216 if target and title:
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
217 link = '{0}({1} "{2}")'.format(link, target, title)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
218 elif target:
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
219 link = '{0}({1})'.format(link, target)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
220 elif title:
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
221 link = '{0}("{1}")'.format(link, title)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
222
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
223 editor.beginUndoAction()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
224 cline, cindex = editor.getCursorPosition()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
225 editor.insert(link)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
226 editor.setCursorPosition(cline, cindex + len(link))
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
227 editor.endUndoAction()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
228
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
229 def hasLine(self):
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
230 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
231 Public method to indicate the availability of a horizontal line markup.
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
232
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
233 @return flag indicating the availability of a horizontal line markup
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
234 @rtype bool
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
235 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
236 return True
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
237
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
238 def line(self, editor):
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
239 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
240 Public method to generate a horizontal line text.
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
241
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
242 @param editor reference to the editor to work on
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
243 @type Editor
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
244 """
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
245 if editor is None:
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
246 return
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
247
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
248 lineSeparator = editor.getLineSeparator()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
249 editor.beginUndoAction()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
250 markup = "{0}-----{0}{0}".format(lineSeparator)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
251 editor.insert(markup)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
252 cline, cindex = editor.getCursorPosition()
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
253 editor.setCursorPosition(cline + 3, 0)
6b19ad5470a3 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5402
diff changeset
254 editor.endUndoAction()
5407
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
255
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
256 def hasQuote(self):
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
257 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
258 Public method to indicate the availability of block quote markup.
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
259
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
260 @return flag indicating the availability of block quote markup
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
261 @rtype bool
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
262 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
263 return True
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
264
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
265 def quote(self, editor):
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
266 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
267 Public method to generate block quote text.
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
268
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
269 @param editor reference to the editor to work on
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
270 @type Editor
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
271 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
272 if editor is None:
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
273 return
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
274
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
275 editor.beginUndoAction()
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
276 markup = "> "
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
277 sline, sindex, eline, eindex = editor.getSelection()
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
278 for line in range(sline, eline + 1 if eindex > 0 else eline):
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
279 editor.insertAt(markup, line, 0)
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
280 editor.endUndoAction()
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
281
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
282 def hasImage(self):
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
283 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
284 Public method to indicate the availability of image markup.
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
285
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
286 @return flag indicating the availability of image markup
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
287 @rtype bool
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
288 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
289 return True
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
290
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
291 def image(self, editor):
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
292 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
293 Public method to generate image text.
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
294
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
295 @param editor reference to the editor to work on
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
296 @type Editor
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
297 """
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
298 if editor is None:
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
299 return
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
300
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
301 from .ImageMarkupDialog import ImageMarkupDialog
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
302 dlg = ImageMarkupDialog(ImageMarkupDialog.MarkDownMode)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
303 if dlg.exec() == QDialog.Accepted:
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
304 address, altText, title, originalSize, width, height = (
5407
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
305 dlg.getData()
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
306 )
5407
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
307
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
308 if title:
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
309 markup = '![{0}]({1} "{2}")'.format(altText, address, title)
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
310 else:
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
311 markup = '![{0}]({1})'.format(altText, address)
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
312
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
313 editor.beginUndoAction()
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
314 editor.insert(markup)
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
315 cline, cindex = editor.getCursorPosition()
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
316 editor.setCursorPosition(cline, cindex + len(markup))
f833f89571b8 Continued implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5404
diff changeset
317 editor.endUndoAction()
5411
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
318
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
319 def hasBulletedList(self):
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
320 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
321 Public method to indicate the availability of bulleted list markup.
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
322
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
323 @return flag indicating the availability of bulleted list markup
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
324 @rtype bool
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
325 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
326 return True
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
327
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
328 def bulletedList(self, editor):
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
329 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
330 Public method to generate bulleted list text.
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
331
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
332 @param editor reference to the editor to work on
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
333 @type Editor
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
334 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
335 self.__makeList(editor, False)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
336
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
337 def hasNumberedList(self):
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
338 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
339 Public method to indicate the availability of numbered list markup.
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
340
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
341 @return flag indicating the availability of numbered list markup
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
342 @rtype bool
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
343 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
344 return True
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
345
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
346 def numberedList(self, editor):
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
347 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
348 Public method to generate numbered list text.
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
349
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
350 @param editor reference to the editor to work on
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
351 @type Editor
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
352 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
353 self.__makeList(editor, True)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
354
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
355 def __makeList(self, editor, numberedList):
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
356 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
357 Private method to generate the desired list markup.
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
358
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
359 @param editor reference to the editor to work on
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
360 @type Editor
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
361 @param numberedList flag indicating the generation of a numbered list
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
362 @type bool
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
363 """
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
364 if editor is None:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
365 return
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
366
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
367 if numberedList:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
368 markup = " 1. "
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
369 else:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
370 markup = " * "
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
371 lineSeparator = editor.getLineSeparator()
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
372 editor.beginUndoAction()
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
373 if editor.hasSelectedText():
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
374 startLine, startIndex, endLine, endIndex = (
5411
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
375 editor.getSelection()
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
376 )
5411
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
377 if endIndex == 0:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
378 endLine -= 1
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
379 for line in range(startLine, endLine + 1):
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
380 editor.insertAt(markup, line, 0)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
381 editor.setCursorPosition(endLine + 1, 0)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
382 else:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
383 listElements, ok = QInputDialog.getInt(
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
384 None,
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
385 QCoreApplication.translate(
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
386 "MarkdownProvider", "Create List"),
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
387 QCoreApplication.translate(
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
388 "MarkdownProvider",
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
389 "Enter desired number of list elements:"),
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
390 0, 0, 99, 1)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
391 if ok:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
392 if listElements == 0:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
393 listElements = 1
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
394 cline, cindex = editor.getCursorPosition()
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
395 listBody = (
5411
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
396 listElements * "{1}{0}".format(lineSeparator, markup)
7267
aedc309827c7 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
397 )
5411
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
398 if cindex == 0:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
399 editor.insertAt(listBody, cline, cindex)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
400 editor.setCursorPosition(cline, len(markup))
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
401 else:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
402 if cline == editor.lines() - 1:
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
403 editor.insertAt(lineSeparator, cline, 1000)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
404 editor.insertAt(listBody, cline + 1, 0)
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
405 editor.setCursorPosition(cline + 1, len(markup))
a163fbbf2bea Finished implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5407
diff changeset
406 editor.endUndoAction()

eric ide

mercurial