DumbService.queueTask(DumbModeTask)

This commit is contained in:
peter
2014-04-03 13:10:53 +02:00
parent 28413294e7
commit f6262c4f2d
6 changed files with 81 additions and 24 deletions
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2014 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.openapi.project;
import com.intellij.openapi.progress.ProgressIndicator;
import org.jetbrains.annotations.NotNull;
/**
* @author peter
*/
public abstract class DumbModeTask {
public abstract void performInDumbMode(@NotNull ProgressIndicator indicator);
}
@@ -190,6 +190,8 @@ public abstract class DumbService {
return new ArrayList<T>(collection);
}
public abstract void queueTask(DumbModeTask task);
public abstract JComponent wrapGently(@NotNull JComponent dumbUnawareContent, @NotNull Disposable parentDisposable);
public void makeDumbAware(@NotNull final JComponent component, @NotNull Disposable disposable) {
@@ -16,6 +16,8 @@
package com.intellij.mock;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.project.DumbModeTask;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
@@ -46,6 +48,11 @@ public class MockDumbService extends DumbService {
public void waitForSmartMode() {
}
@Override
public void queueTask(DumbModeTask task) {
task.performInDumbMode(new EmptyProgressIndicator());
}
@Override
public JComponent wrapGently(@NotNull JComponent dumbUnawareContent, @NotNull Disposable parentDisposable) {
throw new UnsupportedOperationException();
@@ -20,6 +20,9 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
/**
* @deprecated use {@link com.intellij.openapi.project.DumbModeTask}
*/
public interface CacheUpdater {
int getNumberOfPendingUpdateJobs();
@@ -15,22 +15,18 @@
*/
package com.intellij.internal;
import com.intellij.ide.caches.CacheUpdater;
import com.intellij.ide.caches.FileContent;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.DumbModeTask;
import com.intellij.openapi.project.DumbServiceImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.TimeoutUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
/**
* @author peter
*/
@@ -46,29 +42,15 @@ public class ToggleDumbModeAction extends AnAction implements DumbAware {
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
if (project == null) return;
CacheUpdater updater = new CacheUpdater() {
public int getNumberOfPendingUpdateJobs() {
return 0;
}
@NotNull
public VirtualFile[] queryNeededFiles(@NotNull ProgressIndicator indicator) {
DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {
@Override
public void performInDumbMode(@NotNull ProgressIndicator indicator) {
while (myDumb) {
indicator.checkCanceled();
TimeoutUtil.sleep(100);
}
return VirtualFile.EMPTY_ARRAY;
}
public void processFile(@NotNull FileContent fileContent) {
}
public void updatingDone() {
}
public void canceled() {
}
};
DumbServiceImpl.getInstance(project).queueCacheUpdateInDumbMode(Arrays.asList(updater));
});
}
}
@@ -17,6 +17,7 @@ package com.intellij.openapi.project;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.caches.CacheUpdater;
import com.intellij.ide.caches.FileContent;
import com.intellij.ide.util.DelegatingProgressIndicator;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
@@ -28,6 +29,7 @@ import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.ShutDownTracker;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.AppIconScheme;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.WindowManager;
@@ -45,6 +47,7 @@ import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.BlockingQueue;
@@ -65,6 +68,38 @@ public class DumbServiceImpl extends DumbService {
return (DumbServiceImpl)DumbService.getInstance(project);
}
@Override
public void queueTask(final DumbModeTask task) {
CacheUpdater wrapper = new CacheUpdater() {
@Override
public int getNumberOfPendingUpdateJobs() {
return 0;
}
@NotNull
@Override
public VirtualFile[] queryNeededFiles(@NotNull ProgressIndicator indicator) {
task.performInDumbMode(indicator);
return new VirtualFile[0];
}
@Override
public void processFile(@NotNull FileContent fileContent) {
}
@Override
public void updatingDone() {
}
@Override
public void canceled() {
}
};
queueCacheUpdateInDumbMode(Arrays.asList(wrapper));
}
public DumbServiceImpl(Project project, MessageBus bus) {
myProject = project;
myPublisher = bus.syncPublisher(DUMB_MODE);