Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions basex-api/src/main/webapp/dba/static/cm6.js

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions basex-api/src/main/webapp/dba/static/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ function applyTab() {
function showTab() {
renderTabs();
checkButtons();
if(_editor.setLanguage) _editor.setLanguage(fileLanguage(tab()?.name));
_editor.focus();
}

Expand Down Expand Up @@ -365,12 +366,25 @@ async function stopQuery() {
setJob();
}

/**
* Guesses the result language from its first character.
* @param {string} text serialized result
* @returns {string} language for _output.setLanguage
*/
function resultLanguage(text) {
const s = text.replace(/^\s+/, "");
if(s[0] === "<") return "xml";
if(s[0] === "{" || s[0] === "[") return "json";
return "text";
}

/**
* Shows the result of a query.
* @param {string} text result
*/
function showResult(text) {
setText("Query was successful.", "info");
if(_output.setLanguage) _output.setLanguage(resultLanguage(text));
_output.setValue(text);
}

Expand All @@ -384,6 +398,20 @@ function runnable() {
return !t || !t.name || XQUERY_SUFFIXES.test(t.name);
}

/**
* Chooses the editor language from the file name: XQuery (see runnable), else by
* extension, else plain text.
* @param {string} name file name (may be empty)
* @returns {string} language for _editor.setLanguage
*/
function fileLanguage(name) {
if(!name || XQUERY_SUFFIXES.test(name)) return "xquery";
const ext = name.replace(/^.*\./, "").toLowerCase();
if([ "xml", "xsd", "xsl", "xslt", "svg", "rng", "rdf", "wsdl", "xhtml" ].includes(ext)) return "xml";
if(ext === "json") return "json";
return "text";
}

/**
* Opens a file in a tab of its own; a file that is already open is shown again.
* @param {string} file file name
Expand Down
Loading