diff --git a/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubAccountsPanel.kt b/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubAccountsPanel.kt index 42d61e35d639..7538063c00fd 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubAccountsPanel.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubAccountsPanel.kt @@ -15,34 +15,27 @@ import com.intellij.ui.* import com.intellij.ui.SimpleTextAttributes.STYLE_PLAIN import com.intellij.ui.SimpleTextAttributes.STYLE_UNDERLINE import com.intellij.ui.components.JBList -import com.intellij.util.IconUtil -import com.intellij.util.ImageLoader import com.intellij.util.progress.ProgressVisibilityManager -import com.intellij.util.ui.GridBag -import com.intellij.util.ui.JBUI -import com.intellij.util.ui.StatusText -import com.intellij.util.ui.UIUtil +import com.intellij.util.ui.* import com.intellij.util.ui.components.BorderLayoutPanel -import icons.GithubIcons import org.jetbrains.plugins.github.api.GithubApiRequestExecutor import org.jetbrains.plugins.github.api.GithubApiRequests import org.jetbrains.plugins.github.api.GithubServerPath -import org.jetbrains.plugins.github.api.data.GithubUserDetailed +import org.jetbrains.plugins.github.api.data.GithubAuthenticatedUser import org.jetbrains.plugins.github.authentication.accounts.GithubAccount import org.jetbrains.plugins.github.authentication.accounts.GithubAccountManager import org.jetbrains.plugins.github.exceptions.GithubAuthenticationException +import org.jetbrains.plugins.github.pullrequest.avatars.CachingGithubAvatarIconsProvider import org.jetbrains.plugins.github.util.CachingGithubUserAvatarLoader import org.jetbrains.plugins.github.util.GithubImageResizer import org.jetbrains.plugins.github.util.GithubUIUtil import java.awt.* import java.awt.event.MouseAdapter import java.awt.event.MouseEvent -import java.util.concurrent.CompletableFuture import javax.swing.* import javax.swing.event.ListDataEvent import javax.swing.event.ListDataListener -private const val ACCOUNT_PICTURE_SIZE: Int = 40 private const val LINK_TAG = "EDIT_LINK" internal class GithubAccountsPanel(private val project: Project, @@ -50,6 +43,8 @@ internal class GithubAccountsPanel(private val project: Project, private val avatarLoader: CachingGithubUserAvatarLoader, private val imageResizer: GithubImageResizer) : BorderLayoutPanel(), Disposable { + private val accountIconSize = JBValue.UIInteger("Github.Profile.Avatar.Size", 40) + private val accountListModel = CollectionListModel().apply { // disable link handler when there are no errors addListDataListener(object : ListDataListener { @@ -59,7 +54,10 @@ internal class GithubAccountsPanel(private val project: Project, }) } private val accountList = JBList(accountListModel).apply { - cellRenderer = GithubAccountDecoratorRenderer() + val decoratorRenderer = GithubAccountDecoratorRenderer() + cellRenderer = decoratorRenderer + UIUtil.putClientProperty(this, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, listOf(decoratorRenderer)) + selectionMode = ListSelectionModel.SINGLE_SELECTION emptyText.apply { appendText("No GitHub accounts added.") @@ -223,28 +221,20 @@ internal class GithubAccountsPanel(private val project: Project, }) return } - val pictureSize = JBUI.scale(ACCOUNT_PICTURE_SIZE) - // compute when parent frame is known, otherwise it will always be the default monitor scale - val scaleContext = JBUI.ScaleContext.create(accountList) + val executor = executorFactory.create(token) progressManager.run(object : Task.Backgroundable(project, "Not Visible") { - lateinit var data: Pair + lateinit var loadedDetails: GithubAuthenticatedUser override fun run(indicator: ProgressIndicator) { - val executor = executorFactory.create(token) - val details = executor.execute(indicator, GithubApiRequests.CurrentUser.get(account.server)) - val image = avatarLoader.requestAvatar(executor, details) - .thenCompose { - if (it != null) imageResizer.requestImageResize(it, pictureSize, scaleContext) - else CompletableFuture.completedFuture(null) - } - .join() - data = details to image + loadedDetails = executor.execute(indicator, GithubApiRequests.CurrentUser.get(account.server)) } override fun onSuccess() { accountListModel.contentsChanged(accountData.apply { - fullName = data.first.name - profilePicture = data.second + details = loadedDetails + iconProvider = CachingGithubAvatarIconsProvider(avatarLoader, imageResizer, executor, accountIconSize, accountList).apply { + Disposer.register(this@GithubAccountsPanel, this) + } loadingError = null showLoginLink = false }) @@ -335,22 +325,20 @@ private class GithubAccountDecoratorRenderer : ListCellRenderer