PageRenderTime 26ms CodeModel.GetById 23ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Unknown | 53 lines | 46 code | 7 blank | 0 comment | 0 complexity | c1b912ea82dce06a849c8cc6d5b0e760 MD5 | raw file
 1/*
 2 * Insert_Selection.bsh - Inserts the contents of the
 3 * current selection (assuming it's the path to a file)
 4 * into the current buffer -- replacing the selected
 5 * text.  Text must be selected and it must not span
 6 * multiple lines.
 7 *
 8 * Copyright (C) 2004 Ollie Rutherfurd <oliver@jedit.org>
 9 *
10 * $Id: Insert_Selection.bsh 5037 2004-05-06 22:35:11Z spestov $
11 */
12
13insertSelected(View view, String path){
14
15	// read into temporary buffer
16	Buffer b = jEdit.openTemporary(view,null,path,false);
17	try{
18		if(b == null)
19			return;
20
21		while(!b.isLoaded())
22			VFSManager.waitForRequests();
23		String text = b.getText(0,b.getLength());
24		view.getTextArea().setSelectedText(text);
25	}finally{
26		if(b != null)
27			b.close();
28	}
29}
30
31if(buffer.isReadOnly()){
32	getToolkit().beep();
33}
34else{
35	String selected = view.getTextArea().getSelectedText();
36	if(selected == null || selected.indexOf('\n') != -1)
37		getToolkit().beep();
38	else
39		insertSelected(view,selected);
40}
41
42/*
43
44<listitem>
45	<para><filename>Insert_Selection.bsh</filename></para>
46	<abstract><para>Assumes the current selection is 
47	file path and tries replaces the selection with the
48	contents of the file.  Does nothing if no text is 
49	selected or the selection spans multiple lines.
50	</para></abstract>
51</listitem>
52
53*/