mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-160367 Settings Repository: login dialog should get focus when appears
This commit is contained in:
@@ -38,12 +38,21 @@ inline fun <T> runBatchUpdate(messageBus: MessageBus, runnable: () -> T): T {
|
||||
/**
|
||||
* @exclude Internal use only
|
||||
*/
|
||||
fun invokeAndWaitIfNeed(runnable: () -> Unit) {
|
||||
fun <T> 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user