eclipse plugin: added menus for opening a map in the editor
This commit is contained in:
parent
d8606ab938
commit
42ddd83b02
8 changed files with 158 additions and 57 deletions
|
@ -33,7 +33,7 @@
|
|||
<action
|
||||
class="wesnoth_eclipse_plugin.builder.ToggleNatureAction"
|
||||
enablesFor="+"
|
||||
icon="icons/wesnoth-icon.png"
|
||||
icon="icons/wesnoth-icon_16.png"
|
||||
id="actions.addRemoveNature"
|
||||
label="Add/Remove Sample Nature"
|
||||
menubarPath="additions">
|
||||
|
@ -47,12 +47,26 @@
|
|||
<action
|
||||
class="wesnoth_eclipse_plugin.action.ImportMap"
|
||||
enablesFor="1"
|
||||
icon="icons/wesnoth_editor-icon.png"
|
||||
icon="icons/wesnoth_editor-icon_16.png"
|
||||
id="actions.importmap"
|
||||
label="Import map"
|
||||
menubarPath="additions">
|
||||
</action>
|
||||
</objectContribution>
|
||||
<objectContribution
|
||||
adaptable="false"
|
||||
id="Wesnoth Eclipse Plugin.mapFilesContributions"
|
||||
nameFilter="*.map"
|
||||
objectClass="org.eclipse.core.resources.IFile">
|
||||
<action
|
||||
class="wesnoth_eclipse_plugin.action.OpenMapInEditor"
|
||||
enablesFor="1"
|
||||
icon="icons/wesnoth_editor-icon_16.png"
|
||||
id="actions.openMapInEditor"
|
||||
label="Open map in editor"
|
||||
menubarPath="additions">
|
||||
</action>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
<extension
|
||||
id="xmlProblem"
|
||||
|
@ -155,6 +169,12 @@
|
|||
id="Wesnoth_Eclipse_Plugin.commands.importMap"
|
||||
name="importMap">
|
||||
</command>
|
||||
<command
|
||||
defaultHandler="wesnoth_eclipse_plugin.handlers.OpenMapHandler"
|
||||
description="Opens the selected map in the map editor"
|
||||
id="Wesnoth_Eclipse_Plugin.commands.openMapInEditor"
|
||||
name="openMapInEditor">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
|
@ -181,6 +201,12 @@
|
|||
icon="icons/wesnoth_editor-icon_16.png"
|
||||
label="Import Map">
|
||||
</command>
|
||||
<command
|
||||
commandId="Wesnoth_Eclipse_Plugin.commands.openMapInEditor"
|
||||
icon="icons/wesnoth_editor-icon_16.png"
|
||||
label="Open map with editor"
|
||||
style="push">
|
||||
</command>
|
||||
</menu>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package wesnoth_eclipse_plugin.action;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
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.EditorActions;
|
||||
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
|
||||
|
||||
public class OpenMapInEditor implements IObjectActionDelegate
|
||||
{
|
||||
public OpenMapInEditor(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IAction action)
|
||||
{
|
||||
IFile selectedFile = WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow());
|
||||
EditorActions.startEditor(selectedFile.getLocation().toOSString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* @author Timotei Dolean
|
||||
*/
|
||||
package wesnoth_eclipse_plugin.globalactions;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
|
||||
import wesnoth_eclipse_plugin.Activator;
|
||||
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 EditorActions
|
||||
{
|
||||
public static void startEditor(String mapName)
|
||||
{
|
||||
String editorPath = PreferenceInitializer.getString(PreferenceConstants.P_WESNOTH_EXEC_PATH);
|
||||
String workingDir = PreferenceInitializer.getString(PreferenceConstants.P_WESNOTH_WORKING_DIR);
|
||||
|
||||
if (workingDir.isEmpty())
|
||||
workingDir = editorPath.substring(0,editorPath.lastIndexOf(new File(editorPath).getName()));
|
||||
|
||||
if (editorPath.isEmpty())
|
||||
{
|
||||
MessageBox box = new MessageBox(Activator.getShell());
|
||||
box.setMessage(String.format("Please set the wesnoth's executable path first."));
|
||||
box.open();
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.printf("Running: [%s] with args: %s\n", editorPath, getLaunchEditorArguments(mapName, workingDir));
|
||||
ExternalToolInvoker.launchTool(editorPath, getLaunchEditorArguments(mapName, workingDir),true,false, true,
|
||||
WorkspaceUtils.getWorkbenchWindow());
|
||||
}
|
||||
|
||||
public static List<String> getLaunchEditorArguments(String mapName, String workingDir)
|
||||
{
|
||||
List<String> args = new ArrayList<String>(3);
|
||||
|
||||
args.add("-e");
|
||||
args.add(mapName);
|
||||
|
||||
if (!workingDir.isEmpty())
|
||||
{
|
||||
args.add("-datadir");
|
||||
args.add(workingDir);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
|
@ -1,59 +1,18 @@
|
|||
package wesnoth_eclipse_plugin.handlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import wesnoth_eclipse_plugin.builder.ExternalToolInvoker;
|
||||
import wesnoth_eclipse_plugin.preferences.PreferenceConstants;
|
||||
import wesnoth_eclipse_plugin.preferences.PreferenceInitializer;
|
||||
import wesnoth_eclipse_plugin.globalactions.EditorActions;
|
||||
|
||||
public class OpenEditorHandler extends AbstractHandler
|
||||
{
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException
|
||||
{
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
|
||||
String editorPath = PreferenceInitializer.getString(PreferenceConstants.P_WESNOTH_EXEC_PATH);
|
||||
String workingDir = PreferenceInitializer.getString(PreferenceConstants.P_WESNOTH_WORKING_DIR);
|
||||
|
||||
if (workingDir.isEmpty())
|
||||
workingDir = editorPath.substring(0,editorPath.lastIndexOf(new File(editorPath).getName()));
|
||||
|
||||
if (editorPath.isEmpty())
|
||||
{
|
||||
MessageBox box = new MessageBox(window.getShell());
|
||||
box.setMessage(String.format("Please set the wesnoth's executable path first."));
|
||||
box.open();
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.printf("Running: [%s] with args: %s\n", editorPath, getLaunchEditorArguments("", workingDir));
|
||||
ExternalToolInvoker.launchTool(editorPath, getLaunchEditorArguments("", workingDir),true,false, true,
|
||||
window);
|
||||
// no map selected
|
||||
EditorActions.startEditor("");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> getLaunchEditorArguments(String mapName, String workingDir)
|
||||
{
|
||||
List<String> args = new ArrayList<String>(3);
|
||||
|
||||
args.add("-e");
|
||||
args.add(mapName);
|
||||
|
||||
if (!workingDir.isEmpty())
|
||||
{
|
||||
args.add("-datadir");
|
||||
args.add(workingDir);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package wesnoth_eclipse_plugin.handlers;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
|
||||
import wesnoth_eclipse_plugin.Activator;
|
||||
import wesnoth_eclipse_plugin.globalactions.EditorActions;
|
||||
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
|
||||
|
||||
public class OpenMapHandler extends AbstractHandler
|
||||
{
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException
|
||||
{
|
||||
IFile selectedFile = WorkspaceUtils.getSelectedFile(WorkspaceUtils.getWorkbenchWindow());
|
||||
if (!selectedFile.getName().endsWith(".map"))
|
||||
{
|
||||
MessageBox box = new MessageBox(Activator.getShell());
|
||||
box.setMessage("Please select a .map file");
|
||||
box.open();
|
||||
return null;
|
||||
}
|
||||
EditorActions.startEditor(selectedFile.getLocation().toOSString());
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package wesnoth_eclipse_plugin.utils;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -29,6 +30,16 @@ public class WorkspaceUtils
|
|||
|
||||
return (IFolder)selection.getFirstElement();
|
||||
}
|
||||
|
||||
public static IFile getSelectedFile(IWorkbenchWindow window)
|
||||
{
|
||||
IStructuredSelection selection = getSelectedStructuredSelection(window);
|
||||
if (selection == null || !(selection.getFirstElement() instanceof IFile))
|
||||
return null;
|
||||
|
||||
return (IFile)selection.getFirstElement();
|
||||
}
|
||||
|
||||
public static IStructuredSelection getSelectedStructuredSelection(IWorkbenchWindow window)
|
||||
{
|
||||
if (window == null)
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.eclipse.core.resources.IFolder;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
@ -29,18 +28,12 @@ import wesnoth_eclipse_plugin.TemplateProvider;
|
|||
import wesnoth_eclipse_plugin.utils.StringUtils;
|
||||
|
||||
public class CampaignNewWizard extends Wizard implements INewWizard {
|
||||
|
||||
private org.eclipse.ui.IWorkbench workbench;
|
||||
private org.eclipse.jface.viewers.IStructuredSelection selection;
|
||||
|
||||
protected CampaignPage0 page0_;
|
||||
protected CampaignPage1 page1_;
|
||||
protected CampaignPage2 page2_;
|
||||
|
||||
protected int lastPageHashCode_=0;
|
||||
|
||||
private IConfigurationElement fConfig;
|
||||
|
||||
@Override
|
||||
public void addPages() {
|
||||
page0_ = new CampaignPage0();
|
||||
|
@ -63,8 +56,6 @@ public class CampaignNewWizard extends Wizard implements INewWizard {
|
|||
|
||||
@Override
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
||||
this.workbench = workbench;
|
||||
this.selection = selection;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -78,11 +78,9 @@ public class ScenarioPage0 extends WizardPage {
|
|||
}
|
||||
};
|
||||
|
||||
Label label;
|
||||
lblproject = new Label(container, SWT.NULL);
|
||||
lblproject.setText("Project* :");
|
||||
txtProject_ = new Text(container, SWT.BORDER | SWT.SINGLE);
|
||||
GridData gd;
|
||||
gd_txtProject_ = new GridData(GridData.FILL_HORIZONTAL);
|
||||
txtProject_.setLayoutData(gd_txtProject_);
|
||||
txtProject_.addModifyListener(modifyListener);
|
||||
|
|
Loading…
Add table
Reference in a new issue