Skip to content

Commit

Permalink
Adding 'line comments at first column' option
Browse files Browse the repository at this point in the history
  • Loading branch information
LPTK committed Oct 22, 2015
1 parent ce4700b commit 7870080
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Expand Up @@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="d040d" binding="contentPanel" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="d040d" binding="contentPanel" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -26,7 +26,7 @@
</component>
<vspacer id="78b68">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c8e23" class="javax.swing.JCheckBox" binding="replaceWithUnicodeSymbolCheckBox" default-binding="true">
Expand Down Expand Up @@ -62,6 +62,15 @@
<text value="Kind Projector: Replace 'Lambda' with unicode symbol"/>
</properties>
</component>
<component id="c514a" class="javax.swing.JCheckBox" binding="lineCommentAtFirstColumnCheckBox">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="false"/>
<text value="Line comment on first column"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
Expand Up @@ -6,12 +6,14 @@
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.scala.ScalaFileType;
import org.jetbrains.plugins.scala.ScalaLanguage;
import org.jetbrains.plugins.scala.highlighter.ScalaEditorHighlighter;

import javax.swing.*;
Expand All @@ -28,6 +30,7 @@ public class OtherCodeStylePanel extends CodeStyleAbstractPanel {
private JCheckBox replaceWithUnicodeSymbolCheckBox1;
private JCheckBox replaceInForGeneratorCheckBox;
private JCheckBox replaceLambdaWithGreekLetter;
private JCheckBox lineCommentAtFirstColumnCheckBox;

protected OtherCodeStylePanel(@NotNull CodeStyleSettings settings) {
super(settings);
Expand Down Expand Up @@ -67,16 +70,19 @@ public void apply(CodeStyleSettings settings) throws ConfigurationException {
if (!isModified(settings)) return;

ScalaCodeStyleSettings scalaCodeStyleSettings = settings.getCustomSettings(ScalaCodeStyleSettings.class);
CommonCodeStyleSettings commonCodeStyleSettings = settings.getCommonSettings(ScalaLanguage.Instance);
scalaCodeStyleSettings.ENFORCE_FUNCTIONAL_SYNTAX_FOR_UNIT = enforceFunctionalSyntaxForCheckBox.isSelected();
scalaCodeStyleSettings.REPLACE_CASE_ARROW_WITH_UNICODE_CHAR = replaceWithUnicodeSymbolCheckBox.isSelected();
scalaCodeStyleSettings.REPLACE_MAP_ARROW_WITH_UNICODE_CHAR = replaceWithUnicodeSymbolCheckBox1.isSelected();
scalaCodeStyleSettings.REPLACE_FOR_GENERATOR_ARROW_WITH_UNICODE_CHAR = replaceInForGeneratorCheckBox.isSelected();
scalaCodeStyleSettings.REPLACE_LAMBDA_WITH_GREEK_LETTER = replaceLambdaWithGreekLetter.isSelected();
commonCodeStyleSettings.LINE_COMMENT_AT_FIRST_COLUMN = lineCommentAtFirstColumnCheckBox.isSelected();
}

@Override
public boolean isModified(CodeStyleSettings settings) {
ScalaCodeStyleSettings scalaCodeStyleSettings = settings.getCustomSettings(ScalaCodeStyleSettings.class);
CommonCodeStyleSettings commonCodeStyleSettings = settings.getCommonSettings(ScalaLanguage.Instance);

if (scalaCodeStyleSettings.ENFORCE_FUNCTIONAL_SYNTAX_FOR_UNIT != enforceFunctionalSyntaxForCheckBox.isSelected())
return true;
Expand All @@ -88,6 +94,8 @@ public boolean isModified(CodeStyleSettings settings) {
return true;
if (scalaCodeStyleSettings.REPLACE_LAMBDA_WITH_GREEK_LETTER != replaceLambdaWithGreekLetter.isSelected())
return true;
if (commonCodeStyleSettings.LINE_COMMENT_AT_FIRST_COLUMN != lineCommentAtFirstColumnCheckBox.isSelected())
return true;


return false;
Expand All @@ -102,11 +110,13 @@ public JComponent getPanel() {
@Override
protected void resetImpl(CodeStyleSettings settings) {
ScalaCodeStyleSettings scalaCodeStyleSettings = settings.getCustomSettings(ScalaCodeStyleSettings.class);
CommonCodeStyleSettings commonCodeStyleSettings = settings.getCommonSettings(ScalaLanguage.Instance);
enforceFunctionalSyntaxForCheckBox.setSelected(scalaCodeStyleSettings.ENFORCE_FUNCTIONAL_SYNTAX_FOR_UNIT);
replaceWithUnicodeSymbolCheckBox.setSelected(scalaCodeStyleSettings.REPLACE_CASE_ARROW_WITH_UNICODE_CHAR);
replaceWithUnicodeSymbolCheckBox1.setSelected(scalaCodeStyleSettings.REPLACE_MAP_ARROW_WITH_UNICODE_CHAR);
replaceInForGeneratorCheckBox.setSelected(scalaCodeStyleSettings.REPLACE_FOR_GENERATOR_ARROW_WITH_UNICODE_CHAR);
replaceLambdaWithGreekLetter.setSelected(scalaCodeStyleSettings.REPLACE_LAMBDA_WITH_GREEK_LETTER);
lineCommentAtFirstColumnCheckBox.setSelected(commonCodeStyleSettings.LINE_COMMENT_AT_FIRST_COLUMN);
}

{
Expand All @@ -127,13 +137,13 @@ protected void resetImpl(CodeStyleSettings settings) {
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
contentPanel = new JPanel();
contentPanel.setLayout(new GridLayoutManager(6, 1, new Insets(0, 0, 0, 0), -1, -1));
contentPanel.setLayout(new GridLayoutManager(7, 1, new Insets(0, 0, 0, 0), -1, -1));
panel1.add(contentPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
enforceFunctionalSyntaxForCheckBox = new JCheckBox();
enforceFunctionalSyntaxForCheckBox.setText("Enforce procedure syntax for methods with Unit return type");
contentPanel.add(enforceFunctionalSyntaxForCheckBox, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
contentPanel.add(spacer1, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
contentPanel.add(spacer1, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
replaceWithUnicodeSymbolCheckBox = new JCheckBox();
replaceWithUnicodeSymbolCheckBox.setText("Replace '=>' with unicode symbol");
contentPanel.add(replaceWithUnicodeSymbolCheckBox, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
Expand All @@ -147,5 +157,9 @@ protected void resetImpl(CodeStyleSettings settings) {
replaceLambdaWithGreekLetter.setSelected(false);
replaceLambdaWithGreekLetter.setText("Kind Projector: Replace 'Lambda' with unicode symbol");
contentPanel.add(replaceLambdaWithGreekLetter, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
lineCommentAtFirstColumnCheckBox = new JCheckBox();
lineCommentAtFirstColumnCheckBox.setSelected(false);
lineCommentAtFirstColumnCheckBox.setText("Line comment on first column");
contentPanel.add(lineCommentAtFirstColumnCheckBox, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
}
Expand Up @@ -182,6 +182,7 @@ class ScalaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsPr
indentOptions.INDENT_SIZE = 2
indentOptions.TAB_SIZE = 2
indentOptions.CONTINUATION_INDENT_SIZE = 2
commonCodeStyleSettings.LINE_COMMENT_AT_FIRST_COLUMN = true
commonCodeStyleSettings
}

Expand Down

0 comments on commit 7870080

Please sign in to comment.