Skip to content
Draft
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: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@
title = "Save editor contents to file on XRP under a specific path">
Save As to XRP
</button></li>
<li class = "uk-nav-divider"></li>
<li><button
id = "IDFileDeleteNonLib"
class = "uk-button-xmenu uk-button-secondary-xmenu uk-button-small uk-width-1-1"
title = "Delete all non default files">
Delete All Non-Default Files
</button></li>
</ul>
</div>
<!-- VIEW Menu-->
Expand Down
1 change: 1 addition & 0 deletions js/editor_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions js/filesystem_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class FILESYSTEM{
this.onUploadFiles = undefined;
this.onRefresh = undefined;
this.onDownloadFiles = undefined;
this.onDeleteNonLibFiles = undefined;
// this.onNewFile = undefined;


Expand Down
26 changes: 26 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
32 changes: 32 additions & 0 deletions js/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down