PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/InfoViewer/infoviewer/actions/open_file.java

#
Java | 82 lines | 41 code | 18 blank | 23 comment | 12 complexity | 66f447cc19fbbce4f3d21edea06febee 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. * open_file.java - display a file selection box and open a file in InfoViewer
  3. * Copyright (C) 1999-2001 Dirk Moebius
  4. *
  5. * :tabSize=4:indentSize=4:noTabs=true:maxLineLen=0:
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package infoviewer.actions;
  22. import java.awt.Frame;
  23. import java.awt.event.ActionEvent;
  24. import javax.swing.JFileChooser;
  25. import org.gjt.sp.jedit.jEdit;
  26. import org.gjt.sp.jedit.GUIUtilities;
  27. import org.gjt.sp.jedit.View;
  28. import org.gjt.sp.jedit.io.FileVFS;
  29. import org.gjt.sp.jedit.io.VFSManager;
  30. public class open_file extends InfoViewerAction
  31. {
  32. /**
  33. *
  34. */
  35. private static final long serialVersionUID = 8244129956268231628L;
  36. public open_file()
  37. {
  38. super("infoviewer.open_file");
  39. }
  40. public void actionPerformed(ActionEvent evt)
  41. {
  42. if (lastfile == null)
  43. {
  44. lastfile = jEdit.getProperty("infoviewer.lastfile");
  45. if (lastfile == null)
  46. lastfile = jEdit.getJEditHome();
  47. }
  48. Frame frame = getFrame(evt);
  49. View view = jEdit.getFirstView();
  50. if(frame != null && frame instanceof View)
  51. view = (View) frame;
  52. String files[] = GUIUtilities.showVFSFileDialog(
  53. view, lastfile, JFileChooser.OPEN_DIALOG, false);
  54. if (files == null || files.length == 0)
  55. return; // no file chosen
  56. if (VFSManager.getVFSForPath(files[0]) instanceof FileVFS)
  57. lastfile = "file:" + files[0];
  58. else
  59. lastfile = files[0];
  60. jEdit.setProperty("infoviewer.lastfile", lastfile);
  61. getViewer(evt).gotoURL(lastfile, true, -1);
  62. }
  63. private static String lastfile = null;
  64. }