diff --git a/platform/platform-impl/src/com/intellij/openapi/application/actions.kt b/platform/platform-impl/src/com/intellij/openapi/application/actions.kt index 820f04dee7da..2188fe08777f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/actions.kt +++ b/platform/platform-impl/src/com/intellij/openapi/application/actions.kt @@ -38,12 +38,21 @@ inline fun runBatchUpdate(messageBus: MessageBus, runnable: () -> T): T { /** * @exclude Internal use only */ -fun invokeAndWaitIfNeed(runnable: () -> Unit) { +fun invokeAndWaitIfNeed(runnable: () -> T): T { val app = ApplicationManager.getApplication() if (app == null) { - if (SwingUtilities.isEventDispatchThread()) runnable() else SwingUtilities.invokeAndWait(runnable) + if (SwingUtilities.isEventDispatchThread()) { + return runnable() + } + else { + var result: T? = null + SwingUtilities.invokeAndWait { result = runnable() } + return result as T + } } else { - app.invokeAndWait(runnable, ModalityState.defaultModalityState()) + var result: T? = null + app.invokeAndWait({ result = runnable() }, ModalityState.defaultModalityState()) + return result as T } } \ No newline at end of file diff --git a/plugins/settings-repository/src/authForm.kt b/plugins/settings-repository/src/authForm.kt index 1e63bc57179a..5f9e85368785 100644 --- a/plugins/settings-repository/src/authForm.kt +++ b/plugins/settings-repository/src/authForm.kt @@ -21,13 +21,12 @@ import com.intellij.layout.* import com.intellij.layout.CCFlags.* import com.intellij.layout.LCFlags.* import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.invokeAndWaitIfNeed import com.intellij.openapi.ui.dialog -import com.intellij.openapi.util.Computable import com.intellij.ui.DocumentAdapter import com.intellij.util.PathUtilRt import com.intellij.util.nullize import com.intellij.util.trimMiddle -import com.intellij.util.ui.UIUtil import javax.swing.JPasswordField import javax.swing.JTextField import javax.swing.event.DocumentEvent @@ -38,16 +37,16 @@ fun showAuthenticationForm(credentials: Credentials?, uri: String, host: String? } val isGitHub = host == "github.com" - val note = if (sshKeyFile == null) icsMessage(if (isGitHub) "login.github.note" else "login.other.git.provider.note") else null - var username = credentials?.userName - if (username == null && isGitHub && path != null && sshKeyFile == null) { - val firstSlashIndex = path.indexOf('/', 1) - username = path.substring(1, if (firstSlashIndex == -1) path.length else firstSlashIndex) - } + val note = if (sshKeyFile == null) icsMessage(if (isGitHub) "login.github.note" else "login.other.git.provider.note") else null + var username = credentials?.userName + if (username == null && isGitHub && path != null && sshKeyFile == null) { + val firstSlashIndex = path.indexOf('/', 1) + username = path.substring(1, if (firstSlashIndex == -1) path.length else firstSlashIndex) + } - val message = if (sshKeyFile == null) icsMessage("log.in.to", uri.trimMiddle(50)) else icsMessage("enter.your.password.for.ssh.key", PathUtilRt.getFileName(sshKeyFile)) + val message = if (sshKeyFile == null) icsMessage("log.in.to", uri.trimMiddle(50)) else icsMessage("enter.your.password.for.ssh.key", PathUtilRt.getFileName(sshKeyFile)) - return UIUtil.invokeAndWaitIfNeeded(Computable { + return invokeAndWaitIfNeed { val userField = JTextField(username) val passwordField = JPasswordField(credentials?.password.toString()) @@ -69,7 +68,7 @@ fun showAuthenticationForm(credentials: Credentials?, uri: String, host: String? title = "Settings Repository", resizable = false, centerPanel = centerPanel, - preferedFocusComponent = userField, + preferedFocusComponent = if (userField.parent == null) passwordField else userField, okActionEnabled = false) passwordField.document.addDocumentListener(object : DocumentAdapter() { @@ -87,5 +86,5 @@ fun showAuthenticationForm(credentials: Credentials?, uri: String, host: String? else { null } - }) + } } \ No newline at end of file