/* * Rename_Current.bsh - Renames the current buffer. * * David Mlejnek, mailto:davo@nadhlad.sk * */ void renameCurrentBuffer(View view) { try { String fromPath = buffer.getPath(); buffer.saveAs(view, true); VFSManager.waitForRequests(); String toPath = buffer.getPath(); File toFile = new File(toPath); if(fromPath.equals(toPath)) { //nothing to do } else if(!toFile.exists()) { //should not happen Macros.error(view, "Failed to save: " + toPath); } else { //delete old file VFS vfs = VFSManager.getVFSForPath(fromPath); Object session = null; try{ session = vfs.createVFSSession(fromPath, view); if(vfs._delete(session, fromPath, view)){ view.getStatus().setMessageAndClear("Deleted: " + fromPath); } } finally{ if(session != null) vfs._endVFSSession(session, view); } } } catch(Exception e) { Macros.error(view, e.toString()); } } renameCurrentBuffer(view);