mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-16 12:45:41 +02:00
Improve strategy to re-query in ElementSelectionDialog, related to bug 211251
This commit is contained in:
parent
b7e830fccc
commit
dcf186c8c1
1 changed files with 24 additions and 13 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
|
||||||
|
@ -66,6 +66,12 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
|
||||||
*/
|
*/
|
||||||
private class UpdateElementsJob extends Job {
|
private class UpdateElementsJob extends Job {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last used prefix to query the index. <code>null</code> means
|
||||||
|
* the query result should be empty.
|
||||||
|
*/
|
||||||
|
private volatile char[] fCurrentPrefix = null;
|
||||||
|
|
||||||
public UpdateElementsJob(String name) {
|
public UpdateElementsJob(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
setSystem(true);
|
setSystem(true);
|
||||||
|
@ -73,6 +79,15 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
|
||||||
setPriority(Job.LONG);
|
setPriority(Job.LONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public char[] getCurrentPrefix() {
|
||||||
|
return fCurrentPrefix;
|
||||||
|
}
|
||||||
|
public void scheduleQuery(char[] prefix) {
|
||||||
|
fCurrentPrefix= prefix;
|
||||||
|
int delay = fCurrentPrefix == null ? 0 : (fCurrentPrefix.length < 5 ? 400 : 200);
|
||||||
|
schedule(delay);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IStatus run(final IProgressMonitor monitor) {
|
public IStatus run(final IProgressMonitor monitor) {
|
||||||
monitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN);
|
monitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN);
|
||||||
|
@ -148,12 +163,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
|
||||||
return rule == this;
|
return rule == this;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
/**
|
private UpdateElementsJob fUpdateJob;
|
||||||
* The last used prefix to query the index. <code>null</code> means the
|
|
||||||
* query result should be empty.
|
|
||||||
*/
|
|
||||||
private char[] fCurrentPrefix= null;
|
|
||||||
private Job fUpdateJob;
|
|
||||||
private boolean fAllowEmptyPrefix= true;
|
private boolean fAllowEmptyPrefix= true;
|
||||||
private boolean fAllowEmptyString= true;
|
private boolean fAllowEmptyString= true;
|
||||||
private ProgressMonitorPart fProgressMonitorPart;
|
private ProgressMonitorPart fProgressMonitorPart;
|
||||||
|
@ -356,17 +366,18 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
|
||||||
|
|
||||||
protected void scheduleUpdate(String filterText) {
|
protected void scheduleUpdate(String filterText) {
|
||||||
char[] newPrefix= toPrefix(filterText);
|
char[] newPrefix= toPrefix(filterText);
|
||||||
boolean equivalentPrefix= isEquivalentPrefix(fCurrentPrefix, newPrefix);
|
final char[] currentPrefix= fUpdateJob.getCurrentPrefix();
|
||||||
|
final boolean equivalentPrefix= isEquivalentPrefix(currentPrefix, newPrefix);
|
||||||
boolean emptyQuery= newPrefix.length == 0 && !fAllowEmptyPrefix || filterText.length() == 0 && !fAllowEmptyString;
|
boolean emptyQuery= newPrefix.length == 0 && !fAllowEmptyPrefix || filterText.length() == 0 && !fAllowEmptyString;
|
||||||
boolean needQuery= !equivalentPrefix;
|
final int jobState = fUpdateJob.getState();
|
||||||
|
boolean needQuery= !equivalentPrefix || (currentPrefix.length > newPrefix.length && currentPrefix.length < 5 && jobState == Job.RUNNING);
|
||||||
if (emptyQuery) {
|
if (emptyQuery) {
|
||||||
newPrefix= null;
|
newPrefix= null;
|
||||||
needQuery= needQuery || fCurrentPrefix != null;
|
needQuery= needQuery || currentPrefix != null;
|
||||||
}
|
}
|
||||||
if(needQuery || fUpdateJob.getState() == Job.WAITING || fUpdateJob.getState() == Job.SLEEPING) {
|
if(needQuery || jobState == Job.WAITING || jobState == Job.SLEEPING) {
|
||||||
fUpdateJob.cancel();
|
fUpdateJob.cancel();
|
||||||
fCurrentPrefix= newPrefix;
|
fUpdateJob.scheduleQuery(newPrefix);
|
||||||
fUpdateJob.schedule(200);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue