Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions de.vonloesch.pdf4eclipse/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Bundle-ClassPath: .,
lib/jbig2.jar,
lib/PDFrenderer.jar
Bundle-Vendor: %Bundle-Vendor
Export-Package: de.vonloesch.synctex
3 changes: 2 additions & 1 deletion de.vonloesch.pdf4eclipse/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ bin.includes = plugin.xml,\
.,\
icons/,\
lib/,\
OSGI-INF/l10n/bundle.properties
OSGI-INF/l10n/bundle.properties,\
schema/

1 change: 1 addition & 0 deletions de.vonloesch.pdf4eclipse/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="de.vonloesch.pdf4Eclipse.synctexParserAdapter" name="SynctexParserAdapter" schema="schema/de.vonloesch.pdf4Eclipse.synctexParserAdapter.exsd"/>

<extension
point="org.eclipse.ui.editors">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="de.vonloesch.pdf4Eclipse" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="de.vonloesch.pdf4Eclipse" id="de.vonloesch.pdf4Eclipse.synctexParserAdapter" name="SynctexParserAdapter"/>
</appinfo>
<documentation>
SynctexParserAdapter provides an extension to register an adapter to manipulate the SyncTex file resolution.
This could be used the change the file which will open/is open by the PDF-Viewer.

This is especially helpful, when the used .tex files are generated from other files and the editor shall display the source files.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="adapterFactory"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="adapterFactory">
<complexType>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="class" type="string">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":de.vonloesch.synctex.ISynctexParserAdapterFactory"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>


</schema>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
Expand Down Expand Up @@ -88,7 +89,8 @@
import de.vonloesch.pdf4eclipse.model.PDFFactory;
import de.vonloesch.pdf4eclipse.outline.PDFFileOutline;
import de.vonloesch.pdf4eclipse.preferences.PreferenceConstants;
import de.vonloesch.synctex.SimpleSynctexParser;
import de.vonloesch.synctex.DefaultSynctexParserFactory;
import de.vonloesch.synctex.ISynctexParser;

/**
*
Expand Down Expand Up @@ -127,6 +129,7 @@ public class PDFEditor extends EditorPart implements IResourceChangeListener,

private Cursor cursorHand;
private Cursor cursorArrow;
private IProject eclipseProject;

public PDFEditor() {
super();
Expand Down Expand Up @@ -176,7 +179,9 @@ public void readPdfFile() throws PartInitException{
file = new File(((FileStoreEditorInput)input).getURI());
}
else if ((input instanceof IFileEditorInput)) {
file = new File(((IFileEditorInput) input).getFile().getLocationURI());
IFileEditorInput eclipseInputFile = (IFileEditorInput) input;
file = new File(eclipseInputFile.getFile().getLocationURI());
eclipseProject = eclipseInputFile.getFile().getProject();
}
else {
throw new PartInitException(Messages.PDFEditor_ErrorMsg1);
Expand Down Expand Up @@ -523,7 +528,7 @@ private File getSyncTeXFile() {
return null;
}

private SimpleSynctexParser createSimpleSynctexParser(File f)
private ISynctexParser createSimpleSynctexParser(File f)
throws IOException {
InputStream in;
if (f.getName().toLowerCase().endsWith(".gz")) {
Expand All @@ -533,7 +538,7 @@ private SimpleSynctexParser createSimpleSynctexParser(File f)
in = new FileInputStream(f);
}
BufferedReader r = new BufferedReader(new InputStreamReader(in));
return new SimpleSynctexParser(r);
return DefaultSynctexParserFactory.create(r);
}

/**
Expand All @@ -551,8 +556,8 @@ public int forwardSearch(String file, int lineNr) {
if (syncTeXFile == null) return FORWARD_SEARCH_NO_SYNCTEX;
try {
//FIXME: Create a job for this
SimpleSynctexParser p = createSimpleSynctexParser(syncTeXFile);
//System.out.println("Start Forward search");
ISynctexParser p = createSimpleSynctexParser(syncTeXFile);
p.setEclipseProject(eclipseProject);
p.setForwardSearchInformation(file, lineNr);
p.startForward();
p.close();
Expand Down Expand Up @@ -595,23 +600,25 @@ public void reverseSearch(double pdfX, double pdfY) {
//File f = new File (((IFileEditorInput) getEditorInput()).getFile().getRawLocation().removeFileExtension().addFileExtension("synctex.gz").toOSString());
try {
//FIXME: Create a job for this
SimpleSynctexParser p = createSimpleSynctexParser(f);
ISynctexParser p = createSimpleSynctexParser(f);
p.setReverseSearchInformation(currentPage, pdfX, pdfY);
p.startReverse();
p.close();

if (p.sourceFilePath == null) {
String sourceFilePath = p.getSourceFilePath();
int sourceLineNr = p.getSourceLineNr();
if (sourceFilePath == null) {
//Could not find a source file
writeStatusLineError(Messages.PDFEditor_SynctexMsg2);
return;
}

File sourceFile = new File(p.sourceFilePath);
String path = p.sourceFilePath;
File sourceFile = new File(sourceFilePath);
String path = sourceFilePath;
if (!sourceFile.isAbsolute()) {
//Append it to the path of the pdf
path = f.getCanonicalPath();
path = path.substring(0, path.lastIndexOf(File.separatorChar)+1) + p.sourceFilePath;
path = path.substring(0, path.lastIndexOf(File.separatorChar)+1) + sourceFilePath;
}
IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(new File(path));
if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
Expand All @@ -621,12 +628,12 @@ public void reverseSearch(double pdfX, double pdfY) {
if (part instanceof AbstractTextEditor) {
AbstractTextEditor t = (AbstractTextEditor) part;
IDocument doc = t.getDocumentProvider().getDocument(t.getEditorInput());
t.selectAndReveal(doc.getLineOffset(p.sourceLineNr - 1), doc.getLineLength(p.sourceLineNr - 1));
t.selectAndReveal(doc.getLineOffset(sourceLineNr - 1), doc.getLineLength(sourceLineNr - 1));
}
} catch (PartInitException e) {
e.printStackTrace();
} catch (BadLocationException e) {
writeStatusLineError(NLS.bind(Messages.PDFEditor_SynctexMsg3, p.sourceLineNr - 1));
writeStatusLineError(NLS.bind(Messages.PDFEditor_SynctexMsg3, sourceLineNr - 1));
}
} else {
writeStatusLineError(NLS.bind(Messages.PDFEditor_SynctexMsg4, path));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2016 Boris von Loesch.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andreas Turban - initial API and implementation
******************************************************************************/
package de.vonloesch.synctex;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;

/**
* Factory to create {@link ISynctexParser} instances and wrap them with
* contributed adapters of the {@link ISynctexParser}, with
* {@link ISynctexParserAdapterFactory}.
*
* <p>
* The {@link ISynctexParserAdapterFactory} instances are contributed via an
* eclipse extension point.
* </p>
*
* @author Andreas Turban
*
*/
public class DefaultSynctexParserFactory {

private static final String EXT_ID = "de.vonloesch.pdf4Eclipse.synctexParserAdapter";

private static final List<ISynctexParserAdapterFactory> adapters;

static {
ArrayList<ISynctexParserAdapterFactory> adaptersLoc = new ArrayList<ISynctexParserAdapterFactory>();
IConfigurationElement[] configurationElements = Platform.getExtensionRegistry()
.getConfigurationElementsFor(EXT_ID);
for (IConfigurationElement elem : configurationElements) {
try {
Object obj = elem.createExecutableExtension("class");
if (obj instanceof ISynctexParserAdapterFactory) {
adaptersLoc.add((ISynctexParserAdapterFactory) obj);
}
} catch (CoreException e) {
// Ignore wrong contributed adapter
}
}
adaptersLoc.trimToSize();
adapters = Collections.unmodifiableList(adaptersLoc);
}

public static ISynctexParser create(BufferedReader r) {
ISynctexParser parser = new SimpleSynctexParser(r);
for (ISynctexParserAdapterFactory factory : adapters) {
parser = factory.createAdapter(parser);
}
return parser;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2016 Boris von Loesch.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andreas Turban - initial API
******************************************************************************/
package de.vonloesch.synctex;

import java.io.IOException;

import org.eclipse.core.resources.IProject;

/**
* {@link ISynctexParser} defines the API for the Synctex search feature.
*
* @author Andreas Turban
* @author Boris von Loesch
* @see DefaultSynctexParserFactory
*/
public interface ISynctexParser {

void setReverseSearchInformation(int currentPage, double pdfX, double pdfY);

void startReverse() throws IOException;

void startForward() throws IOException;

void close() throws IOException;

String getSourceFilePath();

int getSourceLineNr();

void setForwardSearchInformation(String file, int lineNr);

double[] getForwardSearchResult();

void setEclipseProject(IProject eclipseProject);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2016 Boris von Loesch.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andreas Turban - initial API and implementation
******************************************************************************/
package de.vonloesch.synctex;


/**
* {@link ISynctexParserAdapterFactory} wraps an passed {@link ISynctexParser} with an adapter to change the forward and reverse search behavior.
* contributed adapters of the {@link ISynctexParser}, with
* {@link ISynctexParserAdapterFactory}.
*
* <p>
* The {@link ISynctexParserAdapterFactory} instances are contributed via the
* eclipse extension point "de.vonloesch.pdf4Eclipse.synctexParserAdapter".
* </p>
*
* @author Andreas Turban
*
*/
public interface ISynctexParserAdapterFactory {

/**
* Shall wrap the passed {@link ISynctexParser} to adapt the forward and reverse search behavior.
*/
ISynctexParser createAdapter(ISynctexParser parser);
}
Loading