Skip to content

Commit 1003e3d

Browse files
committed
make themes available and enable code folding
1 parent 2f53287 commit 1003e3d

File tree

7 files changed

+197
-6
lines changed

7 files changed

+197
-6
lines changed

_build/readThemes.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
let i = 0;
5+
process.argv.forEach((parameter) => {
6+
console.log(i++ + ': ' + parameter);
7+
})
8+
9+
if (process.argv.length !== 3) {
10+
throw new Error("Requires the base path as argument.");
11+
}
12+
13+
const basePath = process.argv[2];
14+
if (!basePath.match(/[\\\/]$/)) {
15+
throw new Error("Path must end with a slash - any slash will do.");
16+
} else if (!fs.existsSync(basePath)) {
17+
throw new Error(`Invalid path, '${basePath}' does not exist or is not readable.`);
18+
}
19+
20+
const absoluteBasePath = path.toNamespacedPath(basePath) + "\\";
21+
[
22+
`files\\js\\3rdParty\\codemirror-mc\\theme\\`,
23+
].forEach((path) => {
24+
const directory = absoluteBasePath + path;
25+
console.log(`##### Searching in ${directory} #####\n`);
26+
27+
fs.readdirSync(directory)
28+
.filter(filename => {
29+
let stat = fs.statSync(directory + filename);
30+
31+
return !!(stat.isFile() && !stat.isSymbolicLink() && filename.match(/\.css$/i));
32+
})
33+
.forEach(async filename => {
34+
let theme = filename;
35+
let displayName;
36+
37+
theme = theme.replace(/\.css$/i, '');
38+
39+
displayName = theme.replace(/^([a-z])/, (match, g1) => {
40+
return g1.toUpperCase();
41+
});
42+
displayName = displayName.replace(/(?:_|-)([a-z])/gi, (match, g1) => {
43+
return ' ' + g1.toUpperCase();
44+
});
45+
46+
console.log(theme + ':' + displayName);
47+
})
48+
});

acptemplates/mcodemirror.tpl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/search/search.js"></script>
77
<script data-relocate="true">window.define.amd = window.__require_define_amd;</script>
88
<script data-relocate="true">
9-
['{@$__wcf->getPath()}js/3rdParty/codemirror-mc/codemirror.css', '{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/dialog/dialog.css'].forEach((href) => {
9+
[
10+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/codemirror.css',
11+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/dialog/dialog.css',
12+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/foldgutter.css',
13+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/theme/{CODEMIRROR_THEME}.css',
14+
].forEach((href) => {
1015
const link = document.createElement('link');
1116
link.rel = 'stylesheet';
1217
link.href = href;
@@ -19,7 +24,13 @@
1924
{if $codemirrorMode != 'smartymixed'}
2025
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/{if $codemirrorMode == 'text/x-less'}css/css{else}{$codemirrorMode}/{$codemirrorMode}{/if}.js"></script>
2126
{/if}
22-
27+
28+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/foldcode.js"></script>
29+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/foldgutter.js"></script>
30+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/brace-fold.js"></script>
31+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/indent-fold.js"></script>
32+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/comment-fold.js"></script>
33+
2334
{if $codemirrorMode == 'htmlmixed' || $codemirrorMode == 'smartymixed' || $codemirrorMode == 'php'}
2435
{if $codemirrorMode == 'smartymixed'}
2536
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/htmlmixed/htmlmixed.js"></script>
@@ -32,6 +43,10 @@
3243
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/css/css.js"></script>
3344
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/javascript/javascript.js"></script>
3445
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/xml/xml.js"></script>
46+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/xml-fold.js"></script>
47+
{/if}
48+
{if $codemirrorMode === 'markdown'}
49+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/markdown-fold.js"></script>
3550
{/if}
3651
<script data-relocate="true">window.define.amd = window.__require_define_amd;</script>
3752
{assign var='codemirrorLoaded' value=true}
@@ -57,7 +72,11 @@
5772
indentWithTabs: true,
5873
lineNumbers: true,
5974
indentUnit: 4,
60-
readOnly: {if !$editable|isset || $editable}false{else}true{/if}
75+
readOnly: {if !$editable|isset || $editable}false{else}true{/if},
76+
theme: '{CODEMIRROR_THEME}',
77+
foldGutter: true,
78+
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
79+
extraKeys: { "Ctrl-Q": (cm) => { cm.foldCode(cm.getCursor()); } },
6180
};
6281
6382
elements.forEach((element) => {
@@ -72,6 +91,7 @@
7291
}
7392
else {
7493
element.codemirror = CodeMirror.fromTextArea(element, config);
94+
element.codemirror.foldCode(CodeMirror.Pos(13, 0));
7595
const oldToTextArea = element.codemirror.toTextArea;
7696
element.codemirror.toTextArea = () => {
7797
oldToTextArea();

language/de-informal.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com https://www.woltlab.com/XSD/5.4/language.xsd" languagecode="de-informal">
3+
<category name="wcf.acp.option">
4+
<item name="wcf.acp.option.category.general.system.codemirror"><![CDATA[Codemirror-Code]]></item>
5+
<item name="wcf.acp.option.codemirror_theme"><![CDATA[Theme]]></item>
6+
</category>
7+
</language>

language/de.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com https://www.woltlab.com/XSD/5.4/language.xsd" languagecode="de">
3+
<category name="wcf.acp.option">
4+
<item name="wcf.acp.option.category.general.system.codemirror"><![CDATA[Codemirror-Code]]></item>
5+
<item name="wcf.acp.option.codemirror_theme"><![CDATA[Theme]]></item>
6+
</category>
7+
</language>

language/en.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com https://www.woltlab.com/XSD/5.4/language.xsd" languagecode="en">
3+
<category name="wcf.acp.option">
4+
<item name="wcf.acp.option.category.general.system.codemirror"><![CDATA[Codemirror-Code]]></item>
5+
<item name="wcf.acp.option.codemirror_theme"><![CDATA[Theme]]></item>
6+
</category>
7+
</language>

option.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com https://www.woltlab.com/XSD/5.4/option.xsd">
3+
<import>
4+
<categories>
5+
<category name="general.system.codemirror">
6+
<parent><![CDATA[general.system]]></parent>
7+
</category>
8+
</categories>
9+
<options>
10+
<option name="codemirror_theme">
11+
<optiontype><![CDATA[select]]></optiontype>
12+
<selectoptions><![CDATA[3024-day:3024 Day
13+
3024-night:3024 Night
14+
abbott:Abbott
15+
abcdef:Abcdef
16+
ambiance-mobile:Ambiance Mobile
17+
ambiance:Ambiance
18+
ayu-dark:Ayu Dark
19+
ayu-mirage:Ayu Mirage
20+
base16-dark:Base16 Dark
21+
base16-light:Base16 Light
22+
bespin:Bespin
23+
blackboard:Blackboard
24+
cobalt:Cobalt
25+
colorforth:Colorforth
26+
darcula:Darcula
27+
dracula:Dracula
28+
duotone-dark:Duotone Dark
29+
duotone-light:Duotone Light
30+
eclipse:Eclipse
31+
elegant:Elegant
32+
erlang-dark:Erlang Dark
33+
gruvbox-dark:Gruvbox Dark
34+
hopscotch:Hopscotch
35+
icecoder:Icecoder
36+
idea:Idea
37+
isotope:Isotope
38+
juejin:Juejin
39+
lesser-dark:Lesser Dark
40+
liquibyte:Liquibyte
41+
lucario:Lucario
42+
material-darker:Material Darker
43+
material-ocean:Material Ocean
44+
material-palenight:Material Palenight
45+
material:Material
46+
mbo:Mbo
47+
mdn-like:Mdn Like
48+
midnight:Midnight
49+
monokai:Monokai
50+
moxer:Moxer
51+
neat:Neat
52+
neo:Neo
53+
night:Night
54+
nord:Nord
55+
oceanic-next:Oceanic Next
56+
panda-syntax:Panda Syntax
57+
paraiso-dark:Paraiso Dark
58+
paraiso-light:Paraiso Light
59+
pastel-on-dark:Pastel On Dark
60+
railscasts:Railscasts
61+
rubyblue:Rubyblue
62+
seti:Seti
63+
shadowfox:Shadowfox
64+
solarized:Solarized
65+
ssms:Ssms
66+
the-matrix:The Matrix
67+
tomorrow-night-bright:Tomorrow Night Bright
68+
tomorrow-night-eighties:Tomorrow Night Eighties
69+
ttcn:Ttcn
70+
twilight:Twilight
71+
vibrant-ink:Vibrant Ink
72+
xq-dark:Xq Dark
73+
xq-light:Xq Light
74+
yeti:Yeti
75+
yonce:Yonce
76+
zenburn:Zenburn]]></selectoptions>
77+
<defaultvalue><![CDATA[darcula]]></defaultvalue>
78+
<categoryname><![CDATA[general.system.codemirror]]></categoryname>
79+
</option>
80+
</options>
81+
</import>
82+
</data>

templates/mcodemirror.tpl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/search/search.js"></script>
77
<script data-relocate="true">window.define.amd = window.__require_define_amd;</script>
88
<script data-relocate="true">
9-
['{@$__wcf->getPath()}js/3rdParty/codemirror-mc/codemirror.css', '{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/dialog/dialog.css'].forEach((href) => {
9+
[
10+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/codemirror.css',
11+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/dialog/dialog.css',
12+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/foldgutter.css',
13+
'{@$__wcf->getPath()}js/3rdParty/codemirror-mc/theme/{CODEMIRROR_THEME}.css',
14+
].forEach((href) => {
1015
const link = document.createElement('link');
1116
link.rel = 'stylesheet';
1217
link.href = href;
@@ -19,7 +24,13 @@
1924
{if $codemirrorMode != 'smartymixed'}
2025
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/{if $codemirrorMode == 'text/x-less'}css/css{else}{$codemirrorMode}/{$codemirrorMode}{/if}.js"></script>
2126
{/if}
22-
27+
28+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/foldcode.js"></script>
29+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/foldgutter.js"></script>
30+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/brace-fold.js"></script>
31+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/indent-fold.js"></script>
32+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/comment-fold.js"></script>
33+
2334
{if $codemirrorMode == 'htmlmixed' || $codemirrorMode == 'smartymixed' || $codemirrorMode == 'php'}
2435
{if $codemirrorMode == 'smartymixed'}
2536
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/htmlmixed/htmlmixed.js"></script>
@@ -32,6 +43,10 @@
3243
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/css/css.js"></script>
3344
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/javascript/javascript.js"></script>
3445
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/mode/xml/xml.js"></script>
46+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/xml-fold.js"></script>
47+
{/if}
48+
{if $codemirrorMode === 'markdown'}
49+
<script data-relocate="true" src="{@$__wcf->getPath()}js/3rdParty/codemirror-mc/addon/fold/markdown-fold.js"></script>
3550
{/if}
3651
<script data-relocate="true">window.define.amd = window.__require_define_amd;</script>
3752
{assign var='codemirrorLoaded' value=true}
@@ -57,7 +72,11 @@
5772
indentWithTabs: true,
5873
lineNumbers: true,
5974
indentUnit: 4,
60-
readOnly: {if !$editable|isset || $editable}false{else}true{/if}
75+
readOnly: {if !$editable|isset || $editable}false{else}true{/if},
76+
theme: '{CODEMIRROR_THEME}',
77+
foldGutter: true,
78+
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
79+
extraKeys: { "Ctrl-Q": (cm) => { cm.foldCode(cm.getCursor()); } },
6180
};
6281
6382
elements.forEach((element) => {
@@ -72,6 +91,7 @@
7291
}
7392
else {
7493
element.codemirror = CodeMirror.fromTextArea(element, config);
94+
element.codemirror.foldCode(CodeMirror.Pos(13, 0));
7595
const oldToTextArea = element.codemirror.toTextArea;
7696
element.codemirror.toTextArea = () => {
7797
oldToTextArea();

0 commit comments

Comments
 (0)