diff --git a/www/js/app.js b/www/js/app.js index 8791b12..61056ad 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -14,6 +14,7 @@ document.addEventListener('deviceready', onDeviceReady, false); ace.require("ace/ext/language_tools"); window.aceEditor = ace.edit('editor'); + aceEditor.setOptions(EDITOR_CONFIG); aceEditor.commands.removeCommand('showSettingsMenu') diff --git a/www/js/components/File_System/readFile.js b/www/js/components/File_System/readFile.js index f920d76..a5c1ac5 100644 --- a/www/js/components/File_System/readFile.js +++ b/www/js/components/File_System/readFile.js @@ -3,7 +3,7 @@ export function readFile(fileEntry) { fileEntry.file(function(file) { - var reader = new FileReader(); + let reader = new FileReader(); reader.onloadend = function() { window.aceEditor.setValue(this.result); diff --git a/www/js/components/main_FileEntry.js b/www/js/components/main_FileEntry.js index be65fcd..5baaf1b 100644 --- a/www/js/components/main_FileEntry.js +++ b/www/js/components/main_FileEntry.js @@ -6,93 +6,108 @@ import { FILES_NOT_ALLOWED, FILE_EXTENSIONS } from "./configs.js"; export async function onDeviceReady() { - /*@@param {Promise} reads-directory-recursively Read the local storage and fill the sidebar with files in it - **/ - - function listDir(url = '', result = []) { - return new Promise(function(res, rej) { - let path; - if (url == '') { - path = cordova.file.externalRootDirectory - } else { - path = url + '/'; + /*@@param {Promise} reads-directory-recursively Read the local storage and fill the sidebar with files in it + **/ + function listDir(url = '', result = []) { + return new Promise(function(res, rej) { + let path; + if (url == '') { + path = cordova.file.externalRootDirectory + } else { + path = url + '/'; + } + window.resolveLocalFileSystemURL(path, + function(fs) { + const reader = fs.createReader(); + reader.readEntries(function(entries) { + for (let i = 0; i < entries.length; i++) { + entries[i].text = entries[i].name + if (entries[i].isDirectory == true) { + entries[i].state = { + checked: false, + expanded: false, + selected: false + } + entries[i].nodes = [] + result.push(entries[i]) + listDir(entries[i].nativeURL, entries[i].nodes) + } else { + entries[i].onclick = "getUrls(this)" + entryIcon(entries[i]) + result.push(entries[i]); + } } - window.resolveLocalFileSystemURL(path, - function(fs) { - const reader = fs.createReader(); - reader.readEntries(function(entries) { - for (let i = 0; i < entries.length; i++) { - entries[i].text = entries[i].name - if (entries[i].isDirectory == true) { - entries[i].state = { - checked: false, - expanded: false, - selected: false - } - entries[i].nodes = [] - result.push(entries[i]) - listDir(entries[i].nativeURL, entries[i].nodes) - } else { - entries[i].onclick = "getUrls(this)" - entryIcon(entries[i]) - result.push(entries[i]); - } - } - }, (rej) => { return rej }); - }, (rej) => { return rej }); - res(result) - }) - } + }, (rej) => { return rej }); + }, (rej) => { return rej }); + res(result) + }) + } - let files = await listDir(); + let files = await listDir(); - function getTree() { - let data = files; - return data; - } - setTimeout(() => { - $("#fileList").treeview({ data: getTree(), showBorder: false }); - },2500) + function getTree() { + let data = files; + return data; + } + setTimeout(() => { + $("#fileList").treeview({ data: getTree(), showBorder: false }); + }, 2500) - window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, - function(fs) { - /** - *@@param {HTML ELEMENT OBJECT } getUrls gets the - * full path of the files and checks whether files - * is good for working with. - **/ - function getUrls(filElm) { +applyEditorSettings() + window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, + function(fs) { + /** + *@@param {HTML ELEMENT OBJECT } getUrls gets the + * full path of the files and checks whether files + * is good for working with. + **/ + function getUrls(filElm) { - let fileUrl = filElm.getAttribute('fullPath'); - let fileTruePath = fileUrl.slice(1) - let fileUrlSplit = fileTruePath.split("/") - let filename = fileUrlSplit[fileUrlSplit.length - 1] - let pattern = /\.[a-z]{1,4}/ - let extension = filename.match(pattern).toString().slice(1); - let checkValidity = FILES_NOT_ALLOWED.find(function(v) { - return v === extension - }) - if (checkValidity == undefined) { - workWithFile(fileTruePath); - window.aceEditor.session.setMode(`ace/mode/${FILE_EXTENSIONS[extension]}`) + let fileUrl = filElm.getAttribute('fullPath'); + let fileTruePath = fileUrl.slice(1) + let fileUrlSplit = fileTruePath.split("/") + let filename = fileUrlSplit[fileUrlSplit.length - 1] + let pattern = /\.[a-z]{1,4}/ + let extension = filename.match(pattern).toString().slice(1); + let checkValidity = FILES_NOT_ALLOWED.find(function(v) { + return v === extension + }) + if (checkValidity == undefined) { + workWithFile(fileTruePath); + window.aceEditor.session.setMode(`ace/mode/${FILE_EXTENSIONS[extension]}`) - } else { - alert(`file ${filename} is not valid`) - } + } else { + alert(`file ${filename} is not valid`) + } + } + + function applyEditorSettings() { + fs.root.getFile('Android/data/com.ace.code/files/settings.json', { + create: true, + exclusive: false + }, function(fEntry) { + fEntry.file(function(file) { + let reader = new FileReader() + reader.onloadend = function() { + aceEditor.setOptions(JSON.parse(this.result)) } - window.getUrls = getUrls - let fE; //Helps to avoid saving the same data in various entries - function workWithFile(filePath) { - fs.root.getFile(filePath, { create: true, exclusive: false }, function(fileEntry) { - - fE = fileEntry - readFile(fE); - //SAVE FILE when saveFs btn is clicked - SAVEFS.addEventListener('click', saveFile); + reader.readAsText(file) + }, null) + }, null) + } + window.getUrls = getUrls + let fE; //Helps to avoid saving the same data in various entries + function workWithFile(filePath) { + fs.root.getFile(filePath, { create: true, exclusive: false }, function(fileEntry) { - function saveFile() { writeFile(fE, null); } + fE = fileEntry + readFile(fE); + //SAVE FILE when saveFs btn is clicked + SAVEFS.addEventListener('click', saveFile); - }, () => { console.log('failed to save file'); }); - } - }, () => { console.log('failed to load file system'); }); + function saveFile() { writeFile(fE, null); } + + }, () => { console.log('failed to save file'); }); + } + }, () => { console.log('failed to load file system'); }); } \ No newline at end of file