rendered paste bodyIndex: source/net/sourceforge/texlipse/TexlipsePluginResources.properties
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/TexlipsePluginResources.properties,v
retrieving revision 1.16
diff -u -r1.16 TexlipsePluginResources.properties
--- source/net/sourceforge/texlipse/TexlipsePluginResources.properties 26 Mar 2006 19:31:18 -0000 1.16
+++ source/net/sourceforge/texlipse/TexlipsePluginResources.properties 3 Apr 2006 15:30:14 -0000
@@ -78,6 +78,7 @@
# Viewers
preferenceViewerPageDescription=The configured viewers. The first viewer in the list is used when launching previewer from the menu. Other configurations are here just for easy switching.
preferenceViewerBuildLabel=Build project automatically before launching viewer.
+preferenceViewerReturnFocusLabel=Return focus to Eclipse after launching previewer.
preferenceViewerPortLabel=The inverse search port number is the port that is opened for external viewer programs to input inverse search (navigation from output file to source file) commands.
preferenceViewerConfigsPort=Inverse search port number (%1-%2):
preferenceViewerConfigsLabel=Viewer configurations (1st is default):
Index: source/net/sourceforge/texlipse/actions/PreviewAction.java
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/actions/PreviewAction.java,v
retrieving revision 1.2
diff -u -r1.2 PreviewAction.java
--- source/net/sourceforge/texlipse/actions/PreviewAction.java 26 Mar 2006 10:53:48 -0000 1.2
+++ source/net/sourceforge/texlipse/actions/PreviewAction.java 3 Apr 2006 15:30:14 -0000
@@ -10,10 +10,14 @@
package net.sourceforge.texlipse.actions;
import net.sourceforge.texlipse.TexlipsePlugin;
+import net.sourceforge.texlipse.builder.BuilderRegistry;
+import net.sourceforge.texlipse.builder.TexlipseNature;
+import net.sourceforge.texlipse.properties.TexlipseProperties;
import net.sourceforge.texlipse.viewer.TexLaunchConfigurationDelegate;
import net.sourceforge.texlipse.viewer.TexLaunchConfigurationTab;
import net.sourceforge.texlipse.viewer.ViewerAttributeRegistry;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -49,6 +53,29 @@
try {
ILaunchConfiguration config = null;
+ // Get the output format
+ IProject project = TexlipsePlugin.getCurrentProject();
+ String outputFormat = TexlipseProperties.getProjectProperty(project,
+ TexlipseProperties.OUTPUT_FORMAT);
+
+ // Select a suitable previewer. This is a workaround for now, and is supposed
+ // to fix bug 1237703. In the future with out new build/preview system people
+ // should be able to set up their favorite pdf-previewer for example.
+ String preferredViewer = "";
+ if (outputFormat.equals("pdf")) {
+ preferredViewer = "acroread";
+ }
+ else if (outputFormat.equals("dvi")) {
+ preferredViewer = "yap";
+ }
+ else if (outputFormat.equals("ps")) {
+ preferredViewer = "gv";
+ }
+ else {
+ BuilderRegistry.printToConsole(TexlipsePlugin.getResourceString("builderErrorOutputFormatNotSet").replaceAll("%s", project.getName()));
+ throw new CoreException(TexlipsePlugin.stat("Project output file format not set."));
+ }
+
// Internal, but will probably not change very much *cross fingers* :P
LaunchConfigurationManager configManager = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
if (configManager != null) {
@@ -57,13 +84,10 @@
ILaunchConfiguration[] configs = history.getHistory();
if (configs != null) {
// Try to find a recent viewer launch first
- ViewerAttributeRegistry registry = new ViewerAttributeRegistry();
- String[] viewers = registry.getViewerList();
- String activeViewer = viewers[registry.getActiveViewerIndex(viewers)];
for (int i = 0; i < configs.length ; i++) {
ILaunchConfiguration c = configs[i];
if (c.getType().getIdentifier().equals(TexLaunchConfigurationDelegate.CONFIGURATION_ID)) {
- if (c.getAttribute("viewerCurrent", "").equals(activeViewer)) {
+ if (c.getAttribute("viewerCurrent", "").equals(preferredViewer)) {
config = c;
break;
}
@@ -81,12 +105,15 @@
ILaunchConfigurationType type = manager.getLaunchConfigurationType(
TexLaunchConfigurationDelegate.CONFIGURATION_ID);
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null,
- manager.generateUniqueLaunchConfigurationNameFrom("Preview Document"));
+ manager.generateUniqueLaunchConfigurationNameFrom("Preview Document in " + preferredViewer));
+ // Request another viewer than the topmost in the preferences
+ workingCopy.setAttribute("viewerCurrent", preferredViewer);
+
// For some reason the Eclipse API wants us to init default values
// for new configurations using the ConfigurationTab dialog.
TexLaunchConfigurationTab tab = new TexLaunchConfigurationTab();
- tab.setDefaults(workingCopy);
+ tab.setDefaults(workingCopy);
config = workingCopy.doSave();
}
Index: source/net/sourceforge/texlipse/properties/TexlipseProperties.java
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/properties/TexlipseProperties.java,v
retrieving revision 1.12
diff -u -r1.12 TexlipseProperties.java
--- source/net/sourceforge/texlipse/properties/TexlipseProperties.java 26 Mar 2006 18:51:18 -0000 1.12
+++ source/net/sourceforge/texlipse/properties/TexlipseProperties.java 3 Apr 2006 15:30:14 -0000
@@ -132,6 +132,7 @@
public static final String BUILDER_NUMBER = "builderNum";
public static final String BUILDER_CONSOLE_OUTPUT = "builderConsole";
public static final String BUILD_BEFORE_VIEW = "buildBeforeView";
+ public static final String BUILDER_RETURN_FOCUS = "returnFocusOnPreivew";
public static final String OUTPUT_FORMAT = "outputFormat";
public static final String OUTPUT_FORMAT_AUX = "aux";
Index: source/net/sourceforge/texlipse/properties/ViewerSettingsPreferencePage.java
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/properties/ViewerSettingsPreferencePage.java,v
retrieving revision 1.2
diff -u -r1.2 ViewerSettingsPreferencePage.java
--- source/net/sourceforge/texlipse/properties/ViewerSettingsPreferencePage.java 26 Mar 2006 10:53:48 -0000 1.2
+++ source/net/sourceforge/texlipse/properties/ViewerSettingsPreferencePage.java 3 Apr 2006 15:30:14 -0000
@@ -12,6 +12,7 @@
import net.sourceforge.texlipse.TexlipsePlugin;
import net.sourceforge.texlipse.viewer.util.FileLocationServer;
+import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.ui.IWorkbench;
@@ -54,9 +55,11 @@
//TexlipsePreferencePage.addSpacer(2, getFieldEditorParent());
//TexlipsePreferencePage.addSeparator(2, getFieldEditorParent());
//addField(new BooleanFieldEditor(TexlipseProperties.BUILD_BEFORE_VIEW, TexlipsePlugin.getResourceString("preferenceViewerBuildLabel"), getFieldEditorParent()));
-
+
TexlipsePreferencePage.addSpacer(2, getFieldEditorParent());
+ TexlipsePreferencePage.addSeparator(2, getFieldEditorParent());
+ TexlipsePreferencePage.addSpacer(2, getFieldEditorParent());
TexlipsePreferencePage.addLabelField(2, TexlipsePlugin.getResourceString("preferenceViewerPortLabel"), getFieldEditorParent());
String message = TexlipsePlugin.getResourceString("preferenceViewerConfigsPort").replaceFirst("%1", "" + MIN_PORT).replaceFirst("%2", "" + MAX_PORT);
@@ -64,6 +67,10 @@
port.setValidateStrategy(IntegerFieldEditor.VALIDATE_ON_KEY_STROKE);
port.setValidRange(MIN_PORT, MAX_PORT);
addField(port);
+
+ TexlipsePreferencePage.addSpacer(2, getFieldEditorParent());
+ addField(new BooleanFieldEditor(TexlipseProperties.BUILDER_RETURN_FOCUS, TexlipsePlugin.getResourceString("preferenceViewerReturnFocusLabel"), getFieldEditorParent()));
+
WorkbenchHelp.setHelp(port.getTextControl(getFieldEditorParent()), TexlipseHelpIds.VIEWER_PORT);
}
Index: source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationDelegate.java
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationDelegate.java,v
retrieving revision 1.2
diff -u -r1.2 TexLaunchConfigurationDelegate.java
--- source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationDelegate.java 26 Mar 2006 10:53:48 -0000 1.2
+++ source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationDelegate.java 3 Apr 2006 15:30:14 -0000
@@ -13,6 +13,7 @@
import java.util.Map;
import net.sourceforge.texlipse.TexlipsePlugin;
+import net.sourceforge.texlipse.properties.TexlipseProperties;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
@@ -21,6 +22,13 @@
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
/**
@@ -32,7 +40,7 @@
public class TexLaunchConfigurationDelegate extends LaunchConfigurationDelegate {
public static final String CONFIGURATION_ID = "net.sourceforge.texlipse.viewer.launchConfigurationType";
-
+
/**
* Constructor, does nothing.
*/
@@ -61,13 +69,23 @@
registry.setValues(regMap);
Map addEnv = configuration.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, new HashMap());
-
+
monitor.beginTask("Viewing document", 100);
Process process = ViewerManager.preview(registry, addEnv, monitor);
- // if this process is added to launcer, the output will not be parsed correctly
- //launch.addProcess(DebugPlugin.newProcess(launch, process, mode));
+ // if this process is added to launcher, the output will not be parsed correctly
+ //launch.addProcess(DebugPlugin.newProcess(launch, process, mode));
+ IPreferenceStore prefs = TexlipsePlugin.getDefault().getPreferenceStore();
+ if (prefs.getBoolean(TexlipseProperties.BUILDER_RETURN_FOCUS)) {
+
+ try {
+ Thread.sleep(500); // A small delay required
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ ViewerManager.returnFocusToEclipse(false);
+ }
}
-
}
Index: source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationTab.java
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationTab.java,v
retrieving revision 1.2
diff -u -r1.2 TexLaunchConfigurationTab.java
--- source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationTab.java 26 Mar 2006 10:53:48 -0000 1.2
+++ source/net/sourceforge/texlipse/viewer/TexLaunchConfigurationTab.java 3 Apr 2006 15:30:15 -0000
@@ -230,18 +230,25 @@
* @param configuration launch configuration
*/
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
-
- String viewer = registry.getActiveViewer();
- configuration.setAttribute(ViewerAttributeRegistry.VIEWER_CURRENT, viewer);
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_COMMAND, registry.getCommand());
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_ARGUMENTS, registry.getArguments());
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_VIEW_COMMAND, registry.getDDEViewCommand());
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_VIEW_SERVER, registry.getDDEViewServer());
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_VIEW_TOPIC, registry.getDDEViewTopic());
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_CLOSE_COMMAND, registry.getDDECloseCommand());
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_CLOSE_SERVER, registry.getDDECloseServer());
- configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_CLOSE_TOPIC, registry.getDDECloseTopic());
+ try {
+ String viewer = configuration.getAttribute("viewerCurrent", registry.getActiveViewer());
+ registry.setActiveViewer(viewer);
+
+ configuration.setAttribute(ViewerAttributeRegistry.VIEWER_CURRENT, viewer);
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_COMMAND, registry.getCommand());
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_ARGUMENTS, registry.getArguments());
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_VIEW_COMMAND, registry.getDDEViewCommand());
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_VIEW_SERVER, registry.getDDEViewServer());
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_VIEW_TOPIC, registry.getDDEViewTopic());
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_CLOSE_COMMAND, registry.getDDECloseCommand());
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_CLOSE_SERVER, registry.getDDECloseServer());
+ configuration.setAttribute(viewer + ViewerAttributeRegistry.ATTRIBUTE_DDE_CLOSE_TOPIC, registry.getDDECloseTopic());
+ } catch (CoreException e) {
+ TexlipsePlugin.log("Populating launch configuration", e);
+ }
}
+
+
/**
* Initializes this tab's controls with values from the given
Index: source/net/sourceforge/texlipse/viewer/ViewerManager.java
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/viewer/ViewerManager.java,v
retrieving revision 1.5
diff -u -r1.5 ViewerManager.java
--- source/net/sourceforge/texlipse/viewer/ViewerManager.java 26 Mar 2006 10:53:48 -0000 1.5
+++ source/net/sourceforge/texlipse/viewer/ViewerManager.java 3 Apr 2006 15:30:15 -0000
@@ -41,6 +41,11 @@
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
/**
@@ -170,8 +175,71 @@
Process process = mgr.getExisting();
if (process != null) {
mgr.sendDDECloseCommand();
+
+ try {
+ Thread.sleep(500); // A small delay required
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ returnFocusToEclipse(false);
}
}
+
+ /**
+ * Returns the application focus to Eclipse after launching an
+ * external previewer. This is done by first activating the
+ * eclipse window, and then setting focus in the editor in a
+ * worker thread. Note the delay needed before setting focus.
+ */
+ public static void returnFocusToEclipse(final boolean useMinimizeTrick) {
+
+ // Return focus/activation to Eclipse/Texlipse
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ if (null != display) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow[] workbenchWindows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for (int i = 0; i < workbenchWindows.length; i++) {
+ Shell shell = workbenchWindows[i].getShell();
+
+ if (useMinimizeTrick) {
+ shell.setMinimized(true);
+ shell.setMinimized(false);
+ }
+
+ shell.setActive();
+ shell.forceActive();
+ break;
+ }
+ }
+ });
+ }
+
+ // Spawn thread to set focus in the editor after the launch has completed
+ // The reason we cannot do this in the current thread is because the progress
+ // window is in the way and will not allow us to set focus on the editor.
+ new Thread(new Runnable() {
+ public void run() {
+ try { Thread.sleep(500); } catch (Exception e) { }
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ if (null != display) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow[] workbenchWindows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for (int i = 0; i < workbenchWindows.length; i++) {
+ IWorkbenchPage activePage = workbenchWindows[i].getActivePage();
+ activePage.activate(activePage.getActiveEditor());
+ // Although setFocus should not be called by clients it is
+ // required for the focus to work. Activate alone is not enough.
+ activePage.getActiveEditor().setFocus();
+ }
+ }
+ });
+ }
+ }
+ }).start();
+ }
/**
* Construct a new viewer launcher.
@@ -341,7 +409,6 @@
}
}
-
/**
* Resolves a relative path from one directory to another.
* The path is returned as an OS-specific string with
Index: source/net/sourceforge/texlipse/viewer/ViewerOutputScanner.java
===================================================================
RCS file: /cvsroot/texlipse/net.sourceforge.texlipse/source/net/sourceforge/texlipse/viewer/ViewerOutputScanner.java,v
retrieving revision 1.2
diff -u -r1.2 ViewerOutputScanner.java
--- source/net/sourceforge/texlipse/viewer/ViewerOutputScanner.java 14 Apr 2005 19:01:02 -0000 1.2
+++ source/net/sourceforge/texlipse/viewer/ViewerOutputScanner.java 3 Apr 2006 15:30:15 -0000
@@ -24,7 +24,9 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.MarkerUtilities;
@@ -111,7 +113,7 @@
* @param lineNumber line number
*/
protected void openFileFromLineNumber(String file, int lineNumber) {
-
+
if (project == null) {
return;
}
@@ -176,6 +178,12 @@
mark.delete();
} catch (CoreException e) {
}
+
+ new Thread(new Runnable() {
+ public void run() {
+ ViewerManager.returnFocusToEclipse(true);
+ }
+ }).start();
}
}