@@ -36,25 +36,38 @@ def to_rgbint(hex_str):
36
36
return rgb (0 , 0 , 0 )
37
37
38
38
39
+ def log (msg ):
40
+ with open ("/tmp/code-highlighter.log" , "a" ) as text_file :
41
+ text_file .write (str (msg ) + "\r \n \r \n " )
42
+
43
+
39
44
def highlightSourceCode (lang , style ):
40
45
ctx = XSCRIPTCONTEXT
41
46
doc = ctx .getDocument ()
42
47
# Get the selected item
43
48
selected_item = doc .getCurrentController ().getSelection ()
44
- for item_idx in range (selected_item .getCount ()):
45
- code_block = selected_item .getByIndex (item_idx )
46
- if 'com.sun.star.drawing.Text' in code_block .SupportedServiceNames :
47
- # TextBox
48
- # highlight_code(style, lang, code_block)
49
- code = code_block .String
50
- cursor = code_block .createTextCursor ()
51
- cursor .gotoStart (False )
52
- else :
53
- # Plain text
54
- # highlight_code_string(style, lang, code_block)
55
- code = code_block .getString ()
56
- cursor = code_block .getText ().createTextCursorByRange (code_block )
57
- cursor .goLeft (0 , False )
49
+ if hasattr (selected_item , 'getCount' ):
50
+ for item_idx in range (selected_item .getCount ()):
51
+ code_block = selected_item .getByIndex (item_idx )
52
+ if 'com.sun.star.drawing.Text' in code_block .SupportedServiceNames :
53
+ # TextBox
54
+ # highlight_code(style, lang, code_block)
55
+ code = code_block .String
56
+ cursor = code_block .createTextCursor ()
57
+ cursor .gotoStart (False )
58
+ else :
59
+ # Plain text
60
+ # highlight_code_string(style, lang, code_block)
61
+ code = code_block .getString ()
62
+ cursor = code_block .getText ().createTextCursorByRange (code_block )
63
+ cursor .goLeft (0 , False )
64
+ highlight_code (code , cursor , lang , style )
65
+ elif hasattr (selected_item , 'SupportedServiceNames' ) and 'com.sun.star.text.TextCursor' in selected_item .SupportedServiceNames :
66
+ # LO Impress text selection
67
+ code_block = selected_item
68
+ code = code_block .getString ()
69
+ cursor = code_block .getText ().createTextCursorByRange (code_block )
70
+ cursor .goLeft (0 , False )
58
71
highlight_code (code , cursor , lang , style )
59
72
60
73
@@ -74,9 +87,11 @@ def highlight_code(code, cursor, lang, style):
74
87
finally :
75
88
cursor .goRight (0 , False ) # deselects the selected text
76
89
90
+
77
91
def highlight_automatic_default (* args ):
78
92
highlightSourceCode (None , 'default' )
79
93
94
+
80
95
def highlight_abap_default (* args ):
81
96
highlightSourceCode ('abap' , 'default' )
82
97
@@ -252,9 +267,11 @@ def highlight_c_objdump_default(*args):
252
267
def highlight_c_default (* args ):
253
268
highlightSourceCode ('c' , 'default' )
254
269
270
+
255
271
def highlight_cpp_default (* args ):
256
272
highlightSourceCode ('cpp' , 'default' )
257
273
274
+
258
275
def highlight_ca65_default (* args ):
259
276
highlightSourceCode ('ca65' , 'default' )
260
277
0 commit comments