From 76dafb18492b90fff25e784ab001aad5d4455968 Mon Sep 17 00:00:00 2001 From: as3boyan Date: Sat, 30 Jan 2016 20:59:21 +0200 Subject: [PATCH 1/4] Generate Main Class from template with main function and open it in editor on new Haxe project generation --- .../internal/HaxeMainClass.hx.ft | 5 +++ .../haxe/ide/HaxeFileTemplateUtil.java | 20 +++++---- .../haxe/ide/actions/CreateClassAction.java | 2 +- .../ide/actions/CreateNMMLFileAction.java | 2 +- .../haxe/ide/module/HaxeModuleBuilder.java | 44 +++++++++++++++++++ .../haxe/ide/module/HaxeModuleType.java | 12 +++++ 6 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 resources/fileTemplates/internal/HaxeMainClass.hx.ft diff --git a/resources/fileTemplates/internal/HaxeMainClass.hx.ft b/resources/fileTemplates/internal/HaxeMainClass.hx.ft new file mode 100644 index 000000000..6e1c0cd1c --- /dev/null +++ b/resources/fileTemplates/internal/HaxeMainClass.hx.ft @@ -0,0 +1,5 @@ +package ${PACKAGE_NAME}; +class ${NAME} { + public static function main() { + } +} diff --git a/src/common/com/intellij/plugins/haxe/ide/HaxeFileTemplateUtil.java b/src/common/com/intellij/plugins/haxe/ide/HaxeFileTemplateUtil.java index 4b58f2a86..a75f3ebc8 100644 --- a/src/common/com/intellij/plugins/haxe/ide/HaxeFileTemplateUtil.java +++ b/src/common/com/intellij/plugins/haxe/ide/HaxeFileTemplateUtil.java @@ -20,6 +20,7 @@ import com.intellij.ide.fileTemplates.FileTemplate; import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.ide.fileTemplates.FileTemplateUtil; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; import com.intellij.plugins.haxe.HaxeFileType; import com.intellij.plugins.haxe.nmml.NMMLFileType; @@ -39,28 +40,28 @@ public class HaxeFileTemplateUtil { private final static String HAXE_TEMPLATE_PREFIX = "Haxe"; - public static List getApplicableTemplates() { + public static List getApplicableTemplates(Project project) { return getApplicableTemplates(new Condition() { @Override public boolean value(FileTemplate fileTemplate) { return HaxeFileType.DEFAULT_EXTENSION.equals(fileTemplate.getExtension()); } - }); + }, project); } - public static List getNMMLTemplates() { + public static List getNMMLTemplates(Project project) { return getApplicableTemplates(new Condition() { @Override public boolean value(FileTemplate fileTemplate) { return NMMLFileType.DEFAULT_EXTENSION.equals(fileTemplate.getExtension()); } - }); + }, project); } - public static List getApplicableTemplates(Condition filter) { + public static List getApplicableTemplates(Condition filter, Project project) { List applicableTemplates = new SmartList(); - applicableTemplates.addAll(ContainerUtil.findAll(FileTemplateManager.getInstance().getInternalTemplates(), filter)); - applicableTemplates.addAll(ContainerUtil.findAll(FileTemplateManager.getInstance().getAllTemplates(), filter)); + applicableTemplates.addAll(ContainerUtil.findAll(FileTemplateManager.getInstance(project).getInternalTemplates(), filter)); + applicableTemplates.addAll(ContainerUtil.findAll(FileTemplateManager.getInstance(project).getAllTemplates(), filter)); return applicableTemplates; } @@ -88,11 +89,12 @@ else if ("Enum".equals(name)) { public static PsiElement createClass(String className, String packageName, PsiDirectory directory, String templateName, @org.jetbrains.annotations.Nullable java.lang.ClassLoader classLoader) throws Exception { - final Properties props = new Properties(FileTemplateManager.getInstance().getDefaultProperties(directory.getProject())); + Project project = directory.getProject(); + final Properties props = new Properties(FileTemplateManager.getInstance(project).getDefaultProperties()); props.setProperty(FileTemplate.ATTRIBUTE_NAME, className); props.setProperty(FileTemplate.ATTRIBUTE_PACKAGE_NAME, packageName); - final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate(templateName); + final FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(templateName); return FileTemplateUtil.createFromTemplate(template, className, props, directory, classLoader); } diff --git a/src/common/com/intellij/plugins/haxe/ide/actions/CreateClassAction.java b/src/common/com/intellij/plugins/haxe/ide/actions/CreateClassAction.java index 6c0c45ad8..54c62f979 100644 --- a/src/common/com/intellij/plugins/haxe/ide/actions/CreateClassAction.java +++ b/src/common/com/intellij/plugins/haxe/ide/actions/CreateClassAction.java @@ -75,7 +75,7 @@ protected String getActionName(PsiDirectory directory, String newName, String te @Override protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder.setTitle(IdeBundle.message("action.create.new.class")); - for (FileTemplate fileTemplate : HaxeFileTemplateUtil.getApplicableTemplates()) { + for (FileTemplate fileTemplate : HaxeFileTemplateUtil.getApplicableTemplates(project)) { final String templateName = fileTemplate.getName(); final String shortName = HaxeFileTemplateUtil.getTemplateShortName(templateName); final Icon icon = HaxeFileTemplateUtil.getTemplateIcon(templateName); diff --git a/src/common/com/intellij/plugins/haxe/ide/actions/CreateNMMLFileAction.java b/src/common/com/intellij/plugins/haxe/ide/actions/CreateNMMLFileAction.java index 4acb9bd8b..92c1998ea 100644 --- a/src/common/com/intellij/plugins/haxe/ide/actions/CreateNMMLFileAction.java +++ b/src/common/com/intellij/plugins/haxe/ide/actions/CreateNMMLFileAction.java @@ -49,7 +49,7 @@ protected boolean isAvailable(DataContext dataContext) { @Override protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder.setTitle(HaxeBundle.message("create.nmml.file.action")); - for (FileTemplate fileTemplate : HaxeFileTemplateUtil.getNMMLTemplates()) { + for (FileTemplate fileTemplate : HaxeFileTemplateUtil.getNMMLTemplates(project)) { final String templateName = fileTemplate.getName(); final String shortName = HaxeFileTemplateUtil.getTemplateShortName(templateName); builder.addKind(shortName, icons.HaxeIcons.Nmml_16, templateName); diff --git a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java index 94f514e54..2bba1c30c 100644 --- a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java +++ b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java @@ -17,18 +17,34 @@ */ package com.intellij.plugins.haxe.ide.module; +import com.intellij.codeInsight.navigation.NavigationUtil; +import com.intellij.ide.actions.OpenFileAction; import com.intellij.ide.util.projectWizard.JavaModuleBuilder; import com.intellij.ide.util.projectWizard.ModuleBuilderListener; import com.intellij.ide.util.projectWizard.SourcePathsBuilder; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.SdkTypeId; import com.intellij.openapi.roots.CompilerModuleExtension; import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; +import com.intellij.plugins.haxe.ide.HaxeFileTemplateUtil; +import com.intellij.psi.PsiManager; +import com.intellij.util.PathUtil; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class HaxeModuleBuilder extends JavaModuleBuilder implements SourcePathsBuilder, ModuleBuilderListener { @Override public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { @@ -51,6 +67,34 @@ public void moduleCreated(@NotNull Module module) { final CompilerModuleExtension model = (CompilerModuleExtension)CompilerModuleExtension.getInstance(module).getModifiableModel(true); model.setCompilerOutputPath(model.getCompilerOutputUrl()); model.inheritCompilerOutputPath(false); + + Project project = module.getProject(); + List> sourcePaths = getSourcePaths(); + String srcPath = null; + + if ((sourcePaths.size() > 0)) { + srcPath = sourcePaths.get(0).getFirst(); + VirtualFile dir = VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.pathToUrl(srcPath)); + + if (dir != null) { + try { + HaxeFileTemplateUtil + .createClass("Main", "", PsiManager.getInstance(project).findDirectory(dir), "HaxeMainClass", + null); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + HaxeModuleSettings.getInstance(module).setMainClass("Main"); + + assert dir != null; + VirtualFile file = LocalFileSystem.getInstance().findFileByPath(dir.getCanonicalPath() + "/Main.hx"); + assert (file != null); + FileEditorManager.getInstance(project).openFile(file, true); + } + model.commit(); } } diff --git a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java index c1af93ac5..4ee57b3e3 100644 --- a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java +++ b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java @@ -17,14 +17,26 @@ */ package com.intellij.plugins.haxe.ide.module; +import com.intellij.ide.fileTemplates.FileTemplateManager; +import com.intellij.ide.fileTemplates.FileTemplateUtil; import com.intellij.ide.util.projectWizard.ModuleWizardStep; import com.intellij.ide.util.projectWizard.ProjectJdkForModuleStep; import com.intellij.ide.util.projectWizard.WizardContext; +import com.intellij.openapi.fileEditor.impl.PsiAwareFileEditorManagerImpl; import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleTypeManager; +import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.plugins.haxe.HaxeBundle; +import com.intellij.plugins.haxe.HaxeFileType; import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; +import com.intellij.plugins.haxe.hxml.HXMLFileTypeFactory; +import com.intellij.plugins.haxe.ide.HaxeFileTemplateUtil; +import com.intellij.psi.PsiFileFactory; +import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.file.PsiDirectoryFactory; import javax.swing.*; From 153396f489426b33eef78fefda0a76af81b402a7 Mon Sep 17 00:00:00 2001 From: as3boyan Date: Tue, 2 Feb 2016 19:33:23 +0200 Subject: [PATCH 2/4] Fix issue https://github.com/TiVo/intellij-haxe/issues/397 HaxelibManager attempts to do something when creating a Java project by adding a SDK check to sync project classpath function Set run configuration module to current Check if Main.hx is already in project Set more project settings (probably some are not necessary) --- .../haxe/haxelib/HaxelibProjectUpdater.java | 18 +++-- .../haxe/ide/module/HaxeModuleBuilder.java | 72 +++++++++++++++---- 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/src/common/com/intellij/plugins/haxe/haxelib/HaxelibProjectUpdater.java b/src/common/com/intellij/plugins/haxe/haxelib/HaxelibProjectUpdater.java index 871cdac71..050c846fc 100644 --- a/src/common/com/intellij/plugins/haxe/haxelib/HaxelibProjectUpdater.java +++ b/src/common/com/intellij/plugins/haxe/haxelib/HaxelibProjectUpdater.java @@ -29,6 +29,8 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectType; +import com.intellij.openapi.project.ProjectTypeService; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootManager; @@ -40,6 +42,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; import com.intellij.plugins.haxe.hxml.HXMLFileType; import com.intellij.plugins.haxe.hxml.psi.HXMLClasspath; import com.intellij.plugins.haxe.hxml.psi.HXMLLib; @@ -579,13 +582,20 @@ private HaxeClasspath getProjectClasspath(@NotNull ProjectTracker tracker) { @NotNull private void syncProjectClasspath(@NotNull ProjectTracker tracker) { HaxeDebugTimeLog timeLog = new HaxeDebugTimeLog("syncProjectClasspath"); - timeLog.stamp("Start synchronizing project " + tracker.getProject().getName()); + Project project = tracker.getProject(); + timeLog.stamp("Start synchronizing project " + project.getName()); + + Sdk sdk = HaxelibSdkUtils.lookupSdk(project); + boolean isHaxeSDK = sdk.getSdkType().equals(HaxeSdkType.getInstance()); + + if (!isHaxeSDK) { + return; + } - Sdk sdk = HaxelibSdkUtils.lookupSdk(tracker.getProject()); HaxelibLibraryCache libCache = tracker.getSdkManager().getLibraryCache(sdk); HaxeClasspath currentProjectClasspath = HaxelibClasspathUtils.getProjectLibraryClasspath( - tracker.getProject()); - List currentLibraryNames = HaxelibClasspathUtils.getProjectLibraryNames(tracker.getProject(), true); + project); + List currentLibraryNames = HaxelibClasspathUtils.getProjectLibraryNames(project, true); HaxeClasspath haxelibClasspaths = libCache.getClasspathForHaxelibs(currentLibraryNames); // Libraries that we want to remove are those specified as 'haxelib' entries and are diff --git a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java index 2bba1c30c..9e08fb329 100644 --- a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java +++ b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java @@ -17,13 +17,15 @@ */ package com.intellij.plugins.haxe.ide.module; -import com.intellij.codeInsight.navigation.NavigationUtil; -import com.intellij.ide.actions.OpenFileAction; +import com.intellij.execution.RunManager; +import com.intellij.execution.RunnerAndConfigurationSettings; +import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.ConfigurationTypeUtil; +import com.intellij.execution.configurations.RunConfiguration; import com.intellij.ide.util.projectWizard.JavaModuleBuilder; import com.intellij.ide.util.projectWizard.ModuleBuilderListener; import com.intellij.ide.util.projectWizard.SourcePathsBuilder; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleType; @@ -33,16 +35,21 @@ import com.intellij.openapi.roots.CompilerModuleExtension; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.plugins.haxe.config.HaxeTarget; import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; import com.intellij.plugins.haxe.ide.HaxeFileTemplateUtil; +import com.intellij.plugins.haxe.module.impl.HaxeModuleSettingsBaseImpl; +import com.intellij.plugins.haxe.runner.HaxeApplicationConfiguration; +import com.intellij.plugins.haxe.runner.HaxeRunConfigurationType; import com.intellij.psi.PsiManager; import com.intellij.util.PathUtil; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.util.List; public class HaxeModuleBuilder extends JavaModuleBuilder implements SourcePathsBuilder, ModuleBuilderListener { @@ -68,7 +75,7 @@ public void moduleCreated(@NotNull Module module) { model.setCompilerOutputPath(model.getCompilerOutputUrl()); model.inheritCompilerOutputPath(false); - Project project = module.getProject(); + final Project project = module.getProject(); List> sourcePaths = getSourcePaths(); String srcPath = null; @@ -78,21 +85,62 @@ public void moduleCreated(@NotNull Module module) { if (dir != null) { try { - HaxeFileTemplateUtil - .createClass("Main", "", PsiManager.getInstance(project).findDirectory(dir), "HaxeMainClass", - null); + VirtualFile mainClassFile = dir.findFileByRelativePath("Main.hx"); + if (mainClassFile == null) { + HaxeFileTemplateUtil + .createClass("Main", "", PsiManager.getInstance(project).findDirectory(dir), "HaxeMainClass", + null); + } } catch (Exception e) { e.printStackTrace(); } } - HaxeModuleSettings.getInstance(module).setMainClass("Main"); + HaxeModuleSettings moduleSettings = HaxeModuleSettings.getInstance(module); + moduleSettings.setMainClass("Main"); + moduleSettings.setArguments(""); + moduleSettings.setNmeFlags(""); + moduleSettings.setHaxeTarget(HaxeTarget.NEKO); + moduleSettings.setExcludeFromCompilation(false); + moduleSettings.setBuildConfig(HaxeModuleSettingsBaseImpl.USE_PROPERTIES); + moduleSettings.setOutputFileName("Main.n"); + String outputFolder = PathUtil.toSystemIndependentName(project.getBasePath() + "/out/production"); + moduleSettings.setOutputFolder(outputFolder); + //String releaseFolder = PathUtil.toSystemIndependentName(outputFolder + "/release"); + //boolean mkdirs = new File(releaseFolder).mkdirs(); + + String url = VfsUtil.pathToUrl(outputFolder); + model.setCompilerOutputPath(url); assert dir != null; - VirtualFile file = LocalFileSystem.getInstance().findFileByPath(dir.getCanonicalPath() + "/Main.hx"); + final VirtualFile file = dir.findFileByRelativePath("Main.hx"); assert (file != null); - FileEditorManager.getInstance(project).openFile(file, true); + + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + FileEditorManager.getInstance(project).openFile(file, true); + } + }); + + ConfigurationFactory[] factories = + ConfigurationTypeUtil.findConfigurationType(HaxeRunConfigurationType.class).getConfigurationFactories(); + + if ((factories.length > 0)) { + RunConfiguration configuration = factories[0].createTemplateConfiguration(project); + RunManager manager = RunManager.getInstance(project); + RunnerAndConfigurationSettings runnerAndConfigurationSettings = manager.createConfiguration(configuration, factories[0]); + RunConfiguration configuration1 = runnerAndConfigurationSettings.getConfiguration(); + if (configuration1 instanceof HaxeApplicationConfiguration) { + HaxeApplicationConfiguration haxeApplicationConfiguration = (HaxeApplicationConfiguration)configuration1; + haxeApplicationConfiguration.setModule(module); + } + manager.addConfiguration(runnerAndConfigurationSettings, false); + manager.setSelectedConfiguration(runnerAndConfigurationSettings); + } + + } model.commit(); From 2d117de1129fad2dfa2df3c260802cdc6691d3eb Mon Sep 17 00:00:00 2001 From: as3boyan Date: Tue, 2 Feb 2016 20:34:24 +0200 Subject: [PATCH 3/4] Code improvements --- .../haxe/ide/module/HaxeModuleBuilder.java | 100 +++++++++--------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java index 9e08fb329..a86a3136a 100644 --- a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java +++ b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleBuilder.java @@ -77,72 +77,76 @@ public void moduleCreated(@NotNull Module module) { final Project project = module.getProject(); List> sourcePaths = getSourcePaths(); - String srcPath = null; + String srcPath; if ((sourcePaths.size() > 0)) { srcPath = sourcePaths.get(0).getFirst(); VirtualFile dir = VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.pathToUrl(srcPath)); + VirtualFile mainClassFile = dir.findFileByRelativePath("Main.hx"); - if (dir != null) { - try { - VirtualFile mainClassFile = dir.findFileByRelativePath("Main.hx"); - if (mainClassFile == null) { + if (mainClassFile == null) { + if (dir != null) { + try { HaxeFileTemplateUtil .createClass("Main", "", PsiManager.getInstance(project).findDirectory(dir), "HaxeMainClass", null); } - } - catch (Exception e) { - e.printStackTrace(); + catch (Exception e) { + e.printStackTrace(); + } } } - HaxeModuleSettings moduleSettings = HaxeModuleSettings.getInstance(module); - moduleSettings.setMainClass("Main"); - moduleSettings.setArguments(""); - moduleSettings.setNmeFlags(""); - moduleSettings.setHaxeTarget(HaxeTarget.NEKO); - moduleSettings.setExcludeFromCompilation(false); - moduleSettings.setBuildConfig(HaxeModuleSettingsBaseImpl.USE_PROPERTIES); - moduleSettings.setOutputFileName("Main.n"); - String outputFolder = PathUtil.toSystemIndependentName(project.getBasePath() + "/out/production"); - moduleSettings.setOutputFolder(outputFolder); - //String releaseFolder = PathUtil.toSystemIndependentName(outputFolder + "/release"); - //boolean mkdirs = new File(releaseFolder).mkdirs(); - - String url = VfsUtil.pathToUrl(outputFolder); - model.setCompilerOutputPath(url); - - assert dir != null; final VirtualFile file = dir.findFileByRelativePath("Main.hx"); - assert (file != null); - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - FileEditorManager.getInstance(project).openFile(file, true); - } - }); - - ConfigurationFactory[] factories = - ConfigurationTypeUtil.findConfigurationType(HaxeRunConfigurationType.class).getConfigurationFactories(); - - if ((factories.length > 0)) { - RunConfiguration configuration = factories[0].createTemplateConfiguration(project); - RunManager manager = RunManager.getInstance(project); - RunnerAndConfigurationSettings runnerAndConfigurationSettings = manager.createConfiguration(configuration, factories[0]); - RunConfiguration configuration1 = runnerAndConfigurationSettings.getConfiguration(); - if (configuration1 instanceof HaxeApplicationConfiguration) { - HaxeApplicationConfiguration haxeApplicationConfiguration = (HaxeApplicationConfiguration)configuration1; - haxeApplicationConfiguration.setModule(module); - } - manager.addConfiguration(runnerAndConfigurationSettings, false); - manager.setSelectedConfiguration(runnerAndConfigurationSettings); - } + if (file != null) { + setHaxeModuleSettingsForMainFile(module, model, project); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + FileEditorManager.getInstance(project).openFile(file, true); + } + }); + } + createHaxeRunConfigurationAndSetActive(module, project); } model.commit(); } + + public void createHaxeRunConfigurationAndSetActive(@NotNull Module module, Project project) { + ConfigurationFactory[] factories = + ConfigurationTypeUtil.findConfigurationType(HaxeRunConfigurationType.class).getConfigurationFactories(); + + if ((factories.length > 0)) { + RunConfiguration configuration = factories[0].createTemplateConfiguration(project); + RunManager manager = RunManager.getInstance(project); + RunnerAndConfigurationSettings runnerAndConfigurationSettings = manager.createConfiguration(configuration, factories[0]); + RunConfiguration configuration1 = runnerAndConfigurationSettings.getConfiguration(); + if (configuration1 instanceof HaxeApplicationConfiguration) { + HaxeApplicationConfiguration haxeApplicationConfiguration = (HaxeApplicationConfiguration)configuration1; + haxeApplicationConfiguration.setModule(module); + } + manager.addConfiguration(runnerAndConfigurationSettings, false); + manager.setSelectedConfiguration(runnerAndConfigurationSettings); + } + } + + public void setHaxeModuleSettingsForMainFile(@NotNull Module module, CompilerModuleExtension model, Project project) { + HaxeModuleSettings moduleSettings = HaxeModuleSettings.getInstance(module); + moduleSettings.setMainClass("Main"); + moduleSettings.setArguments(""); + moduleSettings.setNmeFlags(""); + moduleSettings.setHaxeTarget(HaxeTarget.NEKO); + moduleSettings.setExcludeFromCompilation(false); + moduleSettings.setBuildConfig(HaxeModuleSettingsBaseImpl.USE_PROPERTIES); + moduleSettings.setOutputFileName("Main.n"); + String outputFolder = PathUtil.toSystemIndependentName(project.getBasePath() + "/out/production"); + moduleSettings.setOutputFolder(outputFolder); + + String url = VfsUtil.pathToUrl(outputFolder); + model.setCompilerOutputPath(url); + } } From dfdf81f2795ef4be1d52283938468b9caeb8363a Mon Sep 17 00:00:00 2001 From: as3boyan Date: Tue, 2 Feb 2016 20:35:23 +0200 Subject: [PATCH 4/4] Code clean-up: remove unused imports --- .../plugins/haxe/ide/module/HaxeModuleType.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java index 4ee57b3e3..c1af93ac5 100644 --- a/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java +++ b/src/common/com/intellij/plugins/haxe/ide/module/HaxeModuleType.java @@ -17,26 +17,14 @@ */ package com.intellij.plugins.haxe.ide.module; -import com.intellij.ide.fileTemplates.FileTemplateManager; -import com.intellij.ide.fileTemplates.FileTemplateUtil; import com.intellij.ide.util.projectWizard.ModuleWizardStep; import com.intellij.ide.util.projectWizard.ProjectJdkForModuleStep; import com.intellij.ide.util.projectWizard.WizardContext; -import com.intellij.openapi.fileEditor.impl.PsiAwareFileEditorManagerImpl; import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleTypeManager; -import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.plugins.haxe.HaxeBundle; -import com.intellij.plugins.haxe.HaxeFileType; import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; -import com.intellij.plugins.haxe.hxml.HXMLFileTypeFactory; -import com.intellij.plugins.haxe.ide.HaxeFileTemplateUtil; -import com.intellij.psi.PsiFileFactory; -import com.intellij.psi.PsiManager; -import com.intellij.psi.impl.file.PsiDirectoryFactory; import javax.swing.*;