Update of /cvsroot/texeclipse/net.sourceforge.texeclipse/src/net/sourceforge/texeclipse/wizards
In directory sc8-pr-cvs1:/tmp/cvs-serv16922/src/net/sourceforge/texeclipse/wizards
Added Files:
NewTexFileWizard.java NewTexProjectWizard.java
Log Message:
Initial commit. Nothing more then simple syntax highlighting is supported, a new tex project wizard and a new tex file wizard.
--- NEW FILE: NewTexFileWizard.java ---
package net.sourceforge.texeclipse.wizards;
import org.eclipse.ui.IWorkbench;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
/**
* @see Wizard
*/
public class NewTexFileWizard extends Wizard implements INewWizard
{
private IStructuredSelection selection;
private WizardNewFileCreationPage page;
/**
*/
public NewTexFileWizard()
{
}
/**
* Adding the page to the wizard.
*/
public void addPages()
{
page = new WizardNewFileCreationPage("newTexFile",selection);
page.setTitle("New TeX File");
page.setDescription("Create a TeX file.");
page.setFileName("new.tex");
addPage(page);
}
/**
* @see Wizard#performFinish
*/
public boolean performFinish()
{
page.createNewFile();
return true;
}
/**
* @see Wizard#init
*/
public void init(IWorkbench workbench, IStructuredSelection selection)
{
this.selection = selection;
}
}
--- NEW FILE: NewTexProjectWizard.java ---
package net.sourceforge.texeclipse.wizards;
import java.lang.reflect.InvocationTargetException;
import net.sourceforge.texeclipse.TexeclipsePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
public class NewTexProjectWizard extends Wizard implements INewWizard
{
private WizardNewProjectCreationPage page;
private ISelection selection;
private IProject newProject;
/**
* Constructor for NewTexProjectWizard.
*/
public NewTexProjectWizard()
{
super();
setNeedsProgressMonitor(true);
}
/**
* Adding the page to the wizard.
*/
public void addPages()
{
page = new WizardNewProjectCreationPage("newTexProject");
page.setTitle("New TeX Project");
page.setDescription("Create a TeX project.");
addPage(page);
}
/**
* This method is called when 'Finish' button is pressed in
* the wizard. We will create an operation and run it
* using wizard as execution context.
*/
public boolean performFinish()
{
IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(
new IRunnableWithProgress()
{
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
int remaining = 10;
monitor.beginTask("Creating TeX Project",remaining);
newProject = page.getProjectHandle();
try
{
if (!newProject.exists())
{
newProject.create(new SubProgressMonitor(monitor, 1));
remaining--;
}
if (!newProject.isOpen())
{
newProject.open(new SubProgressMonitor(monitor, 1));
remaining--;
}
if (!newProject.hasNature(TexeclipsePlugin.TEX_NATURE_ID))
{
IProjectDescription description = newProject.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = TexeclipsePlugin.TEX_NATURE_ID;
description.setNatureIds(newNatures);
newProject.setDescription(description, monitor);
}
} catch (CoreException e)
{
throw new InvocationTargetException(e);
} finally
{
monitor.done();
}
}
});
try {
getContainer().run(false, true, projectCreationOperation);
} catch (Exception e)
{
MessageDialog.openError(getShell(), "Error", e.getMessage());
return false;
}
return true;
}
/**
* We will accept the selection in the workbench to see if
* we can initialize from it.
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection)
{
this.selection = selection;
}
}
|