PageRenderTime 57ms CodeModel.GetById 50ms app.highlight 1ms RepoModel.GetById 5ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/macros/Files/Delete_Current.bsh

#
Unknown | 75 lines | 63 code | 12 blank | 0 comment | 0 complexity | e7d6c2f8753a2b1096cb36af58687f80 MD5 | raw file
 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
11import javax.swing.SwingUtilities;
12import org.gjt.sp.jedit.io.*;
13
14
15BufferStatusChecker(View view){
16	run(){
17		jEdit.checkBufferStatus(view);
18	}
19	return this;
20}
21
22
23void deleteCurrentBuffer(View view){
24	Buffer buffer = view.getBuffer();
25
26	// don't bother deleting new buffers (don't exist on disk)
27	if(buffer.isNewFile()){
28		Macros.error(view, "Buffer doesn't exist on disk.");
29		return;
30	}
31
32	try{
33		String path = buffer.getPath();
34		VFS vfs = VFSManager.getVFSForPath(path);
35		int caps = vfs.getCapabilities();
36		int del = VFS.DELETE_CAP;
37		int res = caps & del;
38		if(res == 0){
39			Macros.error(view, "VFS " + vfs.getName() 
40						 + " doesn't support deleting.");
41			return;
42		}
43	
44		Object session = null;
45		try{
46			session = vfs.createVFSSession(path,view);
47			if(vfs._delete(session,path,view)){
48				view.getStatus().setMessageAndClear("Deleted: " + path);
49			}
50			// invoke buffer status check
51			SwingUtilities.invokeLater(BufferStatusChecker(view));
52		}
53		finally{
54			if(session != null)
55				vfs._endVFSSession(session,view);
56		}
57	}
58	catch(Exception e){
59		Macros.error(view, e.toString());
60	}
61}
62
63deleteCurrentBuffer(view);
64
65/*
66
67	<listitem>
68		<para><filename>Delete_Current.bsh</filename></para>
69		<abstract><para>
70		Deletes the current buffer's file on disk, but 
71		doesn't close the buffer.
72		</para></abstract>
73	</listitem>
74
75*/