|
What this is
Other links
The source code
/*
* PerspectiveManager.java - Saves view configuration
* :tabSize=8:indentSize=8:noTabs=false:
* :folding=explicit:collapseFolds=1:
*
* Copyright (C) 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;
import com.microstar.xml.*;
import java.io.*;
import org.gjt.sp.util.Log;
/**
* Manages persistence of open buffers and views across jEdit sessions.
* @since jEdit 4.2pre1
* @author Slava Pestov
* @version $Id: PerspectiveManager.java,v 1.12 2004/08/17 06:37:36 spestov Exp $
*/
public class PerspectiveManager
{
//{{{ isPerspectiveDirty() method
/**
* We only autosave the perspective if it has changed, to avoid spinning
* up the disk on laptops.
* @since jEdit 4.2pre13
*/
public static boolean isPerspectiveDirty()
{
return dirty;
} //}}}
//{{{ setPerspectiveDirty() method
/**
* We only autosave the perspective if it has changed, to avoid spinning
* up the disk on laptops.
* @since jEdit 4.2pre13
*/
public static void setPerspectiveDirty(boolean dirty)
{
PerspectiveManager.dirty = dirty;
} //}}}
//{{{ loadPerspective() method
public static View loadPerspective(boolean restoreFiles)
{
String settingsDirectory = jEdit.getSettingsDirectory();
if(settingsDirectory == null)
return null;
File perspective = new File(MiscUtilities.constructPath(
settingsDirectory,"perspective.xml"));
if(!perspective.exists())
return null;
Log.log(Log.MESSAGE,PerspectiveManager.class,"Loading " + perspective);
PerspectiveHandler handler = new PerspectiveHandler(restoreFiles);
XmlParser parser = new XmlParser();
parser.setHandler(handler);
Reader in = null;
try
{
in = new BufferedReader(new FileReader(perspective));
parser.parse(null, null, in);
}
catch(XmlException xe)
{
int line = xe.getLine();
String message = xe.getMessage();
Log.log(Log.ERROR,PerspectiveManager.class,perspective
+ ":" + line + ": " + message);
}
catch(FileNotFoundException fnf)
{
}
catch(Exception e)
{
Log.log(Log.ERROR,PerspectiveManager.class,e);
}
finally
{
try
{
if(in != null)
in.close();
}
catch(IOException io)
{
Log.log(Log.ERROR,PerspectiveManager.class,io);
}
}
return handler.view;
} //}}}
//{{{ savePerspective() method
public static void savePerspective(boolean autosave)
{
String settingsDirectory = jEdit.getSettingsDirectory();
if(settingsDirectory == null)
return;
// backgrounded
if(jEdit.getBufferCount() == 0)
return;
if(!autosave)
Log.log(Log.MESSAGE,PerspectiveManager.class,"Saving perspective.xml");
File file1 = new File(MiscUtilities.constructPath(
settingsDirectory,"#perspective.xml#save#"));
File file2 = new File(MiscUtilities.constructPath(
settingsDirectory,"perspective.xml"));
String lineSep = System.getProperty("line.separator");
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.