mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Right margin option UI for HTML
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.application.options.codeStyle.RightMarginForm">
|
||||
<grid id="27dc6" binding="myTopPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="12cf8" class="com.intellij.ui.components.JBLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ApplicationBundle" key="editbox.right.margin.columns"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="1265c">
|
||||
<constraints>
|
||||
<grid row="1" 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="78fe" class="javax.swing.JTextField" binding="myRightMarginField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="50" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="2"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5ef52" class="javax.swing.JCheckBox" binding="myDefaultGeneralCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ApplicationBundle" key="settings.code.style.default.general"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.application.options.codeStyle;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
/**
|
||||
* Can be used for languages which do not use standard "Wrapping and Braces" panel.
|
||||
* <p>
|
||||
* <strong>Note</strong>: besides adding the panel to UI it is necessary to make sure that language's own
|
||||
* <code>LanguageCodeStyleSettingsProvider</code> explicitly supports RIGHT_MARGIN field in <code>customizeSettings()</code>
|
||||
* method as shown below:
|
||||
* <pre>
|
||||
* public void customizeSettings(...) {
|
||||
* if (settingsType == SettingsType.WRAPPING_AND_BRACES_SETTINGS) {
|
||||
* consumer.showStandardOptions("RIGHT_MARGIN");
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* @author Rustam Vishnyakov
|
||||
*/
|
||||
public class RightMarginForm {
|
||||
private JTextField myRightMarginField;
|
||||
private JCheckBox myDefaultGeneralCheckBox;
|
||||
private JPanel myTopPanel;
|
||||
private final Language myLanguage;
|
||||
private final int myDefaultRightMargin;
|
||||
|
||||
public RightMarginForm(@NotNull Language language, @NotNull CodeStyleSettings settings) {
|
||||
myLanguage = language;
|
||||
myDefaultRightMargin = settings.RIGHT_MARGIN;
|
||||
myDefaultGeneralCheckBox.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (myDefaultGeneralCheckBox.isSelected()) {
|
||||
myRightMarginField.setText(Integer.toString(myDefaultRightMargin));
|
||||
myRightMarginField.setEnabled(false);
|
||||
}
|
||||
else {
|
||||
myRightMarginField.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void reset(@NotNull CodeStyleSettings settings) {
|
||||
CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
|
||||
if (langSettings != settings && langSettings.RIGHT_MARGIN >= 0) {
|
||||
myDefaultGeneralCheckBox.setSelected(false);
|
||||
myRightMarginField.setText(Integer.toString(langSettings.RIGHT_MARGIN));
|
||||
}
|
||||
else {
|
||||
myDefaultGeneralCheckBox.setSelected(true);
|
||||
myRightMarginField.setText(Integer.toString(settings.RIGHT_MARGIN));
|
||||
if (langSettings == settings) {
|
||||
myDefaultGeneralCheckBox.setEnabled(false);
|
||||
myRightMarginField.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void apply(@NotNull CodeStyleSettings settings) {
|
||||
CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
|
||||
if (langSettings != settings) {
|
||||
if (myDefaultGeneralCheckBox.isSelected()) {
|
||||
langSettings.RIGHT_MARGIN = -1;
|
||||
}
|
||||
else {
|
||||
langSettings.RIGHT_MARGIN = getFieldRightMargin(settings.RIGHT_MARGIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isModified(@NotNull CodeStyleSettings settings) {
|
||||
CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
|
||||
if (myDefaultGeneralCheckBox.isSelected()) {
|
||||
return langSettings.RIGHT_MARGIN >= 0;
|
||||
}
|
||||
else {
|
||||
return langSettings.RIGHT_MARGIN != getFieldRightMargin(settings.RIGHT_MARGIN);
|
||||
}
|
||||
}
|
||||
|
||||
private int getFieldRightMargin(int fallBackValue) {
|
||||
String strValue = myRightMarginField.getText();
|
||||
if (!strValue.trim().isEmpty()) {
|
||||
try {
|
||||
return Integer.parseInt(strValue);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
myRightMarginField.setText(Integer.toString(fallBackValue));
|
||||
}
|
||||
}
|
||||
return fallBackValue;
|
||||
}
|
||||
|
||||
public JPanel getTopPanel() {
|
||||
return myTopPanel;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</xy>
|
||||
<grid id="1b801" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="1b801" layout-manager="GridLayoutManager" row-count="2" 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"/>
|
||||
@@ -27,14 +27,14 @@
|
||||
<children>
|
||||
<scrollpane id="3e3f1" class="com.intellij.ui.components.JBScrollPane" binding="myJBScrollPane" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalScrollBarPolicy value="31"/>
|
||||
</properties>
|
||||
<border type="empty"/>
|
||||
<children>
|
||||
<grid id="b4cfb" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="b4cfb" layout-manager="GridLayoutManager" row-count="4" 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/>
|
||||
<properties/>
|
||||
@@ -43,7 +43,7 @@
|
||||
<grid id="ca5bb" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -185,7 +185,7 @@
|
||||
<grid id="b8acc" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -277,7 +277,7 @@
|
||||
<grid id="6dece" layout-manager="GridLayoutManager" row-count="4" column-count="2" 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"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -336,6 +336,15 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="eb695" binding="myRightMarginPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" 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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.application.options;
|
||||
|
||||
import com.intellij.application.options.codeStyle.RightMarginForm;
|
||||
import com.intellij.ide.highlighter.XmlHighlighterFactory;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
@@ -30,6 +31,7 @@ import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ui.Centerizer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -64,6 +66,8 @@ public class CodeStyleHtmlPanel extends CodeStyleAbstractPanel {
|
||||
private JCheckBox myShouldKeepLineBreaksInText;
|
||||
private TextFieldWithBrowseButton myDontBreakIfInlineContent;
|
||||
private JBScrollPane myJBScrollPane;
|
||||
private JPanel myRightMarginPanel;
|
||||
private RightMarginForm myRightMarginForm;
|
||||
|
||||
public CodeStyleHtmlPanel(CodeStyleSettings settings) {
|
||||
super(settings);
|
||||
@@ -95,6 +99,8 @@ public class CodeStyleHtmlPanel extends CodeStyleAbstractPanel {
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
myRightMarginForm = new RightMarginForm(StdFileTypes.HTML.getLanguage(), getSettings());
|
||||
myRightMarginPanel = myRightMarginForm.getTopPanel();
|
||||
myJBScrollPane = new JBScrollPane() {
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
@@ -158,6 +164,7 @@ public class CodeStyleHtmlPanel extends CodeStyleAbstractPanel {
|
||||
settings.HTML_KEEP_WHITESPACES_INSIDE = myKeepWhiteSpacesTagNames.getText();
|
||||
settings.HTML_KEEP_LINE_BREAKS = myShouldKeepBlankLines.isSelected();
|
||||
settings.HTML_KEEP_LINE_BREAKS_IN_TEXT = myShouldKeepLineBreaksInText.isSelected();
|
||||
myRightMarginForm.apply(settings);
|
||||
}
|
||||
|
||||
private static int getIntValue(JTextField keepBlankLines) {
|
||||
@@ -190,6 +197,7 @@ public class CodeStyleHtmlPanel extends CodeStyleAbstractPanel {
|
||||
myInlineElementsTagNames.setText(settings.HTML_INLINE_ELEMENTS);
|
||||
myDontBreakIfInlineContent.setText(settings.HTML_DONT_ADD_BREAKS_IF_INLINE_CONTENT);
|
||||
myKeepWhiteSpacesTagNames.setText(settings.HTML_KEEP_WHITESPACES_INSIDE);
|
||||
myRightMarginForm.reset(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -260,7 +268,7 @@ public class CodeStyleHtmlPanel extends CodeStyleAbstractPanel {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return myRightMarginForm.isModified(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,10 +17,13 @@ package com.intellij.application.options;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.html.HTMLLanguage;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Rustam Vishnyakov
|
||||
*/
|
||||
@@ -36,6 +39,14 @@ public class HtmlLanguageCodeStyleSettings extends LanguageCodeStyleSettingsProv
|
||||
return CodeStyleAbstractPanel.readFromFile(this.getClass(), "preview.html.template");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer,
|
||||
@NotNull SettingsType settingsType) {
|
||||
if (settingsType == SettingsType.WRAPPING_AND_BRACES_SETTINGS) {
|
||||
consumer.showStandardOptions("RIGHT_MARGIN");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonCodeStyleSettings getDefaultCommonSettings() {
|
||||
CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(HTMLLanguage.INSTANCE);
|
||||
|
||||
Reference in New Issue
Block a user