/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
- /*
- * 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 5037 2004-05-06 22:35:11Z spestov $
- */
- 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)
- b.close();
- }
- }
- if(buffer.isReadOnly()){
- getToolkit().beep();
- }
- else{
- String selected = view.getTextArea().getSelectedText();
- if(selected == null || selected.indexOf('\n') != -1)
- getToolkit().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>
- */