Skip to content

Commit 59684b5

Browse files
committed
[issue #32] [beta] Highlight code based on paragraph style (part 4).
Take account of kompilainenn comments: - change finishing dialog from error box to info box; - make selected paragraph style persistent per document and per session.
1 parent 102394a commit 59684b5

File tree

6 files changed

+51
-46
lines changed

6 files changed

+51
-46
lines changed

codehighlighter/dialogs/CodeHighlighter2.xdl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
3-
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="CodeHighlighter" dlg:left="350" dlg:top="113" dlg:width="217" dlg:height="180" dlg:page="1" dlg:closeable="true" dlg:moveable="true" dlg:title="Code Highlighter 2 - v{}">
3+
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="CodeHighlighter" dlg:left="350" dlg:top="113" dlg:width="222" dlg:height="180" dlg:page="1" dlg:closeable="true" dlg:moveable="true" dlg:title="Code Highlighter 2 - v{}">
44
<dlg:styles>
55
<dlg:style dlg:style-id="0" dlg:text-color="0x4c4c4c" dlg:font-height="8" dlg:font-stylename="Normal" dlg:font-family="swiss"/>
66
<dlg:style dlg:style-id="1" dlg:border="none" dlg:font-weight="150" dlg:font-slant="italic"/>
@@ -17,31 +17,31 @@
1717
<dlg:numericfield dlg:id="nb_ratio" dlg:tab-index="6" dlg:left="87" dlg:top="42" dlg:width="47" dlg:height="15" dlg:page="2" dlg:valign="center" dlg:strict-format="true" dlg:decimal-accuracy="0" dlg:value-min="50" dlg:value-max="100" dlg:spin="true" dlg:repeat="50"/>
1818
<dlg:textfield dlg:id="nb_sep" dlg:tab-index="7" dlg:left="87" dlg:top="60" dlg:width="15" dlg:height="15" dlg:page="2" dlg:valign="center"/>
1919
<dlg:textfield dlg:id="nb_pad" dlg:tab-index="8" dlg:left="87" dlg:top="78" dlg:width="15" dlg:height="15" dlg:page="2" dlg:valign="center" dlg:maxlength="1"/>
20-
<dlg:textfield dlg:id="cs_rootstyle" dlg:tab-index="9" dlg:left="97" dlg:top="117" dlg:width="50" dlg:height="15" dlg:page="2" dlg:valign="center"/>
21-
<dlg:button dlg:id="preview" dlg:tab-index="10" dlg:left="137" dlg:top="19" dlg:width="70" dlg:height="16">
20+
<dlg:textfield dlg:id="cs_rootstyle" dlg:tab-index="9" dlg:left="97" dlg:top="121" dlg:width="50" dlg:height="15" dlg:page="2" dlg:valign="center"/>
21+
<dlg:button dlg:id="preview" dlg:tab-index="10" dlg:left="142" dlg:top="23" dlg:width="70" dlg:height="16">
2222
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.UNO:preview" script:language="UNO"/>
2323
</dlg:button>
24-
<dlg:button dlg:id="btn_ok" dlg:tab-index="13" dlg:left="137" dlg:top="40" dlg:width="70" dlg:height="16" dlg:default="true" dlg:button-type="ok"/>
25-
<dlg:button dlg:id="btn_cancel" dlg:tab-index="14" dlg:left="137" dlg:top="60" dlg:width="70" dlg:height="16" dlg:button-type="cancel"/>
26-
<dlg:button dlg:id="topage1" dlg:tab-index="15" dlg:left="137" dlg:top="81" dlg:width="70" dlg:height="16" dlg:page="2">
24+
<dlg:button dlg:id="btn_ok" dlg:tab-index="13" dlg:left="142" dlg:top="44" dlg:width="70" dlg:height="16" dlg:default="true" dlg:button-type="ok"/>
25+
<dlg:button dlg:id="btn_cancel" dlg:tab-index="14" dlg:left="142" dlg:top="64" dlg:width="70" dlg:height="16" dlg:button-type="cancel"/>
26+
<dlg:button dlg:id="topage1" dlg:tab-index="15" dlg:left="142" dlg:top="85" dlg:width="70" dlg:height="16" dlg:page="2">
2727
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.UNO:topage1" script:language="UNO"/>
2828
</dlg:button>
2929
<dlg:text dlg:style-id="0" dlg:id="pygments_ver" dlg:tab-index="16" dlg:left="18" dlg:top="166" dlg:width="85" dlg:height="8" dlg:value="Build upon pygments {}"/>
3030
<dlg:img dlg:style-id="1" dlg:id="pygments_logo" dlg:tab-index="17" dlg:left="5" dlg:top="165" dlg:width="11" dlg:height="9" dlg:scale-mode="isotropic" dlg:src="vnd.sun.star.extension://javahelps.codehighlighter/images/pygments.png"/>
31-
<dlg:fixedline dlg:style-id="1" dlg:id="nb_line" dlg:tab-index="18" dlg:left="10" dlg:top="10" dlg:width="117" dlg:height="10" dlg:page="2"/>
31+
<dlg:fixedline dlg:style-id="1" dlg:id="nb_line" dlg:tab-index="18" dlg:left="10" dlg:top="10" dlg:width="120" dlg:height="10" dlg:page="2"/>
3232
<dlg:text dlg:id="lbl_nb_start" dlg:tab-index="19" dlg:left="10" dlg:top="26" dlg:width="73" dlg:height="15" dlg:page="2" dlg:align="right" dlg:valign="center"/>
3333
<dlg:text dlg:id="lbl_nb_ratio" dlg:tab-index="20" dlg:left="10" dlg:top="42" dlg:width="73" dlg:height="15" dlg:page="2" dlg:align="right" dlg:valign="center"/>
3434
<dlg:text dlg:id="lbl_nb_sep" dlg:tab-index="21" dlg:left="10" dlg:top="61" dlg:width="73" dlg:height="15" dlg:page="2" dlg:align="right" dlg:valign="center"/>
3535
<dlg:text dlg:id="lbl_nb_pad" dlg:tab-index="22" dlg:left="10" dlg:top="78" dlg:width="73" dlg:height="15" dlg:page="2" dlg:align="right" dlg:valign="center"/>
36-
<dlg:fixedline dlg:style-id="1" dlg:id="cs_line" dlg:tab-index="23" dlg:left="10" dlg:top="107" dlg:width="117" dlg:height="10" dlg:page="2"/>
36+
<dlg:fixedline dlg:style-id="1" dlg:id="cs_line" dlg:tab-index="23" dlg:left="10" dlg:top="107" dlg:width="120" dlg:height="10" dlg:page="2"/>
3737
<dlg:text dlg:id="lbl_cs_rootstyle" dlg:tab-index="24" dlg:left="10" dlg:top="121" dlg:width="83" dlg:height="15" dlg:page="2" dlg:align="right" dlg:valign="center"/>
38-
<dlg:button dlg:id="topage2" dlg:tab-index="25" dlg:left="137" dlg:top="81" dlg:width="70" dlg:height="16" dlg:page="1">
38+
<dlg:button dlg:id="topage2" dlg:tab-index="25" dlg:left="142" dlg:top="85" dlg:width="70" dlg:height="16" dlg:page="1">
3939
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.UNO:topage2" script:language="UNO"/>
4040
</dlg:button>
41-
<dlg:fixedline dlg:id="para_line" dlg:tab-index="26" dlg:left="10" dlg:top="116" dlg:width="197" dlg:height="2" dlg:page="1"/>
41+
<dlg:fixedline dlg:id="para_line" dlg:tab-index="26" dlg:left="10" dlg:top="116" dlg:width="202" dlg:height="2" dlg:page="1"/>
4242
<dlg:text dlg:style-id="1" dlg:id="label_parastyle" dlg:tab-index="27" dlg:left="10" dlg:top="122" dlg:width="200" dlg:height="10" dlg:page="1"/>
4343
<dlg:menulist dlg:id="lb_parastyle" dlg:tab-index="28" dlg:left="10" dlg:top="135" dlg:width="100" dlg:height="15" dlg:page="1" dlg:spin="true" dlg:linecount="20"/>
44-
<dlg:button dlg:id="btn_parastyle" dlg:tab-index="29" dlg:left="137" dlg:top="135" dlg:width="70" dlg:page="1" dlg:height="16">
44+
<dlg:button dlg:id="btn_parastyle" dlg:tab-index="29" dlg:left="142" dlg:top="135" dlg:width="70" dlg:page="1" dlg:height="16">
4545
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.UNO:parastyle" script:language="UNO"/>
4646
</dlg:button>
4747
</dlg:bulletinboard>

codehighlighter/python/highlight.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
from com.sun.star.awt.FontWeight import NORMAL as W_NORMAL, BOLD as W_BOLD
8181
from com.sun.star.awt.FontSlant import NONE as SL_NONE, ITALIC as SL_ITALIC
8282
from com.sun.star.awt.FontUnderline import NONE as UL_NONE, SINGLE as UL_SINGLE
83-
from com.sun.star.awt.MessageBoxType import ERRORBOX
83+
from com.sun.star.awt.MessageBoxType import ERRORBOX, INFOBOX
8484
from com.sun.star.beans import PropertyValue
8585
from com.sun.star.container import ElementExistException
8686
from com.sun.star.document import XUndoAction
@@ -98,6 +98,7 @@
9898
CHARSTYLEID = "ch2_"
9999
SNIPPETTAGID = CHARSTYLEID + "options"
100100
INVALID_SELECTION = "Invalid"
101+
SELECTED_PARASTYLE = {}
101102

102103

103104
class UndoAction(unohelper.Base, XUndoAction):
@@ -201,7 +202,6 @@ def __init__(self, ctx):
201202
'CharacterStyles' in self.doc.StyleFamilies and
202203
self.doc.CurrentSelection.ImplementationName != "com.sun.star.drawing.SvxShapeCollection")
203204
self.parastyles = self.loadparastyles()
204-
self.parastyle = None
205205
self.cfg_access = self.create_cfg_access()
206206
self.options = self.load_options()
207207
self.extpath, self.extver = self.getextinfos()
@@ -264,7 +264,7 @@ def callHandlerMethod(self, dialog, event, method):
264264
if locstylename == "":
265265
self.msgbox(_("Please select a paragraph style."))
266266
else:
267-
self.parastyle = self.parastyles[locstylename]
267+
SELECTED_PARASTYLE[self.doc.RuntimeUID] = self.parastyles[locstylename]
268268
dialog.endDialog(2)
269269
return True
270270
except Exception:
@@ -483,6 +483,8 @@ def create_dialog(self):
483483

484484
if self.parastyles:
485485
lb_parastyle.addItems(sorted(self.parastyles.keys(), key=str.casefold), 0)
486+
if SELECTED_PARASTYLE and SELECTED_PARASTYLE.get(self.doc.RuntimeUID, None) in self.parastyles:
487+
lb_parastyle.selectItem(SELECTED_PARASTYLE.get(self.doc.RuntimeUID, None), True)
486488
else:
487489
lb_parastyle.setEnable(False)
488490
if self.doc.supportsService('com.sun.star.text.GenericTextDocument'):
@@ -1298,7 +1300,7 @@ def browse_all_paras(container=None):
12981300
for para in container:
12991301
if not para.supportsService('com.sun.star.text.Paragraph'):
13001302
continue
1301-
if para.ParaStyleName == self.parastyle:
1303+
if para.ParaStyleName == SELECTED_PARASTYLE[self.doc.RuntimeUID]:
13021304
if not cursor:
13031305
cursor = container.createTextCursorByRange(para.Start)
13041306
else:
@@ -1329,7 +1331,7 @@ def browse_all_paras(container=None):
13291331
message = ngettext("{} code snippet has been formatted.",
13301332
"{} code snippets have been formatted.",
13311333
len(code_blocks))
1332-
self.msgbox(message.format(len(code_blocks)))
1334+
self.msgbox(message.format(len(code_blocks)), boxtype=INFOBOX, title=_("Highlight all"))
13331335

13341336
def update_all(self, usetags):
13351337
'''Update all formatted code in the active document.

codehighlighter2.oxt

109 Bytes
Binary file not shown.

locales/en/LC_MESSAGES/ch2.po

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
msgid ""
66
msgstr ""
77
"Project-Id-Version: PACKAGE VERSION\n"
8-
"POT-Creation-Date: 2024-08-25 10:35+0200\n"
8+
"POT-Creation-Date: 2024-08-25 19:31+0200\n"
99
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1010
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1111
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -22,7 +22,7 @@ msgstr "Please select a paragraph style."
2222
#: codehighlighter/python/highlight.py:283
2323
#: codehighlighter/python/highlight.py:312
2424
#: codehighlighter/python/highlight.py:327
25-
#: codehighlighter/python/highlight.py:1076
25+
#: codehighlighter/python/highlight.py:1078
2626
msgid "Unsupported selection."
2727
msgstr "Unsupported selection."
2828

@@ -112,14 +112,15 @@ msgstr "Height (%)"
112112
msgid "Start at"
113113
msgstr "Start at"
114114

115-
#: codehighlighter/python/highlight.py:449
116-
msgid "Highlight all"
117-
msgstr "Highlight all"
118-
119115
#: codehighlighter/python/highlight.py:449
120116
msgid "Highlight all codes formatted with paragraph style:"
121117
msgstr "Highlight all codes formatted with paragraph style:"
122118

119+
#: codehighlighter/python/highlight.py:449
120+
#: codehighlighter/python/highlight.py:1334
121+
msgid "Highlight all"
122+
msgstr "Highlight all"
123+
123124
#: codehighlighter/python/highlight.py:450
124125
msgid "Back"
125126
msgstr "Back"
@@ -144,19 +145,19 @@ msgstr ""
144145
"Highlight every code snippet in the document that is formatted with the "
145146
"given paragraph style."
146147

147-
#: codehighlighter/python/highlight.py:489
148+
#: codehighlighter/python/highlight.py:491
148149
msgid " (There is currently no style in use.)"
149150
msgstr " (There is currently no style in use.)"
150151

151-
#: codehighlighter/python/highlight.py:491
152+
#: codehighlighter/python/highlight.py:493
152153
msgid " (Writer only.)"
153154
msgstr " (Writer only.)"
154155

155-
#: codehighlighter/python/highlight.py:526
156+
#: codehighlighter/python/highlight.py:528
156157
msgid "Unsupported language."
157158
msgstr "Unsupported language."
158159

159-
#: codehighlighter/python/highlight.py:528
160+
#: codehighlighter/python/highlight.py:530
160161
msgid "Unknown style."
161162
msgstr "Unknown style."
162163

locales/fr/LC_MESSAGES/ch2.po

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
msgid ""
66
msgstr ""
77
"Project-Id-Version: PACKAGE VERSION\n"
8-
"POT-Creation-Date: 2024-08-25 10:35+0200\n"
8+
"POT-Creation-Date: 2024-08-25 19:31+0200\n"
99
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1010
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1111
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -22,7 +22,7 @@ msgstr "Sélectionnez un style de paragraphe."
2222
#: codehighlighter/python/highlight.py:283
2323
#: codehighlighter/python/highlight.py:312
2424
#: codehighlighter/python/highlight.py:327
25-
#: codehighlighter/python/highlight.py:1076
25+
#: codehighlighter/python/highlight.py:1078
2626
msgid "Unsupported selection."
2727
msgstr "Sélection invalide."
2828

@@ -113,14 +113,15 @@ msgstr "Taille (%)"
113113
msgid "Start at"
114114
msgstr "Démarrer à"
115115

116-
#: codehighlighter/python/highlight.py:449
117-
msgid "Highlight all"
118-
msgstr "Tout coloriser"
119-
120116
#: codehighlighter/python/highlight.py:449
121117
msgid "Highlight all codes formatted with paragraph style:"
122118
msgstr "Coloriser sur base d'un style de paragraphe :"
123119

120+
#: codehighlighter/python/highlight.py:449
121+
#: codehighlighter/python/highlight.py:1334
122+
msgid "Highlight all"
123+
msgstr "Tout coloriser"
124+
124125
#: codehighlighter/python/highlight.py:450
125126
msgid "Back"
126127
msgstr "Retour"
@@ -145,19 +146,19 @@ msgstr ""
145146
"Colorise l'ensemble des éléments de code du document formatés avec le style "
146147
"de paragraphe donné."
147148

148-
#: codehighlighter/python/highlight.py:489
149+
#: codehighlighter/python/highlight.py:491
149150
msgid " (There is currently no style in use.)"
150151
msgstr " (Aucun style n'est actuellement utilisé.)"
151152

152-
#: codehighlighter/python/highlight.py:491
153+
#: codehighlighter/python/highlight.py:493
153154
msgid " (Writer only.)"
154155
msgstr " (Writer seul.)"
155156

156-
#: codehighlighter/python/highlight.py:526
157+
#: codehighlighter/python/highlight.py:528
157158
msgid "Unsupported language."
158159
msgstr "Langage non supporté."
159160

160-
#: codehighlighter/python/highlight.py:528
161+
#: codehighlighter/python/highlight.py:530
161162
msgid "Unknown style."
162163
msgstr "Style inconnu."
163164

locales/it/LC_MESSAGES/ch2.po

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
msgid ""
66
msgstr ""
77
"Project-Id-Version: PACKAGE VERSION\n"
8-
"POT-Creation-Date: 2024-08-25 10:35+0200\n"
8+
"POT-Creation-Date: 2024-08-25 19:31+0200\n"
99
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1010
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1111
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -22,7 +22,7 @@ msgstr "Selezionare uno stile paragrafo."
2222
#: codehighlighter/python/highlight.py:283
2323
#: codehighlighter/python/highlight.py:312
2424
#: codehighlighter/python/highlight.py:327
25-
#: codehighlighter/python/highlight.py:1076
25+
#: codehighlighter/python/highlight.py:1078
2626
msgid "Unsupported selection."
2727
msgstr "Selezione non supportata."
2828

@@ -116,14 +116,15 @@ msgstr "Altezza (%)"
116116
msgid "Start at"
117117
msgstr "Comincia da"
118118

119-
#: codehighlighter/python/highlight.py:449
120-
msgid "Highlight all"
121-
msgstr "Evidenzia tutto"
122-
123119
#: codehighlighter/python/highlight.py:449
124120
msgid "Highlight all codes formatted with paragraph style:"
125121
msgstr "Evidenzia tutti i codici formattati con lo stile paragrafo:"
126122

123+
#: codehighlighter/python/highlight.py:449
124+
#: codehighlighter/python/highlight.py:1334
125+
msgid "Highlight all"
126+
msgstr "Evidenzia tutto"
127+
127128
#: codehighlighter/python/highlight.py:450
128129
msgid "Back"
129130
msgstr "Indietro"
@@ -148,19 +149,19 @@ msgstr ""
148149
"Evidenzia tutti i codici nel documento formattati con lo stile di paragrafo "
149150
"indicato."
150151

151-
#: codehighlighter/python/highlight.py:489
152+
#: codehighlighter/python/highlight.py:491
152153
msgid " (There is currently no style in use.)"
153154
msgstr " (Attualmente non esiste uno stile in uso.)"
154155

155-
#: codehighlighter/python/highlight.py:491
156+
#: codehighlighter/python/highlight.py:493
156157
msgid " (Writer only.)"
157158
msgstr " (Solo Writer.)"
158159

159-
#: codehighlighter/python/highlight.py:526
160+
#: codehighlighter/python/highlight.py:528
160161
msgid "Unsupported language."
161162
msgstr "Lingua non supportata."
162163

163-
#: codehighlighter/python/highlight.py:528
164+
#: codehighlighter/python/highlight.py:530
164165
msgid "Unknown style."
165166
msgstr "Stile sconosciuto."
166167

0 commit comments

Comments
 (0)