Skip to content

Commit 24f635e

Browse files
committed
add indent options tab
1 parent 98b295f commit 24f635e

File tree

4 files changed

+113
-128
lines changed

4 files changed

+113
-128
lines changed

src/main/java/com/tang/intellij/lua/editor/formatter/LuaCodeStyleSettingsProvider.java

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2017. tangzx([email protected])
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.tang.intellij.lua.editor.formatter
18+
19+
import com.intellij.application.options.CodeStyleAbstractConfigurable
20+
import com.intellij.application.options.CodeStyleAbstractPanel
21+
import com.intellij.application.options.TabbedLanguageCodeStylePanel
22+
import com.intellij.openapi.options.Configurable
23+
import com.intellij.psi.codeStyle.CodeStyleSettings
24+
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider
25+
import com.intellij.psi.codeStyle.CustomCodeStyleSettings
26+
import com.tang.intellij.lua.lang.LuaLanguage
27+
28+
/**
29+
30+
* Created by tangzx on 2017/2/22.
31+
*/
32+
class LuaCodeStyleSettingsProvider : CodeStyleSettingsProvider() {
33+
override fun createSettingsPage(settings: CodeStyleSettings, originalSettings: CodeStyleSettings): Configurable {
34+
return object : CodeStyleAbstractConfigurable(settings, originalSettings, "Lua") {
35+
36+
override fun getHelpTopic() = "reference.settingsdialog.codestyle.lua"
37+
38+
override fun createPanel(codeStyleSettings: CodeStyleSettings): CodeStyleAbstractPanel {
39+
val language = LuaLanguage.INSTANCE
40+
val currentSettings = currentSettings
41+
return object : TabbedLanguageCodeStylePanel(language, currentSettings, settings) {
42+
override fun initTabs(styleSettings: CodeStyleSettings) {
43+
//super.initTabs(styleSettings);
44+
addIndentOptionsTab(styleSettings)
45+
addSpacesTab(styleSettings)
46+
//addBlankLinesTab(styleSettings)
47+
//addWrappingAndBracesTab(styleSettings);
48+
}
49+
}
50+
}
51+
}
52+
}
53+
54+
override fun getConfigurableDisplayName() = LuaLanguage.INSTANCE.id
55+
56+
override fun createCustomSettings(settings: CodeStyleSettings?): CustomCodeStyleSettings? {
57+
return LuaCodeStyleSettings(settings)
58+
}
59+
}

src/main/java/com/tang/intellij/lua/editor/formatter/LuaLanguageCodeStyleSettingsProvider.java

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2017. tangzx([email protected])
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.tang.intellij.lua.editor.formatter
18+
19+
import com.intellij.application.options.CodeStyleAbstractPanel
20+
import com.intellij.application.options.IndentOptionsEditor
21+
import com.intellij.application.options.SmartIndentOptionsEditor
22+
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable
23+
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable.SPACES_OTHER
24+
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider
25+
import com.tang.intellij.lua.lang.LuaLanguage
26+
27+
/**
28+
29+
* Created by tangzx on 2017/2/22.
30+
*/
31+
class LuaLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvider() {
32+
override fun getLanguage() = LuaLanguage.INSTANCE
33+
34+
override fun getCodeSample(settingsType: LanguageCodeStyleSettingsProvider.SettingsType): String {
35+
return CodeStyleAbstractPanel.readFromFile(this.javaClass, "preview.lua.template")
36+
}
37+
38+
override fun getIndentOptionsEditor(): IndentOptionsEditor {
39+
return SmartIndentOptionsEditor()
40+
}
41+
42+
override fun customizeSettings(consumer: CodeStyleSettingsCustomizable, settingsType: LanguageCodeStyleSettingsProvider.SettingsType) {
43+
when (settingsType) {
44+
LanguageCodeStyleSettingsProvider.SettingsType.SPACING_SETTINGS -> {
45+
consumer.showCustomOption(LuaCodeStyleSettings::class.java, "SPACE_AFTER_TABLE_FIELD_SEP", "After field sep", SPACES_OTHER)
46+
consumer.showStandardOptions("SPACE_AROUND_ASSIGNMENT_OPERATORS",
47+
"SPACE_BEFORE_COMMA",
48+
"SPACE_AFTER_COMMA")
49+
}
50+
else -> {
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)