diff --git a/index.html b/index.html index 1c5cf77..3041797 100644 --- a/index.html +++ b/index.html @@ -141,6 +141,13 @@ title = "Save editor contents to file on XRP under a specific path"> Save As to XRP +
  • +
  • diff --git a/js/editor_wrapper.js b/js/editor_wrapper.js index 46bc7ef..3ac5963 100644 --- a/js/editor_wrapper.js +++ b/js/editor_wrapper.js @@ -115,6 +115,7 @@ class EditorWrapper{ this.onOpen = undefined; this.onConvert = undefined; this.onDownloadFile = undefined; + this.onDeleteNonLibFiles = undefined; this.addNewEditor = undefined; // Make sure mouse down anywhere on panel focuses the panel diff --git a/js/filesystem_wrapper.js b/js/filesystem_wrapper.js index 9a20a93..ac2acde 100644 --- a/js/filesystem_wrapper.js +++ b/js/filesystem_wrapper.js @@ -126,6 +126,7 @@ class FILESYSTEM{ this.onUploadFiles = undefined; this.onRefresh = undefined; this.onDownloadFiles = undefined; + this.onDeleteNonLibFiles = undefined; // this.onNewFile = undefined; diff --git a/js/main.js b/js/main.js index 9d884b2..a257b89 100644 --- a/js/main.js +++ b/js/main.js @@ -289,6 +289,12 @@ document.getElementById("IDFileSaveAs").onclick = (event) =>{ EDITORS[id].onSaveAsToThumby(); } +document.getElementById("IDFileDeleteNonLib").onclick = (event) =>{ + UIkit.dropdown(FILE_DROPDOWN).hide(); + let id = localStorage.getItem("activeTabId"); + EDITORS[id].onDeleteNonLibFiles(); +} + // View Menu Support VIEW_BUTTON.onclick = (event) =>{ //get active file id @@ -596,6 +602,15 @@ function registerFilesystem(_container, state){ await downloadFileFromPath(fullFilePaths); } + FS.onDeleteNonLibFiles = async () => { + if(REPL.DISCONNECT == false && await confirmMessage("This will permanently delete ALL files on the XRP, with the exception of the lib folder, the trash folder, and the XRPExamples folder. Are you SURE you want to do this?")){ + REPL.deleteNonLibFiles(); + window.alertMessage("All non-library files have been deleted from the XRP."); + }else{ + window.alertMessage("No XRP is connected. Files can not be deleted. Double-check that the XRP is connected before attempting to delete a file."); + } + } + } async function downloadFileFromPath(fullFilePaths) { @@ -815,6 +830,15 @@ function registerEditor(_container, state) { window.alertMessage("No XRP is connected. Files can not be uploaded. Double-check that the XRP is connected before attempting to upload a file."); } } + + editor.onDeleteNonLibFiles = async () => { + if(REPL.DISCONNECT == false && await confirmMessage("This will permanently delete ALL files on the XRP, with the exception of the lib folder, the trash folder, and the XRPExamples folder. Are you SURE you want to do this?")){ + REPL.deleteNonLibFiles(); + window.alertMessage("All non-library files have been deleted from the XRP."); + }else{ + window.alertMessage("No XRP is connected. Files can not be deleted. Double-check that the XRP is connected before attempting to delete a file."); + } + } editor.onSaveToThumby = async () => { // Warn user when trying to save and no Thumby is connected @@ -1168,6 +1192,7 @@ function disableMenuItems(){ document.getElementById('IDFileExport').disabled = true; document.getElementById('IDFileSave').disabled = true; document.getElementById('IDFileSaveAs').disabled = true; + document.getElementById('IDFileDeleteNonLib').disabled = true; } window.disableMenuItems = disableMenuItems; @@ -1177,6 +1202,7 @@ function enableMenuItems(){ document.getElementById('IDFileExport').disabled = false; document.getElementById('IDFileSave').disabled = false; document.getElementById('IDFileSaveAs').disabled = false; + document.getElementById('IDFileDeleteNonLib').disabled = false; } window.enableMenuItems = enableMenuItems; diff --git a/js/repl.js b/js/repl.js index 1d7c056..7515d60 100644 --- a/js/repl.js +++ b/js/repl.js @@ -872,6 +872,38 @@ class ReplJS{ await this.getOnBoardFSTree(); } + async deleteNonLibFiles(){ + if(this.BUSY == true){ + return; + } + this.BUSY = true; + + var cmd = "import os\n" + + "def rm(d): # Remove file or tree\n" + + " try:\n" + + " if os.stat(d)[0] & 0x4000: # Dir\n" + + " for f in os.ilistdir(d):\n" + + " if f[0] not in ('.', '..'):\n" + + " rm('/'.join((d, f[0]))) # File or Dir\n" + + " os.rmdir(d)\n" + + " else: # File\n" + + " os.remove(d)\n" + + " print('rm_worked')\n" + + " except:\n" + + " print('rm_failed')\n" + + "filelist = os.listdir('/')\n" + + "for f in filelist:\n" + + "if f != 'lib' and f != 'trash' and f!= 'XRPExamples'" + + " rm('/' + f)\n"; + + await this.writeUtilityCmdRaw(cmd, true, 1); + + // Get back into normal mode and omit the 3 lines from the normal message, + // don't want to repeat (assumes already on a normal prompt) + await this.getToNormal(3); + this.BUSY = false; + } + // Given a path, delete it on RP2040 async deleteFileOrDir(path){