From 041141266cfe4a22fd8f15c14da9f861d36d617e Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 10 Nov 2009 14:19:24 +0300 Subject: [PATCH] psiViewer completely rewritten --- .../intellij/internal/psiView/PsiViewerDialog.form | 88 +++-- .../intellij/internal/psiView/PsiViewerDialog.java | 431 +++++++++++++-------- .../internal/psiView/PsiViewerSettings.java | 47 +++ resources/src/META-INF/IdeaPlugin.xml | 2 + 4 files changed, 380 insertions(+), 188 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerSettings.java diff --git a/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.form b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.form index 037b6456ba..769c404b9c 100644 --- a/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.form +++ b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.form @@ -1,40 +1,22 @@
- + - + - - - - - - - - - - - - - - - - - - - - + + @@ -44,8 +26,10 @@ - - + + + + @@ -64,6 +48,7 @@ + @@ -72,8 +57,10 @@ - - + + + + @@ -81,8 +68,10 @@ - - + + + + @@ -91,43 +80,68 @@ - + - + - + + + - + - + + + - + - + - + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java index ff785b0c56..a3d85e0a96 100644 --- a/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java +++ b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java @@ -13,24 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * class PsiViewerDialog - * created Aug 25, 2001 - * @author Jeka - */ package com.intellij.internal.psiView; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.lang.LanguageUtil; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.actionSystem.ex.ComboBoxAction; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.editor.markup.HighlighterLayer; -import com.intellij.openapi.editor.markup.HighlighterTargetArea; -import com.intellij.openapi.editor.markup.RangeHighlighter; -import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.editor.ScrollType; +import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.*; import com.intellij.openapi.fileTypes.impl.AbstractFileType; @@ -38,7 +36,9 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; @@ -46,13 +46,18 @@ import com.intellij.psi.PsiReference; import com.intellij.psi.search.FilenameIndex; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.ui.SortedComboBoxModel; +import com.intellij.ui.TitledBorderWithMnemonic; import com.intellij.ui.TreeSpeedSearch; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.IncorrectOperationException; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; @@ -63,9 +68,10 @@ import java.awt.event.*; import java.util.*; import java.util.List; +/** + * @author Konstantin Bulenkov + */ public class PsiViewerDialog extends DialogWrapper { - private static final Object EXTENSION_KEY = new Object(); - private final Project myProject; private final Tree myTree; @@ -76,20 +82,19 @@ public class PsiViewerDialog extends DialogWrapper { private Editor myEditor; private String myLastParsedText = null; - private List myExtensionButtons = new ArrayList(); - private JRadioButton[] myFileTypeButtons; - private FileType[] myFileTypes; - private JCheckBox myShowWhiteSpacesBox; private JPanel myStructureTreePanel; private JPanel myTextPanel; private JPanel myPanel; - private JPanel myChoicesPanel; private JCheckBox myShowTreeNodesCheckBox; private JComboBox myDialectsComboBox; private JPanel myReferencesPanel; + private JPanel myButtonPanel; + private Presentation myPresentation = new Presentation(); + private Map handlers = new HashMap(); + private DefaultActionGroup myGroup; - public PsiViewerDialog(Project project,boolean modal) { + public PsiViewerDialog(Project project, boolean modal) { super(project, true); setTitle("PSI Viewer"); myProject = project; @@ -117,16 +122,17 @@ public class PsiViewerDialog extends DialogWrapper { refPanel.add(refScrollPane, BorderLayout.CENTER); myReferencesPanel.setLayout(new BorderLayout()); myReferencesPanel.add(refPanel, BorderLayout.CENTER); - final GoToListener listener = new GoToListener(myRefs, project); + final GoToListener listener = new GoToListener(); myRefs.addKeyListener(listener); myRefs.addMouseListener(listener); + myRefs.getSelectionModel().addListSelectionListener(listener); setModal(modal); setOKButtonText("&Build PSI Tree"); init(); } - protected String getDimensionServiceKey(){ + protected String getDimensionServiceKey() { return "#com.intellij.internal.psiView.PsiViewerDialog"; } @@ -134,69 +140,51 @@ public class PsiViewerDialog extends DialogWrapper { return myEditor.getContentComponent(); } + private void updatePresentation(Presentation p) { + myPresentation.setText(p.getText()); + myPresentation.setIcon(p.getIcon()); + } + protected void init() { - EditorFactory editorFactory = EditorFactory.getInstance(); - Document document = editorFactory.createDocument(""); + initBorders(); + final List items = new ArrayList(); + final EditorFactory editorFactory = EditorFactory.getInstance(); + final Document document = editorFactory.createDocument(""); myEditor = editorFactory.createEditor(document, myProject); myEditor.getSettings().setFoldingOutlineShown(false); - for(PsiViewerExtension extension: Extensions.getExtensions(PsiViewerExtension.EP_NAME)) { - JRadioButton button = new JRadioButton(extension.getName()); - button.putClientProperty(EXTENSION_KEY, extension); - myExtensionButtons.add(button); + for (PsiViewerExtension extension : Extensions.getExtensions(PsiViewerExtension.EP_NAME)) { + final Presentation p = new Presentation(extension.getName()); + p.setIcon(extension.getIcon()); + handlers.put(p.getText(), extension); + items.add(p); } - - FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); - Arrays.sort(fileTypes,new Comparator() { - public int compare(final FileType o1, final FileType o2) { - return o1.getName().compareTo(o2.getName()); - } - }); - - List customFileTypes = new ArrayList(); - - for (FileType fileType : fileTypes) { - if (fileType != StdFileTypes.GUI_DESIGNER_FORM && fileType != StdFileTypes.IDEA_MODULE && fileType != StdFileTypes.IDEA_PROJECT && - fileType != StdFileTypes.IDEA_WORKSPACE && fileType != FileTypes.ARCHIVE && fileType != FileTypes.UNKNOWN && - fileType != FileTypes.PLAIN_TEXT && !(fileType instanceof AbstractFileType) && !fileType.isBinary() && !fileType.isReadOnly()) { - customFileTypes.add(fileType); + for (FileType fileType : FileTypeManager.getInstance().getRegisteredFileTypes()) { + if (fileType != StdFileTypes.GUI_DESIGNER_FORM && + fileType != StdFileTypes.IDEA_MODULE && + fileType != StdFileTypes.IDEA_PROJECT && + fileType != StdFileTypes.IDEA_WORKSPACE && + fileType != FileTypes.ARCHIVE && + fileType != FileTypes.UNKNOWN && + fileType != FileTypes.PLAIN_TEXT && + !(fileType instanceof AbstractFileType) && + !fileType.isBinary() && + !fileType.isReadOnly()) { + final Presentation p = new Presentation(fileType.getName() + " file"); + p.setIcon(fileType.getIcon()); + handlers.put(p.getText(), fileType); + items.add(p); } } - myFileTypes = customFileTypes.toArray(new FileType[customFileTypes.size()]); - myFileTypeButtons = new JRadioButton[myFileTypes.length]; - - ButtonGroup bg = new ButtonGroup(); - for (JRadioButton button : myExtensionButtons) { - bg.add(button); - } - - final int rows = 1 + myFileTypes.length / 7; - JPanel choicesBox = new JPanel(new GridLayout(rows, 7)); - - for (JRadioButton extensionButton : myExtensionButtons) { - choicesBox.add(extensionButton); - } - - for (int i = 0; i < myFileTypes.length; i++) { - FileType fileType = myFileTypes[i]; - JRadioButton button = new JRadioButton(fileType.getName()+" file"); - bg.add(button); - choicesBox.add(button); - myFileTypeButtons[i] = button; - } - - final ActionListener updateDialectsListener = new ActionListener() { - public void actionPerformed(final ActionEvent e) { - updateDialectsCombo(); + final Presentation[] popupItems = items.toArray(new Presentation[items.size()]); + Arrays.sort(popupItems, new Comparator() { + public int compare(Presentation p1, Presentation p2) { + return p1.getText().toUpperCase().compareTo(p2.getText().toUpperCase()); } - }; - final Enumeration buttonEnum = bg.getElements(); - while (buttonEnum.hasMoreElements()) { - buttonEnum.nextElement().addActionListener(updateDialectsListener); - } - updateDialectsCombo(); + }); + myDialectsComboBox.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(final JList list, @@ -210,54 +198,130 @@ public class PsiViewerDialog extends DialogWrapper { } }); - if (myExtensionButtons.size() > 0) { - myExtensionButtons.get(0).setSelected(true); - } - else { - myFileTypeButtons [0].setSelected(true); - } - - myChoicesPanel.setLayout(new BorderLayout()); - myChoicesPanel.add(choicesBox, BorderLayout.CENTER); - final ViewerTreeStructure treeStructure = (ViewerTreeStructure)myTreeBuilder.getTreeStructure(); myShowWhiteSpacesBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { treeStructure.setShowWhiteSpaces(myShowWhiteSpacesBox.isSelected()); - myTreeBuilder.updateFromRoot(); + myTreeBuilder.queueUpdate(); } }); myShowTreeNodesCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { treeStructure.setShowTreeNodes(myShowTreeNodesCheckBox.isSelected()); - myTreeBuilder.updateFromRoot(); + myTreeBuilder.queueUpdate(); } }); myTextPanel.setLayout(new BorderLayout()); myTextPanel.add(myEditor.getComponent(), BorderLayout.CENTER); + myGroup = new DefaultActionGroup(); + for (final Presentation popupItem : popupItems) { + myGroup.add(new AnAction(popupItem.getText(), popupItem.getText(), popupItem.getIcon()) { + public void actionPerformed(AnActionEvent e) { + updatePresentation(e.getPresentation()); + } + }); + } + + final PsiViewerSettings settings = PsiViewerSettings.getSettings(); + final String type = settings.type; + for (Presentation popupItem : popupItems) { + if (popupItem.getText().equals(type)) { + updatePresentation(popupItem); + break; + } + } + + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + myEditor.getDocument().setText(settings.text); + } + }); + + myShowWhiteSpacesBox.setSelected(settings.showWhiteSpaces); + myShowTreeNodesCheckBox.setSelected(settings.showTreeNodes); + + final ChoosePsiTypeButton typeButton = new ChoosePsiTypeButton(); + myButtonPanel.add(typeButton.createCustomComponent(myPresentation), BorderLayout.CENTER); + + updateDialectsCombo(); + + final Component component = myButtonPanel.getComponents()[0]; + if (component instanceof JComponent) { + final Component button = ((JComponent)component).getComponents()[0]; + if (button instanceof JButton) { + final JButton jButton = (JButton)button; + final int mask = SystemInfo.isMac ? KeyEvent.META_DOWN_MASK : KeyEvent.ALT_DOWN_MASK; + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + jButton.doClick(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_P, mask), JComponent.WHEN_IN_FOCUSED_WINDOW); + + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + IdeFocusManager.getInstance(myProject).requestFocus(myEditor.getContentComponent(), true); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_T, mask), JComponent.WHEN_IN_FOCUSED_WINDOW); + + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + IdeFocusManager.getInstance(myProject).requestFocus(myTree, true); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_S, mask), JComponent.WHEN_IN_FOCUSED_WINDOW); + + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + IdeFocusManager.getInstance(myProject).requestFocus(myRefs, true); + if (myRefs.getModel().getSize() > 0) { + if (myRefs.getSelectedIndex() == -1) { + myRefs.setSelectedIndex(0); + } + } + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_R, mask), JComponent.WHEN_IN_FOCUSED_WINDOW); + + + } + } super.init(); } + private void initBorders() { + myTextPanel.setBorder(new TitledBorderWithMnemonic("&Text")); + myStructureTreePanel.setBorder(new TitledBorderWithMnemonic("PSI &Structure")); + myReferencesPanel.setBorder(new TitledBorderWithMnemonic("&References")); + } + + @Nullable + private PsiElement getPsiElement() { + TreePath path = myTree.getSelectionPath(); + if (path != null) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); + if (node.getUserObject() instanceof ViewerNodeDescriptor) { + ViewerNodeDescriptor descriptor = (ViewerNodeDescriptor)node.getUserObject(); + Object elementObject = descriptor.getElement(); + return elementObject instanceof PsiElement + ? (PsiElement)elementObject + : elementObject instanceof ASTNode ? ((ASTNode)elementObject).getPsi() : null; + } + } + return null; + } + private void updateDialectsCombo() { final SortedComboBoxModel model = new SortedComboBoxModel(new Comparator() { public int compare(final Language o1, final Language o2) { - if (o1 == null) return o2 == null? 0 : -1; + if (o1 == null) return o2 == null ? 0 : -1; if (o2 == null) return 1; return o1.getID().compareTo(o2.getID()); } }); - for (int i = 0; i < myFileTypeButtons.length; i++) { - JRadioButton fileTypeButton = myFileTypeButtons[i]; - if (fileTypeButton.isSelected()) { - final FileType type = myFileTypes[i]; - if (type instanceof LanguageFileType) { - final Language baseLang = ((LanguageFileType)type).getLanguage(); - model.setAll(LanguageUtil.getLanguageDialects(baseLang)); - model.add(null); - } - break; - } + final Object handler = getHandler(); + if (handler instanceof LanguageFileType) { + final Language baseLang = ((LanguageFileType)handler).getLanguage(); + model.setAll(LanguageUtil.getLanguageDialects(baseLang)); + model.add(null); } myDialectsComboBox.setModel(model); myDialectsComboBox.setVisible(model.getSize() > 1); @@ -267,51 +331,45 @@ public class PsiViewerDialog extends DialogWrapper { return myPanel; } + private Object getHandler() { + return handlers.get(myPresentation.getText()); + } + protected void doOKAction() { final String text = myEditor.getDocument().getText(); - if ("".equals(text.trim())) { - return; - } + if (text.trim().length() == 0) return; + myLastParsedText = text; PsiElement rootElement = null; + final Object handler = getHandler(); + try { - for (JRadioButton button : myExtensionButtons) { - if (button.isSelected()) { - PsiViewerExtension ext = (PsiViewerExtension) button.getClientProperty(EXTENSION_KEY); - rootElement = ext.createElement(myProject, text); - } + if (handler instanceof PsiViewerExtension) { + final PsiViewerExtension ext = (PsiViewerExtension)handler; + rootElement = ext.createElement(myProject, text); } - if (rootElement == null) { - for (int i = 0; i < myFileTypeButtons.length; i++) { - JRadioButton fileTypeButton = myFileTypeButtons[i]; - - if (fileTypeButton.isSelected()) { - final FileType type = myFileTypes[i]; - if (type instanceof LanguageFileType) { - final Language language = ((LanguageFileType)type).getLanguage(); - final Language dialect = (Language)myDialectsComboBox.getSelectedItem(); - rootElement = PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + type.getDefaultExtension(), dialect == null? language : dialect, text); - } - else { - rootElement = PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + type.getDefaultExtension(), text); - } - } + else if (handler instanceof FileType) { + final FileType type = (FileType)handler; + if (type instanceof LanguageFileType) { + final Language language = ((LanguageFileType)type).getLanguage(); + final Language dialect = (Language)myDialectsComboBox.getSelectedItem(); + rootElement = PsiFileFactory.getInstance(myProject) + .createFileFromText("Dummy." + type.getDefaultExtension(), dialect == null ? language : dialect, text); + } + else { + rootElement = PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + type.getDefaultExtension(), text); } } + IdeFocusManager.getInstance(myProject).requestFocus(myTree, true); } catch (IncorrectOperationException e1) { rootElement = null; - Messages.showMessageDialog( - myProject, - e1.getMessage(), - "Error", - Messages.getErrorIcon() - ); + Messages.showMessageDialog(myProject, e1.getMessage(), "Error", Messages.getErrorIcon()); } ViewerTreeStructure structure = (ViewerTreeStructure)myTreeBuilder.getTreeStructure(); structure.setRootPsiElement(rootElement); - myTreeBuilder.updateFromRoot(); + myTreeBuilder.queueUpdate(); myTree.setRootVisible(true); myTree.expandRow(0); myTree.setRootVisible(false); @@ -319,7 +377,6 @@ public class PsiViewerDialog extends DialogWrapper { private class MyTreeSelectionListener implements TreeSelectionListener { private final TextAttributes myAttributes; - private RangeHighlighter myHighlighter; public MyTreeSelectionListener() { myAttributes = new TextAttributes(); @@ -330,17 +387,18 @@ public class PsiViewerDialog extends DialogWrapper { public void valueChanged(TreeSelectionEvent e) { if (!myEditor.getDocument().getText().equals(myLastParsedText)) return; TreePath path = myTree.getSelectionPath(); - if (path == null){ + if (path == null) { clearSelection(); } - else{ + else { clearSelection(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); if (!(node.getUserObject() instanceof ViewerNodeDescriptor)) return; ViewerNodeDescriptor descriptor = (ViewerNodeDescriptor)node.getUserObject(); Object elementObject = descriptor.getElement(); - final PsiElement element = elementObject instanceof PsiElement? (PsiElement)elementObject : - elementObject instanceof ASTNode ? ((ASTNode)elementObject).getPsi() : null; + final PsiElement element = elementObject instanceof PsiElement + ? (PsiElement)elementObject + : elementObject instanceof ASTNode ? ((ASTNode)elementObject).getPsi() : null; if (element != null) { TextRange range = element.getTextRange(); int start = range.getStartOffset(); @@ -355,7 +413,10 @@ public class PsiViewerDialog extends DialogWrapper { final int textLength = myEditor.getDocument().getTextLength(); if (end <= textLength) { - myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.FIRST + 1, myAttributes, HighlighterTargetArea.EXACT_RANGE); + myEditor.getMarkupModel() + .addRangeHighlighter(start, end, HighlighterLayer.FIRST + 1, myAttributes, HighlighterTargetArea.EXACT_RANGE); + myEditor.getCaretModel().moveToOffset(start); + myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); } updateReferences(element); } @@ -369,17 +430,23 @@ public class PsiViewerDialog extends DialogWrapper { for (PsiReference reference : element.getReferences()) { model.addElement(reference.getClass().getName()); } - } + } } private void clearSelection() { - if (myHighlighter != null) { - myEditor.getMarkupModel().removeHighlighter(myHighlighter); - myHighlighter = null; - } + myEditor.getMarkupModel().removeAllHighlighters(); } } + public void doCancelAction() { + final PsiViewerSettings settings = PsiViewerSettings.getSettings(); + settings.type = myPresentation.getText(); + settings.text = myEditor.getDocument().getText(); + settings.showTreeNodes = myShowTreeNodesCheckBox.isSelected(); + settings.showWhiteSpaces = myShowWhiteSpacesBox.isSelected(); + super.doCancelAction(); + } + public void dispose() { Disposer.dispose(myTreeBuilder); EditorFactory.getInstance().releaseEditor(myEditor); @@ -387,17 +454,33 @@ public class PsiViewerDialog extends DialogWrapper { super.dispose(); } - private static class GoToListener implements KeyListener, MouseListener { - private final JList myList; - private final Project myProject; + private class ChoosePsiTypeButton extends ComboBoxAction { + protected int getMaxRows() { + return 15; + } - public GoToListener(JList list, Project project) { - myList = list; - myProject = project; + protected int getMinWidth() { + return 150; } + protected int getMinHeight() { + return 200; + } + + @NotNull + protected DefaultActionGroup createPopupActionGroup(JComponent button) { + return myGroup; + } + } + + private class GoToListener implements KeyListener, MouseListener, ListSelectionListener { + private RangeHighlighter myHighlighter; + private final TextAttributes myAttributes = + new TextAttributes(Color.white, new Color(0, 0, 128), Color.red, EffectType.BOXED, Font.PLAIN); + private void navigate() { - final Object value = myList.getSelectedValue(); + clearSelection(); + final Object value = myRefs.getSelectedValue(); if (value instanceof String) { final String fqn = (String)value; String filename = fqn; @@ -427,11 +510,57 @@ public class PsiViewerDialog extends DialogWrapper { } } - public void keyTyped(KeyEvent e) {} - public void keyReleased(KeyEvent e) {} - public void mousePressed(MouseEvent e) {} - public void mouseReleased(MouseEvent e) {} - public void mouseEntered(MouseEvent e) {} - public void mouseExited(MouseEvent e) {} + public void valueChanged(ListSelectionEvent e) { + clearSelection(); + updateDialectsCombo(); + final int ind = myRefs.getSelectedIndex(); + final PsiElement element = getPsiElement(); + if (ind > -1 && element != null) { + final PsiReference[] references = element.getReferences(); + if (ind < references.length) { + final TextRange textRange = references[ind].getRangeInElement(); + TextRange range = element.getTextRange(); + int start = range.getStartOffset(); + int end = range.getEndOffset(); + final ViewerTreeStructure treeStructure = (ViewerTreeStructure)myTreeBuilder.getTreeStructure(); + PsiElement rootPsiElement = treeStructure.getRootPsiElement(); + if (rootPsiElement != null) { + int baseOffset = rootPsiElement.getTextRange().getStartOffset(); + start -= baseOffset; + end -= baseOffset; + } + + start += textRange.getStartOffset(); + end = start + textRange.getLength(); + myHighlighter = myEditor.getMarkupModel() + .addRangeHighlighter(start, end, HighlighterLayer.FIRST + 1, myAttributes, HighlighterTargetArea.EXACT_RANGE); + } + } + } + + public void clearSelection() { + if (myHighlighter != null && Arrays.asList(myEditor.getMarkupModel().getAllHighlighters()).contains(myHighlighter)) { + myEditor.getMarkupModel().removeHighlighter(myHighlighter); + myHighlighter = null; + } + } + + public void keyTyped(KeyEvent e) { + } + + public void keyReleased(KeyEvent e) { + } + + public void mousePressed(MouseEvent e) { + } + + public void mouseReleased(MouseEvent e) { + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } } } diff --git a/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerSettings.java b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerSettings.java new file mode 100644 index 0000000000..7ae4cfd055 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerSettings.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2009 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.internal.psiView; + +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.util.xmlb.XmlSerializerUtil; + +/** + * @author Konstantin Bulenkov + */ +@State( + name = "PsiViewerSettings", + storages = {@Storage(id = "other",file = "$APP_CONFIG$/other.xml")}) +public class PsiViewerSettings implements PersistentStateComponent { + public boolean showWhiteSpaces = true; + public boolean showTreeNodes = true; + public String type = "JAVA file"; + public String text = ""; + + public static PsiViewerSettings getSettings() { + return ServiceManager.getService(PsiViewerSettings.class); + } + + public PsiViewerSettings getState() { + return this; + } + + public void loadState(PsiViewerSettings state) { + XmlSerializerUtil.copyBean(state, this); + } +} diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 4101d1fb34..dac264652e 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -295,6 +295,8 @@ + -- 2.11.4.GIT