PageRenderTime 12ms CodeModel.GetById 4ms app.highlight 7ms 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
24
25
26CmdThread(cmd, view)
27{
28	run()
29	{
30		process = Runtime.getRuntime().exec(cmd);
31		process.waitFor();
32		view.getBuffer().checkFileStatus(view);
33	}
34	return this;
35}
36
37
38void ToggleReadOnly(view)
39{
40
41	buffer = view.getBuffer();
42
43	// must be using file vfs
44	if(!buffer.getVFS().getName().equals("file"))
45	{
46		Macros.error(view, "This macro only works on local files.");
47		return;
48	}
49
50	// is read-only be turned on or off
51	readonly = buffer.isReadOnly();
52
53	if (OperatingSystem.isUnix() || OperatingSystem.isMacOS())
54	{
55		cmd = "chmod " + (readonly ? "+" : "-") + "w " 
56			+ buffer.getPath();
57	}
58	else if(OperatingSystem.isWindows())
59	{
60		cmd = "ATTRIB.EXE " + (readonly ? "-" : "+") + "R \"" 
61			+ buffer.getPath() + "\"";
62	}
63	else
64	{
65		Macros.error(view, "This macro only works on Windows, Unix, & MacOS X.");
66		return;
67	}
68
69	toggle = CmdThread(cmd, view);
70	SwingUtilities.invokeLater(toggle);
71}
72
73ToggleReadOnly(view);
74
75/*
76	Macro index data (in DocBook format)
77
78<listitem>
79	<para><filename>Toggle_ReadOnly.bsh</filename></para>
80	<abstract><para>
81	Toggles a local file's read-only flag. Uses platform-specific commands, so it only works on Windows, Unix and MacOS X.
82	</para></abstract>
83</listitem>
84
85*/
86
87// :indentSize=4:lineSeparator=\n:noTabs=false:tabSize=4:folding=explicit:collapseFolds=1: