Skip to content
This repository was archived by the owner on Aug 20, 2023. It is now read-only.

Commit 437ed5d

Browse files
committed
Fix error in LO Impress
1 parent 36d23ff commit 437ed5d

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

codehighlighter/description.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:d = "http://openoffice.org/extensions/description/2006"
44
xmlns:l = "http://libreoffice.org/extensions/description/2011"
55
xmlns:xlink="http://www.w3.org/1999/xlink">
6-
<version value="1.4"/>
6+
<version value="1.5"/>
77
<identifier value="javahelps.codehighlighter"/>
88
<icon>
99
<default xlink:href="images/icon_48.png" />

codehighlighter/python/highlight.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,38 @@ def to_rgbint(hex_str):
3636
return rgb(0, 0, 0)
3737

3838

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+
3944
def highlightSourceCode(lang, style):
4045
ctx = XSCRIPTCONTEXT
4146
doc = ctx.getDocument()
4247
# Get the selected item
4348
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)
5871
highlight_code(code, cursor, lang, style)
5972

6073

@@ -74,9 +87,11 @@ def highlight_code(code, cursor, lang, style):
7487
finally:
7588
cursor.goRight(0, False) # deselects the selected text
7689

90+
7791
def highlight_automatic_default(*args):
7892
highlightSourceCode(None, 'default')
7993

94+
8095
def highlight_abap_default(*args):
8196
highlightSourceCode('abap', 'default')
8297

@@ -252,9 +267,11 @@ def highlight_c_objdump_default(*args):
252267
def highlight_c_default(*args):
253268
highlightSourceCode('c', 'default')
254269

270+
255271
def highlight_cpp_default(*args):
256272
highlightSourceCode('cpp', 'default')
257273

274+
258275
def highlight_ca65_default(*args):
259276
highlightSourceCode('ca65', 'default')
260277

0 commit comments

Comments
 (0)