mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
github: Allow OAuth in GH clone dialog login panel (IDEA-199502)
GitOrigin-RevId: 225bc778ed0ad78464508b4aaa9ad28c74fb7633
This commit is contained in:
committed by
intellij-monorepo-bot
parent
68162be2a3
commit
433dbb4c66
@@ -48,6 +48,7 @@ internal class GithubLoginPanel(
|
||||
set(value) {
|
||||
passwordUi.footer = value
|
||||
tokenUi.footer = value
|
||||
oauthUi.footer = value
|
||||
applyUi(currentUi)
|
||||
}
|
||||
|
||||
|
||||
+38
-6
@@ -14,10 +14,13 @@ import com.intellij.ui.SimpleColoredComponent
|
||||
import com.intellij.ui.SimpleTextAttributes.ERROR_ATTRIBUTES
|
||||
import com.intellij.ui.components.JBPanel
|
||||
import com.intellij.ui.components.labels.LinkLabel
|
||||
import com.intellij.ui.components.panels.HorizontalLayout
|
||||
import com.intellij.ui.components.panels.VerticalLayout
|
||||
import com.intellij.ui.layout.*
|
||||
import com.intellij.ui.scale.JBUIScale.scale
|
||||
import com.intellij.util.ui.JBEmptyBorder
|
||||
import com.intellij.util.ui.JBUI.Borders.empty
|
||||
import com.intellij.util.ui.JBUI.Panels.simplePanel
|
||||
import com.intellij.util.ui.JBUI.emptyInsets
|
||||
import com.intellij.util.ui.UIUtil.getRegularPanelInsets
|
||||
import org.jetbrains.plugins.github.api.GithubApiRequestExecutor
|
||||
@@ -33,6 +36,7 @@ import org.jetbrains.plugins.github.util.successOnEdt
|
||||
import javax.swing.JButton
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.SwingConstants.TOP
|
||||
|
||||
internal class CloneDialogLoginPanel(private val account: GithubAccount?) :
|
||||
JBPanel<CloneDialogLoginPanel>(VerticalLayout(0)) {
|
||||
@@ -43,8 +47,9 @@ internal class CloneDialogLoginPanel(private val account: GithubAccount?) :
|
||||
private val loginPanel = GithubLoginPanel(GithubApiRequestExecutor.Factory.getInstance()) { name, server ->
|
||||
if (account == null) authenticationManager.isAccountUnique(name, server) else true
|
||||
}
|
||||
private val inlineCancelPanel = simplePanel()
|
||||
private val loginButton = JButton(message("button.login.mnemonic"))
|
||||
private val backLink = LinkLabel<Any?>(IdeBundle.message("button.back"), null)
|
||||
private val backLink = LinkLabel<Any?>(IdeBundle.message("button.back"), null).apply { verticalAlignment = TOP }
|
||||
|
||||
private var loginIndicator: ProgressIndicator? = null
|
||||
|
||||
@@ -75,17 +80,44 @@ internal class CloneDialogLoginPanel(private val account: GithubAccount?) :
|
||||
null
|
||||
)
|
||||
|
||||
fun setTokenUi() = loginPanel.setTokenUi()
|
||||
fun setPasswordUi() = loginPanel.setPasswordUi()
|
||||
fun setTokenUi() {
|
||||
setupNewUi(false)
|
||||
loginPanel.setTokenUi()
|
||||
}
|
||||
|
||||
fun setPasswordUi() {
|
||||
setupNewUi(false)
|
||||
loginPanel.setPasswordUi()
|
||||
}
|
||||
|
||||
fun setOAuthUi() {
|
||||
setupNewUi(true)
|
||||
loginPanel.setOAuthUi()
|
||||
|
||||
login()
|
||||
}
|
||||
|
||||
fun setServer(path: String, editable: Boolean) = loginPanel.setServer(path, editable)
|
||||
|
||||
private fun buildLayout() {
|
||||
loginPanel.footer = { buttonPanel() } // footer is used to put buttons in 2-nd column - align under text boxes
|
||||
|
||||
add(loginPanel)
|
||||
add(JPanel(HorizontalLayout(0)).apply {
|
||||
add(loginPanel)
|
||||
add(inlineCancelPanel.apply { border = JBEmptyBorder(getRegularPanelInsets().apply { left = scale(6) }) })
|
||||
})
|
||||
add(errorPanel.apply { border = JBEmptyBorder(getRegularPanelInsets().apply { top = 0 }) })
|
||||
}
|
||||
|
||||
private fun setupNewUi(isOAuth: Boolean) {
|
||||
loginButton.isVisible = !isOAuth
|
||||
backLink.text = if (isOAuth) IdeBundle.message("link.cancel") else IdeBundle.message("button.back")
|
||||
|
||||
loginPanel.footer = { if (!isOAuth) buttonPanel() } // footer is used to put buttons in 2-nd column - align under text boxes
|
||||
if (isOAuth) inlineCancelPanel.addToCenter(backLink)
|
||||
inlineCancelPanel.isVisible = isOAuth
|
||||
|
||||
errorPanel.removeAll()
|
||||
}
|
||||
|
||||
private fun LayoutBuilder.buttonPanel() =
|
||||
row("") {
|
||||
cell {
|
||||
|
||||
+10
-2
@@ -28,6 +28,7 @@ import org.jetbrains.plugins.github.authentication.accounts.GithubAccountInforma
|
||||
import org.jetbrains.plugins.github.authentication.accounts.GithubAccountManager.Companion.ACCOUNT_REMOVED_TOPIC
|
||||
import org.jetbrains.plugins.github.authentication.accounts.GithubAccountManager.Companion.ACCOUNT_TOKEN_CHANGED_TOPIC
|
||||
import org.jetbrains.plugins.github.authentication.accounts.isGHAccount
|
||||
import org.jetbrains.plugins.github.authentication.isOAuthEnabled
|
||||
import org.jetbrains.plugins.github.i18n.GithubBundle.message
|
||||
import org.jetbrains.plugins.github.util.CachingGithubUserAvatarLoader
|
||||
import org.jetbrains.plugins.github.util.GithubImageResizer
|
||||
@@ -91,7 +92,7 @@ private class GHCloneDialogExtensionComponent(project: Project) : BaseCloneDialo
|
||||
if (isExistingAccount) message("login.action") else message("login.via.github.action"),
|
||||
{
|
||||
switchToLogin(account)
|
||||
getLoginPanel()?.setPasswordUi()
|
||||
getLoginPanel()?.setPrimaryLoginUi()
|
||||
},
|
||||
showSeparatorAbove = !isExistingAccount
|
||||
)
|
||||
@@ -126,7 +127,7 @@ private class GHCloneDialogLoginPanel(account: GithubAccount?) :
|
||||
JPanel(HorizontalLayout(0)).apply {
|
||||
border = JBEmptyBorder(getRegularPanelInsets())
|
||||
|
||||
val loginViaGHButton = JButton(message("login.via.github.action")).apply { addActionListener { setPasswordUi() } }
|
||||
val loginViaGHButton = JButton(message("login.via.github.action")).apply { addActionListener { setPrimaryLoginUi() } }
|
||||
val useTokenLink = LinkLabel.create(message("link.label.use.token")) { setTokenUi() }
|
||||
|
||||
add(loginViaGHButton)
|
||||
@@ -144,6 +145,8 @@ private class GHCloneDialogLoginPanel(account: GithubAccount?) :
|
||||
|
||||
fun setChooseLoginUi() = setContent(chooseLoginUiPanel)
|
||||
|
||||
fun setPrimaryLoginUi() = if (isOAuthEnabled()) setOAuthUi() else setPasswordUi()
|
||||
|
||||
fun setTokenUi() {
|
||||
setContent(loginPanel)
|
||||
loginPanel.setTokenUi() // after `loginPanel` is set as content to ensure correct focus behavior
|
||||
@@ -154,6 +157,11 @@ private class GHCloneDialogLoginPanel(account: GithubAccount?) :
|
||||
loginPanel.setPasswordUi() // after `loginPanel` is set as content to ensure correct focus behavior
|
||||
}
|
||||
|
||||
fun setOAuthUi() {
|
||||
setContent(loginPanel)
|
||||
loginPanel.setOAuthUi()
|
||||
}
|
||||
|
||||
private fun setContent(content: JComponent) {
|
||||
contentPanel.setContent(content)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user