From 61408ca8f0ed9b342c3f55aaea4fde4ece956e46 Mon Sep 17 00:00:00 2001 From: Timotei Dolean Date: Thu, 27 May 2010 20:04:31 +0000 Subject: [PATCH] eclipse plugin: actual implementation... ...of the "show preprocessed config" menus --- .../java/eclipse_plugin/META-INF/MANIFEST.MF | 3 +- .../action/ShowPlainPreprocessedConfig.java | 6 +++- .../action/ShowPreprocessedConfig.java | 6 +++- .../globalactions/PreprocessorActions.java | 31 +++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/utils/java/eclipse_plugin/META-INF/MANIFEST.MF b/utils/java/eclipse_plugin/META-INF/MANIFEST.MF index d48ae0e2e33..b1fc6c38ebb 100644 --- a/utils/java/eclipse_plugin/META-INF/MANIFEST.MF +++ b/utils/java/eclipse_plugin/META-INF/MANIFEST.MF @@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.ui, org.wesnoth.wml.ide;bundle-version="1.0.0", org.wesnoth.wml.ide.generator;bundle-version="1.0.0", org.wesnoth.wml.ide.ui;bundle-version="1.0.0", - org.apache.ant;bundle-version="1.7.1" + org.apache.ant;bundle-version="1.7.1", + org.eclipse.core.filesystem;bundle-version="1.2.1" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPlainPreprocessedConfig.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPlainPreprocessedConfig.java index aabbe727319..a017e6a933b 100644 --- a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPlainPreprocessedConfig.java +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPlainPreprocessedConfig.java @@ -5,6 +5,9 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; +import wesnoth_eclipse_plugin.globalactions.PreprocessorActions; +import wesnoth_eclipse_plugin.utils.WorkspaceUtils; + public class ShowPlainPreprocessedConfig implements IObjectActionDelegate { public ShowPlainPreprocessedConfig(){} @@ -16,7 +19,8 @@ public class ShowPlainPreprocessedConfig implements IObjectActionDelegate @Override public void run(IAction action) { - + PreprocessorActions.openPreprocessedFileInEditor(WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow()), + true); } @Override diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPreprocessedConfig.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPreprocessedConfig.java index 8fa66dd4bb1..e4486db44d6 100644 --- a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPreprocessedConfig.java +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/ShowPreprocessedConfig.java @@ -5,6 +5,9 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; +import wesnoth_eclipse_plugin.globalactions.PreprocessorActions; +import wesnoth_eclipse_plugin.utils.WorkspaceUtils; + public class ShowPreprocessedConfig implements IObjectActionDelegate { public ShowPreprocessedConfig() { } @@ -16,7 +19,8 @@ public class ShowPreprocessedConfig implements IObjectActionDelegate @Override public void run(IAction action) { - + PreprocessorActions.openPreprocessedFileInEditor(WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow()), + false); } @Override diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/globalactions/PreprocessorActions.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/globalactions/PreprocessorActions.java index d8de554247f..28a168003d9 100644 --- a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/globalactions/PreprocessorActions.java +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/globalactions/PreprocessorActions.java @@ -6,9 +6,16 @@ package wesnoth_eclipse_plugin.globalactions; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.Path; +import org.eclipse.ui.ide.IDE; + import wesnoth_eclipse_plugin.builder.ExternalToolInvoker; import wesnoth_eclipse_plugin.preferences.PreferenceConstants; import wesnoth_eclipse_plugin.preferences.PreferenceInitializer; +import wesnoth_eclipse_plugin.utils.WorkspaceUtils; public class PreprocessorActions { @@ -53,4 +60,28 @@ public class PreprocessorActions return false; } } + + /** + * Opens the preprocessed version of the specified file + * @param file the file to show preprocessed output + * @param openPlain true if it should open the plain preprocessed version + * or false for the normal one + */ + public static void openPreprocessedFileInEditor(IFile file, boolean openPlain) + { + if (file == null) + return; + + IFileStore preprocFile = EFS.getLocalFileSystem().getStore(new Path(WorkspaceUtils.getTemporaryFolder())); + preprocFile = preprocFile.getChild(file.getName() + (openPlain == true? ".plain" : "") ); + + try + { + IDE.openEditorOnFileStore(WorkspaceUtils.getWorkbenchWindow().getActivePage(), preprocFile); + } + catch (Exception e) + { + e.printStackTrace(); + } + } }