mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 218124: Mark Occurrences makes C++ editor sluggish
This commit is contained in:
parent
d3af1cd424
commit
39053ae062
3 changed files with 38 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2007 2008 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -17,6 +17,7 @@ public class Messages extends NLS {
|
||||||
public static String IndexUI_infoNotInIndex;
|
public static String IndexUI_infoNotInIndex;
|
||||||
public static String IndexUI_infoNotInSource;
|
public static String IndexUI_infoNotInSource;
|
||||||
public static String IndexUI_infoSelectIndexAllFiles;
|
public static String IndexUI_infoSelectIndexAllFiles;
|
||||||
|
public static String SelectionListenerWithASTManager_jobName;
|
||||||
static {
|
static {
|
||||||
// initialize resource bundle
|
// initialize resource bundle
|
||||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,14 +7,17 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.ListenerList;
|
import org.eclipse.core.runtime.ListenerList;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
@ -58,6 +61,11 @@ public class SelectionListenerWithASTManager {
|
||||||
private ISelectionChangedListener fSelectionListener;
|
private ISelectionChangedListener fSelectionListener;
|
||||||
private Job fCurrentJob;
|
private Job fCurrentJob;
|
||||||
private ListenerList fAstListeners;
|
private ListenerList fAstListeners;
|
||||||
|
/**
|
||||||
|
* Lock to avoid having more than one calculateAndInform job in parallel.
|
||||||
|
* Only jobs may synchronize on this as otherwise deadlocks are possible.
|
||||||
|
*/
|
||||||
|
private final Object fJobLock= new Object();
|
||||||
|
|
||||||
public PartListenerGroup(ITextEditor editorPart) {
|
public PartListenerGroup(ITextEditor editorPart) {
|
||||||
fPart= editorPart;
|
fPart= editorPart;
|
||||||
|
@ -116,13 +124,29 @@ public class SelectionListenerWithASTManager {
|
||||||
fCurrentJob.cancel();
|
fCurrentJob.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fPart.getEditorInput());
|
final IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fPart.getEditorInput());
|
||||||
if (workingCopy == null)
|
if (workingCopy == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
fCurrentJob= new Job(Messages.SelectionListenerWithASTManager_jobName) {
|
||||||
|
public IStatus run(IProgressMonitor monitor) {
|
||||||
|
if (monitor == null) {
|
||||||
|
monitor= new NullProgressMonitor();
|
||||||
|
}
|
||||||
|
synchronized (fJobLock) {
|
||||||
|
return calculateASTandInform(workingCopy, selection, monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fCurrentJob.setPriority(Job.DECORATE);
|
||||||
|
fCurrentJob.setSystem(true);
|
||||||
|
fCurrentJob.schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IStatus calculateASTandInform(final IWorkingCopy workingCopy, final ITextSelection selection, final IProgressMonitor monitor) {
|
||||||
|
return ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit astRoot) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit astRoot) {
|
||||||
if (astRoot != null) {
|
if (astRoot != null && !monitor.isCanceled()) {
|
||||||
Object[] listeners;
|
Object[] listeners;
|
||||||
synchronized (PartListenerGroup.this) {
|
synchronized (PartListenerGroup.this) {
|
||||||
listeners= fAstListeners.getListeners();
|
listeners= fAstListeners.getListeners();
|
||||||
|
@ -130,18 +154,19 @@ public class SelectionListenerWithASTManager {
|
||||||
for (int i= 0; i < listeners.length; i++) {
|
for (int i= 0; i < listeners.length; i++) {
|
||||||
((ISelectionListenerWithAST) listeners[i]).selectionChanged(fPart, selection, astRoot);
|
((ISelectionListenerWithAST) listeners[i]).selectionChanged(fPart, selection, astRoot);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Map fListenerGroups;
|
private Map<ITextEditor, PartListenerGroup> fListenerGroups;
|
||||||
|
|
||||||
private SelectionListenerWithASTManager() {
|
private SelectionListenerWithASTManager() {
|
||||||
fListenerGroups= new HashMap();
|
fListenerGroups= new HashMap<ITextEditor, PartListenerGroup>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,7 +176,7 @@ public class SelectionListenerWithASTManager {
|
||||||
*/
|
*/
|
||||||
public void addListener(ITextEditor part, ISelectionListenerWithAST listener) {
|
public void addListener(ITextEditor part, ISelectionListenerWithAST listener) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
PartListenerGroup partListener= (PartListenerGroup) fListenerGroups.get(part);
|
PartListenerGroup partListener= fListenerGroups.get(part);
|
||||||
if (partListener == null) {
|
if (partListener == null) {
|
||||||
partListener= new PartListenerGroup(part);
|
partListener= new PartListenerGroup(part);
|
||||||
fListenerGroups.put(part, partListener);
|
fListenerGroups.put(part, partListener);
|
||||||
|
@ -167,7 +192,7 @@ public class SelectionListenerWithASTManager {
|
||||||
*/
|
*/
|
||||||
public void removeListener(ITextEditor part, ISelectionListenerWithAST listener) {
|
public void removeListener(ITextEditor part, ISelectionListenerWithAST listener) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
PartListenerGroup partListener= (PartListenerGroup) fListenerGroups.get(part);
|
PartListenerGroup partListener= fListenerGroups.get(part);
|
||||||
if (partListener != null) {
|
if (partListener != null) {
|
||||||
partListener.uninstall(listener);
|
partListener.uninstall(listener);
|
||||||
if (partListener.isEmpty()) {
|
if (partListener.isEmpty()) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
# Copyright (c) 2007 Wind River Systems, Inc. and others.
|
# Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||||
# All rights reserved. This program and the accompanying materials
|
# All rights reserved. This program and the accompanying materials
|
||||||
# are made available under the terms of the Eclipse Public License v1.0
|
# are made available under the terms of the Eclipse Public License v1.0
|
||||||
# which accompanies this distribution, and is available at
|
# which accompanies this distribution, and is available at
|
||||||
|
@ -11,3 +11,4 @@
|
||||||
IndexUI_infoNotInSource=The element ''{0}'' does not belong to a source file.
|
IndexUI_infoNotInSource=The element ''{0}'' does not belong to a source file.
|
||||||
IndexUI_infoNotInIndex=The file ''{0}'' is currently not part of the index.
|
IndexUI_infoNotInIndex=The file ''{0}'' is currently not part of the index.
|
||||||
IndexUI_infoSelectIndexAllFiles=For headers that are never included, or sources that are not part of the build, consider selecting the preference 'Index all files'.
|
IndexUI_infoSelectIndexAllFiles=For headers that are never included, or sources that are not part of the build, consider selecting the preference 'Index all files'.
|
||||||
|
SelectionListenerWithASTManager_jobName=Notifying selection listeners
|
||||||
|
|
Loading…
Add table
Reference in a new issue