diff --git a/openapi/src/com/intellij/psi/codeStyle/CodeStyleSettings.java b/openapi/src/com/intellij/psi/codeStyle/CodeStyleSettings.java index 3cfda2e7549b..52a1334b438e 100644 --- a/openapi/src/com/intellij/psi/codeStyle/CodeStyleSettings.java +++ b/openapi/src/com/intellij/psi/codeStyle/CodeStyleSettings.java @@ -763,6 +763,30 @@ public class CodeStyleSettings implements Cloneable, JDOMExternalizable { public boolean XML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE = false; public boolean XML_SPACE_AROUND_TAG_NAME = false; + // --------------------------------------------------------------------------------------- + + // ---------------------------------- HTML formatting options ------------------------- + public boolean HTML_KEEP_WHITESPACES = false; + public int HTML_ATTRIBUTE_WRAP = WRAP_AS_NEEDED; + public int HTML_TEXT_WRAP = WRAP_AS_NEEDED; + + public boolean HTML_KEEP_LINE_BREAKS = true; + public int HTML_KEEP_BLANK_LINES = 2; + + public boolean HTML_ALIGN_ATTRIBUTES = true; + public boolean HTML_ALIGN_TEXT = false; + + public boolean HTML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE = false; + public boolean HTML_SPACE_AROUND_TAG_NAME = false; + + public String HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE = "body,div,p,form,h1,h2,h3"; + public String HTML_ELEMENTS_TO_REMOVE_NEW_LINE_BEFORE = "br"; + public String HTML_DO_NOT_ALIGN_CHILDREN_OF = "html,body"; + public int HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_SIZE = 7000; + public String HTML_TEXT_ELEMENTS = "a,b,img,span"; + public String HTML_KEEP_WHITESPACES_INSIDE = "span"; + + // --------------------------------------------------------------------------------------- //-----------------------------------JSPX formatting settings----------------------------- diff --git a/source/com/intellij/application/options/CodeStyleXmlConfigurable.java b/source/com/intellij/application/options/CodeStyleAbstractConfigurable.java similarity index 86% rename from source/com/intellij/application/options/CodeStyleXmlConfigurable.java rename to source/com/intellij/application/options/CodeStyleAbstractConfigurable.java index cd1dd6a593d6..cee824fce4a4 100644 --- a/source/com/intellij/application/options/CodeStyleXmlConfigurable.java +++ b/source/com/intellij/application/options/CodeStyleAbstractConfigurable.java @@ -31,23 +31,24 @@ */ package com.intellij.application.options; -import com.intellij.openapi.options.BaseConfigurable; -import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.Configurable; +import com.intellij.openapi.options.ConfigurationException; import com.intellij.psi.codeStyle.CodeStyleSettings; import javax.swing.*; -public class CodeStyleXmlConfigurable implements Configurable{ - private CodeStyleXmlPanel myPanel; +public abstract class CodeStyleAbstractConfigurable implements Configurable{ + private CodeStyleAbstractPanel myPanel; private final CodeStyleSettings mySettings; + private final String myDisplayName; - public CodeStyleXmlConfigurable(CodeStyleSettings settings) { + public CodeStyleAbstractConfigurable(CodeStyleSettings settings, final String displayName) { mySettings = settings; + myDisplayName = displayName; } public String getDisplayName() { - return "XML"; + return myDisplayName; } public Icon getIcon() { @@ -59,10 +60,12 @@ public class CodeStyleXmlConfigurable implements Configurable{ } public JComponent createComponent() { - myPanel = new CodeStyleXmlPanel(mySettings); + myPanel = createPanel(); return myPanel.getPanel(); } + protected abstract CodeStyleAbstractPanel createPanel(); + public void apply() throws ConfigurationException { myPanel.apply(mySettings); } diff --git a/source/com/intellij/application/options/CodeStyleAbstractPanel.java b/source/com/intellij/application/options/CodeStyleAbstractPanel.java new file mode 100644 index 000000000000..57a3976b7545 --- /dev/null +++ b/source/com/intellij/application/options/CodeStyleAbstractPanel.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * -Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * -Redistribution in binary form must reproduct the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * + * Neither the name of JetBrains or IntelliJ IDEA + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT + * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT + * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN + * IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ +package com.intellij.application.options; + +import com.intellij.ide.highlighter.HighlighterFactory; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.editor.EditorSettings; +import com.intellij.openapi.editor.colors.EditorColors; +import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.psi.PsiElementFactory; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.util.IncorrectOperationException; + +import javax.swing.*; + +public abstract class CodeStyleAbstractPanel { + private static Logger LOG = Logger.getInstance("#com.intellij.application.options.CodeStyleXmlPanel"); + protected final Editor myEditor; + protected final CodeStyleSettings mySettings; + private boolean myShouldUpdatePreview; + protected final static int[] ourWrappings = new int[] {CodeStyleSettings.DO_NOT_WRAP, + CodeStyleSettings.WRAP_AS_NEEDED, + CodeStyleSettings.WRAP_ON_EVERY_ITEM, + CodeStyleSettings.WRAP_ALWAYS}; + + public CodeStyleAbstractPanel(CodeStyleSettings settings) { + mySettings = settings; + myEditor = createEditor(); + } + + protected static final Editor createEditor() { + EditorFactory editorFactory = EditorFactory.getInstance(); + Document editorDocument = editorFactory.createDocument(""); + EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument); + + EditorSettings editorSettings = editor.getSettings(); + editorSettings.setWhitespacesShown(true); + editorSettings.setLineMarkerAreaShown(false); + editorSettings.setLineNumbersShown(false); + editorSettings.setFoldingOutlineShown(false); + editorSettings.setAdditionalColumnsCount(0); + editorSettings.setAdditionalLinesCount(1); + + EditorColorsScheme scheme = editor.getColorsScheme(); + scheme.setColor(EditorColors.CARET_ROW_COLOR, null); + + editor.setHighlighter(HighlighterFactory.createXMLHighlighter(scheme)); + return editor; + } + + protected final void updatePreview() { + if (!myShouldUpdatePreview) { + return; + } + final String text = getPreviewText(); + + final Project project = ProjectManager.getInstance().getDefaultProject(); + final PsiManager manager = PsiManager.getInstance(project); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + PsiElementFactory factory = manager.getElementFactory(); + try { + PsiFile psiFile = factory.createFileFromText("a." + getFileType().getDefaultExtension(), text); + + CodeStyleSettings clone = (CodeStyleSettings)mySettings.clone(); + apply(clone); + + CodeStyleSettingsManager.getInstance(project).setTemporarySettings(clone); + CodeStyleManager.getInstance(project).reformat(psiFile); + CodeStyleSettingsManager.getInstance(project).dropTemporarySettings(); + + myEditor.getSettings().setTabSize(clone.getTabSize(getFileType())); + Document document = myEditor.getDocument(); + document.replaceString(0, document.getTextLength(), psiFile.getText()); + + } + catch (IncorrectOperationException e) { + LOG.error(e); + } + } + + }); + } + + protected abstract FileType getFileType(); + + protected abstract String getPreviewText(); + + public abstract void apply(CodeStyleSettings settings); + + public final void reset() { + myShouldUpdatePreview = false; + try { + resetImpl(); + } + finally { + myShouldUpdatePreview = true; + updatePreview(); + } + } + + protected int getIndexForWrapping(int value) { + for (int i = 0; i < ourWrappings.length; i++) { + int ourWrapping = ourWrappings[i]; + if (ourWrapping == value) return i; + } + LOG.assertTrue(false); + return 0; + } + + public abstract boolean isModified(CodeStyleSettings settings); + + public abstract JComponent getPanel(); + + public final void dispose() { + EditorFactory.getInstance().releaseEditor(myEditor); + } + + protected abstract void resetImpl(); + + protected void fillWrappingCombo(final JComboBox wrapCombo) { + wrapCombo.addItem("Do not wrap"); + wrapCombo.addItem("Wrap if long"); + wrapCombo.addItem("Chop down if long"); + wrapCombo.addItem("Wrap always"); + } +} diff --git a/source/com/intellij/application/options/CodeStyleHtmlPanel.form b/source/com/intellij/application/options/CodeStyleHtmlPanel.form new file mode 100644 index 000000000000..571697cfce2b --- /dev/null +++ b/source/com/intellij/application/options/CodeStyleHtmlPanel.form @@ -0,0 +1,285 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/source/com/intellij/application/options/CodeStyleHtmlPanel.java b/source/com/intellij/application/options/CodeStyleHtmlPanel.java new file mode 100644 index 000000000000..e35f3db26a29 --- /dev/null +++ b/source/com/intellij/application/options/CodeStyleHtmlPanel.java @@ -0,0 +1,428 @@ +/* + * Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * -Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * -Redistribution in binary form must reproduct the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * + * Neither the name of JetBrains or IntelliJ IDEA + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT + * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT + * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN + * IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ +package com.intellij.application.options; + +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.StdFileTypes; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class CodeStyleHtmlPanel extends CodeStyleAbstractPanel { + + private JTextField myKeepBlankLines; + private JComboBox myWrapAttributes; + private JCheckBox myAlignAttributes; + private JCheckBox myKeepWhiteSpaces; + + private JPanel myPanel; + private JPanel myPreviewPanel; + + private JCheckBox mySpacesAroundEquality; + private JCheckBox mySpacesAroundTagName; + private JCheckBox myAlignText; + private JComboBox myTextWrapping; + private JTextField myInsertNewLineTagNames; + private JTextField myRemoveNewLineTagNames; + private JTextField myDoNotAlignChildrenTagNames; + private JTextField myKeepWhiteSpacesTagNames; + private JTextField myTextElementsTagNames; + private JTextField myDoNotAlignChildrenMinSize; + + public CodeStyleHtmlPanel(CodeStyleSettings settings) { + super(settings); + myPreviewPanel.setLayout(new BorderLayout()); + myPreviewPanel.add(myEditor.getComponent(), BorderLayout.CENTER); + + fillWrappingCombo(myWrapAttributes); + fillWrappingCombo(myTextWrapping); + + ActionListener actionListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + updatePreview(); + } + }; + + myKeepBlankLines.addActionListener(actionListener); + myWrapAttributes.addActionListener(actionListener); + myTextWrapping.addActionListener(actionListener); + myKeepWhiteSpaces.addActionListener(actionListener); + myAlignAttributes.addActionListener(actionListener); + mySpacesAroundEquality.addActionListener(actionListener); + mySpacesAroundTagName.addActionListener(actionListener); + myAlignText.addActionListener(actionListener); + + final DocumentListener documentListener = new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + updatePreview(); + } + + public void insertUpdate(DocumentEvent e) { + updatePreview(); + } + + public void removeUpdate(DocumentEvent e) { + updatePreview(); + } + }; + + myKeepBlankLines.getDocument().addDocumentListener(documentListener); + + myInsertNewLineTagNames.getDocument().addDocumentListener(documentListener); + myRemoveNewLineTagNames.getDocument().addDocumentListener(documentListener); + myDoNotAlignChildrenTagNames.getDocument().addDocumentListener(documentListener); + myDoNotAlignChildrenMinSize.getDocument().addDocumentListener(documentListener); + myTextElementsTagNames.getDocument().addDocumentListener(documentListener); + myKeepWhiteSpacesTagNames.getDocument().addDocumentListener(documentListener); + } + + public void apply(CodeStyleSettings settings) { + settings.HTML_KEEP_BLANK_LINES = getIntValue(myKeepBlankLines); + settings.HTML_ATTRIBUTE_WRAP = ourWrappings[myWrapAttributes.getSelectedIndex()]; + settings.HTML_TEXT_WRAP = ourWrappings[myTextWrapping.getSelectedIndex()]; + settings.HTML_ALIGN_ATTRIBUTES = myAlignAttributes.isSelected(); + settings.HTML_ALIGN_TEXT = myAlignText.isSelected(); + settings.HTML_KEEP_WHITESPACES = myKeepWhiteSpaces.isSelected(); + settings.HTML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE = mySpacesAroundEquality.isSelected(); + settings.HTML_SPACE_AROUND_TAG_NAME = mySpacesAroundTagName.isSelected(); + + settings.HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE = myInsertNewLineTagNames.getText(); + settings.HTML_ELEMENTS_TO_REMOVE_NEW_LINE_BEFORE = myRemoveNewLineTagNames.getText(); + settings.HTML_DO_NOT_ALIGN_CHILDREN_OF = myDoNotAlignChildrenTagNames.getText(); + settings.HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_SIZE = getIntValue(myDoNotAlignChildrenMinSize); + settings.HTML_TEXT_ELEMENTS = myTextElementsTagNames.getText(); + settings.HTML_KEEP_WHITESPACES_INSIDE = myKeepWhiteSpacesTagNames.getText(); + } + + private int getIntValue(JTextField keepBlankLines) { + try { + return Integer.parseInt(keepBlankLines.getText()); + } + catch (NumberFormatException e) { + return 0; + } + } + + protected void resetImpl() { + myKeepBlankLines.setText(String.valueOf(mySettings.HTML_KEEP_BLANK_LINES)); + myWrapAttributes.setSelectedIndex(getIndexForWrapping(mySettings.HTML_ATTRIBUTE_WRAP)); + myTextWrapping.setSelectedIndex(getIndexForWrapping(mySettings.HTML_TEXT_WRAP)); + myAlignAttributes.setSelected(mySettings.HTML_ALIGN_ATTRIBUTES); + myAlignText.setSelected(mySettings.HTML_ALIGN_TEXT); + myKeepWhiteSpaces.setSelected(mySettings.HTML_KEEP_WHITESPACES); + mySpacesAroundTagName.setSelected(mySettings.HTML_SPACE_AROUND_TAG_NAME); + mySpacesAroundEquality.setSelected(mySettings.HTML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE); + + myInsertNewLineTagNames.setText(mySettings.HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE); + myRemoveNewLineTagNames.setText(mySettings.HTML_ELEMENTS_TO_REMOVE_NEW_LINE_BEFORE); + myDoNotAlignChildrenTagNames.setText(mySettings.HTML_DO_NOT_ALIGN_CHILDREN_OF); + myDoNotAlignChildrenMinSize.setText(String.valueOf(mySettings.HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_SIZE)); + myTextElementsTagNames.setText(mySettings.HTML_TEXT_ELEMENTS); + myKeepWhiteSpacesTagNames.setText(mySettings.HTML_KEEP_WHITESPACES_INSIDE); + + } + + public boolean isModified(CodeStyleSettings settings) { + if (settings.HTML_KEEP_BLANK_LINES != getIntValue(myKeepBlankLines)) { + return true; + } + if (settings.HTML_ATTRIBUTE_WRAP != ourWrappings[myWrapAttributes.getSelectedIndex()]) { + return true; + } + + if (settings.HTML_TEXT_WRAP != ourWrappings[myTextWrapping.getSelectedIndex()]) { + return true; + } + + if (settings.HTML_ALIGN_ATTRIBUTES != myAlignAttributes.isSelected()) { + return true; + } + + if (settings.HTML_ALIGN_TEXT != myAlignText.isSelected()) { + return true; + } + + if (settings.HTML_KEEP_WHITESPACES != myKeepWhiteSpaces.isSelected()) { + return true; + } + + if (settings.HTML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE != mySpacesAroundEquality.isSelected()){ + return true; + } + + if (settings.HTML_SPACE_AROUND_TAG_NAME != mySpacesAroundTagName.isSelected()){ + return true; + } + + if (!Comparing.equal(settings.HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE, myInsertNewLineTagNames.getText().trim())){ + return true; + } + + if (!Comparing.equal(settings.HTML_ELEMENTS_TO_REMOVE_NEW_LINE_BEFORE, myRemoveNewLineTagNames.getText().trim())){ + return true; + } + + if (!Comparing.equal(settings.HTML_DO_NOT_ALIGN_CHILDREN_OF, myDoNotAlignChildrenTagNames.getText().trim())){ + return true; + } + + if (settings.HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_SIZE != getIntValue(myDoNotAlignChildrenMinSize)){ + return true; + } + + if (!Comparing.equal(settings.HTML_TEXT_ELEMENTS, myTextElementsTagNames.getText().trim())){ + return true; + } + + if (!Comparing.equal(settings.HTML_KEEP_WHITESPACES_INSIDE, myKeepWhiteSpacesTagNames.getText().trim())){ + return true; + } + + return false; + } + + public JComponent getPanel() { + return myPanel; + } + + protected String getPreviewText() { + return "\n" + + "\n" + + "\n" + + "ReSharper: The Most Intelligent Add-In To VisualStudio .NET\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
\n" + + "\n" + + "
\n" + + "
\"JetBrains
\n" + + "\n" + + "
\n" + + " \n" + + "
\n" + + "
\n" + + "\n" + + "

ReSharper

\n" + + "
\n" + + " \n" + + "
\n" + + "\n" + + "
\n" + + "
Home\"\"/>Products\"\"/>ReSharper
\n" + + "
\n" + + " \"\"/\n" + + "
\n" + + " \t

License Lottery

\n" + + "
\n" + + "

Participate and win
\n" + + " free ReSharper license\n" + + "

\n" + + "
\n" + + "\n" + + "
\n" + + "\n" + + "
\n" + + " \t\t

Keep Me Informed

\n" + + " \t\t

Subscribe to JetBrains product news and documentation updates

\n" + + "\n" + + " \t\t
\n" + + " name:\n" + + " \t\t
\n" + + " \t\t\t\n" + + " \t\t
\n" + + " \t\te-mail:\n" + + " \t\t
\n" + + " \t\t\t\n" + + " \t\t
\n" + + " \t\t\"subscribe\"/\n" + + " \t\t
\n" + + " \t
\n" + + " \t
\n" + + "

"Resharper has been making its way through my team like a virus. I've been using it for a couple of months now, and I think I can say I'm sold."

\n" + + "

Steve Maine,
Solutions developer,
Avanade

\n" + + "
\n" + + "

\n" + + "\n" + + "
\n" + + "

"Incidentally, if you want excellent refactoring support for C# in Visual Studio.Net\n" + + " today, check out JetBrains' super ReSharper tool. It supports renaming, extracting methods, turning fields\n" + + " into properties, encapsulating code with if or while constructs, templates and much more!"

\n" + + "

Roy Dictus,
Architect and Trainer,
U2U, Belgium's leading .Net Competence Center

\n" + + "
\n" + + "

\n" + + "\n" + + "
\n" + + "

"If you are a C# developer you simply owe it to yourself to get this tool. It has\n" + + " dramatically made my life better (SERIOUSLY!). I put it up there with amazing tools…"

\n" + + "

Damon Wilder Carr,
Chief Technologist and CEO,
Agilerfactor

\n" + + "
\n" + + "

\n" + + "\n" + + "
\n" + + " \n" + + " \"ADT\n" + + "

ADT Magazine reviews ReSharper 1.0.1

\n" + + "
\n" + + " \"SD\n" + + "

"Another IDEA: JetBrains to Launch C#, RAD Tools"

\n" + + "
\n" + + "\n" + + "
\n" + + "\n" + + "
\n" + + "

The Most Intelligent Add-In To VisualStudio.NET

\n" + + "
\n" + + "
\n" + + "

\"ReSharper

\n" + + "
\n" + + "
\n" + + "

download

\n" + + "

buy

\n" + + "
\n" + + "
\n" + + "
\n" + + "
\n" + + "
\n" + + "\t\t\t

ReSharper was created with the single purpose in mind: to increase the productivity of\n" + + " C# developers. It comes equipped with a rich set of features, such as intelligent coding assistance, on-the-fly\n" + + " error highlighting and quick error correction, unmatched support for code refactoring, and a whole lot more.\n" + + " ReSharper's tight integration with Visual Studio .NET provides quick and easy access to all of its advanced\n" + + " features right from the IDE.

\n" + + "

\"PDF\"/  ReSharper Data Sheet (111 Kb)

\n" + + "

\"PDF\"/  ReSharper 1.0 Default Keymap (44 Kb)

\n" + + "
\n" + + "\n" + + "

ReSharper Key Features

\n" + + "
\n" + + "
\n" + + "

Error Highlighting

\n" + + " \"Error\n" + + "

One of the most powerful and helpful features in ReSharper is its ability to quickly detect and\n" + + " highlight errors in code, without the need to compile it. ReSharper automatically analyzes your code while\n" + + " you work and will highlight a variety of possible syntax or logical errors. It can also detect and emphasize\n" + + " statements or constructs that you should be warned about (e.g., unused or uninitialized variables).

\n" + + "

More about this feature…

\n" + + "
\n" + + "
\n" + + "

Error Quick-Fixes

\n" + + " \"Error\n" + + "

Not only does ReSharper highlight errors, but it also provides useful quick-fixes that enable you to\n" + + " instantly correct the code. When you place the caret on a highlighted error, if quick-fixes for this error\n" + + " are available, a small light-bulb icon pops up at the relevant line. Click it or use the Alt+Enter shortcut,\n" + + " to see the list of available quick-fixes. Select the desired quick-fix and press Enter to apply it.

\n" + + "

More about this feature…

\n" + + "
\n" + + "
\n" + + "

Refactoring Support

\n" + + "

Refactoring can significantly improve your code design and efficiency. ReSharper's automated refactoring\n" + + " support takes care of code consistency and compilability after even the most dramatic modifications.

\n" + + "

ReSharper supports the following types of refactoring:

\n" + + "
    \n" + + "
  • Rename symbol with reference correction
  • \n" + + "
  • Move type to another namespace with reference correction
  • \n" + + "
  • Move type declaration to a separate file
  • \n" + + "
  • Change method signature (add/remove/reorder parameters, change parameter type or return type)
  • \n" + + "
  • Extract method
  • \n" + + "
  • Introduce variable
  • \n" + + "
  • Inline variable
  • \n" + + "
  • Convert method to property
  • \n" + + "
  • Convert property to method(s)
  • \n" + + "
\n" + + "

More about this feature…

\n" + + "
\n" + + "
\n" + + "

Live Templates

\n" + + " \"Live\n" + + "

Live templates represent predefined code fragments that can "interact" with the developer\n" + + " when inserted. You can use them to insert common or custom code constructs into a source code file quickly,\n" + + " efficiently, and accurately.

\n" + + "

Just type a particular template's abbreviation, then press the Tab key to expand it into your source file.

\n" + + "

More about this feature…

\n" + + "
\n" + + "\n" + + "

To get the full story on ReSharper’s feature set, please visit the Features page.

\n" + + "\n" + + "

Why ReSharper

\n" + + "

ReSharper makes C# development a real pleasure. It decreases the time you spend on routine, repetitive\n" + + " handwork, giving you more time to focus on the task at hand. Its robust set of features for automatic error-checking\n" + + " and code correction cuts development time and increases your efficiency. You'll find that ReSharper quickly\n" + + " pays back it's cost in increased developer productivity and improved code quality.

\n" + + "

The wait is over… ReSharper is here and now C# developers can experience what we mean when we say\n" + + " \"Develop with pleasure!\" Download a copy today!

\n" + + "
\n" + + "\n" + + "
\n" + + "
\n" + + "
\n" + + "
\n" + + "
\n" + + "
\n" + + "
Copyright © 2000-2004 JetBrains. All rights reserved
\n" + + "
Comments? Write to webmaster@jetbrains.com
\n" + + "
\n" + + "
\n" + + "\n" + + "\n" + + ""; + } + + protected FileType getFileType() { + return StdFileTypes.HTML; + } +} diff --git a/source/com/intellij/application/options/CodeStyleXmlPanel.java b/source/com/intellij/application/options/CodeStyleXmlPanel.java index 943d297e87e5..8865796ce123 100644 --- a/source/com/intellij/application/options/CodeStyleXmlPanel.java +++ b/source/com/intellij/application/options/CodeStyleXmlPanel.java @@ -31,65 +31,36 @@ */ package com.intellij.application.options; -import com.intellij.ide.highlighter.HighlighterFactory; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.editor.EditorSettings; -import com.intellij.openapi.editor.colors.EditorColors; -import com.intellij.openapi.editor.colors.EditorColorsScheme; -import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import com.intellij.psi.PsiElementFactory; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; -import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.psi.codeStyle.CodeStyleSettingsManager; -import com.intellij.util.IncorrectOperationException; import javax.swing.*; -import javax.swing.event.DocumentListener; import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import java.awt.*; -import java.awt.event.ActionListener; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; -public class CodeStyleXmlPanel { - private static Logger LOG = Logger.getInstance("#com.intellij.application.options.CodeStyleXmlPanel"); - +public class CodeStyleXmlPanel extends CodeStyleAbstractPanel{ private JTextField myKeepBlankLines; private JComboBox myWrapAttributes; private JCheckBox myAlignAttributes; private JCheckBox myKeepWhiteSpaces; - private final Editor myEditor; - private final CodeStyleSettings mySettings; - private boolean myShouldUpdatePreview; - private JPanel myPreviewPanel; private JPanel myPanel; + private JPanel myPreviewPanel; - private final static int[] ourWrappings = new int[] {CodeStyleSettings.DO_NOT_WRAP, - CodeStyleSettings.WRAP_AS_NEEDED, - CodeStyleSettings.WRAP_ON_EVERY_ITEM, - CodeStyleSettings.WRAP_ALWAYS}; private JCheckBox mySpacesAroundEquality; private JCheckBox mySpacesAroundTagName; public CodeStyleXmlPanel(CodeStyleSettings settings) { - mySettings = settings; - myEditor = createEditor(); + super(settings); myPreviewPanel.setLayout(new BorderLayout()); myPreviewPanel.add(myEditor.getComponent(), BorderLayout.CENTER); - myWrapAttributes.addItem("Do not wrap"); - myWrapAttributes.addItem("Wrap if long"); - myWrapAttributes.addItem("Chop down if long"); - myWrapAttributes.addItem("Wrap always"); + fillWrappingCombo(myWrapAttributes); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -119,205 +90,6 @@ public class CodeStyleXmlPanel { }); } - private static Editor createEditor() { - EditorFactory editorFactory = EditorFactory.getInstance(); - Document editorDocument = editorFactory.createDocument(""); - EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument); - - EditorSettings editorSettings = editor.getSettings(); - editorSettings.setWhitespacesShown(true); - editorSettings.setLineMarkerAreaShown(false); - editorSettings.setLineNumbersShown(false); - editorSettings.setFoldingOutlineShown(false); - editorSettings.setAdditionalColumnsCount(0); - editorSettings.setAdditionalLinesCount(1); - - EditorColorsScheme scheme = editor.getColorsScheme(); - scheme.setColor(EditorColors.CARET_ROW_COLOR, null); - - editor.setHighlighter(HighlighterFactory.createXMLHighlighter(scheme)); - return editor; - } - - private void updatePreview() { - if (!myShouldUpdatePreview) { - return; - } - final String text = - "\n" + - " CVS\n" + - " CVS integration\n" + - " 0.1\n" + - " IntelliJ\n" + - " \n" + - "\n" + - " \n" + - " \n" + - " com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration\n" + - " \n" + - " \n" + - " com.intellij.cvsSupport2.application.CvsEntriesManager\n" + - " \n" + - " \n" + - " com.intellij.cvsSupport2.connections.ssh.SSHPasswordProvider\n" + - " \n" + - "\n" + - " \n" + - " com.intellij.openapi.cvsIntegration.CvsServices\n" + - " com.intellij.cvsSupport2.impl.CvsServicesImpl\n" + - " \n" + - " \n" + - " com.intellij.cvsSupport2.config.ImportConfiguration\n" + - " \n" + - "\n" + - " \n" + - "\n" + - " \n" + - " \n" + - " com.intellij.cvsSupport2.config.CvsConfiguration\n" + - " \n" + - "\n" + - " \n" + - " com.intellij.cvsSupport2.CvsVcs2\n" + - " \n" + - " \n" + - " com.intellij.cvsSupport2.ui.CvsTabbedWindow\n" + - " \n" + - " \n" + - " com.intellij.cvsSupport2.application.CvsStorageSupportingDeletionComponent\n" + - " \n" + - "\n" + - " \n" + - "\n" + - "\n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - "\n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - "\n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; - - final Project project = ProjectManager.getInstance().getDefaultProject(); - final PsiManager manager = PsiManager.getInstance(project); - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - PsiElementFactory factory = manager.getElementFactory(); - try { - PsiFile psiFile = factory.createFileFromText("a.xml", text); - - CodeStyleSettings clone = (CodeStyleSettings)mySettings.clone(); - apply(clone); - - CodeStyleSettingsManager.getInstance(project).setTemporarySettings(clone); - CodeStyleManager.getInstance(project).reformat(psiFile); - CodeStyleSettingsManager.getInstance(project).dropTemporarySettings(); - - myEditor.getSettings().setTabSize(clone.getTabSize(StdFileTypes.XML)); - Document document = myEditor.getDocument(); - document.replaceString(0, document.getTextLength(), psiFile.getText()); - - } - catch (IncorrectOperationException e) { - LOG.error(e); - } - } - - }); - } - public void apply(CodeStyleSettings settings) { settings.XML_KEEP_BLANK_LINES = getIntValue(myKeepBlankLines); settings.XML_ATTRIBUTE_WRAP = ourWrappings[myWrapAttributes.getSelectedIndex()]; @@ -337,30 +109,13 @@ public class CodeStyleXmlPanel { } } - public void reset() { - myShouldUpdatePreview = false; - try { - myKeepBlankLines.setText(String.valueOf(mySettings.XML_KEEP_BLANK_LINES)); - myWrapAttributes.setSelectedIndex(getIndexForWrapping()); - myAlignAttributes.setSelected(mySettings.XML_ALIGN_ATTRIBUTES); - myKeepWhiteSpaces.setSelected(mySettings.XML_KEEP_WHITESPACES); - mySpacesAroundTagName.setSelected(mySettings.XML_SPACE_AROUND_TAG_NAME); - mySpacesAroundEquality.setSelected(mySettings.XML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE); - } - finally { - myShouldUpdatePreview = true; - updatePreview(); - } - } - - private int getIndexForWrapping() { - int wrapping = mySettings.XML_ATTRIBUTE_WRAP; - for (int i = 0; i < ourWrappings.length; i++) { - int ourWrapping = ourWrappings[i]; - if (ourWrapping == wrapping) return i; - } - LOG.assertTrue(false); - return 0; + protected void resetImpl() { + myKeepBlankLines.setText(String.valueOf(mySettings.XML_KEEP_BLANK_LINES)); + myWrapAttributes.setSelectedIndex(getIndexForWrapping(mySettings.HTML_TEXT_WRAP)); + myAlignAttributes.setSelected(mySettings.XML_ALIGN_ATTRIBUTES); + myKeepWhiteSpaces.setSelected(mySettings.XML_KEEP_WHITESPACES); + mySpacesAroundTagName.setSelected(mySettings.XML_SPACE_AROUND_TAG_NAME); + mySpacesAroundEquality.setSelected(mySettings.XML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE); } public boolean isModified(CodeStyleSettings settings) { @@ -392,7 +147,155 @@ public class CodeStyleXmlPanel { return myPanel; } - public void dispose() { - EditorFactory.getInstance().releaseEditor(myEditor); + protected String getPreviewText() { + return "\n" + + " CVS\n" + + " CVS integration\n" + + " 0.1\n" + + " IntelliJ\n" + + " \n" + + "\n" + + " \n" + + " \n" + + " com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration\n" + + " \n" + + " \n" + + " com.intellij.cvsSupport2.application.CvsEntriesManager\n" + + " \n" + + " \n" + + " com.intellij.cvsSupport2.connections.ssh.SSHPasswordProvider\n" + + " \n" + + "\n" + + " \n" + + " com.intellij.openapi.cvsIntegration.CvsServices\n" + + " com.intellij.cvsSupport2.impl.CvsServicesImpl\n" + + " \n" + + " \n" + + " com.intellij.cvsSupport2.config.ImportConfiguration\n" + + " \n" + + "\n" + + " \n" + + "\n" + + " \n" + + " \n" + + " com.intellij.cvsSupport2.config.CvsConfiguration\n" + + " \n" + + "\n" + + " \n" + + " com.intellij.cvsSupport2.CvsVcs2\n" + + " \n" + + " \n" + + " com.intellij.cvsSupport2.ui.CvsTabbedWindow\n" + + " \n" + + " \n" + + " com.intellij.cvsSupport2.application.CvsStorageSupportingDeletionComponent\n" + + " \n" + + "\n" + + " \n" + + "\n" + + "\n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + } + + protected FileType getFileType() { + return StdFileTypes.XML; } }