import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.ui.UIUtil;
import com.intellij.vcsUtil.VcsUtil;
import org.zmlx.hg4idea.command.HgTagBranchCommand;
import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
class HgCurrentBranchStatusUpdater implements HgUpdater {
}
public void update(final Project project) {
- Editor textEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
- if (textEditor != null) {
- Document document = textEditor.getDocument();
+ final AtomicReference<Editor> textEditor = new AtomicReference<Editor>();
+ UIUtil.invokeAndWaitIfNeeded(new Runnable() {
+ @Override
+ public void run() {
+ ApplicationManager.getApplication().runReadAction(new Runnable() {
+ @Override
+ public void run() {
+ textEditor.set(FileEditorManager.getInstance(project).getSelectedTextEditor());
+ }
+ });
+ }
+ });
+
+ if (textEditor.get() != null) {
+ Document document = textEditor.get().getDocument();
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
final VirtualFile repo = VcsUtil.getVcsRootFor(project, file);
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
+import com.intellij.util.ui.UIUtil;
import org.zmlx.hg4idea.command.HgTagBranch;
import org.zmlx.hg4idea.command.HgTagBranchCommand;
private void loadBranches(VirtualFile root) {
new HgTagBranchCommand(project, root).listBranches(new Consumer<List<HgTagBranch>>() {
@Override
- public void consume(List<HgTagBranch> branches) {
- branchSelector.setModel(new DefaultComboBoxModel(branches.toArray()));
+ public void consume(final List<HgTagBranch> branches) {
+ UIUtil.invokeAndWaitIfNeeded(new Runnable() {
+ @Override
+ public void run() {
+ branchSelector.setModel(new DefaultComboBoxModel(branches.toArray()));
+ }
+ });
}
});
}
private void loadTags(VirtualFile root) {
new HgTagBranchCommand(project, root).listTags(new Consumer<List<HgTagBranch>>() {
@Override
- public void consume(List<HgTagBranch> tags) {
- tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
+ public void consume(final List<HgTagBranch> tags) {
+ UIUtil.invokeAndWaitIfNeeded(new Runnable() {
+ @Override
+ public void run() {
+ tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
+ }
+ });
}
});
}