add colored synthax (from user pref for themes)

This commit is contained in:
Jean-Christian Denis 2021-11-06 15:37:56 +01:00
parent 290597d3cd
commit 008d347893
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
4 changed files with 55 additions and 19 deletions

View file

@ -45,9 +45,16 @@ class tweakStoresBehaviors
# addd some js # addd some js
public static function modulesToolsHeaders(dcCore $core, $plugin) public static function modulesToolsHeaders(dcCore $core, $plugin)
{ {
$core->auth->user_prefs->addWorkspace('interface');
return return
dcPage::jsVars(['dotclear.ts_copied' => __('Copied to clipboard')]) . dcPage::jsVars(['dotclear.ts_copied' => __('Copied to clipboard')]) .
dcPage::jsLoad(dcPage::getPF('tweakStores/js/admin.js')); dcPage::jsLoad(dcPage::getPF('tweakStores/js/admin.js')) .
(
!$core->auth->user_prefs->interface->colorsyntax ? '' :
dcPage::jsLoadCodeMirror($core->auth->user_prefs->interface->colorsyntax_theme) .
dcPage::jsLoad(dcPage::getPF('tweakStores/js/cms.js'))
);
} }
# admin plugins page tab # admin plugins page tab
@ -65,10 +72,11 @@ class tweakStoresBehaviors
# generic page tab # generic page tab
protected static function modulesToolsTabs(dcCore $core, $modules, $excludes, $page_url) protected static function modulesToolsTabs(dcCore $core, $modules, $excludes, $page_url)
{ {
$combo = self::comboModules($modules, $excludes); $core->auth->user_prefs->addWorkspace('interface');
$user_ui_colorsyntax = $core->auth->user_prefs->interface->colorsyntax;
# zip file url pattern $user_ui_colorsyntax_theme = $core->auth->user_prefs->interface->colorsyntax_theme;
$file_pattern = $core->blog->settings->tweakStores->file_pattern; $combo = self::comboModules($modules, $excludes);
$file_pattern = $core->blog->settings->tweakStores->file_pattern;
# check dcstore repo # check dcstore repo
$url = ''; $url = '';
@ -154,10 +162,14 @@ class tweakStoresBehaviors
( (
empty($file_content) ? '' : empty($file_content) ? '' :
'<pre>' . form::textArea('file_xml', 165, 14, [ '<pre>' . form::textArea('file_xml', 165, 14, [
'default' => html::escapeHTML(str_replace('><', ">\n<", $file_content)), 'default' => html::escapeHTML(tweakStores::prettyXML($file_content)),
'class' => 'maximal', 'class' => 'maximal',
'extra_html' => 'readonly="true"' 'extra_html' => 'readonly="true"'
]) . '</pre>' ]) . '</pre>' .
(
!$user_ui_colorsyntax ? '' :
dcPage::jsRunCodeMirror('editor', 'file_xml', 'dotclear', $user_ui_colorsyntax_theme)
)
) . ) .
'</div>'; '</div>';
} }
@ -197,10 +209,14 @@ class tweakStoresBehaviors
} }
echo echo
'<pre>' . form::textArea('gen_xml', 165, 14, [ '<pre>' . form::textArea('gen_xml', 165, 14, [
'default' => html::escapeHTML(str_replace('><', ">\n<", $xml_content)), 'default' => html::escapeHTML(tweakStores::prettyXML($xml_content)),
'class' => 'maximal', 'class' => 'maximal',
'extra_html' => 'readonly="true"' 'extra_html' => 'readonly="true"'
]) . '</pre>'; ]) . '</pre>' .
(
!$user_ui_colorsyntax ? '' :
dcPage::jsRunCodeMirror('editor', 'gen_xml', 'dotclear', $user_ui_colorsyntax_theme)
);
if (empty(tweakStores::$failed) if (empty(tweakStores::$failed)
&& $modules[$_POST['buildxml_id']]['root_writable'] && $modules[$_POST['buildxml_id']]['root_writable']

View file

@ -182,7 +182,7 @@ class tweakStores
$res = new xmlTag('modules', $rsp); $res = new xmlTag('modules', $rsp);
$res->insertAttr('xmlns:da', 'http://dotaddict.org/da/'); $res->insertAttr('xmlns:da', 'http://dotaddict.org/da/');
return $res->toXML(); return self::prettyXML($res->toXML());
} }
public static function writeXML($id, $module, $file_pattern) public static function writeXML($id, $module, $file_pattern)
@ -197,7 +197,7 @@ class tweakStores
} }
try { try {
files::putContent($module['root'] . '/dcstore.xml', str_replace('><', ">\n<", $content)); files::putContent($module['root'] . '/dcstore.xml', $content);
} catch (Exception $e) { } catch (Exception $e) {
self::$failed[] = $e->getMessage(); self::$failed[] = $e->getMessage();
@ -206,4 +206,18 @@ class tweakStores
return true; return true;
} }
public static function prettyXML(string $str): string
{
if (class_exists('DOMDocument')) {
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($str);
return $dom->saveXML();
}
return str_replace('><', ">\n<", $str);
}
} }

View file

@ -3,19 +3,18 @@
$(function(){ $(function(){
$("#ts_copy_button").click(function() { $("#ts_copy_button").click(function() {
tsCopy("#gen_xml"); var style = $("#gen_xml").attr('style');
return false; $("#gen_xml").attr('style', '').attr("contenteditable", true)
});
function tsCopy(element_id) {
$(element_id).attr("contenteditable", true)
.select() .select()
.on("focus", function() { .on("focus", function() {
document.execCommand('selectAll', false, null) document.execCommand('selectAll', false, null)
}) })
.focus() .focus()
document.execCommand("Copy"); document.execCommand("Copy");
$(element_id).removeAttr("contenteditable"); $("#gen_xml").removeAttr("contenteditable").attr('style', style);
$("#ts_copy_button").focus();
alert(dotclear.ts_copied); alert(dotclear.ts_copied);
} return false;
});
}); });

7
js/cms.js Normal file
View file

@ -0,0 +1,7 @@
/*global CodeMirror, dotclear */
'use strict';
window.CodeMirror.defineMode('dotclear', function (config) {
config.readOnly = true;
return CodeMirror.getMode(config, 'php');
});