PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Unknown | 87 lines | 72 code | 15 blank | 0 comment | 0 complexity | 9a8db3eb186011f3f731877b6055ef87 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. * Toggle_ReadOnly.bsh - a BeanShell macro for jEdit that toggles
  3. * a local file's read-only flag.
  4. *
  5. * Copyright (C) 2002,2003 Ollie Rutherfurd, oliver@rutherfurd.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with the jEdit program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. * $Id: Toggle_ReadOnly.bsh 4937 2003-12-22 04:14:55Z spestov $
  22. */
  23. CmdThread(cmd, view)
  24. {
  25. run()
  26. {
  27. process = Runtime.getRuntime().exec(cmd);
  28. process.waitFor();
  29. view.getBuffer().checkFileStatus(view);
  30. }
  31. return this;
  32. }
  33. void ToggleReadOnly(view)
  34. {
  35. buffer = view.getBuffer();
  36. // must be using file vfs
  37. if(!buffer.getVFS().getName().equals("file"))
  38. {
  39. Macros.error(view, "This macro only works on local files.");
  40. return;
  41. }
  42. // is read-only be turned on or off
  43. readonly = buffer.isReadOnly();
  44. if (OperatingSystem.isUnix() || OperatingSystem.isMacOS())
  45. {
  46. cmd = "chmod " + (readonly ? "+" : "-") + "w "
  47. + buffer.getPath();
  48. }
  49. else if(OperatingSystem.isWindows())
  50. {
  51. cmd = "ATTRIB.EXE " + (readonly ? "-" : "+") + "R \""
  52. + buffer.getPath() + "\"";
  53. }
  54. else
  55. {
  56. Macros.error(view, "This macro only works on Windows, Unix, & MacOS X.");
  57. return;
  58. }
  59. toggle = CmdThread(cmd, view);
  60. SwingUtilities.invokeLater(toggle);
  61. }
  62. ToggleReadOnly(view);
  63. /*
  64. Macro index data (in DocBook format)
  65. <listitem>
  66. <para><filename>Toggle_ReadOnly.bsh</filename></para>
  67. <abstract><para>
  68. Toggles a local file's read-only flag. Uses platform-specific commands, so it only works on Windows, Unix and MacOS X.
  69. </para></abstract>
  70. </listitem>
  71. */
  72. // :indentSize=4:lineSeparator=\n:noTabs=false:tabSize=4:folding=explicit:collapseFolds=1: