File: Delete_Current.bsh

package info (click to toggle)
jedit 5.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,252 kB
  • ctags: 11,190
  • sloc: java: 98,480; xml: 94,070; makefile: 52; sh: 42; cpp: 6; python: 6
file content (79 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Delete_Current.bsh - Deletes the current
 * buffer's file on disk, but doesn't close 
 * the buffer.
 *
 * Copyright (C) 2003-2004 Ollie Rutherfurd <oliver@rutherfurd.net>
 *
 * $Id: Delete_Current.bsh 21353 2012-03-14 09:46:51Z jojaba_67 $
 */

import javax.swing.SwingUtilities;
import org.gjt.sp.jedit.io.*;

//Localization
final static String NotOnDiskError = jEdit.getProperty("macro.rs.DeleteCurrent.NotOnDisk.error", "Buffer doesn't exist on disk.");
final static String DeleteNotSupportError = jEdit.getProperty("macro.rs.DeleteCurrent.DeleteNotSupport.error", "doesn't support deleting.");
final static String DeletedMessage = jEdit.getProperty("macro.rs.DeleteCurrent.Deleted.message", "Deleted:");

BufferStatusChecker(View view){
	run(){
		jEdit.checkBufferStatus(view);
	}
	return this;
}


void deleteCurrentBuffer(View view){
	Buffer buffer = view.getBuffer();

	// don't bother deleting new buffers (don't exist on disk)
	if(buffer.isNewFile()){
		Macros.error(view, NotOnDiskError );
		return;
	}

	try{
		String path = buffer.getPath();
		VFS vfs = VFSManager.getVFSForPath(path);
		int caps = vfs.getCapabilities();
		int del = VFS.DELETE_CAP;
		int res = caps & del;
		if(res == 0){
			Macros.error(view, "VFS " + vfs.getName() 
						 + " " + DeleteNotSupportError);
			return;
		}
	
		Object session = null;
		try{
			session = vfs.createVFSSession(path,view);
			if(vfs._delete(session,path,view)){
				view.getStatus().setMessageAndClear(DeletedMessage + " " + path);
			}
			// invoke buffer status check
			SwingUtilities.invokeLater(BufferStatusChecker(view));
		}
		finally{
			if(session != null)
				vfs._endVFSSession(session,view);
		}
	}
	catch(Exception e){
		Macros.error(view, e.toString());
	}
}

deleteCurrentBuffer(view);

/*

	<listitem>
		<para><filename>Delete_Current.bsh</filename></para>
		<abstract><para>
		Deletes the current buffer's file on disk, but 
		doesn't close the buffer.
		</para></abstract>
	</listitem>

*/