|
What this is
Other links
The source code
/*
* BufferHistory.java - Remembers caret positions
* :tabSize=8:indentSize=8:noTabs=false:
* :folding=explicit:collapseFolds=1:
*
* Copyright (C) 2000, 2003 Slava Pestov
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.gjt.sp.jedit;
//{{{ Imports
import com.microstar.xml.*;
import java.io.*;
import java.util.*;
import org.gjt.sp.jedit.msg.DynamicMenuChanged;
import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.util.Log;
//}}}
/**
* Recent file list.
* @author Slava Pestov
* @version $Id: BufferHistory.java,v 1.16 2004/08/12 22:42:43 spestov Exp $
*/
public class BufferHistory
{
//{{{ getEntry() method
public static Entry getEntry(String path)
{
Iterator iter = history.iterator();
while(iter.hasNext())
{
Entry entry = (Entry)iter.next();
if(pathsCaseInsensitive)
{
if(entry.path.equalsIgnoreCase(path))
return entry;
}
else
{
if(entry.path.equals(path))
return entry;
}
}
return null;
} //}}}
//{{{ setEntry() method
public static void setEntry(String path, int caret, Selection[] selection,
String encoding)
{
removeEntry(path);
addEntry(new Entry(path,caret,selectionToString(selection),
encoding));
EditBus.send(new DynamicMenuChanged("recent-files"));
} //}}}
//{{{ getHistory() method
/**
* @since jEdit 4.2pre2
*/
public static List getHistory()
{
return history;
} //}}}
//{{{ getBufferHistory() method
/**
* @deprecated Call {@link #getHistory()} instead.
*/
public static Vector getBufferHistory()
{
Vector retVal = new Vector(history.size());
Iterator iter = history.iterator();
while(iter.hasNext())
retVal.add(iter.next());
return retVal;
} //}}}
//{{{ load() method
public static void load()
{
String settingsDirectory = jEdit.getSettingsDirectory();
if(settingsDirectory == null)
return;
File recent = new File(MiscUtilities.constructPath(
settingsDirectory,"recent.xml"));
if(!recent.exists())
return;
recentModTime = recent.lastModified();
Log.log(Log.MESSAGE,BufferHistory.class,"Loading recent.xml");
RecentHandler handler = new RecentHandler();
XmlParser parser = new XmlParser();
Reader in = null;
parser.setHandler(handler);
try
{
in = new BufferedReader(new FileReader(recent));
parser.parse(null, null, in);
}
catch(XmlException xe)
{
int line = xe.getLine();
String message = xe.getMessage();
Log.log(Log.ERROR,BufferHistory.class,recent + ":" + line
+ ": " + message);
}
catch(FileNotFoundException fnf)
{
//Log.log(Log.DEBUG,BufferHistory.class,fnf);
}
catch(Exception e)
{
Log.log(Log.ERROR,BufferHistory.class,e);
}
finally
{
try
{
if(in != null)
in.close();
}
catch(IOException io)
{
Log.log(Log.ERROR,BufferHistory.class,io);
}
}
} //}}}
//{{{ save() method
public static void save()
{
String settingsDirectory = jEdit.getSettingsDirectory();
if(settingsDirectory == null)
return;
File file1 = new File(MiscUtilities.constructPath(
settingsDirectory, "#recent.xml#save#"));
File file2 = new File(MiscUtilities.constructPath(
settingsDirectory, "recent.xml"));
if(file2.exists() && file2.lastModified() != recentModTime)
{
Log.log(Log.WARNING,BufferHistory.class,file2
+ " changed on disk; will not save recent"
+ " files");
return;
}
jEdit.backupSettingsFile(file2);
Log.log(Log.MESSAGE,BufferHistory.class,"Saving " + file1);
String lineSep = System.getProperty("line.separator");
boolean ok = false;
BufferedWriter out = null;
try
{
out = new BufferedWriter(new FileWriter(file1));
out.write("");
out.write(lineSep);
out.write("");
out.write(lineSep);
out.write("
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.