Implement choose browser combobox.
This commit is contained in:
@@ -63,7 +63,7 @@ public final class K2JSBrowserProgramRunner extends GenericProgramRunner {
|
|||||||
private static void openBrowser(@NotNull K2JSConfigurationSettings configurationSettings) {
|
private static void openBrowser(@NotNull K2JSConfigurationSettings configurationSettings) {
|
||||||
String filePath = configurationSettings.getFilePath();
|
String filePath = configurationSettings.getFilePath();
|
||||||
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, filePath);
|
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, filePath);
|
||||||
BrowsersConfiguration.launchBrowser(BrowsersConfiguration.BrowserFamily.FIREFOX, url);
|
BrowsersConfiguration.launchBrowser(configurationSettings.getBrowserFamily(), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.k2jsrun;
|
package org.jetbrains.jet.plugin.k2jsrun;
|
||||||
|
|
||||||
|
import com.intellij.ide.browsers.BrowsersConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +27,18 @@ public class K2JSConfigurationSettings {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private String filePath = "";
|
private String filePath = "";
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private BrowsersConfiguration.BrowserFamily browserFamily = BrowsersConfiguration.getInstance().getActiveBrowsers().get(0);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public BrowsersConfiguration.BrowserFamily getBrowserFamily() {
|
||||||
|
return browserFamily;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrowserFamily(@NotNull BrowsersConfiguration.BrowserFamily browserFamily) {
|
||||||
|
this.browserFamily = browserFamily;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getFilePath() {
|
public String getFilePath() {
|
||||||
return filePath;
|
return filePath;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<text value="Browser"/>
|
<text value="Browser"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="a2cc0" class="javax.swing.JComboBox">
|
<component id="a2cc0" class="javax.swing.JComboBox" binding="browserComboBox">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.k2jsrun;
|
package org.jetbrains.jet.plugin.k2jsrun;
|
||||||
|
|
||||||
|
import com.intellij.ide.browsers.BrowsersConfiguration;
|
||||||
|
import com.intellij.ide.ui.ListCellRendererWrapper;
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||||
@@ -36,6 +38,7 @@ public final class K2JSRunConfigurationEditor extends SettingsEditor<K2JSRunConf
|
|||||||
|
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private TextFieldWithBrowseButton chooseFile;
|
private TextFieldWithBrowseButton chooseFile;
|
||||||
|
private JComboBox browserComboBox;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Project project;
|
private final Project project;
|
||||||
|
|
||||||
@@ -46,11 +49,16 @@ public final class K2JSRunConfigurationEditor extends SettingsEditor<K2JSRunConf
|
|||||||
@Override
|
@Override
|
||||||
protected void resetEditorFrom(K2JSRunConfiguration configuration) {
|
protected void resetEditorFrom(K2JSRunConfiguration configuration) {
|
||||||
chooseFile.setText(configuration.settings().getFilePath());
|
chooseFile.setText(configuration.settings().getFilePath());
|
||||||
|
browserComboBox.setSelectedItem(configuration.settings().getBrowserFamily());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void applyEditorTo(@NotNull K2JSRunConfiguration configuration) throws ConfigurationException {
|
protected void applyEditorTo(@NotNull K2JSRunConfiguration configuration) throws ConfigurationException {
|
||||||
configuration.settings().setFilePath(FileUtil.toSystemIndependentName(chooseFile.getText()));
|
configuration.settings().setFilePath(FileUtil.toSystemIndependentName(chooseFile.getText()));
|
||||||
|
Object item = browserComboBox.getSelectedItem();
|
||||||
|
if (item instanceof BrowsersConfiguration.BrowserFamily) {
|
||||||
|
configuration.settings().setBrowserFamily((BrowsersConfiguration.BrowserFamily)item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -59,9 +67,32 @@ public final class K2JSRunConfigurationEditor extends SettingsEditor<K2JSRunConf
|
|||||||
FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(StdFileTypes.HTML);
|
FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(StdFileTypes.HTML);
|
||||||
fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRootUrls());
|
fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRootUrls());
|
||||||
chooseFile.addBrowseFolderListener("Choose file", "Yeah!", project, fileChooserDescriptor);
|
chooseFile.addBrowseFolderListener("Choose file", "Yeah!", project, fileChooserDescriptor);
|
||||||
|
setupBrowserCombobox();
|
||||||
return mainPanel;
|
return mainPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupBrowserCombobox() {
|
||||||
|
for (BrowsersConfiguration.BrowserFamily family : BrowsersConfiguration.getInstance().getActiveBrowsers()) {
|
||||||
|
browserComboBox.addItem(family);
|
||||||
|
}
|
||||||
|
browserComboBox.setRenderer(new ListCellRendererWrapper<BrowsersConfiguration.BrowserFamily>(browserComboBox) {
|
||||||
|
@Override
|
||||||
|
public void customize(JList list, BrowsersConfiguration.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
|
@Override
|
||||||
protected void disposeEditor() {
|
protected void disposeEditor() {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|||||||
Reference in New Issue
Block a user