diff --git a/utils/java/eclipse_plugin/plugin.xml b/utils/java/eclipse_plugin/plugin.xml index 9896611482a..7c8ef85cef6 100644 --- a/utils/java/eclipse_plugin/plugin.xml +++ b/utils/java/eclipse_plugin/plugin.xml @@ -33,7 +33,7 @@ @@ -47,12 +47,26 @@ + + + + + + @@ -181,6 +201,12 @@ icon="icons/wesnoth_editor-icon_16.png" label="Import Map"> + + diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/OpenMapInEditor.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/OpenMapInEditor.java new file mode 100644 index 00000000000..9672cfc010e --- /dev/null +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/action/OpenMapInEditor.java @@ -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) { + } +} diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/globalactions/EditorActions.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/globalactions/EditorActions.java new file mode 100644 index 00000000000..4de492e5190 --- /dev/null +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/globalactions/EditorActions.java @@ -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 getLaunchEditorArguments(String mapName, String workingDir) + { + List args = new ArrayList(3); + + args.add("-e"); + args.add(mapName); + + if (!workingDir.isEmpty()) + { + args.add("-datadir"); + args.add(workingDir); + } + + return args; + } +} diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/OpenEditorHandler.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/OpenEditorHandler.java index 817fc0e5547..bc5127f0d52 100644 --- a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/OpenEditorHandler.java +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/OpenEditorHandler.java @@ -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 getLaunchEditorArguments(String mapName, String workingDir) - { - List args = new ArrayList(3); - - args.add("-e"); - args.add(mapName); - - if (!workingDir.isEmpty()) - { - args.add("-datadir"); - args.add(workingDir); - } - - return args; - } } diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/OpenMapHandler.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/OpenMapHandler.java new file mode 100644 index 00000000000..fe99dac5c0b --- /dev/null +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/OpenMapHandler.java @@ -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; + } +} diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/WorkspaceUtils.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/WorkspaceUtils.java index a5a845c2805..7b2a67b42b8 100644 --- a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/WorkspaceUtils.java +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/WorkspaceUtils.java @@ -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) diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java index bb92c674491..e704ce27fe3 100644 --- a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/CampaignNewWizard.java @@ -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 diff --git a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioPage0.java b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioPage0.java index 1507c109584..b7e4097bf17 100644 --- a/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioPage0.java +++ b/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/ScenarioPage0.java @@ -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);