PageRenderTime 91ms CodeModel.GetById 87ms app.highlight 2ms RepoModel.GetById 1ms 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
 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
22package infoviewer.actions;
23
24import java.awt.Frame;
25import java.awt.event.ActionEvent;
26import javax.swing.JFileChooser;
27import org.gjt.sp.jedit.jEdit;
28import org.gjt.sp.jedit.GUIUtilities;
29import org.gjt.sp.jedit.View;
30import org.gjt.sp.jedit.io.FileVFS;
31import org.gjt.sp.jedit.io.VFSManager;
32
33
34public class open_file extends InfoViewerAction
35{
36
37    /**
38	 * 
39	 */
40	private static final long serialVersionUID = 8244129956268231628L;
41
42
43	public open_file()
44    {
45        super("infoviewer.open_file");
46    }
47
48
49    public void actionPerformed(ActionEvent evt)
50    {
51        if (lastfile == null)
52        {
53            lastfile = jEdit.getProperty("infoviewer.lastfile");
54            if (lastfile == null)
55                lastfile = jEdit.getJEditHome();
56        }
57
58        Frame frame = getFrame(evt);
59        View view = jEdit.getFirstView();
60        if(frame != null && frame instanceof View)
61            view = (View) frame;
62
63        String files[] = GUIUtilities.showVFSFileDialog(
64            view, lastfile, JFileChooser.OPEN_DIALOG, false);
65
66        if (files == null || files.length == 0)
67            return; // no file chosen
68
69        if (VFSManager.getVFSForPath(files[0]) instanceof FileVFS)
70            lastfile = "file:" + files[0];
71        else
72            lastfile = files[0];
73
74        jEdit.setProperty("infoviewer.lastfile", lastfile);
75        getViewer(evt).gotoURL(lastfile, true, -1);
76    }
77
78
79    private static String lastfile = null;
80
81}
82