/** * save selected file to disk */ private void saveFile() { // get the text handler Editor editor=(Editor)getJPE().getEditor(); if (editor!=null) { // get the selected file from the text handler OpenFile file=editor.getEditFile(); if (file!=null) { // signal the use we are saving and save it to disk getJPE().say("Saving file "+file.getName()); file.saveFile(); getJPE().say("Saved file "+file.getName()); } } }
@Override public String getName() { String ret = mFile.getName(); if (ret.endsWith("/")) ret = ret.substring(0, ret.length() - 1); ret = ret.substring(ret.lastIndexOf("/") + 1); return ret; }
/** * close the selected file, meaning removing it from the Opened * list and removing it from the auto reload on startup list */ private void closeFile() { OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened"); Editor editor=(Editor)getJPE().getEditor(); if (editor!=null) { OpenFile file=editor.getEditFile(); if (!file.isDirty()) { ofh.removeFile(file); addRecent(file.getName()); ofh.switchOpenFile(); } else { getJPE().setAskMode(this,"close","File not saved, save first (y/n) ? ",true); } } }
/** * ask the user for a filename (using a file requester) and save * the current file under that name */ private void saveAsFile() { // get openfile handlers OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened"); if (ofh!=null) { // ask the user for the file name String filename=getFileName(FileDialog.SAVE); // get the text handler Editor editor=(Editor)getJPE().getEditor(); // get the selected file OpenFile file=editor.getEditFile(); // remove the file from the opened list ofh.removeFile(file); if (file!=null) { // set the new name in the file file.setName(filename); getJPE().say("Saving file "+file.getName()); // save the file under this new name file.saveFile(); // add the file to the opened files again (now new name) ofh.addFile(file); getJPE().say("Saved file "+file.getName()); } } }