diff --git a/colorSchemes/src/colorSchemes/Darcula.xml b/colorSchemes/src/colorSchemes/Darcula.xml
index d23ad4939e3b..017aca7ea6f5 100644
--- a/colorSchemes/src/colorSchemes/Darcula.xml
+++ b/colorSchemes/src/colorSchemes/Darcula.xml
@@ -967,6 +967,26 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform/lang-impl/src/com/intellij/openapi/vfs/encoding/FileEncodingConfigurable.java b/platform/lang-impl/src/com/intellij/openapi/vfs/encoding/FileEncodingConfigurable.java
index 4a94cd891809..2187a429fd05 100644
--- a/platform/lang-impl/src/com/intellij/openapi/vfs/encoding/FileEncodingConfigurable.java
+++ b/platform/lang-impl/src/com/intellij/openapi/vfs/encoding/FileEncodingConfigurable.java
@@ -170,7 +170,7 @@ public class FileEncodingConfigurable implements SearchableConfigurable, Optiona
Charset ideCharset = mySelectedIdeCharset.get();
EncodingManager.getInstance().setDefaultCharsetName(ideCharset == null ? "" : ideCharset.name());
- Charset projectCharset = mySelectedIdeCharset.get();
+ Charset projectCharset = mySelectedProjectCharset.get();
EncodingProjectManager.getInstance(myProject).setEncoding(null, projectCharset);
}
diff --git a/platform/lang-impl/src/com/intellij/util/ui/tree/AbstractFileTreeTable.java b/platform/lang-impl/src/com/intellij/util/ui/tree/AbstractFileTreeTable.java
index 372645bd038d..747e8c765b75 100644
--- a/platform/lang-impl/src/com/intellij/util/ui/tree/AbstractFileTreeTable.java
+++ b/platform/lang-impl/src/com/intellij/util/ui/tree/AbstractFileTreeTable.java
@@ -164,16 +164,14 @@ public abstract class AbstractFileTreeTable extends TreeTable {
if (subdirectoryMappings.isEmpty()) {
return true;
}
- else {
- int ret = Messages.showYesNoCancelDialog(myProject, message, title, "Override", "Do Not Override", "Cancel",
- Messages.getWarningIcon());
- if (ret == 0) {
- for (VirtualFile file : subdirectoryMappings.keySet()) {
- myModel.setValueAt(null, new DefaultMutableTreeNode(file), 1);
- }
+ int ret = Messages.showYesNoCancelDialog(myProject, message, title, "Override", "Do Not Override", "Cancel",
+ Messages.getWarningIcon());
+ if (ret == 0) {
+ for (VirtualFile file : subdirectoryMappings.keySet()) {
+ myModel.setValueAt(null, new DefaultMutableTreeNode(file), 1);
}
- return ret != 2;
}
+ return ret != 2;
}
@NotNull
diff --git a/platform/platform-impl/src/com/intellij/ide/XmlRpcServerImpl.java b/platform/platform-impl/src/com/intellij/ide/XmlRpcServerImpl.java
index e09509c0009b..360bcc3d040e 100644
--- a/platform/platform-impl/src/com/intellij/ide/XmlRpcServerImpl.java
+++ b/platform/platform-impl/src/com/intellij/ide/XmlRpcServerImpl.java
@@ -100,6 +100,7 @@ public class XmlRpcServerImpl extends SimpleChannelUpstreamHandler implements Xm
public void messageReceived(ChannelHandlerContext context, MessageEvent e) throws Exception {
if (e.getMessage() instanceof HttpRequest) {
HttpRequest request = (HttpRequest)e.getMessage();
+
if (request.getMethod() == HttpMethod.POST) {
ChannelBuffer result;
ChannelBufferInputStream in = new ChannelBufferInputStream(request.getContent());
@@ -120,6 +121,15 @@ public class XmlRpcServerImpl extends SimpleChannelUpstreamHandler implements Xm
Responses.send(response, request, context);
return;
}
+
+ if (request.getMethod() == HttpMethod.OPTIONS &&
+ HttpMethod.POST.getName().equals(request.getHeader("Access-Control-Request-Method"))) {
+ HttpResponse response = Responses.create("text/plain");
+ response.setHeader("Access-Control-Allow-Origin", "*");
+ response.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
+ Responses.send(response, request, context);
+ return;
+ }
}
context.sendUpstream(e);
diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java
index 6476e9cf7349..5602538652aa 100644
--- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java
@@ -88,6 +88,7 @@ import gnu.trove.TIntArrayList;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntIntHashMap;
import org.intellij.lang.annotations.JdkConstants;
+import org.intellij.lang.annotations.MagicConstant;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -200,6 +201,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
private EditorHighlighter myHighlighter;
private final TextDrawingCallback myTextDrawingCallback = new MyTextDrawingCallback();
+ @MagicConstant(intValues = {VERTICAL_SCROLLBAR_LEFT, VERTICAL_SCROLLBAR_RIGHT})
private int myScrollBarOrientation;
private boolean myMousePressedInsideSelection;
private FontMetrics myPlainFontMetrics;
@@ -2695,6 +2697,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
myPaintSelection = paintSelection;
}
+ @Override
@NotNull
@NonNls
public String dumpState() {
@@ -4699,24 +4702,15 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
@Override
public void setVerticalScrollbarVisible(boolean b) {
- if (b) {
- myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
- }
- else {
- myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
- }
+ myScrollPane.setVerticalScrollBarPolicy(b ? ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS : ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
}
@Override
public void setHorizontalScrollbarVisible(boolean b) {
- if (b) {
- myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- }
- else {
- myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
- }
+ myScrollPane.setHorizontalScrollBarPolicy(b ? ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED : ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
}
+ @Override
public int getVerticalScrollbarOrientation() {
return myScrollBarOrientation;
}
diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java
index 57476f4c42fe..5a4ff366f932 100644
--- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java
+++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java
@@ -235,7 +235,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
String suffix = getEncodedSuffix();
int rawNameLength = o instanceof String ? ((String)o).length() : ((byte[])o).length;
int nameLength = rawNameLength + suffix.length();
- boolean appendSlash = SystemInfo.isWindows && myParent == null && suffix.length() == 0 && rawNameLength == 2 &&
+ boolean appendSlash = SystemInfo.isWindows && myParent == null && suffix.isEmpty() && rawNameLength == 2 &&
(o instanceof String ? ((String)o).charAt(1) : (char)((byte[])o)[1]) == ':';
char[] chars;
@@ -398,7 +398,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
}
private static void validateName(String name) throws IOException {
- if (name == null || name.length() == 0) throw new IOException("File name cannot be empty");
+ if (name == null || name.isEmpty()) throw new IOException("File name cannot be empty");
if (name.indexOf('/') >= 0 || name.indexOf(File.separatorChar) >= 0) {
throw new IOException("File name cannot contain file path separators: '" + name + "'");
}
@@ -419,7 +419,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
}
public void setNewName(@NotNull final String newName) {
- if (newName.length() == 0) {
+ if (newName.isEmpty()) {
throw new IllegalArgumentException("Name of the virtual file cannot be set to empty string");
}
@@ -446,37 +446,36 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
@Override
public Charset getCharset() {
+ return isCharsetSet() ? super.getCharset() : computeCharset();
+ }
+
+ private Charset computeCharset() {
Charset charset;
- if (isCharsetSet()) {
+ if (isDirectory()) {
+ Charset configured = EncodingManager.getInstance().getEncoding(this, true);
+ charset = configured == null ? Charset.defaultCharset() : configured;
+ setCharset(charset);
+ }
+ else if (SingleRootFileViewProvider.isTooLargeForContentLoading(this)) {
charset = super.getCharset();
}
else {
- if (isDirectory()) {
- Charset configured = EncodingManager.getInstance().getEncoding(this, true);
- charset = configured == null ? Charset.defaultCharset() : configured;
- setCharset(charset);
- }
- else if (SingleRootFileViewProvider.isTooLargeForContentLoading(this)) {
- charset = super.getCharset();
- }
- else {
+ try {
+ final byte[] content;
try {
- final byte[] content;
- try {
- content = contentsToByteArray();
- }
- catch (FileNotFoundException e) {
- // file has already been deleted from disk
- return super.getCharset();
- }
- charset = LoadTextUtil.detectCharsetAndSetBOM(this, content);
+ content = contentsToByteArray();
}
- catch (FileTooBigException e) {
+ catch (FileNotFoundException e) {
+ // file has already been deleted from disk
return super.getCharset();
}
- catch (IOException e) {
- throw new RuntimeException(e);
- }
+ charset = LoadTextUtil.detectCharsetAndSetBOM(this, content);
+ }
+ catch (FileTooBigException e) {
+ return super.getCharset();
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
}
}
return charset;
@@ -486,7 +485,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
public String getPresentableName() {
if (UISettings.getInstance().HIDE_KNOWN_EXTENSION_IN_TABS && !isDirectory()) {
final String nameWithoutExtension = getNameWithoutExtension();
- return nameWithoutExtension.length() == 0 ? getName() : nameWithoutExtension;
+ return nameWithoutExtension.isEmpty() ? getName() : nameWithoutExtension;
}
return getName();
}
@@ -507,12 +506,11 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
if (isSymLink()) {
return getUserData(SYMLINK_TARGET);
}
- else if (myParent != null) {
- return myParent.getCanonicalPath() + "/" + getName();
- }
- else {
- return getName();
+ VirtualDirectoryImpl parent = myParent;
+ if (parent != null) {
+ return parent.getCanonicalPath() + "/" + getName();
}
+ return getName();
}
return getPath();
}
diff --git a/platform/platform-impl/src/org/jetbrains/io/WebServer.java b/platform/platform-impl/src/org/jetbrains/io/WebServer.java
index a4689dc4fa14..39307bf48b19 100644
--- a/platform/platform-impl/src/org/jetbrains/io/WebServer.java
+++ b/platform/platform-impl/src/org/jetbrains/io/WebServer.java
@@ -352,6 +352,7 @@ public class WebServer {
HttpResponse response;
if (new QueryStringDecoder(message.getUri()).getPath().equals(START_TIME_PATH)) {
response = new DefaultHttpResponse(HTTP_1_1, OK);
+ response.setHeader("Access-Control-Allow-Origin", "*");
response.setContent(ChannelBuffers.copiedBuffer(getApplicationStartTime(), CharsetUtil.US_ASCII));
}
else {
diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java
index 3b36cdcc33a9..dd20c25fd090 100644
--- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java
+++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java
@@ -139,7 +139,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
}
}
- private static void autodetectPlatformPrefix() {
+ static void autodetectPlatformPrefix() {
if (ourPlatformPrefixInitialized) {
return;
}
@@ -785,6 +785,17 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
initPlatformPrefix(IDEA_MARKER_CLASS, "PlatformLangXml");
}
+ /**
+ * This is the main point to set up your platform prefix. This allows you to use some sub-set of
+ * core plugin descriptors to make initialization faster (e.g. for running tests in classpath of the module where the test is located).
+ * It is calculated by some marker class presence in classpath.
+ * Note that it applies NEGATIVE logic for detection: prefix will be set if only marker class
+ * is NOT present in classpath.
+ * Also, only the very FIRST call to this method will take effect.
+ *
+ * @param classToTest marker class qualified name e.g. {@link #IDEA_MARKER_CLASS}.
+ * @param prefix platform prefix to be set up if marker class not found in classpath.
+ */
public static void initPlatformPrefix(String classToTest, String prefix) {
if (!ourPlatformPrefixInitialized) {
ourPlatformPrefixInitialized = true;
@@ -801,7 +812,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
}
}
- public static void setPlatformPrefix(String prefix) {
+ private static void setPlatformPrefix(String prefix) {
System.setProperty("idea.platform.prefix", prefix);
}
diff --git a/platform/util-rt/src/com/intellij/util/containers/HashMap.java b/platform/util-rt/src/com/intellij/util/containers/HashMap.java
index 235d46edbbc8..af41488814d0 100644
--- a/platform/util-rt/src/com/intellij/util/containers/HashMap.java
+++ b/platform/util-rt/src/com/intellij/util/containers/HashMap.java
@@ -33,6 +33,7 @@ public class HashMap extends java.util.HashMap {
super(map);
}
+ @Override
public void clear() {
if (size() == 0) return; // optimization
super.clear();
diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
index cad488a0ad07..85085a37f17e 100644
--- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
@@ -1683,7 +1683,7 @@ public class StringUtil extends StringUtilRt {
}
@NotNull
- public static String doubleQuote(@NotNull String str) {
+ public static String wrapWithDoubleQuote(@NotNull String str) {
return '\"' + str + "\"";
}
diff --git a/platform/util/src/com/intellij/util/text/CharSequenceReader.java b/platform/util/src/com/intellij/util/text/CharSequenceReader.java
index c238d523e64b..e92bb6a7a140 100644
--- a/platform/util/src/com/intellij/util/text/CharSequenceReader.java
+++ b/platform/util/src/com/intellij/util/text/CharSequenceReader.java
@@ -15,6 +15,8 @@
*/
package com.intellij.util.text;
+import org.jetbrains.annotations.NotNull;
+
import java.io.Reader;
/**
@@ -24,17 +26,20 @@ public class CharSequenceReader extends Reader {
private final CharSequence myText;
private int myCurPos;
- public CharSequenceReader(final CharSequence text) {
+ public CharSequenceReader(@NotNull CharSequence text) {
myText = text;
myCurPos = 0;
}
+ @Override
public void close() {}
+ @Override
public int read(char[] cbuf, int off, int len) {
if (off < 0 || off > cbuf.length || len < 0 || off + len > cbuf.length || off + len < 0) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
+ throw new IndexOutOfBoundsException("cbuf.length="+cbuf.length+"; off="+off+"; len="+len);
+ }
+ if (len == 0) {
return 0;
}
@@ -56,6 +61,7 @@ public class CharSequenceReader extends Reader {
return charsToCopy;
}
+ @Override
public int read() {
if (myCurPos >= myText.length()) return -1;
return myText.charAt(myCurPos++);
diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java
index 03364f4df605..9cd90e1f0b0a 100644
--- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java
+++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java
@@ -25,6 +25,7 @@ import com.intellij.ide.SelectInContext;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.ide.structureView.newStructureView.StructureViewComponent;
import com.intellij.ide.util.treeView.AbstractTreeNode;
+import com.intellij.ide.util.treeView.AbstractTreeUi;
import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesUtil;
@@ -36,10 +37,7 @@ import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.CommandProcessor;
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.*;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.event.DocumentAdapter;
@@ -62,6 +60,8 @@ import com.intellij.ui.JBSplitter;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.Alarm;
import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.containers.*;
+import com.intellij.util.containers.Stack;
import com.intellij.util.ui.UIUtil;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
@@ -71,6 +71,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.TitledBorder;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -83,26 +85,32 @@ import java.util.*;
import java.util.List;
public class ResourceBundleEditor extends UserDataHolderBase implements FileEditor {
- private static final Logger LOG = Logger.getInstance("#com.intellij.lang.properties.editor.ResourceBundleEditor");
- private JPanel myPanel;
- private JPanel myValuesPanel;
- private JPanel myStructureViewPanel;
- private JPanel mySplitParent;
- private final StructureViewComponent myStructureViewComponent;
+ private static final Logger LOG =
+ Logger.getInstance("#com.intellij.lang.properties.editor.ResourceBundleEditor");
+ @NonNls private static final String VALUES = "values";
+ @NonNls private static final String NO_PROPERTY_SELECTED = "noPropertySelected";
+
+ private final StructureViewComponent myStructureViewComponent;
private final Map myEditors;
- private final ResourceBundle myResourceBundle;
+ private final ResourceBundle myResourceBundle;
private final Map myTitledPanels;
- private final JComponent myNoPropertySelectedPanel = new NoPropertySelectedPanel().getComponent();
- private final Map myDocumentListeners = new THashMap();
- private final Project myProject;
- private boolean myDisposed;
+ private final JComponent myNoPropertySelectedPanel = new NoPropertySelectedPanel().getComponent();
+ private final Map myDocumentListeners = new THashMap();
+ private final Project myProject;
private final DataProviderPanel myDataProviderPanel;
// user pressed backslash in the corresponding editor.
// we cannot store it back to properties file right now, so just append the backslash to the editor and wait for the subsequent chars
- private final Set myBackSlashPressed = new THashSet();
- @NonNls private static final String VALUES = "values";
- @NonNls private static final String NO_PROPERTY_SELECTED = "noPropertySelected";
+ private final Set myBackSlashPressed = new THashSet();
+ private final Alarm myUpdateEditorAlarm = new Alarm();
+ private final Alarm mySelectionChangeAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
+
+ private JPanel myPanel;
+ private JPanel myValuesPanel;
+ private JPanel myStructureViewPanel;
+ private JPanel mySplitParent;
+ private boolean myDisposed;
private VirtualFileListener myVfsListener;
+ private Editor mySelectedEditor;
public ResourceBundleEditor(Project project, ResourceBundle resourceBundle) {
myProject = project;
@@ -121,7 +129,8 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
// filter out temp unselect/select events
if (getSelectedPropertyName() == null) return;
if (!Comparing.strEqual(selectedPropertyName, getSelectedPropertyName())
- || !Comparing.equal(selectedPropertiesFile, getSelectedPropertiesFile())) {
+ || !Comparing.equal(selectedPropertiesFile, getSelectedPropertiesFile()))
+ {
selectedPropertyName = getSelectedPropertyName();
selectedPropertiesFile = getSelectedPropertiesFile();
selectionChanged();
@@ -141,11 +150,124 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
setState(new ResourceBundleEditorState(propName));
}
myDataProviderPanel = new DataProviderPanel(myPanel);
-
+
getSplitter().setSplitterProportionKey(getClass() + ".splitter");
+ project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
+ @Override
+ public void selectionChanged(FileEditorManagerEvent event) {
+ onSelectionChanged(event);
+ }
+ });
+ }
+
+ private void onSelectionChanged(@NotNull FileEditorManagerEvent event) {
+ // Ignore events which don't target current editor.
+ FileEditor oldEditor = event.getOldEditor();
+ FileEditor newEditor = event.getNewEditor();
+ if (oldEditor != this && newEditor != this) {
+ return;
+ }
+
+ // We want to sync selected property key on selection change.
+ if (newEditor == this) {
+ if (oldEditor instanceof TextEditor) {
+ setStructureViewSelectionFromPropertiesFile(((TextEditor)oldEditor).getEditor());
+ }
+ }
+ else if (newEditor instanceof TextEditor) {
+ setPropertiesFileSelectionFromStructureView(((TextEditor)newEditor).getEditor());
+ }
+ }
+
+ private void setStructureViewSelectionFromPropertiesFile(@NotNull Editor propertiesFileEditor) {
+ int line = propertiesFileEditor.getCaretModel().getLogicalPosition().line;
+ Document document = propertiesFileEditor.getDocument();
+ if (line >= document.getLineCount()) {
+ return;
+ }
+ final String propertyName = getPropertyName(document, line);
+ if (propertyName == null) {
+ return;
+ }
+ setStructureViewSelection(propertyName);
+ }
+
+ private void setStructureViewSelection(@NotNull final String propertyName) {
+ JTree tree = myStructureViewComponent.getTree();
+ if (tree == null) {
+ return;
+ }
+
+ Object root = tree.getModel().getRoot();
+ if (AbstractTreeUi.isLoadingChildrenFor(root)) {
+ mySelectionChangeAlarm.cancelAllRequests();
+ mySelectionChangeAlarm.addRequest(new Runnable() {
+ @Override
+ public void run() {
+ mySelectionChangeAlarm.cancelAllRequests();
+ setStructureViewSelection(propertyName);
+ }
+ }, 500);
+ return;
+ }
+
+ Stack toCheck = ContainerUtilRt.newStack();
+ toCheck.push((DefaultMutableTreeNode)root);
+ DefaultMutableTreeNode nodeToSelect = null;
+ while (!toCheck.isEmpty()) {
+ DefaultMutableTreeNode node = toCheck.pop();
+ String value = getNodeValue(node);
+ if (propertyName.equals(value)) {
+ nodeToSelect = node;
+ break;
+ }
+ else {
+ for (int i = 0; i < node.getChildCount(); i++) {
+ toCheck.push((DefaultMutableTreeNode)node.getChildAt(i));
+ }
+ }
+ }
+ if (nodeToSelect != null) {
+ tree.setSelectionPath(new TreePath(nodeToSelect.getPath()));
+ }
+ }
+
+ @Nullable
+ private static String getPropertyName(@NotNull Document document, int line) {
+ int startOffset = document.getLineStartOffset(line);
+ int endOffset = StringUtil.indexOf(document.getCharsSequence(), '=', startOffset, document.getLineEndOffset(line));
+ if (endOffset <= startOffset) {
+ return null;
+ }
+ String propertyName = document.getCharsSequence().subSequence(startOffset, endOffset).toString().trim();
+ return propertyName.isEmpty() ? null : propertyName;
+ }
+
+ private void setPropertiesFileSelectionFromStructureView(@NotNull Editor propertiesFileEditor) {
+ String selectedPropertyName = getSelectedPropertyName();
+ if (selectedPropertyName == null) {
+ return;
+ }
+
+ Document document = propertiesFileEditor.getDocument();
+ for (int i = 0; i < document.getLineCount(); i++) {
+ String propertyName = getPropertyName(document, i);
+ if (selectedPropertyName.equals(propertyName)) {
+ propertiesFileEditor.getCaretModel().moveToLogicalPosition(new LogicalPosition(i, 0));
+ return;
+ }
+ }
+ }
+
+ @Nullable
+ private static String getNodeValue(@NotNull DefaultMutableTreeNode node) {
+ Object userObject = node.getUserObject();
+ if (!(userObject instanceof AbstractTreeNode)) return null;
+ Object value = ((AbstractTreeNode)userObject).getValue();
+ return value instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement)value).getValue()
+ : null;
}
- private Editor mySelectedEditor;
private void recreateEditorsPanel() {
myUpdateEditorAlarm.cancelAllRequests();
@@ -296,8 +418,6 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
};
PsiManager.getInstance(myProject).addPsiTreeChangeListener(psiTreeChangeAdapter, this);
}
-
- private final Alarm myUpdateEditorAlarm = new Alarm();
private void selectionChanged() {
myBackSlashPressed.clear();
UIUtil.invokeLaterIfNeeded(new Runnable() {
@@ -475,11 +595,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
if (tree == null) return null;
TreePath selected = tree.getSelectionModel().getSelectionPath();
if (selected == null) return null;
- DefaultMutableTreeNode node = (DefaultMutableTreeNode)selected.getLastPathComponent();
- Object userObject = node.getUserObject();
- if (!(userObject instanceof AbstractTreeNode)) return null;
- Object value = ((AbstractTreeNode)userObject).getValue();
- return value instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement)value).getValue() : null;
+ return getNodeValue((DefaultMutableTreeNode)selected.getLastPathComponent());
}
@NotNull
diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java
index 56d627edadcd..43a7a016b686 100644
--- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java
+++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java
@@ -132,7 +132,7 @@ public abstract class InputExpressionDialog extends
myComboBox.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, HistoryElement value, int index, boolean selected, boolean hasFocus) {
- setText(value.expression);
+ setText(value != null ? value.expression : "");
}
});
myComboBox.setModel(myModel);
diff --git a/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java b/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java
index 87717f089698..4be0765bfedd 100644
--- a/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java
+++ b/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java
@@ -78,7 +78,7 @@ public class HtmlStructureViewElementProvider implements XmlStructureViewElement
}
private static String shortenTextIfLong(final String text) {
- if (text.length() < MAX_TEXT_LENGTH) return text;
+ if (text.length() <= MAX_TEXT_LENGTH) return text;
int index;
for (index = MAX_TEXT_LENGTH; index > MAX_TEXT_LENGTH - 20; index--) {