Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/show hide token in settings #89

Merged
merged 3 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,66 @@
import com.intellij.ui.components.JBPasswordField
import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.FormBuilder
import java.awt.GridBagConstraints

Check warning on line 7 in src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/SettingComponent.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import java.awt.GridBagLayout

Check warning on line 8 in src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/SettingComponent.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JTextField
import javax.swing.JToggleButton


class SettingComponent {
private var myMainPanel: JPanel? = null
private val ghTokenText = JBPasswordField()
private var ghTokenTextField: JTextField =JBTextField()
private var ghTokenPasswordField: JTextField = JBPasswordField()
private val ghesHostnameText = JBTextField()
private val ghesTokenText = JBPasswordField()
private var ghesTokenTextField: JTextField = JBTextField()
private var ghesTokenPasswordField: JTextField = JBPasswordField()
private val toggleButton = JToggleButton("Show/Hide PAT")

private var isGhTokenVisible: Boolean = false

init {

ghTokenTextField.isVisible = isGhTokenVisible
ghesTokenTextField.isVisible = isGhTokenVisible
myMainPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel("GitHub.com PAT "), ghTokenText, 1, false)
.addSeparator()
.addLabeledComponent(JBLabel("GHES Hostname"), ghesHostnameText, 2, false)
.addLabeledComponent(JBLabel("GHES PAT"), ghesTokenText, 3, false)
.addComponentFillVertically(JPanel(), 0)
.getPanel()
.addComponent(JBLabel("GitHub.com PAT "))
.addComponent(ghTokenTextField)
.addComponent(ghTokenPasswordField)
.addSeparator(48)
.addComponent(JBLabel("GHES Hostname "))

Check warning on line 35 in src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/SettingComponent.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Incorrect string capitalization

String 'GHES Hostname ' is not properly capitalized. It should have sentence capitalization
.addComponent(ghesHostnameText)
.addComponent(JBLabel("GHES PAT "))
.addComponent(ghesTokenTextField)
.addComponent(ghesTokenPasswordField)
.addComponentFillVertically(JPanel(), 0)
.addSeparator()
.addLabeledComponent("", toggleButton, 1, false)
.panel

toggleButton.addActionListener {
isGhTokenVisible = !isGhTokenVisible
if (isGhTokenVisible) {
ghTokenTextField.text = ghTokenPasswordField.text
ghTokenTextField.isVisible = true
ghTokenPasswordField.isVisible = false

ghesTokenTextField.text = ghesTokenPasswordField.text
ghesTokenTextField.isVisible = true
ghesTokenPasswordField.isVisible = false
} else {
ghTokenPasswordField.text = ghTokenTextField.text
ghTokenTextField.isVisible = false
ghTokenPasswordField.isVisible = true

ghesTokenPasswordField.text = ghesTokenTextField.text
ghesTokenTextField.isVisible = false
ghesTokenPasswordField.isVisible = true
}
myMainPanel!!.revalidate() // Notify the layout manager
myMainPanel!!.repaint() // Redraw the components
}
}


Expand All @@ -30,30 +72,47 @@
}

fun getPreferredFocusedComponent(): JComponent {
return ghTokenText
return if (toggleButton.isSelected) {
ghTokenTextField
} else {
ghTokenPasswordField
}
}

fun getGhTokenText(): String {
return ghTokenText.text
return if (isGhTokenVisible) {
ghTokenTextField.text
} else {
ghTokenPasswordField.text
}
}

fun setGhTokenText(newText: String) {
ghTokenText.text = newText
ghTokenTextField.text = newText
ghTokenPasswordField.text = newText
}

fun getGhesHostnameText(): String {
return ghesHostnameText.text
}

fun getGhesTokenText(): String {
return ghesTokenText.text
return if (isGhTokenVisible) {
ghesTokenTextField.text
} else {
ghesTokenPasswordField.text
}
}

fun setGhesHostnameText(newText: String) {
ghesHostnameText.text = newText
}

fun setGhesTokenText(newText: String) {
ghesTokenText.text = newText
ghesTokenTextField.text = newText
ghesTokenPasswordField.text = newText
}
}
}



Loading