mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote branch 'origin/master'
This commit is contained in:
@@ -967,6 +967,26 @@
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="Implicit conversion first part">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="1a5746" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="-1" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="Implicit conversion second part">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="1e7866" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="-1" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INCLUDE_JAVA_CALL">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="f7b891" />
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,16 +164,14 @@ public abstract class AbstractFileTreeTable<T> 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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+30
-32
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ public class HashMap<K, V> extends java.util.HashMap<K, V> {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (size() == 0) return; // optimization
|
||||
super.clear();
|
||||
|
||||
@@ -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 + "\"";
|
||||
}
|
||||
|
||||
|
||||
@@ -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++);
|
||||
|
||||
+144
-28
@@ -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<PropertiesFile, Editor> myEditors;
|
||||
private final ResourceBundle myResourceBundle;
|
||||
private final ResourceBundle myResourceBundle;
|
||||
private final Map<PropertiesFile, JPanel> myTitledPanels;
|
||||
private final JComponent myNoPropertySelectedPanel = new NoPropertySelectedPanel().getComponent();
|
||||
private final Map<Editor, DocumentListener> myDocumentListeners = new THashMap<Editor, DocumentListener>();
|
||||
private final Project myProject;
|
||||
private boolean myDisposed;
|
||||
private final JComponent myNoPropertySelectedPanel = new NoPropertySelectedPanel().getComponent();
|
||||
private final Map<Editor, DocumentListener> myDocumentListeners = new THashMap<Editor, DocumentListener>();
|
||||
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<PropertiesFile> myBackSlashPressed = new THashSet<PropertiesFile>();
|
||||
@NonNls private static final String VALUES = "values";
|
||||
@NonNls private static final String NO_PROPERTY_SELECTED = "noPropertySelected";
|
||||
private final Set<PropertiesFile> myBackSlashPressed = new THashSet<PropertiesFile>();
|
||||
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<DefaultMutableTreeNode> 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
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ public abstract class InputExpressionDialog<FormType extends InputForm> extends
|
||||
myComboBox.setRenderer(new ListCellRendererWrapper<HistoryElement>() {
|
||||
@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);
|
||||
|
||||
@@ -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--) {
|
||||
|
||||
Reference in New Issue
Block a user