diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java
index 1c8c9c4f8613..f36da9923d22 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java
@@ -65,6 +65,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
final boolean needLeftParenth = isToInsertParenth(context, item);
final boolean hasParams = needLeftParenth && hasParams(context, item);
+ final boolean annotation = insertingAnnotation(context, item);
if (CompletionUtil.isOverwrite(item, completionChar)) {
removeEndOfIdentifier(needLeftParenth && hasParams, context);
@@ -114,7 +115,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
});
}
- if (insertingAnnotation(context, item)) {
+ if (annotation) {
// Check if someone inserts annotation class that require @
PsiElement elementAt = file.findElementAt(context.getStartOffset());
final PsiElement parentElement = elementAt != null ? elementAt.getParent():null;
diff --git a/platform/lang-api/src/com/intellij/psi/ReferenceRange.java b/platform/lang-api/src/com/intellij/psi/ReferenceRange.java
index f079c906fdfd..2ac202ecb1ae 100644
--- a/platform/lang-api/src/com/intellij/psi/ReferenceRange.java
+++ b/platform/lang-api/src/com/intellij/psi/ReferenceRange.java
@@ -59,12 +59,12 @@ public class ReferenceRange {
public static boolean containsOffsetInElement(PsiReference ref, int offset) {
if (ref instanceof MultiRangeReference) {
for (TextRange range : ((MultiRangeReference)ref).getRanges()) {
- if (range.contains(offset)) return true;
+ if (range.containsOffset(offset)) return true;
}
return false;
}
- return ref.getRangeInElement().contains(offset);
+ return ref.getRangeInElement().containsOffset(offset);
}
public static boolean containsRangeInElement(PsiReference ref, TextRange rangeInElement) {
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java
index 952d526dfe78..924ed2bd50d0 100644
--- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java
@@ -402,7 +402,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
LOG.assertTrue(fileCopy.findElementAt(offset) == insertedElement, "wrong offset");
final TextRange range = insertedElement.getTextRange();
- LOG.assertTrue(range.substring(fileCopy.getText()).equals(insertedElement.getText()), "wrong text");
+ if (!range.substring(fileCopy.getText()).equals(insertedElement.getText())) {
+ LOG.error("wrong text: copy='" + fileCopy.getText() + "'; element='" + insertedElement.getText() + "'");
+ }
return new CompletionParameters(insertedElement, fileCopy.getOriginalFile(), myCompletionType, offset, invocationCount);
}
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
index 1098fcf0f15a..de32ec8550c1 100644
--- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
@@ -273,7 +273,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
private boolean isOutdated() {
if (!myDisposed) {
- LOG.assertTrue(this == CompletionServiceImpl.getCompletionService().getCurrentCompletion());
+ CompletionProgressIndicator current = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
+ LOG.assertTrue(this == current, current);
}
return myDisposed || myEditor.isDisposed() || getProject().isDisposed();
}
@@ -391,10 +392,14 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
myLookup.show();
+ //todo remove these assertions before X release
+ if (!ApplicationManager.getApplication().isUnitTestMode()) {
+ LOG.assertTrue(myLookup.isVisible());
+ }
}
myLookup.refreshUi();
if (!ApplicationManager.getApplication().isUnitTestMode()) {
- LOG.assertTrue(myLookup.isVisible());
+ LOG.assertTrue(myLookup.isVisible(), "really?");
}
hideAutopopupIfMeaningless();
}
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/FoldingActionGroup.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/FoldingActionGroup.java
deleted file mode 100644
index 1a139fcb1870..000000000000
--- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/FoldingActionGroup.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.codeInsight.folding.impl.actions;
-
-import com.intellij.openapi.actionSystem.*;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.ex.FoldingModelEx;
-import com.intellij.openapi.project.DumbAware;
-
-public class FoldingActionGroup extends DefaultActionGroup implements DumbAware {
- public FoldingActionGroup() {
- super();
- }
-
- public void update(AnActionEvent event){
- Presentation presentation = event.getPresentation();
- DataContext dataContext = event.getDataContext();
-
- Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
- if (editor == null){
- presentation.setVisible(false);
- return;
- }
-
- FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel();
- presentation.setVisible(foldingModel.isFoldingEnabled());
- }
-}
\ No newline at end of file
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java
index 7c5a9fdf31fc..f9761622f173 100644
--- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java
@@ -476,7 +476,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
JComponent internalComponent = myEditor.getContentComponent();
final JRootPane rootPane = editorComponent.getRootPane();
if (rootPane == null) {
- LOG.error(myArranger);
+ LOG.error(myArranger + "; " + myEditor.isDisposed());
}
JLayeredPane layeredPane = rootPane.getLayeredPane();
Point layeredPanePoint=SwingUtilities.convertPoint(internalComponent,location, layeredPane);
@@ -712,6 +712,9 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
public Rectangle getCurrentItemBounds(){
int index = myList.getSelectedIndex();
+ if (index < 0) {
+ LOG.error("No selected element, size=" + myList.getModel().getSize() + "; items" + getItems());
+ }
Rectangle itmBounds = myList.getCellBounds(index, index);
if (itmBounds == null){
LOG.error("No bounds for " + index + "; size=" + myList.getModel().getSize());
diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java
index 4b9a4b34f958..bc2768702e63 100644
--- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java
+++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java
@@ -369,14 +369,19 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
//offset can be changed after text trimming after insert due to buffer constraints
appendToHistoryDocument(history, text);
int offset = history.getTextLength() - text.length();
- final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(0);
+ final int localStartOffset = textRange.getStartOffset();
+ final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(localStartOffset);
+ final int localEndOffset = textRange.getEndOffset();
while (!iterator.atEnd()) {
- final int localOffset = textRange.getStartOffset();
- final int start = Math.max(iterator.getStart(), localOffset) - localOffset;
- final int end = Math.min(iterator.getEnd(), textRange.getEndOffset()) - localOffset;
- markupModel.addRangeHighlighter(start + offset, end + offset, HighlighterLayer.SYNTAX, iterator.getTextAttributes(),
- HighlighterTargetArea.EXACT_RANGE);
-
+ final int itStart = iterator.getStart();
+ if (itStart > localEndOffset) break;
+ final int itEnd = iterator.getEnd();
+ if (itEnd >= localStartOffset) {
+ final int start = Math.max(itStart, localStartOffset) - localStartOffset + offset;
+ final int end = Math.min(itEnd, localEndOffset) - localStartOffset + offset;
+ markupModel.addRangeHighlighter(start, end, HighlighterLayer.SYNTAX, iterator.getTextAttributes(),
+ HighlighterTargetArea.EXACT_RANGE);
+ }
iterator.advance();
}
if (myDoSaveErrorsToHistory) {
diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/actions/ProjectViewActionGroup.java b/platform/lang-impl/src/com/intellij/ide/projectView/actions/ProjectViewActionGroup.java
deleted file mode 100644
index f34fcf03bcbb..000000000000
--- a/platform/lang-impl/src/com/intellij/ide/projectView/actions/ProjectViewActionGroup.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.ide.projectView.actions;
-
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DefaultActionGroup;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
-import com.intellij.openapi.actionSystem.Presentation;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.wm.ToolWindowId;
-import com.intellij.openapi.wm.ToolWindowManager;
-
-public final class ProjectViewActionGroup extends DefaultActionGroup {
- public ProjectViewActionGroup() {
- super();
- }
-
- public void update(AnActionEvent event){
- Presentation presentation = event.getPresentation();
- Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
- if (project == null) {
- presentation.setVisible(false);
- return;
- }
- String id = ToolWindowManager.getInstance(project).getActiveToolWindowId();
- boolean isProjectViewActive = ToolWindowId.PROJECT_VIEW.equals(id);
- presentation.setVisible(isProjectViewActive);
- }
-}
\ No newline at end of file
diff --git a/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java b/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java
index 495501a1e9b2..19e00da24583 100644
--- a/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java
+++ b/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java
@@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.impl.light.LightElement;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.impl.source.PsiFileWithStubSupport;
+import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubTree;
@@ -65,7 +66,7 @@ public abstract class PsiAnchor {
final StubBasedPsiElement elt = (StubBasedPsiElement)element;
if (elt.getStub() != null || elt.getElementType().shouldCreateStub(element.getNode())) {
int index = calcStubIndex((StubBasedPsiElement)element);
- if (index != -1) return new StubIndexReference(file, index);
+ if (index != -1) return new StubIndexReference(file, index, elt.getElementType());
}
}
@@ -220,8 +221,10 @@ public abstract class PsiAnchor {
private final VirtualFile myVirtualFile;
private final Project myProject;
private final int myIndex;
+ private final IStubElementType myElementType;
- public StubIndexReference(@NotNull PsiFile file, final int index) {
+ public StubIndexReference(@NotNull PsiFile file, final int index, IStubElementType elementType) {
+ myElementType = elementType;
myVirtualFile = file.getVirtualFile();
myProject = file.getProject();
myIndex = index;
@@ -253,6 +256,8 @@ public abstract class PsiAnchor {
if (myIndex >= list.size()) return null;
StubElement stub = list.get(myIndex);
+ if (stub.getStubType() != myElementType) return null;
+
if (foreign) {
final PsiElement cachedPsi = ((StubBase)stub).getCachedPsi();
if (cachedPsi != null) return cachedPsi;
@@ -274,12 +279,12 @@ public abstract class PsiAnchor {
final StubIndexReference that = (StubIndexReference)o;
- return myIndex == that.myIndex && myVirtualFile.equals(that.myVirtualFile);
+ return myIndex == that.myIndex && myVirtualFile.equals(that.myVirtualFile) && myElementType.equals(that.myElementType);
}
@Override
public int hashCode() {
- return 31 * myVirtualFile.hashCode() + myIndex;
+ return (31 * myVirtualFile.hashCode() + myIndex) * 31 + myElementType.hashCode();
}
public int getStartOffset() {
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java
index a99d6c01788c..59754f994cb8 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java
@@ -68,7 +68,7 @@ public class SharedPsiElementImplUtil {
LOG.error(element);
}
for (TextRange range : ReferenceRange.getRanges(reference)) {
- if (range.getStartOffset() <= offset && offset <= range.getEndOffset()) {
+ if (range.containsOffset(offset)) {
outReferences.add(reference);
}
}
diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java
index 561beab8581f..c03611f3fc18 100644
--- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java
+++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java
@@ -91,6 +91,11 @@ public class RenameDialog extends RefactoringDialog {
myHelpID = RenamePsiElementProcessor.forElement(psiElement).getHelpID(psiElement);
}
+ @Override
+ protected boolean hasPreviewButton() {
+ return RenamePsiElementProcessor.forElement(myPsiElement).showRenamePreviewButton(myPsiElement);
+ }
+
protected void dispose() {
myNameSuggestionsField.removeDataChangedListener(myNameChangedListener);
super.dispose();
diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java
index 3de38efaca85..dde8aeda8421 100644
--- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java
+++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java
@@ -139,6 +139,10 @@ public abstract class RenamePsiElementProcessor {
}
}
+ public boolean showRenamePreviewButton(final PsiElement psiElement){
+ return true;
+ }
+
/**
* Returns the element to be renamed instead of the element on which the rename refactoring was invoked (for example, a super method
* of an inherited method).
diff --git a/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java b/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java
index 0a91e3cff630..dc84b0d8d1dc 100644
--- a/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java
+++ b/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java
@@ -37,6 +37,21 @@ public abstract class FileEditorManager {
*/
@NotNull public abstract FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor);
+
+ /**
+ * Opens a file
+ *
+ * @param file file to open
+ * @param focusEditor true if need to focus
+ * @param useActiveSplitter if false then manager will search
+ * the file through all splitters
+ *
+ * @return array of opened editors
+ */
+ @NotNull public FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor, boolean useActiveSplitter) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
/**
* Closes all editors opened for the file.
*
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java b/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java
deleted file mode 100644
index 43597f77ac24..000000000000
--- a/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.ide.actions;
-
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DefaultActionGroup;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
-import com.intellij.openapi.actionSystem.Presentation;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.wm.ToolWindowManager;
-
-public class CodeEditorActionGroup extends DefaultActionGroup implements DumbAware {
- public CodeEditorActionGroup() {
- super();
- }
-
- public void update(AnActionEvent event){
- Presentation presentation = event.getPresentation();
- Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
- if (project == null) {
- presentation.setVisible(false);
- return;
- }
- boolean active = ToolWindowManager.getInstance(project).isEditorComponentActive();
- presentation.setVisible(active);
- }
-}
\ No newline at end of file
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java
index 4c39bbe0b6f9..d9ed5b2d62a6 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java
+++ b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java
@@ -21,8 +21,11 @@ import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
+import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager;
+import com.intellij.openapi.fileEditor.impl.EditorWindow;
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
@@ -102,11 +105,13 @@ public class Switcher extends AnAction implements DumbAware {
public void actionPerformed(AnActionEvent e) {
final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
if (project == null) return;
+ boolean selectFirstItem = false;
if (SWITCHER == null) {
synchronized (Switcher.class) {
if (SWITCHER == null) {
SWITCHER = new SwitcherPanel(project);
FeatureUsageTracker.getInstance().triggerFeatureUsed(SWITCHER_FEATURE_ID);
+ selectFirstItem = !FileEditorManagerEx.getInstanceEx(project).hasOpenedFile();
}
}
}
@@ -114,7 +119,11 @@ public class Switcher extends AnAction implements DumbAware {
if (e.getInputEvent().isShiftDown()) {
SWITCHER.goBack();
} else {
- SWITCHER.goForward();
+ if (selectFirstItem) {
+ SWITCHER.files.setSelectedIndex(0);
+ } else {
+ SWITCHER.goForward();
+ }
}
}
@@ -128,6 +137,7 @@ public class Switcher extends AnAction implements DumbAware {
final JLabel pathLabel = new JLabel(" ");
final JPanel descriptions;
final Project project;
+ final Map files2editors;
SwitcherPanel(Project project) {
super(new BorderLayout(0, 0));
@@ -212,11 +222,20 @@ public class Switcher extends AnAction implements DumbAware {
separator.setBackground(Color.WHITE);
final FileEditorManager editorManager = FileEditorManager.getInstance(project);
- final VirtualFile[] openFiles = editorManager.getOpenFiles();
-
- try {
- Arrays.sort(openFiles, new RecentFilesComparator(project));
- } catch (Exception e) {// IndexNotReadyException
+ final FileEditor[] allEditors = editorManager.getAllEditors();
+ files2editors = new HashMap();
+ for (FileEditor editor : allEditors) {
+ files2editors.put(((FileEditorManagerImpl)editorManager).getFile(editor), editor);
+ }
+ final VirtualFile[] recentFiles = EditorHistoryManager.getInstance(project).getFiles();
+ final ArrayList openFiles = new ArrayList();
+ for (VirtualFile recentFile : recentFiles) {
+ openFiles.add(0, recentFile);
+ }
+ final ArrayList tmp = new ArrayList(files2editors.keySet());
+ tmp.removeAll(openFiles);
+ for (VirtualFile virtualFile : tmp) {
+ openFiles.add(0, virtualFile);
}
final DefaultListModel filesModel = new DefaultListModel();
@@ -315,7 +334,15 @@ public class Switcher extends AnAction implements DumbAware {
return true;
}
}).createPopup();
- myPopup.showInCenterOf(ideFrame.getContentPane());
+ Component comp = null;
+ final EditorWindow result = FileEditorManagerEx.getInstanceEx(project).getActiveWindow().getResult();
+ if (result != null) {
+ comp = result.getOwner();
+ }
+ if (comp == null) {
+ comp = ideFrame.getContentPane();
+ }
+ myPopup.showInCenterOf(comp);
}
private int getModifiers(ShortcutSet shortcutSet) {
@@ -494,7 +521,8 @@ public class Switcher extends AnAction implements DumbAware {
((ToolWindow)value).activate(null, true, true);
}
else if (value instanceof VirtualFile) {
- FileEditorManager.getInstance(project).openFile((VirtualFile)value, true);
+ final VirtualFile file = (VirtualFile)value;
+ FileEditorManager.getInstance(project).openFile(file, true, true);
}
}
diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java
index 2db93fc7644b..156c2836d3c1 100644
--- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java
+++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java
@@ -123,10 +123,18 @@ public abstract class FileEditorManagerEx extends FileEditorManager {
@NotNull
public FileEditor[] openFile(@NotNull final VirtualFile file, final boolean focusEditor) {
- return openFileWithProviders(file, focusEditor).getFirst ();
+ return openFileWithProviders(file, focusEditor, false).getFirst ();
}
- @NotNull public abstract Pair openFileWithProviders(@NotNull VirtualFile file, boolean focusEditor);
+ @NotNull
+ @Override
+ public FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor, boolean useActiveSplitter) {
+ return openFileWithProviders(file, focusEditor, useActiveSplitter).getFirst();
+ }
+
+ @NotNull public abstract Pair openFileWithProviders(@NotNull VirtualFile file,
+ boolean focusEditor,
+ boolean useActiveSplitter);
public abstract boolean isChanged(@NotNull EditorComposite editor);
diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java
index f453068d29ab..d6d351e878c3 100644
--- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java
@@ -547,18 +547,34 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
//-------------------------------------- Open File ----------------------------------------
- @NotNull public Pair openFileWithProviders(@NotNull final VirtualFile file, final boolean focusEditor) {
+ @NotNull public Pair openFileWithProviders(@NotNull final VirtualFile file,
+ final boolean focusEditor,
+ boolean useActiveSplitter) {
if (!file.isValid()) {
throw new IllegalArgumentException("file is not valid: " + file);
}
assertDispatchThread();
- EditorsSplitters splitters = getSplitters();
- EditorWindow wndToOpenIn = splitters.getCurrentWindow();
+ EditorWindow wndToOpenIn = null;
+ if (useActiveSplitter) {
+ for (EditorsSplitters splitters : getAllSplitters()) {
+ final EditorWindow window = splitters.getCurrentWindow();
+ if (window == null) continue;
+
+ if (window.isFileOpen(file)) {
+ wndToOpenIn = window;
+ if (wndToOpenIn != getActiveWindow().getResult()) {
+ System.out.println("Not active");
+ }
+ break;
+ }
+ }
+ } else {
+ wndToOpenIn = getSplitters().getCurrentWindow();
+ }
if (wndToOpenIn == null) {
- wndToOpenIn = splitters.getOrCreateCurrentWindow(file);
+ wndToOpenIn = getSplitters().getOrCreateCurrentWindow(file);
}
-
return openFileImpl2(wndToOpenIn, file, focusEditor);
}
@@ -728,7 +744,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
if (!ApplicationManagerEx.getApplicationEx().isUnitTestMode()) {
if (focusEditor) {
//myFirstIsActive = myTabbedContainer1.equals(tabbedContainer);
- window.setAsCurrentWindow(false);
+ window.setAsCurrentWindow(true);
ToolWindowManager.getInstance(myProject).activateEditorComponent();
}
}
@@ -1018,10 +1034,13 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
public FileEditor[] getAllEditors() {
assertReadAccess();
final ArrayList result = new ArrayList();
- final EditorWithProviderComposite[] editorsComposites = getSplitters().getEditorsComposites();
- for (EditorWithProviderComposite editorsComposite : editorsComposites) {
- final FileEditor[] editors = editorsComposite.getEditors();
- ContainerUtil.addAll(result, editors);
+ final Set allSplitters = getAllSplitters();
+ for (EditorsSplitters splitter : allSplitters) {
+ final EditorWithProviderComposite[] editorsComposites = splitter.getEditorsComposites();
+ for (EditorWithProviderComposite editorsComposite : editorsComposites) {
+ final FileEditor[] editors = editorsComposite.getEditors();
+ ContainerUtil.addAll(result, editors);
+ }
}
return result.toArray(new FileEditor[result.size()]);
}
@@ -1168,15 +1187,17 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
}
private EditorWithProviderComposite getEditorComposite(@NotNull final FileEditor editor) {
- final EditorWithProviderComposite[] editorsComposites = getSplitters().getEditorsComposites();
- for (int i = editorsComposites.length - 1; i >= 0; i--) {
- final EditorWithProviderComposite composite = editorsComposites[i];
- final FileEditor[] editors = composite.getEditors();
- for (int j = editors.length - 1; j >= 0; j--) {
- final FileEditor _editor = editors[j];
- LOG.assertTrue(_editor != null);
- if (editor.equals(_editor)) {
- return composite;
+ for (EditorsSplitters splitters : getAllSplitters()) {
+ final EditorWithProviderComposite[] editorsComposites = splitters.getEditorsComposites();
+ for (int i = editorsComposites.length - 1; i >= 0; i--) {
+ final EditorWithProviderComposite composite = editorsComposites[i];
+ final FileEditor[] editors = composite.getEditors();
+ for (int j = editors.length - 1; j >= 0; j--) {
+ final FileEditor _editor = editors[j];
+ LOG.assertTrue(_editor != null);
+ if (editor.equals(_editor)) {
+ return composite;
+ }
}
}
}
diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java
index 52011d1180bf..f4b1eb5a862b 100644
--- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java
@@ -443,7 +443,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Projec
private void gotoPlaceInfo(@NotNull PlaceInfo info) { // TODO: Msk
final boolean wasActive = myToolWindowManager.isEditorComponentActive();
- final Pair editorsWithProviders = myEditorManager.openFileWithProviders(info.getFile(), wasActive);
+ final Pair editorsWithProviders = myEditorManager.openFileWithProviders(info.getFile(), wasActive, false);
final FileEditor [] editors = editorsWithProviders.getFirst();
final FileEditorProvider[] providers = editorsWithProviders.getSecond();
for (int i = 0; i < editors.length; i++) {
diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml
index 9c08ef8d9014..2f5f09ae5270 100644
--- a/platform/platform-resources/src/idea/LangActions.xml
+++ b/platform/platform-resources/src/idea/LangActions.xml
@@ -134,7 +134,7 @@
-
+
@@ -146,7 +146,7 @@
-
+
@@ -156,7 +156,7 @@
-
+
diff --git a/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java b/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java
index 1ca79f76ec81..b63fe23b8477 100644
--- a/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java
+++ b/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java
@@ -66,7 +66,9 @@ import java.util.Map;
@Override
@NotNull
- public Pair openFileWithProviders(@NotNull VirtualFile file, boolean focusEditor) {
+ public Pair openFileWithProviders(@NotNull VirtualFile file,
+ boolean focusEditor,
+ boolean useActiveSplitter) {
Editor editor = openTextEditor(new OpenFileDescriptor(myProject, file), focusEditor);
final FileEditor fileEditor = TextEditorProvider.getInstance().getTextEditor(editor);
return Pair.create (new FileEditor[] {fileEditor}, new FileEditorProvider[] {getProvider (fileEditor)});
diff --git a/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java b/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java
index 1739d9ac1881..75a12e9a590c 100644
--- a/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java
+++ b/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java
@@ -31,6 +31,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* Date: Aug 24, 2010
*/
public class LowMemoryWatcher {
+ private static final long MEM_THRESHOLD = 5 /*MB*/ * 1024 * 1024;
public static abstract class ForceableAdapter implements Forceable {
public boolean isDirty() {
@@ -49,6 +50,7 @@ public class LowMemoryWatcher {
static {
final Thread thread = new Thread("LowMemoryWatcher") {
+ boolean shouldCleanup = false;
public void run() {
updateRef();
final Set> toRemove = new HashSet>();
@@ -57,18 +59,25 @@ public class LowMemoryWatcher {
try {
ourRefQueue.remove();
updateRef();
-
+
+ if (!shouldCleanup) {
+ final Runtime runtime = Runtime.getRuntime();
+ shouldCleanup = (runtime.maxMemory() - runtime.totalMemory()) <= MEM_THRESHOLD;
+ }
+
for (WeakReference instanceRef : ourInstances) {
final LowMemoryWatcher watcher = instanceRef.get();
if (watcher == null) {
toRemove.add(instanceRef);
}
else {
- try {
- watcher.doCleanup();
- }
- catch (Throwable e) {
- LOG.info(e);
+ if (shouldCleanup) {
+ try {
+ watcher.doCleanup();
+ }
+ catch (Throwable e) {
+ LOG.info(e);
+ }
}
}
}
diff --git a/platform/util/src/com/intellij/openapi/util/TextRange.java b/platform/util/src/com/intellij/openapi/util/TextRange.java
index 83af33e86d94..e0d555ba26af 100644
--- a/platform/util/src/com/intellij/openapi/util/TextRange.java
+++ b/platform/util/src/com/intellij/openapi/util/TextRange.java
@@ -57,6 +57,10 @@ public class TextRange {
return myStartOffset <= startOffset && myEndOffset >= endOffset;
}
+ public boolean containsOffset(int offset) {
+ return myStartOffset <= offset && offset <= myEndOffset;
+ }
+
public String toString() {
return "(" + myStartOffset + "," + myEndOffset + ")";
}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java
index 69ab68c70340..f8705143bfc1 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java
@@ -131,16 +131,7 @@ public class GrabDependencies implements IntentionAction {
return grAnnotation.getText();
}
};
- String common = StringUtil.join(excludes, mapper, ",");
- if (!resolvers.isEmpty()) {
- if (!common.isEmpty()) {
- common += ",";
- }
- common += StringUtil.join(resolvers, mapper, ",");
- }
- if (!common.isEmpty()) {
- common = "," + common;
- }
+ String common = StringUtil.join(excludes, mapper, " ") + " " + StringUtil.join(resolvers, mapper, " ");
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
assert sdk != null;
@@ -151,7 +142,7 @@ public class GrabDependencies implements IntentionAction {
final Map lines = new HashMap();
for (GrAnnotation grab : grabs) {
String grabText = grab.getText();
- String query = "@Grapes([" + grabText + common + "])";
+ String query = grabText + " " + common;
final JavaParameters javaParameters = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
//debug
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java
index bb6665a7753b..18a6b01dd057 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java
@@ -71,7 +71,7 @@ public class GroovyClassNameInsertHandler implements InsertHandler createTagNameRange(final XmlTag tag) {
final PsiElement startToken = XmlTagUtil.getStartTagNameElement(tag);
- assert startToken != null;
+ assert startToken != null : tag.getText();
return Pair.create(startToken.getTextRange().shiftRight(-tag.getTextRange().getStartOffset()), (PsiElement)tag);
}
diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java
index 546ed073f57c..efed641ff164 100644
--- a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java
+++ b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java
@@ -15,6 +15,7 @@
*/
package com.intellij.util.xml.impl;
+import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlEntityRef;
@@ -82,10 +83,28 @@ public class PhysicalDomParentStrategy implements DomParentStrategy {
final XmlElement thatElement = ((PhysicalDomParentStrategy)o).myElement;
if (xmlElementsEqual(myElement, thatElement)) {
if (myElement != thatElement) {
+ //todo remove this assertion before X release
+ if (ApplicationManagerEx.getApplicationEx().isInternal()) {
+ PsiElement cur = myElement;
+ while (cur != null && !cur.isPhysical()) {
+ cur = cur.getParent();
+ }
+ throw new AssertionError(myElement.getText() + "; including=" + (cur == null ? null : cur.getText()));
+ }
+
final PsiElement nav1 = myElement.getNavigationElement();
final PsiElement nav2 = thatElement.getNavigationElement();
- assert nav1 == nav2 : nav1.getContainingFile() + ":" + nav1.getTextRange().getStartOffset() + "!=" + nav2.getContainingFile() + ":" + nav2.getTextRange().getStartOffset() +
- "; " + (nav1==myElement) + ";" + (nav2==thatElement);
+ assert nav1 == nav2 : nav1.getContainingFile() +
+ ":" +
+ nav1.getTextRange().getStartOffset() +
+ "!=" +
+ nav2.getContainingFile() +
+ ":" +
+ nav2.getTextRange().getStartOffset() +
+ "; " +
+ (nav1 == myElement) +
+ ";" +
+ (nav2 == thatElement);
}
return true;
}
@@ -95,7 +114,7 @@ public class PhysicalDomParentStrategy implements DomParentStrategy {
private static boolean xmlElementsEqual(@NotNull final PsiElement fst, @NotNull final PsiElement snd) {
if (fst.equals(snd)) return true;
- if (fst.isPhysical() || snd.isPhysical()) return false;
+ if (fst.isValid() && fst.isPhysical() || snd.isValid() && snd.isPhysical()) return false;
if (fst.getTextLength() != snd.getTextLength()) return false;
if (fst.getStartOffsetInParent() != snd.getStartOffsetInParent()) return false;