@@ -15,11 +15,13 @@ import javax.swing.JPanel
1515
1616class GitMojiConfig (private val project : Project ) : SearchableConfigurable {
1717 private val mainPanel: JPanel
18+ private val useProjectSettings = JCheckBox (" Use project-specific settings (instead of global)" )
1819 private val useUnicode = JCheckBox (GitmojiBundle .message(" config.useUnicode" ))
1920 private val displayEmoji =
2021 JCheckBox (GitmojiBundle .message(" config.displayEmoji" ))
2122 private val insertInCursorPosition = JCheckBox (GitmojiBundle .message(" config.insertInCursorPosition" ))
2223 private val includeGitMojiDescription = JCheckBox (GitmojiBundle .message(" config.includeGitMojiDescription" ))
24+ private var useProjectSettingsConfig: Boolean = false
2325 private var useUnicodeConfig: Boolean = false
2426 private var displayEmojiConfig: String = " emoji"
2527 private var insertInCursorPositionConfig: Boolean = false
@@ -32,13 +34,12 @@ class GitMojiConfig(private val project: Project) : SearchableConfigurable {
3234 private var languagesConfig: String = " auto"
3335
3436 override fun isModified (): Boolean =
35- Configurable .isCheckboxModified(displayEmoji, displayEmojiConfig == " emoji" ) || Configurable .isCheckboxModified(
36- useUnicode,
37- useUnicodeConfig
38- ) || isModified(textAfterUnicode, textAfterUnicodeConfig) || Configurable .isCheckboxModified(
39- insertInCursorPosition,
40- insertInCursorPositionConfig
41- ) || Configurable .isCheckboxModified(includeGitMojiDescription, includeGitMojiDescriptionConfig)
37+ Configurable .isCheckboxModified(useProjectSettings, useProjectSettingsConfig) ||
38+ Configurable .isCheckboxModified(displayEmoji, displayEmojiConfig == " emoji" ) ||
39+ Configurable .isCheckboxModified(useUnicode, useUnicodeConfig) ||
40+ isModified(textAfterUnicode, textAfterUnicodeConfig) ||
41+ Configurable .isCheckboxModified(insertInCursorPosition, insertInCursorPositionConfig) ||
42+ Configurable .isCheckboxModified(includeGitMojiDescription, includeGitMojiDescriptionConfig)
4243
4344 private fun isModified (comboBox : ComboBox <String >, value : String ): Boolean {
4445 return ! Comparing .equal(comboBox.selectedItem, value)
@@ -50,6 +51,8 @@ class GitMojiConfig(private val project: Project) : SearchableConfigurable {
5051 init {
5152 val flow = GridLayout (20 , 2 )
5253 mainPanel = JPanel (flow)
54+ mainPanel.add(useProjectSettings, null )
55+ mainPanel.add(JPanel (), null ) // empty cell
5356 mainPanel.add(displayEmoji, null )
5457 mainPanel.add(useUnicode, null )
5558 mainPanel.add(insertInCursorPosition, null )
@@ -65,6 +68,9 @@ class GitMojiConfig(private val project: Project) : SearchableConfigurable {
6568 }
6669
6770 override fun apply () {
71+ val wasProjectSettings = useProjectSettingsConfig
72+ useProjectSettingsConfig = useProjectSettings.isSelected
73+
6874 displayEmojiConfig = if (displayEmoji.isSelected) " emoji" else " icon"
6975 useUnicodeConfig = useUnicode.isSelected
7076 insertInCursorPositionConfig = insertInCursorPosition.isSelected
@@ -76,27 +82,68 @@ class GitMojiConfig(private val project: Project) : SearchableConfigurable {
7682 }
7783 languagesConfig = languageOptions[languages.selectedIndex]
7884
79- val projectInstance = PropertiesComponent .getInstance(project)
80- val instance = PropertiesComponent .getInstance()
81- projectInstance.setValue(CONFIG_DISPLAY_ICON , displayEmojiConfig)
82- projectInstance.setValue(CONFIG_INSERT_IN_CURSOR_POSITION , insertInCursorPositionConfig)
83- projectInstance.setValue(CONFIG_USE_UNICODE , useUnicodeConfig)
84- projectInstance.setValue(CONFIG_INCLUDE_GITMOJI_DESCRIPTION , includeGitMojiDescriptionConfig)
85- projectInstance.setValue(CONFIG_AFTER_UNICODE , textAfterUnicodeConfig)
86- instance.setValue(CONFIG_LANGUAGE , languagesConfig)
85+ val projectProps = PropertiesComponent .getInstance(project)
86+ val appProps = PropertiesComponent .getInstance()
87+
88+ // Save the toggle itself in project
89+ projectProps.setValue(CONFIG_USE_PROJECT_SETTINGS , useProjectSettingsConfig)
90+
91+ if (useProjectSettingsConfig) {
92+ // Save in project
93+ projectProps.setValue(CONFIG_DISPLAY_ICON , displayEmojiConfig)
94+ projectProps.setValue(CONFIG_INSERT_IN_CURSOR_POSITION , insertInCursorPositionConfig)
95+ projectProps.setValue(CONFIG_USE_UNICODE , useUnicodeConfig)
96+ projectProps.setValue(CONFIG_INCLUDE_GITMOJI_DESCRIPTION , includeGitMojiDescriptionConfig)
97+ projectProps.setValue(CONFIG_AFTER_UNICODE , textAfterUnicodeConfig)
98+ projectProps.setValue(CONFIG_LANGUAGE , languagesConfig)
99+ } else {
100+ // Save in global
101+ appProps.setValue(CONFIG_DISPLAY_ICON , displayEmojiConfig)
102+ appProps.setValue(CONFIG_INSERT_IN_CURSOR_POSITION , insertInCursorPositionConfig)
103+ appProps.setValue(CONFIG_USE_UNICODE , useUnicodeConfig)
104+ appProps.setValue(CONFIG_INCLUDE_GITMOJI_DESCRIPTION , includeGitMojiDescriptionConfig)
105+ appProps.setValue(CONFIG_AFTER_UNICODE , textAfterUnicodeConfig)
106+ appProps.setValue(CONFIG_LANGUAGE , languagesConfig)
107+
108+ // If we just unchecked, remove project settings
109+ if (wasProjectSettings && ! useProjectSettingsConfig) {
110+ clearProjectSettings(projectProps)
111+ }
112+ }
113+
87114 GitmojiLocale .loadTranslations()
88115 }
89116
117+ private fun clearProjectSettings (props : PropertiesComponent ) {
118+ try {
119+ props.unsetValue(CONFIG_DISPLAY_ICON )
120+ props.unsetValue(CONFIG_INSERT_IN_CURSOR_POSITION )
121+ props.unsetValue(CONFIG_USE_UNICODE )
122+ props.unsetValue(CONFIG_INCLUDE_GITMOJI_DESCRIPTION )
123+ props.unsetValue(CONFIG_AFTER_UNICODE )
124+ props.unsetValue(CONFIG_LANGUAGE )
125+ } catch (_: Exception ) {
126+ // Ignore errors during cleanup
127+ }
128+ }
129+
90130 override fun reset () {
91- val propertiesComponent = PropertiesComponent .getInstance(project)
92- val instance = PropertiesComponent .getInstance()
93-
94- displayEmojiConfig = propertiesComponent.getValue(CONFIG_DISPLAY_ICON , defaultDisplayType())
95- useUnicodeConfig = propertiesComponent.getBoolean(CONFIG_USE_UNICODE , false )
96- insertInCursorPositionConfig = propertiesComponent.getBoolean(CONFIG_INSERT_IN_CURSOR_POSITION , false )
97- includeGitMojiDescriptionConfig = propertiesComponent.getBoolean(CONFIG_INCLUDE_GITMOJI_DESCRIPTION , false )
98- textAfterUnicodeConfig = propertiesComponent.getValue(CONFIG_AFTER_UNICODE , " " )
99- languagesConfig = instance.getValue(CONFIG_LANGUAGE , " auto" )
131+ val projectProps = PropertiesComponent .getInstance(project)
132+ val appProps = PropertiesComponent .getInstance()
133+
134+ // Check if using project settings
135+ useProjectSettingsConfig = projectProps.getBoolean(CONFIG_USE_PROJECT_SETTINGS , false )
136+ useProjectSettings.isSelected = useProjectSettingsConfig
137+
138+ // Load from appropriate source
139+ val props = if (useProjectSettingsConfig) projectProps else appProps
140+
141+ displayEmojiConfig = props.getValue(CONFIG_DISPLAY_ICON , defaultDisplayType())
142+ useUnicodeConfig = props.getBoolean(CONFIG_USE_UNICODE , false )
143+ insertInCursorPositionConfig = props.getBoolean(CONFIG_INSERT_IN_CURSOR_POSITION , false )
144+ includeGitMojiDescriptionConfig = props.getBoolean(CONFIG_INCLUDE_GITMOJI_DESCRIPTION , false )
145+ textAfterUnicodeConfig = props.getValue(CONFIG_AFTER_UNICODE , " " )
146+ languagesConfig = props.getValue(CONFIG_LANGUAGE , " auto" )
100147
101148 displayEmoji.isSelected = displayEmojiConfig == " emoji"
102149 useUnicode.isSelected = useUnicodeConfig
0 commit comments