Skip to content

Add sample apps to AS NPW #3134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ private FlutterCreateAdditionalSettings makeAdditionalSettings() {
.setKotlin(isNotModule() && myModel.useKotlin().get() ? true : null)
.setSwift(isNotModule() && myModel.useSwift().get() ? true : null)
.setOffline(myModel.isOfflineSelected().get())
.setSampleContent(myModel.getSample())
.build();
}

Expand Down
12 changes: 12 additions & 0 deletions flutter-studio/src/io/flutter/project/FlutterProjectModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.project.Project;
import io.flutter.module.FlutterProjectType;
import io.flutter.samples.FlutterSample;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Note that a single instance of this class is shared among all the steps in the wizard.
Expand All @@ -41,6 +43,7 @@ public class FlutterProjectModel extends WizardModel {
@NotNull final private BoolValueProperty mySwift = new BoolValueProperty();
@NotNull final private OptionalProperty<Project> myProject = new OptionalValueProperty<>();
@NotNull final private BoolValueProperty myIsOfflineSelected = new BoolValueProperty();
private FlutterSample mySelectedSample;

public FlutterProjectModel(@NotNull FlutterProjectType type) {
myProjectType.set(new OptionalValueProperty<>(type));
Expand All @@ -62,6 +65,15 @@ public FlutterProjectModel(@NotNull FlutterProjectType type) {
mySwift.addListener(sender -> setInitialSwiftSupport(mySwift.get()));
}

public void setSample(@Nullable FlutterSample sample) {
mySelectedSample = sample;
}

@Nullable
public FlutterSample getSample() {
return mySelectedSample;
}

@NotNull
public OptionalValueProperty<FlutterProjectType> projectType() {
return myProjectType;
Expand Down
48 changes: 42 additions & 6 deletions flutter-studio/src/io/flutter/project/FlutterSettingsStep.form
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="io.flutter.project.FlutterSettingsStep">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="13" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="14" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="5" bottom="0" right="5"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<xy x="20" y="20" width="500" height="452"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -20,12 +20,12 @@
</component>
<vspacer id="85806">
<constraints>
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="13" 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>
<component id="3d5fb" class="javax.swing.JLabel" binding="myLanguageLabel">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font style="1"/>
Expand Down Expand Up @@ -72,7 +72,7 @@
</vspacer>
<component id="533e3" class="javax.swing.JCheckBox" binding="myKotlinCheckBox">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Kotlin"/>
Expand All @@ -81,7 +81,7 @@
</component>
<component id="15a79" class="javax.swing.JCheckBox" binding="mySwiftCheckBox">
<constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Swift"/>
Expand Down Expand Up @@ -112,6 +112,42 @@
<text value="Applications and plugins need to generate platform-specific code"/>
</properties>
</component>
<grid id="a336f" binding="mySamplePanel" layout-manager="GridLayoutManager" row-count="3" 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="9" 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="fe85" 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"/>
</constraints>
<properties>
<font style="1"/>
<text value="Sample Application"/>
</properties>
</component>
<hspacer id="c6bbb">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<nested-form id="4869f" form-file="io/flutter/module/settings/ProjectType.form" binding="myProjectTypeForm">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</nested-form>
<vspacer id="d5f9">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="16"/>
</grid>
</constraints>
</vspacer>
</children>
</grid>
</children>
</grid>
</form>
14 changes: 14 additions & 0 deletions flutter-studio/src/io/flutter/project/FlutterSettingsStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.android.tools.idea.ui.wizard.WizardUtils;
import com.android.tools.idea.wizard.model.SkippableWizardStep;
import io.flutter.FlutterBundle;
import io.flutter.module.FlutterProjectType;
import io.flutter.module.settings.ProjectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -43,6 +45,8 @@ public class FlutterSettingsStep extends SkippableWizardStep<FlutterProjectModel
private JCheckBox myKotlinCheckBox;
private JCheckBox mySwiftCheckBox;
private JLabel myLanguageLabel;
private JPanel mySamplePanel;
private ProjectType myProjectTypeForm;
private boolean hasEntered = false;

public FlutterSettingsStep(FlutterProjectModel model, String title, Icon icon) {
Expand Down Expand Up @@ -117,6 +121,16 @@ protected void onEntering() {
myBindings.bindTwoWay(new SelectedProperty(myKotlinCheckBox), getModel().useKotlin());
myBindings.bindTwoWay(new SelectedProperty(mySwiftCheckBox), getModel().useSwift());
}
//noinspection OptionalGetWithoutIsPresent
FlutterProjectType projectType = getModel().projectType().get().get();
mySamplePanel.setVisible(projectType == FlutterProjectType.APP);
myProjectTypeForm.getProjectTypeCombo().setSelectedItem(projectType);
myProjectTypeForm.getProjectTypeCombo().setVisible(false);
hasEntered = true;
}

@Override
protected void onProceeding() {
getModel().setSample(myProjectTypeForm.getSample());
}
}
5 changes: 4 additions & 1 deletion src/io/flutter/module/settings/ProjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void createUIComponents() {
projectTypeCombo.addItemListener(e -> {
final boolean appType = getType() == FlutterProjectType.APP;
if (!appType) {
// Make sure sample generattion is de-selected in non-app contexts.
// Make sure sample generation is de-selected in non-app contexts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

generateSampleContentCheckBox.setSelected(false);
}
generateSampleContentCheckBox.setEnabled(appType);
Expand Down Expand Up @@ -154,6 +154,9 @@ public FlutterSample getSample() {
return generateSampleContentCheckBox.isVisible() && generateSampleContentCheckBox.isSelected() ? (FlutterSample)snippetSelectorCombo.getSelectedItem() : null;
}

public ComboBox getProjectTypeCombo() {
return projectTypeCombo;
}

public void addListener(ItemListener listener) {
projectTypeCombo.addItemListener(listener);
Expand Down