eclipse plugin: add menus for showing wmllint for different file types

This commit is contained in:
Timotei Dolean 2010-05-28 10:21:39 +00:00
parent 9727ee7db4
commit 1c77f312fa
7 changed files with 184 additions and 3 deletions

View file

@ -15,6 +15,7 @@ Require-Bundle: org.eclipse.ui,
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.eclipse.core.filesystem;bundle-version="1.2.1"
org.eclipse.core.filesystem;bundle-version="1.2.1",
org.eclipse.ui.console;bundle-version="3.4.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy

View file

@ -108,6 +108,27 @@
label="Show plain preprocessed file"
menubarPath="plugin.preprocessorMenu/preprocessorMenuMarker">
</action>
<menu
icon="icons/wesnoth-icon_16.png"
id="plugin.wmltoolsMenu"
label="WML Tools"
path="_wesnoth">
<groupMarker
name="wmltoolsMenuMarker">
</groupMarker>
</menu>
<action
class="wesnoth_eclipse_plugin.action.RunWMLLintOnFile"
id="Wesnoth Eclipse Plugin.action5"
label="Run &quot;wmllint&quot; on this file"
menubarPath="plugin.wmltoolsMenu/wmltoolsMenuMarker">
</action>
<action
class="wesnoth_eclipse_plugin.action.RunWMLLintOnPreprocFile"
id="Wesnoth Eclipse Plugin.action6"
label="Run &quot;wmllint&quot; on preprocessed file"
menubarPath="plugin.wmltoolsMenu/wmltoolsMenuMarker">
</action>
</objectContribution>
</extension>
<extension

View file

@ -0,0 +1,29 @@
package wesnoth_eclipse_plugin.action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import wesnoth_eclipse_plugin.globalactions.WMLTools;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
public class RunWMLLintOnFile implements IObjectActionDelegate
{
public RunWMLLintOnFile(){ }
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart){
}
@Override
public void run(IAction action)
{
WMLTools.runWMLLint(WorkspaceUtils.getPathRelativeToUserDir(WorkspaceUtils.getSelectedFile()),
true, true,false);
}
@Override
public void selectionChanged(IAction action, ISelection selection){
}
}

View file

@ -0,0 +1,32 @@
package wesnoth_eclipse_plugin.action;
import org.eclipse.jface.action.IAction;
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.globalactions.WMLTools;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
public class RunWMLLintOnPreprocFile implements IObjectActionDelegate
{
public RunWMLLintOnPreprocFile(){ }
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart){
}
@Override
public void run(IAction action)
{
PreprocessorActions.preprocessIfNotExists(WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow()),
false,true);
WMLTools.runWMLLint(PreprocessorActions.getPreprocessedFilePath(
WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow()),false), true, true,false);
}
@Override
public void selectionChanged(IAction action, ISelection selection){
}
}

View file

@ -131,7 +131,7 @@ public class SampleBuilder extends IncrementalProjectBuilder {
deleteMarkers(file);
PreprocessorActions.preprocessFile(WorkspaceUtils.getPathRelativeToUserDir(file),
WorkspaceUtils.getTemporaryFolder(), null, true);
WorkspaceUtils.getTemporaryFolder(), null, true,false);
/*
IMarker[] resIMarkers = file.findMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO);

View file

@ -3,6 +3,7 @@
*/
package wesnoth_eclipse_plugin.globalactions;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -25,9 +26,11 @@ public class PreprocessorActions
* @param targetDirectory target directory where should be put the results
* @param defines the list of additional defines to be added when preprocessing the file
* @param useThread true if the preprocessing should use a thread
* @param waitForIt true to wait for the preprocessing to finish
* @return
*/
public static boolean preprocessFile(String fileName,String targetDirectory,List<String> defines, boolean useThread)
public static boolean preprocessFile(String fileName,String targetDirectory,List<String> defines,
boolean useThread, boolean waitForIt)
{
try{
List<String> arguments = new ArrayList<String>();
@ -53,6 +56,8 @@ public class PreprocessorActions
arguments, useThread);
System.out.printf("preprocessing : %s\n", arguments);
wesnoth.run();
if (waitForIt)
wesnoth.waitFor();
return true;
}
catch (Exception e) {
@ -84,4 +89,20 @@ public class PreprocessorActions
e.printStackTrace();
}
}
public static String getPreprocessedFilePath(IFile file, boolean plain)
{
IFileStore preprocFile = EFS.getLocalFileSystem().getStore(new Path(WorkspaceUtils.getTemporaryFolder()));
preprocFile = preprocFile.getChild(file.getName() + (plain == true? ".plain" : "") );
return preprocFile.toString();
}
public static void preprocessIfNotExists(IFile file,boolean useThread, boolean waitForIt)
{
if (new File(WorkspaceUtils.getTemporaryFolder() + file.getName()).exists())
return;
PreprocessorActions.preprocessFile(WorkspaceUtils.getPathRelativeToUserDir(file),
WorkspaceUtils.getTemporaryFolder(), null,useThread, waitForIt);
}
}

View file

@ -0,0 +1,77 @@
/**
* @author Timotei Dolean
*/
package wesnoth_eclipse_plugin.globalactions;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import wesnoth_eclipse_plugin.builder.ExternalToolInvoker;
import wesnoth_eclipse_plugin.preferences.PreferenceConstants;
import wesnoth_eclipse_plugin.preferences.PreferenceInitializer;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
public class WMLTools
{
/**
* Runs "wmllint" on the specified file
* @param filePath the full path of the file where "wmllint" will be runned on
* @param writeToConsole true to write the output of "wmllint" in console
* @param dryrun true to run "wmllint" in dry mode - i.e. no changes in the config file.
* @param useThread whether the tool should be runned in a new thread
*/
public static void runWMLLint(String filePath,boolean dryrun, boolean writeToConsole, boolean useThread)
{
File wmllintFile = new File(PreferenceInitializer.getString(PreferenceConstants.P_WESNOTH_WMLTOOLS_DIR) +
Path.SEPARATOR + "wmllint");
if (!wmllintFile.exists())
{
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(),
"Please set the wmltools directory in the preferences before you use this feature.");
return;
}
if (filePath == null || filePath.isEmpty() || !new File(filePath).exists())
return;
List<String> arguments = new ArrayList<String>();
arguments.add(wmllintFile.getAbsolutePath());
arguments.add("--dryrun");
arguments.add("--verbose");
arguments.add("--nospellcheck");
arguments.add(filePath);
try
{
ExternalToolInvoker wmllint = new ExternalToolInvoker("python", arguments, useThread);
wmllint.run();
wmllint.waitFor();
if (writeToConsole)
{
MessageConsole console = new MessageConsole("wmllint result", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });
MessageConsoleStream stream = console.newMessageStream();
String line = "";
while((line = wmllint.readOutputLine())!= null)
stream.write(line);
while((line = wmllint.readErrorLine())!= null)
stream.write(line);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}