PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/macros/Files/Delete_Current.bsh

#
Unknown | 75 lines | 63 code | 12 blank | 0 comment | 0 complexity | e7d6c2f8753a2b1096cb36af58687f80 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * Delete_Current.bsh - Deletes the current
  3. * buffer's file on disk, but doesn't close
  4. * the buffer.
  5. *
  6. * Copyright (C) 2003-2004 Ollie Rutherfurd <oliver@rutherfurd.net>
  7. *
  8. * $Id: Delete_Current.bsh 4995 2004-03-19 15:58:00Z spestov $
  9. */
  10. import javax.swing.SwingUtilities;
  11. import org.gjt.sp.jedit.io.*;
  12. BufferStatusChecker(View view){
  13. run(){
  14. jEdit.checkBufferStatus(view);
  15. }
  16. return this;
  17. }
  18. void deleteCurrentBuffer(View view){
  19. Buffer buffer = view.getBuffer();
  20. // don't bother deleting new buffers (don't exist on disk)
  21. if(buffer.isNewFile()){
  22. Macros.error(view, "Buffer doesn't exist on disk.");
  23. return;
  24. }
  25. try{
  26. String path = buffer.getPath();
  27. VFS vfs = VFSManager.getVFSForPath(path);
  28. int caps = vfs.getCapabilities();
  29. int del = VFS.DELETE_CAP;
  30. int res = caps & del;
  31. if(res == 0){
  32. Macros.error(view, "VFS " + vfs.getName()
  33. + " doesn't support deleting.");
  34. return;
  35. }
  36. Object session = null;
  37. try{
  38. session = vfs.createVFSSession(path,view);
  39. if(vfs._delete(session,path,view)){
  40. view.getStatus().setMessageAndClear("Deleted: " + path);
  41. }
  42. // invoke buffer status check
  43. SwingUtilities.invokeLater(BufferStatusChecker(view));
  44. }
  45. finally{
  46. if(session != null)
  47. vfs._endVFSSession(session,view);
  48. }
  49. }
  50. catch(Exception e){
  51. Macros.error(view, e.toString());
  52. }
  53. }
  54. deleteCurrentBuffer(view);
  55. /*
  56. <listitem>
  57. <para><filename>Delete_Current.bsh</filename></para>
  58. <abstract><para>
  59. Deletes the current buffer's file on disk, but
  60. doesn't close the buffer.
  61. </para></abstract>
  62. </listitem>
  63. */