From 15f25178c67acfec946784ae116eceb8d10fffe5 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Tue, 27 Sep 2011 15:24:08 +0200 Subject: [PATCH] AppCode: writing fileEncoding to the model, when changing it in AppCode --- .../openapi/vfs/ex/VirtualFileManagerEx.java | 30 +++++++++---------- .../vfs/impl/VirtualFileManagerImpl.java | 14 ++++++--- .../util/containers/ContainerUtil.java | 18 +++++++++++ 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java b/platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java index 174f859f487f..c373cd784842 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java @@ -1,24 +1,24 @@ - /* - * Copyright 2000-2009 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. - */ +* Copyright 2000-2009 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.vfs.ex; import com.intellij.openapi.vfs.VirtualFileManager; public abstract class VirtualFileManagerEx extends VirtualFileManager { public abstract void fireBeforeRefreshStart(boolean asynchronous); + public abstract void fireAfterRefreshFinish(boolean asynchronous); } diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java index 4b35483ed32e..f001784e4bea 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java @@ -24,7 +24,9 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.KeyedExtensionCollector; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; -import com.intellij.openapi.vfs.newvfs.*; +import com.intellij.openapi.vfs.newvfs.BulkFileListener; +import com.intellij.openapi.vfs.newvfs.CachingVirtualFileSystem; +import com.intellij.openapi.vfs.newvfs.FileSystemPersistence; import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent; import com.intellij.util.EventDispatcher; import com.intellij.util.containers.ContainerUtil; @@ -193,10 +195,10 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { @Override public void notifyPropertyChanged(final VirtualFile virtualFile, final String property, final Object oldValue, final Object newValue) { final Application application = ApplicationManager.getApplication(); - application.invokeLater(new Runnable() { + final Runnable runnable = new Runnable() { public void run() { if (virtualFile.isValid() && !application.isDisposed()) { - application.runWriteAction(new Runnable(){ + application.runWriteAction(new Runnable() { public void run() { List events = Collections .singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false)); @@ -207,7 +209,11 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { }); } } - }, ModalityState.NON_MODAL); + }; + if (application.isDispatchThread()) { + runnable.run(); + } + application.invokeLater(runnable, ModalityState.NON_MODAL); } public void fireBeforeRefreshStart(boolean asynchronous) { diff --git a/platform/util/src/com/intellij/util/containers/ContainerUtil.java b/platform/util/src/com/intellij/util/containers/ContainerUtil.java index 08c94b60d0e1..82b1f63e7018 100644 --- a/platform/util/src/com/intellij/util/containers/ContainerUtil.java +++ b/platform/util/src/com/intellij/util/containers/ContainerUtil.java @@ -19,7 +19,9 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Factory; +import com.intellij.openapi.util.Pair; import com.intellij.util.*; +import gnu.trove.THashMap; import gnu.trove.TIntArrayList; import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; @@ -275,6 +277,22 @@ public class ContainerUtil { return set; } + @NotNull + public static Map map2Map(@NotNull T[] collection, @NotNull Function> mapper) { + return map2Map(Arrays.asList(collection), mapper); + } + + @NotNull + public static Map map2Map(@NotNull Collection collection, + @NotNull Function> mapper) { + final Map set = new THashMap(collection.size()); + for (T t : collection) { + Pair pair = mapper.fun(t); + set.put(pair.first, pair.second); + } + return set; + } + @NotNull public static Object[] map2Array(@NotNull T[] array, @NotNull Function mapper) { return map2Array(array, Object.class, mapper);