Skip to content

Commit

Permalink
Merge pull request #109 from SchweinchenFuntik/migraton_version
Browse files Browse the repository at this point in the history
Migraton version
  • Loading branch information
edvin authored Jul 26, 2020
2 parents 0e49544 + 6ef4167 commit 73fddd0
Show file tree
Hide file tree
Showing 87 changed files with 749 additions and 2,421 deletions.
23 changes: 14 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
plugins {
id 'java'
id "org.jetbrains.kotlin.jvm" version "1.2.51"
id "org.jetbrains.intellij" version "0.3.4"
id 'org.jetbrains.kotlin.jvm' version "1.3.72"
// id "org.jetbrains.intellij" version "0.3.12"
id "org.jetbrains.intellij" version "0.4.21"
}

group 'no.tornado'
version '1.7.17'
version '1.7.18'

repositories {
mavenCentral()
}

intellij {
version '2018.1'
plugins = ['Kotlin','properties']
version '2020.1' // 2018.2 2018.3.6 2019.1.4, 2019.2, 2019.3.5 , 2020.1
plugins = ['Kotlin','properties', 'java']
patchPluginXml {
untilBuild = "" // Be forward compatible
// sinceBuild is inferred from the version above
Expand All @@ -22,8 +26,9 @@ publishPlugin {
password publishPassword
}

task wrapper(type: Wrapper) {
gradleVersion = project.gradleVersion
distributionType = Wrapper.DistributionType.ALL
distributionUrl = "http://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationEx

}

public ModuleType getModuleType() {
public ModuleType<TornadoFXModuleBuilder> getModuleType() {
return TornadoFXModuleType.getInstance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.psi.JavaCodeFragment;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.EditorTextFieldWithBrowseButton;
import com.intellij.ui.PanelWithAnchor;
Expand All @@ -54,8 +53,8 @@ public class TornadoFXSettingsEditor extends SettingsEditor<TornadoFXConfigurati
private final ConfigurationModuleSelector myModuleSelector;
private JrePathEditor myJrePathEditor;
private JCheckBox myShowSwingInspectorCheckbox;
private LabeledComponent typeWrapper;
private LabeledComponent myDevOptions;
private LabeledComponent<JPanel> typeWrapper;
private LabeledComponent<JPanel> myDevOptions;
private final JreVersionDetector myVersionDetector;
private final Project myProject;
private JComponent myAnchor;
Expand All @@ -78,7 +77,7 @@ public TornadoFXSettingsEditor(final Project project) {
myAnchor = UIUtil.mergeComponentsWithAnchor(myViewClass, myAppClass, myDevOptions, typeWrapper, myCommonProgramParameters, myJrePathEditor, myModule);
}

public void applyEditorTo(final TornadoFXConfiguration configuration) throws ConfigurationException {
public void applyEditorTo(@NotNull final TornadoFXConfiguration configuration) throws ConfigurationException {
myCommonProgramParameters.applyTo(configuration);
myModuleSelector.applyTo(configuration);
configuration.RUN_TYPE = appButton.isSelected() ? App : View;
Expand All @@ -93,13 +92,13 @@ public void applyEditorTo(final TornadoFXConfiguration configuration) throws Con
configuration.LIVE_STYLESHEETS = liveStylesheetsButton.isSelected();
configuration.DUMP_STYLESHEETS = dumpStylesheetsButton.isSelected();
configuration.LIVE_VIEWS = liveViewsButton.isSelected();
configuration.ALTERNATIVE_JRE_PATH = myJrePathEditor.getJrePathOrName();
configuration.ALTERNATIVE_JRE_PATH_ENABLED = myJrePathEditor.isAlternativeJreSelected();
configuration.setAlternativeJrePath(myJrePathEditor.getJrePathOrName());
configuration.setAlternativeJrePathEnabled(myJrePathEditor.isAlternativeJreSelected());
configuration.setSwingInspectorEnabled((myVersionDetector.isJre50Configured(configuration) || myVersionDetector.isModuleJre50Configured(configuration)) && myShowSwingInspectorCheckbox.isSelected());
updateShowSwingInspector(configuration);
}

public void resetEditorFrom(final TornadoFXConfiguration configuration) {
public void resetEditorFrom(@NotNull final TornadoFXConfiguration configuration) {
myCommonProgramParameters.reset(configuration);
myModuleSelector.reset(configuration);
if (configuration.RUN_TYPE == App) {
Expand All @@ -116,7 +115,7 @@ public void resetEditorFrom(final TornadoFXConfiguration configuration) {
liveStylesheetsButton.setSelected(configuration.LIVE_STYLESHEETS);
dumpStylesheetsButton.setSelected(configuration.DUMP_STYLESHEETS);
liveViewsButton.setSelected(configuration.LIVE_VIEWS);
myJrePathEditor.setPathOrName(configuration.ALTERNATIVE_JRE_PATH, configuration.ALTERNATIVE_JRE_PATH_ENABLED);
myJrePathEditor.setPathOrName(configuration.getAlternativeJrePath(), configuration.isAlternativeJrePathEnabled());
updateShowSwingInspector(configuration);
}

Expand Down Expand Up @@ -151,22 +150,20 @@ public JComponent createEditor() {

private void createUIComponents() {
myViewClass = new LabeledComponent<>();
myViewClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, new JavaCodeFragment.VisibilityChecker() {
public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
return (declaration instanceof PsiClass && isViewClass((PsiClass) declaration))
? Visibility.VISIBLE : Visibility.NOT_VISIBLE;
}
}));
JavaCodeFragment.VisibilityChecker vh1 =
(declaration, place) -> (declaration instanceof PsiClass && isViewClass((PsiClass) declaration))
? JavaCodeFragment.VisibilityChecker.Visibility.VISIBLE : JavaCodeFragment.VisibilityChecker.Visibility.NOT_VISIBLE;

myViewClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, vh1));

myAppClass = new LabeledComponent<>();
myAppClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, new JavaCodeFragment.VisibilityChecker() {
public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
return (declaration instanceof PsiClass && isAppClass((PsiClass) declaration))
? Visibility.VISIBLE : Visibility.NOT_VISIBLE;
}
}));
JavaCodeFragment.VisibilityChecker vh2 =
(declaration, place) -> (declaration instanceof PsiClass && isAppClass((PsiClass) declaration))
? JavaCodeFragment.VisibilityChecker.Visibility.VISIBLE : JavaCodeFragment.VisibilityChecker.Visibility.NOT_VISIBLE;

myAppClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, vh2));

typeWrapper = new LabeledComponent<EditorTextFieldWithBrowseButton>();
typeWrapper = new LabeledComponent<>();
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEADING));
ButtonGroup typeGroup = new ButtonGroup();
appButton = new JBRadioButton("Application");
Expand Down Expand Up @@ -194,7 +191,7 @@ public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place)
devPanel.add(liveViewsButton);
devPanel.add(liveStylesheetsButton);
devPanel.add(dumpStylesheetsButton);
myDevOptions = new LabeledComponent();
myDevOptions = new LabeledComponent<>();
myDevOptions.setComponent(devPanel);
}

Expand Down Expand Up @@ -265,7 +262,7 @@ protected PsiClass findClass(final String className) {
return myModuleSelector.findClass(className);
}

protected ClassFilter.ClassFilterWithScope getFilter() throws NoFilterException {
protected ClassFilter.ClassFilterWithScope getFilter() {
final Module module = myModuleSelector.getModule();
final GlobalSearchScope scope;
if (module == null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/no/tornado/tornadofx/idea/FXTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FXTools {

fun isTornadoFXType(psiClass: PsiClass): Boolean {
for (supa in psiClass.supers)
if (supa.qualifiedName?.startsWith("tornadofx.") ?: false) {
if (supa.qualifiedName?.startsWith("tornadofx.") == true) {
return true
} else {
val superIs = isTornadoFXType(supa)
Expand Down Expand Up @@ -65,6 +65,6 @@ fun Project.allRoots(): List<VirtualFile> = allModules()
.map { ModuleRootManager.getInstance(it).modifiableModel }
.flatMap { it.sourceRoots.toList() }

fun Project.firstModuleWithTornadoFXLib() = allModules().filter {
fun Project.firstModuleWithTornadoFXLib() = allModules().firstOrNull {
JavaPsiFacade.getInstance(this).findClass("tornadofx.App", it.moduleWithLibrariesScope) != null
}.firstOrNull()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil

@State(name = "TornadoFXSettings", storages = arrayOf(Storage("other.xml")))
@State(name = "TornadoFXSettings", storages = [Storage("other.xml")])
class TornadoFXSettings : PersistentStateComponent<TornadoFXSettings> {
var alternativePropertySyntax = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.ui.EditorTextField
import com.intellij.ui.EditorTextFieldWithBrowseButton
import no.tornado.tornadofx.idea.FXTools
import no.tornado.tornadofx.idea.FXTools.Companion.isComponent
Expand All @@ -30,24 +31,22 @@ class InjectComponentAction : AnAction() {
val componentClass = browser.requestComponentClass()
if (componentClass != null) {
val element = getElementAtCaret(e)!!
object : WriteCommandAction.Simple<String>(e.project!!, element.containingFile) {
override fun run() {
val factory = KtPsiFactory(project)
val propName = componentClass.substringAfterLast(".").let {
it.first().toLowerCase() + it.substring(1)
}
val componentPsiClass = FXTools.psiClass(componentClass, e.project!!)!!
val injectType = if (FXTools.isFragment(componentPsiClass)) "fragment" else "inject"
val prop = factory.createProperty("val $propName: $componentClass by $injectType()")
val ktClassBody = PsiTreeUtil.getParentOfType(element, KtClassBody::class.java)!!
val added = ktClassBody.addAfter(prop, ktClassBody.firstChild) as KtElement
ShortenReferences().process(added)
WriteCommandAction.writeCommandAction(e.project!!, element.containingFile).run<Throwable> {
val factory = KtPsiFactory(e.project!!)
val propName = componentClass.substringAfterLast(".").let {
it.first().toLowerCase() + it.substring(1)
}
}.execute()
val componentPsiClass = FXTools.psiClass(componentClass, e.project!!)!!
val injectType = if (FXTools.isFragment(componentPsiClass)) "fragment" else "inject"
val prop = factory.createProperty("val $propName: $componentClass by $injectType()")
val ktClassBody = PsiTreeUtil.getParentOfType(element, KtClassBody::class.java)!!
val added = ktClassBody.addAfter(prop, ktClassBody.firstChild) as KtElement
ShortenReferences().process(added)
}
}
}

fun getElementAtCaret(e: AnActionEvent): PsiElement? {
private fun getElementAtCaret(e: AnActionEvent): PsiElement? {
val psiFile = e.getData(LangDataKeys.PSI_FILE)
val editor = e.getData(PlatformDataKeys.EDITOR)

Expand Down Expand Up @@ -79,7 +78,7 @@ class InjectComponentAction : AnAction() {
e.presentation.isEnabled = isComponent(psiClass)
}

inner class ComponentBrowser(project: Project) : ClassBrowser(project, "Select Component to Inject") {
class ComponentBrowser(project: Project) : ClassBrowser<EditorTextField>(project, "Select Component to Inject") {
init {
// Inject a fake field, we need it because myField.text is called while browsing
setField(EditorTextFieldWithBrowseButton(project, true, null))
Expand Down
65 changes: 35 additions & 30 deletions src/main/kotlin/no/tornado/tornadofx/idea/actions/NewViewAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import com.intellij.ide.fileTemplates.FileTemplateUtil
import com.intellij.ide.fileTemplates.actions.CreateFromTemplateActionBase
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataKeys
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.DumbModePermission
import com.intellij.openapi.project.DumbService
//import com.intellij.openapi.project.DumbModePermission
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.MessageType
import com.intellij.openapi.ui.Messages
Expand Down Expand Up @@ -85,35 +83,42 @@ class NewViewAction : AnAction() {
fun createFileFromTemplate(name: String, template: FileTemplate, dir: PsiDirectory, rootType: String, viewType: String): PsiFile? {
var file: PsiFile? = null

DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, Runnable {
val element: PsiElement
val project = dir.project
try {
val props = FileTemplateManager.getInstance(dir.project).defaultProperties
props.put("fqRootType", rootType)
props.put("rootType", rootType.substringAfterLast("."))
props.put("initType", if(hasBuilder(project, rootType)) "builder" else "construct")
props.put("viewType", viewType)
element = FileTemplateUtil.createFromTemplate(template, name, props, dir)
val psiFile = element.containingFile

val virtualFile = psiFile.virtualFile
if (virtualFile != null) {
if (template.isLiveTemplateEnabled) {
CreateFromTemplateActionBase.startLiveTemplate(psiFile)
} else {
FileEditorManager.getInstance(project).openFile(virtualFile, true)
}
file = psiFile


// val dumbService = DumbService.getInstance(dir.project)
// object : DumbModeTask() {}
// dumbService.queueTask()
// dumbService.completeJustSubmittedTasks()

//DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, Runnable {
val element: PsiElement
val project = dir.project
try {
val props = FileTemplateManager.getInstance(dir.project).defaultProperties
props["fqRootType"] = rootType
props["rootType"] = rootType.substringAfterLast(".")
props["initType"] = if(hasBuilder(project, rootType)) "builder" else "construct"
props["viewType"] = viewType
element = FileTemplateUtil.createFromTemplate(template, name, props, dir)
val psiFile = element.containingFile

val virtualFile = psiFile.virtualFile
if (virtualFile != null) {
if (template.isLiveTemplateEnabled) {
CreateFromTemplateActionBase.startLiveTemplate(psiFile)
} else {
FileEditorManager.getInstance(project).openFile(virtualFile, true)
}
} catch (e: ParseException) {
Messages.showErrorDialog(project, "Error parsing Velocity template: " + e.message, "Create File from Template")
} catch (e: IncorrectOperationException) {
throw e
} catch (e: Exception) {
log.error(e)
file = psiFile
}
})
} catch (e: ParseException) {
Messages.showErrorDialog(project, "Error parsing Velocity template: " + e.message, "Create File from Template")
} catch (e: IncorrectOperationException) {
throw e
} catch (e: Exception) {
log.error(e)
}
//})

return file
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.intellij.psi.JavaCodeFragment
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClass
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.ui.EditorTextField
import com.intellij.ui.EditorTextFieldWithBrowseButton
import com.intellij.util.PlatformIcons
import org.jetbrains.kotlin.idea.KotlinIcons
Expand All @@ -23,6 +24,7 @@ import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTextField

@Suppress("MemberVisibilityCanBePrivate", "UNUSED_ANONYMOUS_PARAMETER")
class NewViewDialog(val project: Project) : DialogWrapper(project) {
val myPanel = JPanel(GridBagLayout())
val myKindCombo = TemplateKindCombo()
Expand Down Expand Up @@ -74,10 +76,10 @@ class NewViewDialog(val project: Project) : DialogWrapper(project) {
override fun createCenterPanel() = myPanel

fun isParentClass(psiClass: PsiClass): Boolean {
if (psiClass.qualifiedName?.startsWith("com.sun.") ?: false) return false
if (psiClass.qualifiedName?.startsWith("com.sun.") == true) return false

for (supa in psiClass.supers) {
if ("javafx.scene.Parent" == supa.qualifiedName && !(supa.qualifiedName?.startsWith("com.sun.") ?: false))
if ("javafx.scene.Parent" == supa.qualifiedName && supa.qualifiedName?.startsWith("com.sun.") != true)
return true

val superIs = isParentClass(supa)
Expand All @@ -86,7 +88,7 @@ class NewViewDialog(val project: Project) : DialogWrapper(project) {
return false
}

inner class RootClassBrowser() : ClassBrowser(project, "Select Root Class") {
inner class RootClassBrowser : ClassBrowser<EditorTextField>(project, "Select Root Class") {
init {
setField(rootType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.tornado.tornadofx.idea.annotator

import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
Expand Down Expand Up @@ -52,14 +53,15 @@ class CSSBoxAnnotator : Annotator {
args.forEach { values.add(it.text.convertOrNull()) }

if (values.isAllSimplifiable()) {
holder.createWeakWarningAnnotation(element.right!!.textRange,
"Can be simplified to box(${values[0]!!.first}${values[0]!!.second}).")
.registerFix(BoxQuickFix(element, values[0]!!))

holder.newAnnotation(HighlightSeverity.WEAK_WARNING, "Can be simplified to box(${values[0]!!.first}${values[0]!!.second}).")
.range(element.right!!.textRange)
.withFix(BoxQuickFix(element, values[0]!!))
.create()
} else if (values.isVHSimplifiable()) {
holder.createWeakWarningAnnotation(element.right!!.textRange,
"Can be simplified to box(${values[0]!!.first}${values[0]!!.second}, ${values[1]!!.first}${values[1]!!.second}).")
.registerFix(BoxQuickFix(element, values[0]!!, values[1]!!))
holder.newAnnotation(HighlightSeverity.WEAK_WARNING, "Can be simplified to box(${values[0]!!.first}${values[0]!!.second}, ${values[1]!!.first}${values[1]!!.second}).")
.range(element.right!!.textRange)
.withFix(BoxQuickFix(element, values[0]!!, values[1]!!))
.create()
}
}
}
Expand Down
Loading

0 comments on commit 73fddd0

Please sign in to comment.