|
22 | 22 | import consulo.content.bundle.SdkTable; |
23 | 23 | import consulo.content.bundle.SdkUtil; |
24 | 24 | import consulo.disposer.Disposable; |
25 | | -import consulo.ide.newModule.ui.UnifiedProjectOrModuleNameStep; |
26 | 25 | import consulo.ide.setting.ProjectStructureSettingsUtil; |
27 | 26 | import consulo.ide.setting.ShowSettingsUtil; |
28 | 27 | import consulo.localize.LocalizeValue; |
| 28 | +import consulo.module.creation.ui.UnifiedProjectOrModuleNameStep; |
29 | 29 | import consulo.module.ui.BundleBox; |
30 | 30 | import consulo.module.ui.BundleBoxBuilder; |
31 | 31 | import consulo.ui.Button; |
|
38 | 38 | import consulo.ui.model.MutableListModel; |
39 | 39 | import consulo.ui.style.StandardColors; |
40 | 40 | import consulo.ui.util.FormBuilder; |
41 | | -import consulo.unity3d.localize.Unity3dLocalize; |
42 | 41 | import consulo.unity3d.bundle.Unity3dBundleType; |
| 42 | +import consulo.unity3d.localize.Unity3dLocalize; |
43 | 43 | import consulo.unity3d.projectImport.Unity3dProjectImporter; |
44 | 44 | import consulo.unity3d.projectImport.UnityModuleImportContext; |
45 | | - |
46 | 45 | import jakarta.annotation.Nonnull; |
| 46 | + |
47 | 47 | import javax.swing.*; |
48 | 48 | import java.util.Objects; |
49 | 49 | import java.util.function.Consumer; |
|
52 | 52 | * @author VISTALL |
53 | 53 | * @since 01.02.15 |
54 | 54 | */ |
55 | | -public class Unity3dWizardStep extends UnifiedProjectOrModuleNameStep<UnityModuleImportContext> |
56 | | -{ |
57 | | - private final UnityModuleImportContext myContext; |
58 | | - |
59 | | - private BundleBox myBundleBox; |
60 | | - |
61 | | - public Unity3dWizardStep(UnityModuleImportContext context) |
62 | | - { |
63 | | - super(context); |
64 | | - myContext = context; |
65 | | - } |
66 | | - |
67 | | - @RequiredUIAccess |
68 | | - @Override |
69 | | - protected void extend(@Nonnull FormBuilder builder, @Nonnull Disposable uiDisposable) |
70 | | - { |
71 | | - super.extend(builder, uiDisposable); |
72 | | - |
73 | | - String requiredVersion = Unity3dProjectImporter.loadVersionFromProject(myContext.getPath()); |
74 | | - |
75 | | - BundleBoxBuilder boxBuilder = BundleBoxBuilder.create(uiDisposable); |
76 | | - boxBuilder.withSdkTypeFilterByType(Unity3dBundleType.getInstance()); |
77 | | - |
78 | | - ComboBox<BundleBox.BundleBoxItem> comboBox = (myBundleBox = boxBuilder.build()).getComponent(); |
79 | | - DockLayout dock = DockLayout.create(); |
80 | | - dock.center(comboBox); |
81 | | - dock.right(Button.create(LocalizeValue.localizeTODO("Select..."), clickEvent -> |
82 | | - { |
83 | | - JComponent awtComponent = (JComponent) TargetAWT.to(myBundleBox.getComponent()); |
84 | | - |
85 | | - showAddSdk(sdk -> |
86 | | - { |
87 | | - WriteAction.run(() -> SdkTable.getInstance().addSdk(sdk)); |
88 | | - |
89 | | - MutableListModel<BundleBox.BundleBoxItem> listModel = (MutableListModel<BundleBox.BundleBoxItem>) comboBox.getListModel(); |
90 | | - |
91 | | - BundleBox.BaseBundleBoxItem item = new BundleBox.BaseBundleBoxItem(sdk); |
92 | | - |
93 | | - listModel.add(item); |
94 | | - |
95 | | - UIAccess.current().give(() -> comboBox.setValue(item)); |
96 | | - }); |
97 | | - })); |
98 | | - builder.addLabeled(Unity3dLocalize.unityName(), dock); |
99 | | - |
100 | | - if(requiredVersion != null) |
101 | | - { |
102 | | - for(BundleBox.BundleBoxItem item : comboBox.getListModel()) |
103 | | - { |
104 | | - Sdk bundle = item.getBundle(); |
105 | | - |
106 | | - if(bundle != null) |
107 | | - { |
108 | | - String versionString = bundle.getVersionString(); |
109 | | - if(Objects.equals(requiredVersion, versionString)) |
110 | | - { |
111 | | - comboBox.setValue(item); |
112 | | - break; |
113 | | - } |
114 | | - } |
115 | | - } |
116 | | - } |
117 | | - |
118 | | - if(comboBox.getValue() == null && comboBox.getListModel().getSize() > 0) |
119 | | - { |
120 | | - myBundleBox.getComponent().setValueByIndex(0); |
121 | | - } |
122 | | - |
123 | | - if(requiredVersion != null) |
124 | | - { |
125 | | - builder.addBottom(Label.create(Unity3dLocalize.requiredUnityVersionIs0(requiredVersion)).withForegroundColor(StandardColors.GRAY)); |
126 | | - } |
127 | | - } |
128 | | - |
129 | | - @RequiredUIAccess |
130 | | - public static void showAddSdk(@RequiredUIAccess Consumer<Sdk> sdkConsumer) |
131 | | - { |
132 | | - ProjectStructureSettingsUtil settingsUtil = ShowSettingsUtil.getInstance(); |
133 | | - |
134 | | - Unity3dBundleType type = Unity3dBundleType.getInstance(); |
135 | | - |
136 | | - SdkUtil.selectSdkHome(Unity3dBundleType.getInstance(), home -> |
137 | | - { |
138 | | - String newSdkName = SdkUtil.createUniqueSdkName(type, home, settingsUtil.getSdksModel().getBundles()); |
139 | | - Sdk newSdk = SdkTable.getInstance().createSdk(newSdkName, type); |
140 | | - |
141 | | - SdkModificator modificator = newSdk.getSdkModificator(); |
142 | | - modificator.setHomePath(home); |
143 | | - modificator.commitChanges(); |
144 | | - |
145 | | - sdkConsumer.accept(newSdk); |
146 | | - }); |
147 | | - } |
148 | | - |
149 | | - @Override |
150 | | - public void onStepLeave(@Nonnull UnityModuleImportContext context) |
151 | | - { |
152 | | - super.onStepLeave(context); |
153 | | - |
154 | | - if(myBundleBox != null) |
155 | | - { |
156 | | - String selectedBundleName = myBundleBox.getSelectedBundleName(); |
157 | | - if(selectedBundleName != null) |
158 | | - { |
159 | | - context.setSdk(SdkTable.getInstance().findSdk(selectedBundleName)); |
160 | | - } |
161 | | - } |
162 | | - } |
| 55 | +public class Unity3dWizardStep extends UnifiedProjectOrModuleNameStep<UnityModuleImportContext> { |
| 56 | + private final UnityModuleImportContext myContext; |
| 57 | + |
| 58 | + private BundleBox myBundleBox; |
| 59 | + |
| 60 | + public Unity3dWizardStep(UnityModuleImportContext context) { |
| 61 | + super(context); |
| 62 | + myContext = context; |
| 63 | + } |
| 64 | + |
| 65 | + @RequiredUIAccess |
| 66 | + @Override |
| 67 | + protected void extend(@Nonnull FormBuilder builder, @Nonnull Disposable uiDisposable) { |
| 68 | + super.extend(builder, uiDisposable); |
| 69 | + |
| 70 | + String requiredVersion = Unity3dProjectImporter.loadVersionFromProject(myContext.getPath()); |
| 71 | + |
| 72 | + BundleBoxBuilder boxBuilder = BundleBoxBuilder.create(uiDisposable); |
| 73 | + boxBuilder.withSdkTypeFilterByType(Unity3dBundleType.getInstance()); |
| 74 | + |
| 75 | + ComboBox<BundleBox.BundleBoxItem> comboBox = (myBundleBox = boxBuilder.build()).getComponent(); |
| 76 | + DockLayout dock = DockLayout.create(); |
| 77 | + dock.center(comboBox); |
| 78 | + dock.right(Button.create(LocalizeValue.localizeTODO("Select..."), clickEvent -> |
| 79 | + { |
| 80 | + JComponent awtComponent = (JComponent) TargetAWT.to(myBundleBox.getComponent()); |
| 81 | + |
| 82 | + showAddSdk(sdk -> |
| 83 | + { |
| 84 | + WriteAction.run(() -> SdkTable.getInstance().addSdk(sdk)); |
| 85 | + |
| 86 | + MutableListModel<BundleBox.BundleBoxItem> listModel = (MutableListModel<BundleBox.BundleBoxItem>) comboBox.getListModel(); |
| 87 | + |
| 88 | + BundleBox.BaseBundleBoxItem item = new BundleBox.BaseBundleBoxItem(sdk); |
| 89 | + |
| 90 | + listModel.add(item); |
| 91 | + |
| 92 | + UIAccess.current().give(() -> comboBox.setValue(item)); |
| 93 | + }); |
| 94 | + })); |
| 95 | + builder.addLabeled(Unity3dLocalize.unityName(), dock); |
| 96 | + |
| 97 | + if (requiredVersion != null) { |
| 98 | + for (BundleBox.BundleBoxItem item : comboBox.getListModel()) { |
| 99 | + Sdk bundle = item.getBundle(); |
| 100 | + |
| 101 | + if (bundle != null) { |
| 102 | + String versionString = bundle.getVersionString(); |
| 103 | + if (Objects.equals(requiredVersion, versionString)) { |
| 104 | + comboBox.setValue(item); |
| 105 | + break; |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + if (comboBox.getValue() == null && comboBox.getListModel().getSize() > 0) { |
| 112 | + myBundleBox.getComponent().setValueByIndex(0); |
| 113 | + } |
| 114 | + |
| 115 | + if (requiredVersion != null) { |
| 116 | + builder.addBottom(Label.create(Unity3dLocalize.requiredUnityVersionIs0(requiredVersion)).withForegroundColor(StandardColors.GRAY)); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + @RequiredUIAccess |
| 121 | + public static void showAddSdk(@RequiredUIAccess Consumer<Sdk> sdkConsumer) { |
| 122 | + ProjectStructureSettingsUtil settingsUtil = ShowSettingsUtil.getInstance(); |
| 123 | + |
| 124 | + Unity3dBundleType type = Unity3dBundleType.getInstance(); |
| 125 | + |
| 126 | + SdkUtil.selectSdkHome(Unity3dBundleType.getInstance(), home -> |
| 127 | + { |
| 128 | + String newSdkName = SdkUtil.createUniqueSdkName(type, home, settingsUtil.getSdksModel().getBundles()); |
| 129 | + Sdk newSdk = SdkTable.getInstance().createSdk(newSdkName, type); |
| 130 | + |
| 131 | + SdkModificator modificator = newSdk.getSdkModificator(); |
| 132 | + modificator.setHomePath(home); |
| 133 | + modificator.commitChanges(); |
| 134 | + |
| 135 | + sdkConsumer.accept(newSdk); |
| 136 | + }); |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public void onStepLeave(@Nonnull UnityModuleImportContext context) { |
| 141 | + super.onStepLeave(context); |
| 142 | + |
| 143 | + if (myBundleBox != null) { |
| 144 | + String selectedBundleName = myBundleBox.getSelectedBundleName(); |
| 145 | + if (selectedBundleName != null) { |
| 146 | + context.setSdk(SdkTable.getInstance().findSdk(selectedBundleName)); |
| 147 | + } |
| 148 | + } |
| 149 | + } |
163 | 150 | } |
0 commit comments