mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-72261 configure line wrapping per file or per file type (changes for CR-IC-7360, more are coming)
This commit is contained in:
@@ -266,6 +266,12 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
*/
|
||||
@Deprecated
|
||||
public int RIGHT_MARGIN = 120;
|
||||
/**
|
||||
* <b>Do not use this field directly since it doesn't reflect a setting for a specific language which may
|
||||
* overwrite this one. Call {@link #isWrapOnTyping(Language)} method instead.</b>
|
||||
*
|
||||
* @see #WRAP_ON_TYPING
|
||||
*/
|
||||
public boolean WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = false;
|
||||
|
||||
|
||||
@@ -957,4 +963,23 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
public void setDefaultRightMargin(int rightMargin) {
|
||||
RIGHT_MARGIN = rightMargin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines whether or not wrapping should occur when typing reaches right margin.
|
||||
* @param language The language to check the option for or null for a global option.
|
||||
* @return True if wrapping on right margin is enabled.
|
||||
*/
|
||||
public boolean isWrapOnTyping(@Nullable Language language) {
|
||||
if (language != null) {
|
||||
CommonCodeStyleSettings langSettings = getCommonSettings(language);
|
||||
if (langSettings != null) {
|
||||
if (langSettings.WRAP_ON_TYPING != WrapOnTyping.DEFAULT.intValue) {
|
||||
return langSettings.WRAP_ON_TYPING == WrapOnTyping.WRAP.intValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
//noinspection deprecation
|
||||
return WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ public interface CodeStyleSettingsCustomizable {
|
||||
|
||||
enum WrappingOrBraceOption {
|
||||
RIGHT_MARGIN,
|
||||
WRAP_ON_TYPING,
|
||||
KEEP_CONTROL_STATEMENT_IN_ONE_LINE,
|
||||
LINE_COMMENT_AT_FIRST_COLUMN,
|
||||
BLOCK_COMMENT_AT_FIRST_COLUMN,
|
||||
@@ -287,6 +288,17 @@ public interface CodeStyleSettingsCustomizable {
|
||||
CommonCodeStyleSettings.NEXT_LINE_SHIFTED2
|
||||
};
|
||||
|
||||
String[] WRAP_ON_TYPING_OPTIONS = {
|
||||
ApplicationBundle.message("wrapping.wrap.on.typing.no.wrap"),
|
||||
ApplicationBundle.message("wrapping.wrap.on.typing.wrap"),
|
||||
ApplicationBundle.message("wrapping.wrap.on.typing.default")
|
||||
};
|
||||
int [] WRAP_ON_TYPING_VALUES = {
|
||||
CommonCodeStyleSettings.WrapOnTyping.NO_WRAP.intValue,
|
||||
CommonCodeStyleSettings.WrapOnTyping.WRAP.intValue,
|
||||
CommonCodeStyleSettings.WrapOnTyping.DEFAULT.intValue
|
||||
};
|
||||
|
||||
void showAllStandardOptions();
|
||||
|
||||
void showStandardOptions(String... optionNames);
|
||||
|
||||
@@ -890,6 +890,23 @@ public class CommonCodeStyleSettings {
|
||||
|
||||
public int FORCE_REARRANGE_MODE = REARRANGE_ACCORDIND_TO_DIALOG;
|
||||
|
||||
public enum WrapOnTyping {
|
||||
DEFAULT(-1),
|
||||
NO_WRAP (0),
|
||||
WRAP (1);
|
||||
|
||||
public int intValue;
|
||||
|
||||
WrapOnTyping(int i) {
|
||||
this.intValue = i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines if wrapping should occur when typing reaches right margin. <b>Do not use a value of this field directly, call
|
||||
* {@link CodeStyleSettings#isWrapOnTyping(Language)} method instead</b>.
|
||||
*/
|
||||
public int WRAP_ON_TYPING = WrapOnTyping.DEFAULT.intValue;
|
||||
|
||||
//-------------------------Indent options-------------------------------------------------
|
||||
public static class IndentOptions implements JDOMExternalizable, Cloneable {
|
||||
|
||||
+1
@@ -61,6 +61,7 @@ public class WrappingAndBracesPanel extends OptionTableWithPreviewPanel {
|
||||
@Override
|
||||
protected void initTables() {
|
||||
addOption("RIGHT_MARGIN", ApplicationBundle.message("editbox.right.margin.columns"), null, 0, 999, -1, ApplicationBundle.message("settings.code.style.default.general"));
|
||||
addOption("WRAP_ON_TYPING", ApplicationBundle.message("wrapping.wrap.on.typing"), null, WRAP_ON_TYPING_OPTIONS, WRAP_ON_TYPING_VALUES);
|
||||
|
||||
addOption("KEEP_LINE_BREAKS", ApplicationBundle.message("wrapping.keep.line.breaks"), WRAPPING_KEEP);
|
||||
addOption("KEEP_FIRST_COLUMN_COMMENT", ApplicationBundle.message("wrapping.keep.comment.at.first.column"), WRAPPING_KEEP);
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
import com.intellij.formatting.FormatConstants;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.formatter.WhiteSpaceFormattingStrategy;
|
||||
import com.intellij.ide.DataManager;
|
||||
@@ -47,7 +48,7 @@ public class AutoHardWrapHandler {
|
||||
/**
|
||||
* This key is used as a flag that indicates if <code>'auto wrap line on typing'</code> activity is performed now.
|
||||
*
|
||||
* @see CodeStyleSettings#WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN
|
||||
* @see CodeStyleSettings#isWrapOnTyping(Language)
|
||||
*/
|
||||
public static final Key<Boolean> AUTO_WRAP_LINE_IN_PROGRESS_KEY = new Key<Boolean>("AUTO_WRAP_LINE_IN_PROGRESS");
|
||||
|
||||
|
||||
@@ -74,10 +74,16 @@ public class CodeStyleFacadeImpl extends CodeStyleFacade {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isWrapWhenTypingReachesRightMargin() {
|
||||
return CodeStyleSettingsManager.getSettings(myProject).WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapOnTyping(@Nullable Language language) {
|
||||
return CodeStyleSettingsManager.getSettings(myProject).isWrapOnTyping(language);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTabSize(final FileType fileType) {
|
||||
return CodeStyleSettingsManager.getSettings(myProject).getTabSize(fileType);
|
||||
|
||||
@@ -56,8 +56,17 @@ public abstract class CodeStyleFacade {
|
||||
|
||||
public abstract int getRightMargin(Language language);
|
||||
|
||||
/**
|
||||
* @return True if wrap on typing is enabled
|
||||
* @deprecated Use isWrapOnTyping(language) instead
|
||||
*/
|
||||
public abstract boolean isWrapWhenTypingReachesRightMargin();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isWrapOnTyping(@Nullable Language language) {
|
||||
return isWrapWhenTypingReachesRightMargin();
|
||||
}
|
||||
|
||||
public abstract int getTabSize(final FileType fileType);
|
||||
|
||||
public abstract boolean useTabCharacter(final FileType fileType);
|
||||
|
||||
@@ -213,7 +213,7 @@ public class SettingsImpl implements EditorSettings {
|
||||
public boolean isWrapWhenTypingReachesRightMargin(Project project) {
|
||||
return myWrapWhenTypingReachesRightMargin != null ?
|
||||
myWrapWhenTypingReachesRightMargin.booleanValue() :
|
||||
CodeStyleFacade.getInstance(project).isWrapWhenTypingReachesRightMargin();
|
||||
CodeStyleFacade.getInstance(project).isWrapOnTyping(myLanguage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -136,6 +136,11 @@ button.remove.r=&Remove
|
||||
|
||||
wrapping.and.braces=Wrapping and Braces
|
||||
|
||||
wrapping.wrap.on.typing=Wrap on typing
|
||||
wrapping.wrap.on.typing.no.wrap=No
|
||||
wrapping.wrap.on.typing.wrap=Yes
|
||||
wrapping.wrap.on.typing.default=Default
|
||||
|
||||
wrapping.keep.when.reformatting=Keep when reformatting
|
||||
wrapping.keep.line.breaks=Line breaks
|
||||
wrapping.keep.comment.at.first.column=Comment at first column
|
||||
|
||||
Reference in New Issue
Block a user