-
Notifications
You must be signed in to change notification settings - Fork 21
✨ Add a preview commit text in config #35
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,15 @@ | |
| import javax.swing.JComponent | ||
| import javax.swing.JLabel | ||
| import javax.swing.JPanel | ||
| import javax.swing.JTextArea | ||
|
|
||
| class GitMojiConfig(private val project: Project) : SearchableConfigurable { | ||
| private val mainPanel: JPanel | ||
| private val useUnicode = JCheckBox(GitmojiBundle.message("config.useUnicode")) | ||
| private val displayEmoji = | ||
| JCheckBox(GitmojiBundle.message("config.displayEmoji")) | ||
| private val displayEmoji = JCheckBox(GitmojiBundle.message("config.displayEmoji")) | ||
| private val insertInCursorPosition = JCheckBox(GitmojiBundle.message("config.insertInCursorPosition")) | ||
| private val includeGitMojiDescription = JCheckBox(GitmojiBundle.message("config.includeGitMojiDescription")) | ||
| private val previewGitCommitMessage = JTextArea(2, 80) | ||
| private var useUnicodeConfig: Boolean = false | ||
| private var displayEmojiConfig: String = "emoji" | ||
| private var insertInCursorPositionConfig: Boolean = false | ||
|
|
@@ -49,6 +50,9 @@ | |
|
|
||
| init { | ||
| val flow = GridLayout(20, 2) | ||
| useUnicode.addChangeListener { previewCommit() } | ||
| insertInCursorPosition.addChangeListener { previewCommit() } | ||
| includeGitMojiDescription.addChangeListener { previewCommit() } | ||
| mainPanel = JPanel(flow) | ||
| mainPanel.add(displayEmoji, null) | ||
| mainPanel.add(useUnicode, null) | ||
|
|
@@ -62,6 +66,9 @@ | |
| languageJPanel.add(JLabel(GitmojiBundle.message("config.language"))) | ||
| languageJPanel.add(languages, null) | ||
| mainPanel.add(languageJPanel) | ||
| previewGitCommitMessage.isEditable = false | ||
| mainPanel.add(JLabel("Preview")) | ||
| mainPanel.add(previewGitCommitMessage) | ||
| } | ||
|
|
||
| override fun apply() { | ||
|
|
@@ -85,8 +92,8 @@ | |
| projectInstance.setValue(CONFIG_AFTER_UNICODE, textAfterUnicodeConfig) | ||
| instance.setValue(CONFIG_LANGUAGE, languagesConfig) | ||
| GitmojiLocale.loadTranslations() | ||
| previewCommit() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| override fun reset() { | ||
| val propertiesComponent = PropertiesComponent.getInstance(project) | ||
| val instance = PropertiesComponent.getInstance() | ||
|
|
@@ -107,6 +114,31 @@ | |
| else -> textAfterUnicodeOptions.indexOf(textAfterUnicodeConfig) | ||
| } | ||
| languages.selectedIndex = languageOptions.indexOf(languagesConfig) | ||
| previewCommit() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| private fun previewCommit():Boolean { | ||
| var message = "" | ||
| if (insertInCursorPositionConfig) { | ||
| message += "Commit message|" | ||
| } | ||
| if (useUnicodeConfig) { | ||
| message += "✨" | ||
| } | ||
| else { | ||
| message += ":sparkles:" | ||
| } | ||
| message += textAfterUnicodeConfig | ||
| val selectionStart = message.length | ||
| if (includeGitMojiDescriptionConfig) { | ||
| message += "Introduce new features." | ||
| } | ||
| else if (!insertInCursorPositionConfig) { | ||
| message += "Commit message" | ||
| } | ||
| previewGitCommitMessage.text = message | ||
| previewGitCommitMessage.select(selectionStart, message.length) | ||
| return true | ||
| } | ||
|
Comment on lines
+120
to
142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is used to construct the preview commit message. Consider using a private fun updatePreviewCommitText(): Boolean {
val messageBuilder = StringBuilder()
if (insertInCursorPosition.isSelected) {
messageBuilder.append("Commit message|")
}
if (useUnicode.isSelected) {
messageBuilder.append("✨")
} else {
messageBuilder.append(":sparkles:")
}
messageBuilder.append(textAfterUnicode.selectedItem ?: "")
val selectionStart = messageBuilder.length
if (includeGitMojiDescription.isSelected) {
messageBuilder.append("Introduce new features.")
} else if (!insertInCursorPosition.isSelected) {
messageBuilder.append("Commit message")
}
val message = messageBuilder.toString()
previewGitCommitMessage.text = message
previewGitCommitMessage.select(selectionStart, message.length)
return true
} |
||
|
|
||
| override fun createComponent(): JComponent = mainPanel | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting this to a separate function to avoid duplication with the
applyandresetmethods. This will improve maintainability and readability.