File: Insert_Selection.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 (48 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download | duplicates (4)
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
/*
 * Insert_Selection.bsh - Inserts the contents of the
 * current selection (assuming it's the path to a file)
 * into the current buffer -- replacing the selected
 * text.  Text must be selected and it must not span
 * multiple lines.
 *
 * Copyright (C) 2004 Ollie Rutherfurd <oliver@jedit.org>
 *
 * $Id: Insert_Selection.bsh 23971 2015-08-08 19:37:35Z daleanson $
 */

insertSelected(View view, String path){

	// read into temporary buffer
	Buffer b = jEdit.openTemporary(view,null,path,false);
	try{
		if(b == null)
			return;

		while(!b.isLoaded())
			VFSManager.waitForRequests();
		String text = b.getText(0,b.getLength());
		view.getTextArea().setSelectedText(text);
	}finally{
		if(b != null)
			jEdit._closeBuffer(null, b);
	}
}

	String selected = view.getTextArea().getSelectedText();
	if(selected == null || selected.indexOf('\n') != -1)
		Toolkit.getDefaultToolkit().beep();
	else
		insertSelected(view,selected);

/*

<listitem>
	<para><filename>Insert_Selection.bsh</filename></para>
	<abstract><para>Assumes the current selection is 
	file path and tries replaces the selection with the
	contents of the file.  Does nothing if no text is 
	selected or the selection spans multiple lines.
	</para></abstract>
</listitem>

*/