Skip to content

Commit 5752e37

Browse files
committed
Templates: Rework integration with a New Project Wizard
Introduce the ability to install and manage MonoGame templates
1 parent 71db137 commit 5752e37

4 files changed

Lines changed: 25 additions & 148 deletions

File tree

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,13 @@ tasks {
250250
compilerOptions {
251251
jvmTarget = JvmTarget.JVM_21
252252
freeCompilerArgs.add("-Xopt-in=kotlin.RequiresOptIn")
253+
freeCompilerArgs.add("-Xcontext-parameters=true")
253254
}
254255
}
255256
}
256257

257258
patchPluginXml {
258-
sinceBuild.set("253.0")
259+
sinceBuild.set("253.2")
259260
val latestChangelog = try {
260261
changelog.getUnreleased()
261262
} catch (_: MissingVersionException) {
Lines changed: 20 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,41 @@
11
package me.seclerp.rider.plugins.monogame.templates
22

3-
import com.intellij.icons.AllIcons
4-
import com.intellij.openapi.editor.colors.EditorColorsManager
5-
import com.intellij.openapi.editor.colors.EditorFontType
6-
import com.intellij.openapi.ui.DialogPanel
7-
import com.intellij.ui.AnimatedIcon
8-
import com.intellij.ui.EditorNotificationPanel
9-
import com.intellij.ui.components.fields.ExtendableTextComponent
10-
import com.intellij.ui.components.fields.ExtendableTextField
11-
import com.intellij.ui.components.panels.NonOpaquePanel
12-
import com.intellij.ui.components.panels.VerticalLayout
13-
import com.intellij.ui.dsl.builder.Panel
14-
import com.intellij.ui.dsl.builder.Row
15-
import com.intellij.ui.dsl.builder.TopGap
16-
import com.intellij.ui.dsl.builder.panel
17-
import com.intellij.util.ui.JBUI
183
import com.jetbrains.rd.util.lifetime.Lifetime
194
import com.jetbrains.rd.util.reactive.IOptProperty
205
import com.jetbrains.rider.model.RdProjectTemplate
216
import com.jetbrains.rider.projectView.projectTemplates.NewProjectDialogContext
227
import com.jetbrains.rider.projectView.projectTemplates.ProjectTemplatesSharedModel
23-
import com.jetbrains.rider.projectView.projectTemplates.generators.TypeListBasedProjectTemplateGenerator
24-
import me.seclerp.rider.extensions.ClipboardUtil
25-
import me.seclerp.rider.plugins.monogame.MonoGameIcons
8+
import com.jetbrains.rider.projectView.projectTemplates.components.InstallNuGetPackagesController
9+
import com.jetbrains.rider.projectView.projectTemplates.generators.NuGetProjectTemplateGenerator
2610
import me.seclerp.rider.plugins.monogame.MonoGameUiBundle
27-
import me.seclerp.rider.plugins.monogame.templates.MonoGameTemplateMetadata.Names
28-
import java.awt.BorderLayout
29-
import java.awt.Component
30-
import javax.swing.JLabel
31-
import javax.swing.SwingConstants
11+
import org.jetbrains.annotations.Nls
3212

3313
internal class MonoGameProjectTemplateGenerator(
3414
lifetime: Lifetime,
3515
context: NewProjectDialogContext,
3616
sharedModel: ProjectTemplatesSharedModel,
3717
projectTemplates: IOptProperty<Set<RdProjectTemplate>>
38-
) : TypeListBasedProjectTemplateGenerator(lifetime, context, sharedModel, projectTemplates) {
39-
init {
40-
context.isReady.afterChange {
41-
val templates = tryGetAcceptableTemplates()
42-
when {
43-
it && templates.isNullOrEmpty() -> setTemplatesMissingState()
44-
it && !templates.isNullOrEmpty() -> setReadyState()
45-
else -> setLoadingState()
46-
}
47-
}
48-
}
49-
18+
) : NuGetProjectTemplateGenerator(lifetime, context, sharedModel, projectTemplates) {
19+
private val presentableTemplatesName = MonoGameUiBundle.message("new.project.templates.title")
20+
override val installNuGetPackageController: InstallNuGetPackagesController = object : InstallNuGetPackagesController(
21+
lifetime,
22+
context,
23+
presentableTemplatesName,
24+
shouldShowUpdatingIcon
25+
) {
26+
override val packageName: String = "MonoGame.Templates.CSharp"
27+
override val suggestInstallText: @Nls String = MonoGameUiBundle.message("new.project.templates.suggestion")
28+
}
29+
30+
override val contextHelpTitle = MonoGameUiBundle.message("new.project.templates.help", presentableTemplatesName)
5031
override val defaultName = "MonoGameProject1"
5132

52-
override fun getPredefinedTypes() = listOf(
53-
TemplateTypeWithIcon(Names.CROSS_PLATFORM_APP, MonoGameIcons.MgcbFile),
54-
TemplateTypeWithIcon(Names.WINDOWS_DESKTOP_APP, MonoGameIcons.MgcbFile),
55-
TemplateTypeWithIcon(Names.ANDROID_APP, MonoGameIcons.MgcbFile),
56-
TemplateTypeWithIcon(Names.IOS_APP, MonoGameIcons.MgcbFile),
57-
TemplateTypeWithIcon(Names.GAME_LIB, MonoGameIcons.MgcbFile),
58-
TemplateTypeWithIcon(Names.CONTENT_PIPELINE_EXTENSION, MonoGameIcons.MgcbFile),
59-
TemplateTypeWithIcon(Names.SHARED_LIB, MonoGameIcons.MgcbFile),
60-
TemplateTypeWithIcon(Names.CONTENT_BUILDER, MonoGameIcons.MgcbFile),
61-
TemplateTypeWithIcon(Names._2D_START_KIT, MonoGameIcons.MgcbFile),
62-
TemplateTypeWithIcon(Names.BLANK_2D_START_KIT, MonoGameIcons.MgcbFile),
63-
)
33+
init {
34+
installNuGetPackageController.parentInit()
35+
parentInit()
36+
}
6437

6538
override fun getType(template: RdProjectTemplate) = template.name
6639
.removePrefix("MonoGame ")
6740
.replace("Application", "App")
68-
69-
private var myLoadingRow: Row? = null
70-
private var myTemplatesMissingRow: Row? = null
71-
private var myTemplatesRow: Row? = null
72-
73-
override fun createTemplateSpecificPanelAfterLanguage(): DialogPanel {
74-
return panel {
75-
myLoadingRow = createLoadingRow().apply { visible(false)}
76-
myTemplatesMissingRow = createMissingTemplatesRow().apply { visible(false)}
77-
myTemplatesRow = createReadyRow().apply { visible(false)}
78-
setLoadingState()
79-
}
80-
}
81-
82-
private fun setLoadingState() {
83-
myTemplatesRow?.visible(false)
84-
myTemplatesMissingRow?.visible(false)
85-
myLoadingRow?.visible(true)
86-
}
87-
88-
private fun setReadyState() {
89-
myLoadingRow?.visible(false)
90-
myTemplatesMissingRow?.visible(false)
91-
myTemplatesRow?.visible(true)
92-
}
93-
94-
private fun setTemplatesMissingState() {
95-
myLoadingRow?.visible(false)
96-
myTemplatesRow?.visible(false)
97-
myTemplatesMissingRow?.visible(true)
98-
}
99-
100-
private fun Panel.createLoadingRow() = row(" ") {
101-
cell(JLabel(MonoGameUiBundle.message("templates.loading.templates"), AnimatedIcon.Default(), SwingConstants.LEFT))
102-
}
103-
104-
private fun Panel.createReadyRow() = row {
105-
cell(super.createTemplateSpecificPanelAfterLanguage())
106-
}
107-
108-
private fun Panel.createMissingTemplatesRow() = row(" ") {
109-
val installCommand = "dotnet new install MonoGame.Templates.CSharp"
110-
cell(CustomNotificationPanel(EditorNotificationPanel.Status.Warning))
111-
.applyToComponent {
112-
text(MonoGameUiBundle.message("templates.no.templates.found"))
113-
addBottomItem(JLabel(MonoGameUiBundle.message("templates.no.templates.install.hint")).apply {
114-
border = JBUI.Borders.emptyTop(8)
115-
})
116-
addBottomItem(CodeSnippetTextField(installCommand, 50))
117-
}
118-
.resizableColumn()
119-
topGap(TopGap.SMALL)
120-
}
121-
122-
private class CustomNotificationPanel(status: Status) : EditorNotificationPanel(status) {
123-
private val myBottomPanel = NonOpaquePanel(VerticalLayout(8, VerticalLayout.FILL))
124-
125-
init {
126-
add(myBottomPanel, BorderLayout.SOUTH)
127-
}
128-
129-
fun addBottomItem(comp: Component) {
130-
myBottomPanel.add(comp)
131-
}
132-
}
133-
134-
private class CodeSnippetTextField(text: String, columns: Int = 20) : ExtendableTextField(text, columns) {
135-
init {
136-
isEditable = false
137-
font = EditorColorsManager.getInstance().globalScheme.getFont(EditorFontType.PLAIN)
138-
addExtension(CopyToClipboardExtension())
139-
}
140-
141-
private inner class CopyToClipboardExtension : ExtendableTextComponent.Extension {
142-
override fun getIcon(hovered: Boolean) = AllIcons.General.Copy
143-
144-
override fun getActionOnClick() = Runnable {
145-
ClipboardUtil.copyToClipboard(this@CodeSnippetTextField.text)
146-
}
147-
}
148-
}
14941
}

src/rider/main/kotlin/me/seclerp/rider/plugins/monogame/templates/MonoGameTemplateMetadata.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/rider/main/resources/messages/MonoGameUiBundle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ command.execution.error.message.code=Status code doesn't indicate success: {0}.\
1818
command.mgcb.open.title=Open in external MGCB editor
1919
command.mgcb.open.missing.editor.title=mgcb-editor tool is missing
2020
21-
templates.loading.templates=Loading templates...
22-
templates.no.templates.found=No MonoGame templates were found.
23-
templates.no.templates.install.hint=Please install them using the following command:
21+
new.project.templates.suggestion=Install MonoGame templates to start creating MonoGame projects.
22+
new.project.templates.title=MonoGame Templates
23+
new.project.templates.help=The list of available project types is provided by the installed MonoGame.Templates.CSharp package

0 commit comments

Comments
 (0)