JS: Drop obsolete "Kotlin (JavaScript)" run configuration
#KT-21312 Fixed
This commit is contained in:
@@ -580,8 +580,6 @@
|
|||||||
|
|
||||||
<lang.documentationProvider language="JAVA" implementationClass="org.jetbrains.kotlin.idea.KotlinQuickDocumentationProvider" order="first"/>
|
<lang.documentationProvider language="JAVA" implementationClass="org.jetbrains.kotlin.idea.KotlinQuickDocumentationProvider" order="first"/>
|
||||||
<documentationProvider implementation="org.jetbrains.kotlin.idea.KotlinQuickDocumentationProvider"/>
|
<documentationProvider implementation="org.jetbrains.kotlin.idea.KotlinQuickDocumentationProvider"/>
|
||||||
<configurationType implementation="org.jetbrains.kotlin.idea.k2jsrun.K2JSRunConfigurationType"/>
|
|
||||||
<programRunner implementation="org.jetbrains.kotlin.idea.k2jsrun.K2JSBrowserProgramRunner"/>
|
|
||||||
|
|
||||||
<codeInsight.lineMarkerProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.highlighter.markers.KotlinLineMarkerProvider"/>
|
<codeInsight.lineMarkerProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.highlighter.markers.KotlinLineMarkerProvider"/>
|
||||||
<codeInsight.lineMarkerProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.highlighter.KotlinRecursiveCallLineMarkerProvider"/>
|
<codeInsight.lineMarkerProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.highlighter.KotlinRecursiveCallLineMarkerProvider"/>
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.k2jsrun;
|
|
||||||
|
|
||||||
import com.intellij.execution.ExecutionException;
|
|
||||||
import com.intellij.execution.configurations.RunProfile;
|
|
||||||
import com.intellij.execution.configurations.RunProfileState;
|
|
||||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
|
||||||
import com.intellij.execution.runners.GenericProgramRunner;
|
|
||||||
import com.intellij.execution.ui.RunContentDescriptor;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.idea.k2jsrun.K2JSRunnerUtils.copyJSFileFromOutputToDestination;
|
|
||||||
import static org.jetbrains.kotlin.idea.k2jsrun.K2JSRunnerUtils.openBrowser;
|
|
||||||
|
|
||||||
public final class K2JSBrowserProgramRunner extends GenericProgramRunner {
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
protected RunContentDescriptor doExecute(
|
|
||||||
Project project,
|
|
||||||
RunProfileState state,
|
|
||||||
RunContentDescriptor contentToReuse,
|
|
||||||
ExecutionEnvironment env
|
|
||||||
) throws ExecutionException {
|
|
||||||
if (project == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
copyJSFileFromOutputToDestination(project, K2JSRunnerUtils.getSettings(env));
|
|
||||||
openBrowser(K2JSRunnerUtils.getSettings(env));
|
|
||||||
}
|
|
||||||
catch (Throwable e) {
|
|
||||||
throw new ExecutionException(e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getRunnerId() {
|
|
||||||
return "K2JSBrowserRunner";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
|
|
||||||
return (profile instanceof K2JSRunConfiguration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.k2jsrun;
|
|
||||||
|
|
||||||
import com.intellij.ide.browsers.BrowserFamily;
|
|
||||||
import com.intellij.ide.browsers.WebBrowserManager;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public final class K2JSConfigurationSettings {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String pageToOpenFilePath = "";
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String generatedFilePath;
|
|
||||||
|
|
||||||
private boolean shouldOpenInBrowserAfterTranslation = false;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private BrowserFamily browserFamily = WebBrowserManager.getInstance().getActiveBrowsers().get(0).getFamily();
|
|
||||||
|
|
||||||
public K2JSConfigurationSettings(@NotNull Project project) {
|
|
||||||
String basePath = project.getBasePath();
|
|
||||||
generatedFilePath = basePath != null ? basePath : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public K2JSConfigurationSettings() {
|
|
||||||
generatedFilePath = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public BrowserFamily getBrowserFamily() {
|
|
||||||
return browserFamily;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBrowserFamily(@NotNull BrowserFamily browserFamily) {
|
|
||||||
this.browserFamily = browserFamily;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getPageToOpenFilePath() {
|
|
||||||
return pageToOpenFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPageToOpenFilePath(@NotNull String pageToOpenFilePath) {
|
|
||||||
this.pageToOpenFilePath = pageToOpenFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getGeneratedFilePath() {
|
|
||||||
return generatedFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGeneratedFilePath(@NotNull String generatedFilePath) {
|
|
||||||
this.generatedFilePath = generatedFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isShouldOpenInBrowserAfterTranslation() {
|
|
||||||
return shouldOpenInBrowserAfterTranslation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShouldOpenInBrowserAfterTranslation(boolean shouldOpenInBrowserAfterTranslation) {
|
|
||||||
this.shouldOpenInBrowserAfterTranslation = shouldOpenInBrowserAfterTranslation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.k2jsrun;
|
|
||||||
|
|
||||||
import com.intellij.execution.DefaultExecutionResult;
|
|
||||||
import com.intellij.execution.ExecutionException;
|
|
||||||
import com.intellij.execution.ExecutionResult;
|
|
||||||
import com.intellij.execution.Executor;
|
|
||||||
import com.intellij.execution.configurations.*;
|
|
||||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
|
||||||
import com.intellij.execution.runners.ProgramRunner;
|
|
||||||
import com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction;
|
|
||||||
import com.intellij.openapi.module.Module;
|
|
||||||
import com.intellij.openapi.module.ModuleManager;
|
|
||||||
import com.intellij.openapi.options.SettingsEditor;
|
|
||||||
import com.intellij.openapi.util.InvalidDataException;
|
|
||||||
import com.intellij.openapi.util.WriteExternalException;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
|
||||||
import com.intellij.util.xmlb.XmlSerializer;
|
|
||||||
import org.jdom.Element;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public final class K2JSRunConfiguration extends ModuleBasedConfiguration<RunConfigurationModule>
|
|
||||||
implements RunConfigurationWithSuppressedDefaultRunAction {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private K2JSConfigurationSettings settings = new K2JSConfigurationSettings(getProject());
|
|
||||||
|
|
||||||
public K2JSRunConfiguration(String name, RunConfigurationModule runConfigurationModule, ConfigurationFactory factory) {
|
|
||||||
super(name, runConfigurationModule, factory);
|
|
||||||
runConfigurationModule.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Module> getValidModules() {
|
|
||||||
return Arrays.asList(ModuleManager.getInstance(getProject()).getModules());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalSearchScope getSearchScope() {
|
|
||||||
return SearchScopeProvider.createSearchScope(getModules());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ModuleBasedConfiguration createInstance() {
|
|
||||||
return new K2JSRunConfiguration(getName(), getConfigurationModule(), getFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
|
|
||||||
return new K2JSRunConfigurationEditor(getProject());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment)
|
|
||||||
throws ExecutionException {
|
|
||||||
return new MyProfileState();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class MyProfileState implements RunProfileState {
|
|
||||||
@Override
|
|
||||||
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
|
|
||||||
return new DefaultExecutionResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public K2JSConfigurationSettings settings() {
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readExternal(Element element) throws InvalidDataException {
|
|
||||||
super.readExternal(element);
|
|
||||||
Element settingsElement = element.getChild(K2JSConfigurationSettings.class.getSimpleName());
|
|
||||||
if (settingsElement != null) {
|
|
||||||
K2JSConfigurationSettings deserializedSettings = XmlSerializer.deserialize(settingsElement, K2JSConfigurationSettings.class);
|
|
||||||
if (deserializedSettings != null) {
|
|
||||||
settings = deserializedSettings;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeExternal(Element element) throws WriteExternalException {
|
|
||||||
super.writeExternal(element);
|
|
||||||
element.addContent(XmlSerializer.serialize(settings()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.idea.k2jsrun.K2JSRunConfigurationEditor">
|
|
||||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<xy x="20" y="20" width="500" height="400"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="aad78" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="cf71a" class="javax.swing.JLabel" binding="htmlFileLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="155" height="16"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<enabled value="false"/>
|
|
||||||
<text value="HTML file"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="f4230" class="javax.swing.JLabel" binding="chooseBrowserLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="155" height="16"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<enabled value="false"/>
|
|
||||||
<labelFor value="a2cc0"/>
|
|
||||||
<text value="Browser"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="a2cc0" class="javax.swing.JComboBox" binding="browserComboBox">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<enabled value="false"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="beb35" class="javax.swing.JCheckBox" binding="openInBrowserCheckBox">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="155" height="24"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Open in browser after translation"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="f6a73" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="155" height="16"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Generated JavaScript file directory"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="12973" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="generatedChooseFile">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="5ba6" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="htmlChooseFile">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<enabled value="false"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<vspacer id="e9321">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<buttonGroups>
|
|
||||||
<group name="group">
|
|
||||||
<member id="5e12a"/>
|
|
||||||
<member id="ae2bc"/>
|
|
||||||
</group>
|
|
||||||
</buttonGroups>
|
|
||||||
</form>
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.k2jsrun;
|
|
||||||
|
|
||||||
import com.intellij.ide.browsers.BrowserFamily;
|
|
||||||
import com.intellij.ide.browsers.WebBrowser;
|
|
||||||
import com.intellij.ide.browsers.WebBrowserManager;
|
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
|
||||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
|
||||||
import com.intellij.openapi.options.ConfigurationException;
|
|
||||||
import com.intellij.openapi.options.SettingsEditor;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.roots.ProjectRootManager;
|
|
||||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
|
||||||
import com.intellij.ui.JBColor;
|
|
||||||
import com.intellij.ui.ListCellRendererWrapper;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.event.DocumentEvent;
|
|
||||||
import javax.swing.event.DocumentListener;
|
|
||||||
import java.awt.event.ItemEvent;
|
|
||||||
import java.awt.event.ItemListener;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName;
|
|
||||||
|
|
||||||
public final class K2JSRunConfigurationEditor extends SettingsEditor<K2JSRunConfiguration> {
|
|
||||||
|
|
||||||
private JPanel mainPanel;
|
|
||||||
private TextFieldWithBrowseButton htmlChooseFile;
|
|
||||||
private JComboBox browserComboBox;
|
|
||||||
private JCheckBox openInBrowserCheckBox;
|
|
||||||
private TextFieldWithBrowseButton generatedChooseFile;
|
|
||||||
private JLabel chooseBrowserLabel;
|
|
||||||
private JLabel htmlFileLabel;
|
|
||||||
@NotNull
|
|
||||||
private final Project project;
|
|
||||||
|
|
||||||
public K2JSRunConfigurationEditor(@NotNull Project project) {
|
|
||||||
this.project = project;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void resetEditorFrom(@NotNull K2JSRunConfiguration configuration) {
|
|
||||||
htmlChooseFile.setText(toSystemIndependentName(configuration.settings().getPageToOpenFilePath()));
|
|
||||||
browserComboBox.setSelectedItem(configuration.settings().getBrowserFamily());
|
|
||||||
generatedChooseFile.setText(toSystemIndependentName(configuration.settings().getGeneratedFilePath()));
|
|
||||||
openInBrowserCheckBox.setSelected(configuration.settings().isShouldOpenInBrowserAfterTranslation());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void applyEditorTo(@NotNull K2JSRunConfiguration configuration) throws ConfigurationException {
|
|
||||||
K2JSConfigurationSettings settings = configuration.settings();
|
|
||||||
settings.setPageToOpenFilePath(toSystemIndependentName(htmlChooseFile.getText()));
|
|
||||||
Object item = browserComboBox.getSelectedItem();
|
|
||||||
if (item instanceof BrowserFamily) {
|
|
||||||
settings.setBrowserFamily((BrowserFamily) item);
|
|
||||||
}
|
|
||||||
settings.setGeneratedFilePath(toSystemIndependentName(generatedChooseFile.getText()));
|
|
||||||
settings.setShouldOpenInBrowserAfterTranslation(openInBrowserCheckBox.isSelected());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected JComponent createEditor() {
|
|
||||||
setUpShowInBrowserCheckBox();
|
|
||||||
setUpChooseHtmlToShow();
|
|
||||||
setUpBrowserCombobox();
|
|
||||||
setUpChooseGenerateFilePath();
|
|
||||||
return mainPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setUpChooseGenerateFilePath() {
|
|
||||||
FileChooserDescriptor fileChooserDescriptor =
|
|
||||||
FileChooserDescriptorFactory.getDirectoryChooserDescriptor("directory where generated files will be stored");
|
|
||||||
fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots());
|
|
||||||
generatedChooseFile.addBrowseFolderListener(null, null, project, fileChooserDescriptor);
|
|
||||||
final JTextField textField = generatedChooseFile.getTextField();
|
|
||||||
textField.getDocument().addDocumentListener(new DocumentListener() {
|
|
||||||
@Override
|
|
||||||
public void insertUpdate(@NotNull DocumentEvent e) {
|
|
||||||
onChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeUpdate(@NotNull DocumentEvent e) {
|
|
||||||
onChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void changedUpdate(@NotNull DocumentEvent e) {
|
|
||||||
onChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onChange() {
|
|
||||||
File file = new File(generatedChooseFile.getText());
|
|
||||||
if (!file.isDirectory()) {
|
|
||||||
textField.setForeground(JBColor.red);
|
|
||||||
} else {
|
|
||||||
textField.setForeground(JBColor.foreground());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setUpShowInBrowserCheckBox() {
|
|
||||||
openInBrowserCheckBox.addItemListener(new ItemListener() {
|
|
||||||
@Override
|
|
||||||
public void itemStateChanged(@NotNull ItemEvent e) {
|
|
||||||
boolean selected = openInBrowserCheckBox.isSelected();
|
|
||||||
htmlChooseFile.setEnabled(selected);
|
|
||||||
browserComboBox.setEnabled(selected);
|
|
||||||
htmlFileLabel.setEnabled(selected);
|
|
||||||
chooseBrowserLabel.setEnabled(selected);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setUpChooseHtmlToShow() {
|
|
||||||
FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(StdFileTypes.HTML);
|
|
||||||
fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots());
|
|
||||||
htmlChooseFile.addBrowseFolderListener("Choose file to show after translation is finished", null, project, fileChooserDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setUpBrowserCombobox() {
|
|
||||||
for (WebBrowser browser : WebBrowserManager.getInstance().getActiveBrowsers()) {
|
|
||||||
browserComboBox.addItem(browser.getFamily());
|
|
||||||
}
|
|
||||||
browserComboBox.setRenderer(new ListCellRendererWrapper<BrowserFamily>() {
|
|
||||||
@Override
|
|
||||||
public void customize(JList list, BrowserFamily family, int index, boolean selected, boolean hasFocus) {
|
|
||||||
if (family != null) {
|
|
||||||
setText(family.getName());
|
|
||||||
setIcon(family.getIcon());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (browserComboBox.getItemCount() < 2) {
|
|
||||||
browserComboBox.setVisible(false);
|
|
||||||
browserComboBox.setVisible(false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
browserComboBox.setSelectedItem(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void disposeEditor() {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.k2jsrun;
|
|
||||||
|
|
||||||
import com.intellij.execution.configurations.*;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinIcons;
|
|
||||||
|
|
||||||
public final class K2JSRunConfigurationType extends ConfigurationTypeBase {
|
|
||||||
public static K2JSRunConfigurationType getInstance() {
|
|
||||||
return ConfigurationTypeUtil.findConfigurationType(K2JSRunConfigurationType.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public K2JSRunConfigurationType() {
|
|
||||||
super("K2JSConfigurationType", "Kotlin (JavaScript)", "Kotlin to JavaScript configuration", KotlinIcons.SMALL_LOGO_13);
|
|
||||||
addFactory(new K2JSConfigurationFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class K2JSConfigurationFactory extends ConfigurationFactory {
|
|
||||||
protected K2JSConfigurationFactory() {
|
|
||||||
super(K2JSRunConfigurationType.this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
|
||||||
return new K2JSRunConfiguration("Kotlin to JavaScript", new RunConfigurationModule(project), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.k2jsrun;
|
|
||||||
|
|
||||||
import com.intellij.execution.configurations.RunProfile;
|
|
||||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
|
||||||
import com.intellij.ide.browsers.BrowserLauncher;
|
|
||||||
import com.intellij.ide.browsers.WebBrowser;
|
|
||||||
import com.intellij.ide.browsers.WebBrowserManager;
|
|
||||||
import com.intellij.openapi.module.Module;
|
|
||||||
import com.intellij.openapi.module.ModuleManager;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
|
||||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.js.JavaScript;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public final class K2JSRunnerUtils {
|
|
||||||
|
|
||||||
private K2JSRunnerUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static String constructPathToGeneratedFile(@NotNull Project project, @NotNull String outputDirPath) {
|
|
||||||
return outputDirPath + "/" + project.getName() + JavaScript.DOT_EXTENSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void copyJSFileFromOutputToDestination(@NotNull Project project,
|
|
||||||
@NotNull K2JSConfigurationSettings configurationSettings) {
|
|
||||||
VirtualFile outputDir = getOutputDir(project);
|
|
||||||
if (outputDir == null) {
|
|
||||||
throw new RuntimeException("Cannot find output dir for project " + project.getName());
|
|
||||||
}
|
|
||||||
String pathToGeneratedJsFile = constructPathToGeneratedFile(project, outputDir.getPath());
|
|
||||||
try {
|
|
||||||
copyFileToDir(new File(pathToGeneratedJsFile), new File(configurationSettings.getGeneratedFilePath()));
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new RuntimeException("Output JavaScript file was not generated or missing.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//todo[Alefas]: replacement of com.intellij.openapi.compiler.CompilerPaths.getModuleOutputDirectory()
|
|
||||||
@Nullable
|
|
||||||
private static VirtualFile getModuleOutputDirectory(@NotNull Module module) {
|
|
||||||
CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
|
|
||||||
|
|
||||||
if (compilerModuleExtension == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
VirtualFile outPath = compilerModuleExtension.getCompilerOutputPath();
|
|
||||||
|
|
||||||
if (outPath == null || !outPath.isValid()) return null;
|
|
||||||
return outPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static VirtualFile getOutputDir(@NotNull Project project) {
|
|
||||||
Module module = getJsModule(project);
|
|
||||||
return getModuleOutputDirectory(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static Module getJsModule(@NotNull Project project) {
|
|
||||||
//TODO Should not be there, we should know what module we are in
|
|
||||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
|
||||||
if (modules.length != 1) {
|
|
||||||
throw new UnsupportedOperationException("Kotlin to JavaScript translator temporarily does not support multiple modules.");
|
|
||||||
}
|
|
||||||
return modules[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openBrowser(@NotNull K2JSConfigurationSettings configurationSettings) {
|
|
||||||
if (!configurationSettings.isShouldOpenInBrowserAfterTranslation()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String filePath = configurationSettings.getPageToOpenFilePath();
|
|
||||||
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, filePath);
|
|
||||||
|
|
||||||
WebBrowser browser = WebBrowserManager.getInstance().findBrowserById(configurationSettings.getBrowserFamily().getName());
|
|
||||||
BrowserLauncher.getInstance().browse(url, browser);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static K2JSConfigurationSettings getSettings(@NotNull ExecutionEnvironment env) {
|
|
||||||
RunProfile profile = env.getRunProfile();
|
|
||||||
assert profile instanceof K2JSRunConfiguration;
|
|
||||||
return ((K2JSRunConfiguration) profile).settings();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: this method does not really belong here, but dunno where it should be
|
|
||||||
public static void copyFileToDir(@NotNull File file, @NotNull File dir) throws IOException {
|
|
||||||
FileUtil.copy(file, new File(dir, file.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user