PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. insertSelected(View view, String path){
  13. // read into temporary buffer
  14. Buffer b = jEdit.openTemporary(view,null,path,false);
  15. try{
  16. if(b == null)
  17. return;
  18. while(!b.isLoaded())
  19. VFSManager.waitForRequests();
  20. String text = b.getText(0,b.getLength());
  21. view.getTextArea().setSelectedText(text);
  22. }finally{
  23. if(b != null)
  24. b.close();
  25. }
  26. }
  27. if(buffer.isReadOnly()){
  28. getToolkit().beep();
  29. }
  30. else{
  31. String selected = view.getTextArea().getSelectedText();
  32. if(selected == null || selected.indexOf('\n') != -1)
  33. getToolkit().beep();
  34. else
  35. insertSelected(view,selected);
  36. }
  37. /*
  38. <listitem>
  39. <para><filename>Insert_Selection.bsh</filename></para>
  40. <abstract><para>Assumes the current selection is
  41. file path and tries replaces the selection with the
  42. contents of the file. Does nothing if no text is
  43. selected or the selection spans multiple lines.
  44. </para></abstract>
  45. </listitem>
  46. */