diff --git a/assets/js/icecoder.js b/assets/js/icecoder.js index 4a08aea..e8aba03 100644 --- a/assets/js/icecoder.js +++ b/assets/js/icecoder.js @@ -18,6 +18,8 @@ var ICEcoder = { minFilesW: 14, // Min width of files pane maxFilesW: 250, // Max width of files pane selectedTab: 0, // The tab that's currently selected + selectedTabFileExt: '', // File extension of selected tab + selectedTabLangMode: '', // Language mode of selected tab savedPoints: [], // Ints array to indicate save points for docs savedContents: [], // Array of last known saved contents canSwitchTabs: true, // Stops switching of tabs when trying to close @@ -1983,22 +1985,46 @@ var ICEcoder = { // Save a file saveFile: function(saveAs, newFileAutoSave) { let changes, saveType, filePath, pathPrefix; - // If we're not 'saving as', establish changes between current and known saved version from array - if (false === saveAs) { - changes = this.getChangesToSave(); + if ("undefined" !== typeof prettier && ["js", "json", "ts", "css", "scss", "less", "html", "xml", "yaml", "md", "php"].indexOf(this.selectedTabFileExt) > -1) { + switch (this.selectedTabFileExt) { + case "js": parser = "babel"; break; + case "json": parser = "json"; break; + case "ts": parser = "typescript"; break; + case "css": parser = "css"; break; + case "scss": parser = "scss"; break; + case "less": parser = "less"; break; + case "html": parser = "html"; break; + case "xml": parser = "html"; break; + case "yaml": parser = "yaml"; break; + case "md": parser = "markdown"; break; + case "php": parser = "php"; break; + } + this.getThisCM().setValue(prettier.format( + this.getThisCM().getValue(), + { + parser: parser, + plugins: prettierPlugins + } + )); } + setTimeout(function() { + // If we're not 'saving as', establish changes between current and known saved version from array + if (false === saveAs) { + changes = ic.getChangesToSave(); + } - saveType = saveAs ? "saveAs" : "save"; - filePath = this.openFiles[this.selectedTab - 1].replace(iceRoot, "").replace(/\//g, "|"); - if ("|[NEW]" === filePath && 0 < this.selectedFiles.length) { - pathPrefix = this.selectedFiles[0]; - filePath = -1 == pathPrefix.lastIndexOf(".") || pathPrefix.lastIndexOf(".") < pathPrefix.lastIndexOf("|") - ? pathPrefix + filePath - : "|[NEW]"; - } - filePath = filePath.replace("||", "|"); - this.serverQueue("add", iceLoc + "/lib/file-control.php?action=save&fileMDT=" + this.openFileMDTs[this.selectedTab - 1] + "&fileVersion=" + this.openFileVersions[this.selectedTab - 1] + "&saveType=" + saveType + "&newFileAutoSave=" + newFileAutoSave + "&tabNum=" + this.selectedTab + "&csrf=" + this.csrf,encodeURIComponent(filePath), changes); - this.serverMessage('' + t['Saving'] + '
' + this.openFiles[this.selectedTab - 1].replace(iceRoot, "")); + saveType = saveAs ? "saveAs" : "save"; + filePath = ic.openFiles[ic.selectedTab - 1].replace(iceRoot, "").replace(/\//g, "|"); + if ("|[NEW]" === filePath && 0 < ic.selectedFiles.length) { + pathPrefix = ic.selectedFiles[0]; + filePath = -1 == pathPrefix.lastIndexOf(".") || pathPrefix.lastIndexOf(".") < pathPrefix.lastIndexOf("|") + ? pathPrefix + filePath + : "|[NEW]"; + } + filePath = filePath.replace("||", "|"); + ic.serverQueue("add", iceLoc + "/lib/file-control.php?action=save&fileMDT=" + ic.openFileMDTs[ic.selectedTab - 1] + "&fileVersion=" + ic.openFileVersions[ic.selectedTab - 1] + "&saveType=" + saveType + "&newFileAutoSave=" + newFileAutoSave + "&tabNum=" + ic.selectedTab + "&csrf=" + ic.csrf,encodeURIComponent(filePath), changes); + ic.serverMessage('' + t['Saving'] + '
' + ic.openFiles[ic.selectedTab - 1].replace(iceRoot, "")); + }, 0, ic); }, // Prompt a rename dialog diff --git a/editor.php b/editor.php index 31b3199..133e4cd 100644 --- a/editor.php +++ b/editor.php @@ -280,7 +280,8 @@ parent.ICEcoder.switchMode = function(mode) { } } else if (cM && fileName) { - + parent.ICEcoder.selectedTabFileExt = fileExt; + parent.ICEcoder.selectedTabLangMode = mode; if (mode != cM.getOption("mode")) { cM.setOption("mode", mode); cM.setOption("lint", ("js" === fileExt || "json" === fileExt) && parent.ICEcoder.codeAssist ? true : false); diff --git a/index.php b/index.php index 154179a..a1087f0 100644 --- a/index.php +++ b/index.php @@ -86,6 +86,20 @@ $t = $text['index']; } + + + + + + + + + + diff --git a/lib/plugins-manager.php b/lib/plugins-manager.php index 42b46ae..75a4d48 100644 --- a/lib/plugins-manager.php +++ b/lib/plugins-manager.php @@ -172,7 +172,7 @@ if (false === $demoMode && isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] fclose($fh); // Finally, reload ICEcoder itself if plugin requires it or just the iFrame screen for the user if it doesn't if ("install" === $_GET['action'] && "true" === $pluginsData[$_GET['plugin']]['reload']) { - echo ""; + echo ""; } else { header("Location: plugins-manager.php?updatedPlugins&csrf=" . $_SESSION["csrf"]); echo "";