From 2547e23cdcd4320474c49d50773a141254b05f3c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 6 Mar 2018 11:57:41 +0100 Subject: [PATCH] cleanup Kotlin UI DSL, clarify docs about panel fillX and and add FAQ about cell grow/push --- .../src/PasswordSafeConfigurable.kt | 20 ++----------- .../com/intellij/ui/components/components.kt | 14 ++++++---- .../intellij/ui/layout/MigLayoutBuilder.kt | 20 +------------ .../src/com/intellij/ui/layout/Row.kt | 28 ++++++------------- .../src/com/intellij/ui/layout/flags.kt | 21 ++++---------- .../src/com/intellij/ui/layout/layout.kt | 18 ++---------- .../src/com/intellij/ui/layout/readme.md | 8 +++++- plugins/settings-repository/src/authForm.kt | 18 ++---------- 8 files changed, 37 insertions(+), 110 deletions(-) diff --git a/platform/credential-store/src/PasswordSafeConfigurable.kt b/platform/credential-store/src/PasswordSafeConfigurable.kt index fe40e3116a1b..bfa15dfa5201 100644 --- a/platform/credential-store/src/PasswordSafeConfigurable.kt +++ b/platform/credential-store/src/PasswordSafeConfigurable.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.credentialStore import com.intellij.ide.passwordSafe.PasswordSafe @@ -150,7 +136,7 @@ internal class PasswordSafeConfigurableUi : ConfigurableUi fun getCurrentDbFile() = keePassDbFile.text.trim().nullize()?.let { Paths.get(it) } - fun updateEnabledState() { + private fun updateEnabledState() { modeToRow[ProviderType.KEEPASS]?.subRowsEnabled = getProviderType() == ProviderType.KEEPASS } @@ -177,7 +163,7 @@ internal class PasswordSafeConfigurableUi : ConfigurableUi } keePassDbFile = textFieldWithBrowseButton("KeePass Database File", fileChooserDescriptor = fileChooserDescriptor, - fileChoosen = ::normalizeSelectedFile) + fileChosen = ::normalizeSelectedFile) gearButton( object : AnAction("Clear") { override fun actionPerformed(event: AnActionEvent) { diff --git a/platform/platform-impl/src/com/intellij/ui/components/components.kt b/platform/platform-impl/src/com/intellij/ui/components/components.kt index 3af8c77bfc89..8a267f66e1a1 100644 --- a/platform/platform-impl/src/com/intellij/ui/components/components.kt +++ b/platform/platform-impl/src/com/intellij/ui/components/components.kt @@ -1,4 +1,6 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +@file:Suppress("FunctionName") + package com.intellij.ui.components import com.intellij.BundleBase @@ -88,7 +90,7 @@ fun noteComponent(note: String): JComponent { @JvmOverloads fun htmlComponent(text: String = "", font: Font = UIUtil.getLabelFont(), background: Color? = null, foreground: Color? = null, lineWrap: Boolean = false): JEditorPane { val pane = SwingHelper.createHtmlViewer(lineWrap, font, background, foreground) - if (!text.isNullOrEmpty()) { + if (!text.isEmpty()) { pane.text = "${UIUtil.getCssFontDeclaration(font, UIUtil.getLabelForeground(), null, null)}$text" } pane.border = null @@ -161,15 +163,15 @@ fun installFileCompletionAndBrowseDialog(project: Project?, @Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String, fileChooserDescriptor: FileChooserDescriptor, textComponentAccessor: TextComponentAccessor, - fileChoosen: ((chosenFile: VirtualFile) -> String)? = null) { + fileChosen: ((chosenFile: VirtualFile) -> String)? = null) { component.addActionListener( object : BrowseFolderActionListener(browseDialogTitle, null, component, project, fileChooserDescriptor, textComponentAccessor) { override fun onFileChosen(chosenFile: VirtualFile) { - if (fileChoosen == null) { + if (fileChosen == null) { super.onFileChosen(chosenFile) } else { - textComponentAccessor.setText(myTextComponent.childComponent, fileChoosen(chosenFile)) + textComponentAccessor.setText(myTextComponent.childComponent, fileChosen(chosenFile)) } } }) @@ -181,7 +183,7 @@ fun textFieldWithHistoryWithBrowseButton(project: Project?, browseDialogTitle: String, fileChooserDescriptor: FileChooserDescriptor, historyProvider: (() -> List)? = null, - fileChoosen: ((chosenFile: VirtualFile) -> String)? = null): TextFieldWithHistoryWithBrowseButton { + fileChosen: ((chosenFile: VirtualFile) -> String)? = null): TextFieldWithHistoryWithBrowseButton { val component = TextFieldWithHistoryWithBrowseButton() val textFieldWithHistory = component.childComponent textFieldWithHistory.setHistorySize(-1) @@ -196,7 +198,7 @@ fun textFieldWithHistoryWithBrowseButton(project: Project?, browseDialogTitle, fileChooserDescriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT, - fileChoosen = fileChoosen + fileChosen = fileChosen ) return component } diff --git a/platform/platform-impl/src/com/intellij/ui/layout/MigLayoutBuilder.kt b/platform/platform-impl/src/com/intellij/ui/layout/MigLayoutBuilder.kt index c0ab98a9adf3..11b244554cca 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/MigLayoutBuilder.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/MigLayoutBuilder.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.layout import com.intellij.codeInspection.SmartHashMap @@ -204,7 +190,6 @@ private class MigLayoutRow(private val componentConstraints: MutableMap List)? = null, - fileChoosen: ((chosenFile: VirtualFile) -> String)? = null): TextFieldWithHistoryWithBrowseButton { - val component = textFieldWithHistoryWithBrowseButton(project, browseDialogTitle, fileChooserDescriptor, historyProvider, fileChoosen) + fileChosen: ((chosenFile: VirtualFile) -> String)? = null): TextFieldWithHistoryWithBrowseButton { + val component = textFieldWithHistoryWithBrowseButton(project, browseDialogTitle, fileChooserDescriptor, historyProvider, fileChosen) value?.let { component.text = it } component() return component @@ -121,7 +107,8 @@ abstract class Row() { init() } - protected abstract fun alignRight() + @PublishedApi + internal abstract fun alignRight() inline fun row(label: String, init: Row.() -> Unit): Row { val row = createRow(label) @@ -136,7 +123,8 @@ abstract class Row() { return row } - protected abstract fun createRow(label: String?): Row + @PublishedApi + internal abstract fun createRow(label: String?): Row @Deprecated(message = "Nested row is prohibited", level = DeprecationLevel.ERROR) fun row(label: JLabel? = null, init: Row.() -> Unit) { diff --git a/platform/platform-impl/src/com/intellij/ui/layout/flags.kt b/platform/platform-impl/src/com/intellij/ui/layout/flags.kt index 53b016a82ba0..3ae82e85abb4 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/flags.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/flags.kt @@ -1,18 +1,6 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +@file:Suppress("EnumEntryName") + package com.intellij.ui.layout // http://www.migcalendar.com/miglayout/mavensite/docs/cheatsheet.pdf @@ -43,6 +31,9 @@ enum class LCFlags { debug } +/** + * See FAQ in the [docs](https://github.com/JetBrains/intellij-community/tree/master/platform/platform-impl/src/com/intellij/ui/layout). + */ enum class CCFlags { /** * Wrap to the next line/column **after** the component that this constraint belongs to. diff --git a/platform/platform-impl/src/com/intellij/ui/layout/layout.kt b/platform/platform-impl/src/com/intellij/ui/layout/layout.kt index c466ac3cd04f..18dc24c52b11 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/layout.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/layout.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.layout import com.intellij.ui.components.Panel @@ -20,7 +6,7 @@ import com.intellij.ui.layout.LCFlags.* import javax.swing.JPanel /** - * Claims all available space in the container for the columns ([LCFlags.fillX]). + * Claims all available space in the container for the columns ([LCFlags.fillX], if `constraints` is passed, `fillX` will be not applied - add it explicitly if need). * At least one component need to have a [CCFlags.grow] constraint for it to fill the container. * * See [docs](https://github.com/JetBrains/intellij-community/tree/master/platform/platform-impl/src/com/intellij/ui/layout) diff --git a/platform/platform-impl/src/com/intellij/ui/layout/readme.md b/platform/platform-impl/src/com/intellij/ui/layout/readme.md index 76ed4f462a80..a8e4b36ef2f4 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/readme.md +++ b/platform/platform-impl/src/com/intellij/ui/layout/readme.md @@ -44,4 +44,10 @@ val panel = panel { } noteRow("""Do not have an account? Sign Up""") } -``` \ No newline at end of file +``` + +## FAQ + +### One cell is minimum, second one is maximum + +Set `CCFlags.growX` and `CCFlags.pushX` for some component in the second cell. \ No newline at end of file diff --git a/plugins/settings-repository/src/authForm.kt b/plugins/settings-repository/src/authForm.kt index 2175e40f4a61..b0a6cfa503d8 100644 --- a/plugins/settings-repository/src/authForm.kt +++ b/plugins/settings-repository/src/authForm.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.settingsRepository import com.intellij.credentialStore.Credentials @@ -30,7 +16,7 @@ import javax.swing.JTextField import javax.swing.event.DocumentEvent fun showAuthenticationForm(credentials: Credentials?, uri: String, host: String?, path: String?, sshKeyFile: String?): Credentials? { - if (ApplicationManager.getApplication()?.isUnitTestMode === true) { + if (ApplicationManager.getApplication()?.isUnitTestMode == true) { throw AssertionError("showAuthenticationForm called from tests") }