added before event firing

This commit is contained in:
Alexey Kudravtsev
2010-04-22 16:28:44 +04:00
parent 68640d5efb
commit 06f8583069
2 changed files with 13 additions and 7 deletions
@@ -30,6 +30,7 @@ import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -42,7 +43,7 @@ import java.util.Set;
* @author peter
*/
public class FileContentUtil {
public static final String FORCE_RELOAD_REQUESTOR = "FileContentUtil.saveOrReload";
@NonNls public static final String FORCE_RELOAD_REQUESTOR = "FileContentUtil.saveOrReload";
private FileContentUtil() {
}
@@ -67,23 +68,23 @@ public class FileContentUtil {
}
public static void reparseFiles(@NotNull final Project project, @NotNull final Collection<VirtualFile> files, boolean includeOpenFiles) {
final Set<VFilePropertyChangeEvent> list = new THashSet<VFilePropertyChangeEvent>();
final Set<VFilePropertyChangeEvent> events = new THashSet<VFilePropertyChangeEvent>();
for (VirtualFile file : files) {
saveOrReload(file, list);
saveOrReload(file, events);
}
if (includeOpenFiles) {
for (VirtualFile open : FileEditorManager.getInstance(project).getOpenFiles()) {
if (!files.contains(open)) {
saveOrReload(open, list);
saveOrReload(open, events);
}
}
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES)
.before(new ArrayList<VFileEvent>(list));
.before(new ArrayList<VFileEvent>(events));
ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES)
.after(new ArrayList<VFileEvent>(list));
.after(new ArrayList<VFileEvent>(events));
}
});
}
@@ -24,6 +24,7 @@ import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent;
import com.intellij.util.Icons;
import org.jetbrains.annotations.NonNls;
@@ -36,6 +37,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
/**
* Represents a file in <code>{@link VirtualFileSystem}</code>. A particular file is represented by the same
@@ -451,7 +453,10 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica
if (isValid() && !application.isDisposed()) {
application.runWriteAction(new Runnable(){
public void run() {
application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES).after(Collections.singletonList(new VFilePropertyChangeEvent(this, VirtualFile.this, PROP_ENCODING, old, charset, false)));
List<VFilePropertyChangeEvent> events = Collections.singletonList(new VFilePropertyChangeEvent(this, VirtualFile.this, PROP_ENCODING, old, charset, false));
BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
listener.before(events);
listener.after(events);
}
});
}