Skip to content

Commit

Permalink
Merge pull request #111 from gyorokpeter/nounindent
Browse files Browse the repository at this point in the history
disable auto-unidenting of closing curly braces
  • Loading branch information
gyorokpeter authored Jun 27, 2022
2 parents 28935cb + a60c5b6 commit 0035fb3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/studio/core/Studio.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import studio.kdb.Lm;
import studio.kdb.Server;
import studio.kdb.Workspace;
import studio.qeditor.RSTokenMaker;
import studio.ui.StudioPanel;
import studio.ui.Util;
import studio.ui.action.WorkspaceSaver;
Expand Down Expand Up @@ -39,6 +40,7 @@ private static void initLogger() {
public static void init0() {
//called from main and integration tests
studio.ui.I18n.setLocale(Locale.getDefault());
RSTokenMaker.setUnindentCurlyBraces(Config.getInstance().getBoolean(Config.RSTA_UNINDENT_CURLY_BRACES));
}

public static StudioPanel createPanel(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions src/main/studio/kdb/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum ThemeEntry { CHARVECTOR, EOLCOMMENT, IDENTIFIER, OPERATOR, BOOLEAN,
public static final String RSTA_WORD_WRAP = configDefault("rstaWordWrap", ConfigType.BOOLEAN, false);
public static final String RSTA_INDENT_SIZE = configDefault("rstaIndentSize", ConfigType.INT, 4);
public static final String RSTA_INDENT_USE_TAB = configDefault("rstaIndentUseTab", ConfigType.BOOLEAN, false);
public static final String RSTA_UNINDENT_CURLY_BRACES = configDefault("rstaUnindentCurlyBraces", ConfigType.BOOLEAN, false);

public static final String DEFAULT_LINE_ENDING = configDefault("defaultLineEnding", ConfigType.ENUM, LineEnding.Unix);

Expand Down
7 changes: 6 additions & 1 deletion src/main/studio/qeditor/RSTokenMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class RSTokenMaker extends TokenMakerBase {
public static final String CONTENT_TYPE = "text/q";

private QSyntaxParser parser = new QSyntaxParser();
private static boolean unindentCurlyBraces = false;

// Make sure the same list and ordering in QToken, RSToken, RSTokenMaker.tokens
private static final RSToken[] tokens = Stream.of(RSToken.values()).skip(1).toArray(RSToken[]::new);
Expand Down Expand Up @@ -61,9 +62,13 @@ public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
return firstToken;
}

public static void setUnindentCurlyBraces(boolean value) {
unindentCurlyBraces = value;
}

@Override
public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex) {
return true;
return unindentCurlyBraces; //if set to true, the closing brace of functions will jump to the beginning of the line, which results in a syntax error
}

@Override
Expand Down
10 changes: 9 additions & 1 deletion src/main/studio/ui/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SettingsDialog extends EscapeDialog {
private JCheckBox chBoxRTSAHighlightCurrentLine;
private JCheckBox chBoxRTSAWordWrap;
private JCheckBox chBoxRTSAIndentUseTab;
private JCheckBox chBoxRTSAUnindentCurlyBraces;
private JComboBox<CustomiszedLookAndFeelInfo> comboBoxLookAndFeel;
private JFormattedTextField txtTabsCount;
private JFormattedTextField txtRTSAIndentSize;
Expand Down Expand Up @@ -124,6 +125,10 @@ public boolean isRTSAIndentUseTab() {
return chBoxRTSAIndentUseTab.isSelected();
}

public boolean isRTSAUnindentCurlyBraces() {
return chBoxRTSAUnindentCurlyBraces.isSelected();
}

public boolean isWordWrap() {
return chBoxRTSAWordWrap.isSelected();
}
Expand Down Expand Up @@ -196,6 +201,9 @@ private void initComponents() {
chBoxRTSAIndentUseTab = new JCheckBox("Use tab characters for indenting");
chBoxRTSAIndentUseTab.setSelected(Config.getInstance().getBoolean(Config.RSTA_INDENT_USE_TAB));

chBoxRTSAUnindentCurlyBraces = new JCheckBox("Unindent curly braces");
chBoxRTSAUnindentCurlyBraces.setSelected(Config.getInstance().getBoolean(Config.RSTA_UNINDENT_CURLY_BRACES));

comboBoxLookAndFeel.setSelectedItem(lf);
JLabel lblResultTabsCount = new JLabel("Result tabs count");
formatter = new NumberFormatter();
Expand Down Expand Up @@ -288,7 +296,7 @@ private void initComponents() {
layout.setStacks(
new GroupLayoutSimple.Stack()
.addLineAndGlue(chBoxRTSAAnimateBracketMatching, chBoxRTSAHighlightCurrentLine, chBoxRTSAWordWrap)
.addLineAndGlue(lblRTSAIndentSize, txtRTSAIndentSize, chBoxRTSAIndentUseTab)
.addLineAndGlue(lblRTSAIndentSize, txtRTSAIndentSize, chBoxRTSAIndentUseTab, chBoxRTSAUnindentCurlyBraces)
.addLineAndGlue(lblDefaultLineEnding, comboBoxLineEnding)
.addLineAndGlue(lblExecAll, comboBoxExecAll)
.addLine(lblFontSize, spnFontSize, cbFontName)
Expand Down
3 changes: 3 additions & 0 deletions src/main/studio/ui/StudioPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import studio.kdb.*;
import studio.kdb.Config.ThemeEntry;
import studio.qeditor.RSToken;
import studio.qeditor.RSTokenMaker;
import studio.ui.action.JSONServerList;
import studio.ui.action.QPadImport;
import studio.ui.action.QueryResult;
Expand Down Expand Up @@ -839,6 +840,7 @@ public static void settings() {
changedEditor |= CONFIG.setBoolean(Config.RSTA_WORD_WRAP, dialog.isWordWrap());
changedEditor |= CONFIG.setInt(Config.RSTA_INDENT_SIZE, dialog.getRTSAIndentSize());
changedEditor |= CONFIG.setBoolean(Config.RSTA_INDENT_USE_TAB, dialog.isRTSAIndentUseTab());
changedEditor |= CONFIG.setBoolean(Config.RSTA_UNINDENT_CURLY_BRACES, dialog.isRTSAUnindentCurlyBraces());
Font font = new Font(dialog.getFontName(), Font.PLAIN, dialog.getFontSize());
changedEditor |= CONFIG.setFont(Config.FONT_EDITOR, font);

Expand Down Expand Up @@ -901,6 +903,7 @@ private static void refreshEditorsSettings() {
editorTab.setTextAreaFont(font);
}
}
RSTokenMaker.setUnindentCurlyBraces(CONFIG.getBoolean(Config.RSTA_UNINDENT_CURLY_BRACES));
}

private static void refreshResultSettings() {
Expand Down

0 comments on commit 0035fb3

Please sign in to comment.