/*
 * Copyright 2013-2015 must-be.org
 *
 * 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 org.mustbe.consulo.unity3d.module;

import com.intellij.ProjectTopics;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.project.Project;

/**
 * @author VISTALL
 * @since 25.01.15
 */
public class UnitySubscriber extends AbstractProjectComponent
{
	public UnitySubscriber(Project project)
	{
		super(project);
	}

	@Override
	public void initComponent()
	{
		myProject.getMessageBus().connect().subscribe(ProjectTopics.MODULE_LAYERS, new UnitySyncModuleRootLayerListener());
	}
}

@@ -645,34 +645,262 @@
 ort 
-com.intellij.ProjectTopics
+java.io.IOException;%0A%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.mustbe.consulo.RequiredReadAction;%0Aimport org.mustbe.consulo.unity3d.Unity3dMetaFileType;%0Aimport com.intellij.ProjectTopics;%0Aimport com.intellij.openapi.command.WriteCommandAction
 ;%0Aim
@@ -962,16 +962,59 @@
 ponent;%0A
+import com.intellij.openapi.module.Module;%0A
 import c
@@ -1049,16 +1049,234 @@
 Project;
+%0Aimport com.intellij.openapi.vfs.VirtualFile;%0Aimport com.intellij.openapi.vfs.VirtualFileAdapter;%0Aimport com.intellij.openapi.vfs.VirtualFileEvent;%0Aimport com.intellij.openapi.vfs.VirtualFileManager;%0Aimport lombok.val;
 %0A%0A/**%0A *
@@ -1488,16 +1488,16 @@
 nt()%0A%09%7B%0A
-
 %09%09myProj
@@ -1605,14 +1605,948 @@
 ener());
+%0A%0A%09%09VirtualFileAdapter virtualFileAdapter = new VirtualFileAdapter()%0A%09%09%7B%0A%09%09%09@Override%0A%09%09%09@RequiredReadAction%0A%09%09%09public void beforeFileDeletion(@NotNull VirtualFileEvent event)%0A%09%09%09%7B%0A%09%09%09%09VirtualFile parent = event.getParent();%0A%09%09%09%09if(parent == null)%0A%09%09%09%09%7B%0A%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%0A%09%09%09%09Module module = Unity3dModuleExtensionUtil.getRootModule(myProject);%0A%09%09%09%09if(module == null)%0A%09%09%09%09%7B%0A%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%0A%09%09%09%09val metaFile = parent.findChild(event.getFile().getNameWithoutExtension() + %22.%22 + Unity3dMetaFileType.INSTANCE.getDefaultExtension%0A%09%09%09%09%09%09());%0A%09%09%09%09if(metaFile == null)%0A%09%09%09%09%7B%0A%09%09%09%09%09return;%0A%09%09%09%09%7D%0A%0A%09%09%09%09WriteCommandAction.runWriteCommandAction(myProject, new Runnable()%0A%09%09%09%09%7B%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public void run()%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09try%0A%09%09%09%09%09%09%7B%0A%09%09%09%09%09%09%09metaFile.delete(null);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09catch(IOException ignored)%0A%09%09%09%09%09%09%7B%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D);%0A%09%09%09%7D%0A%09%09%7D;%0A%09%09VirtualFileManager.getInstance().addVirtualFileListener(virtualFileAdapter, myProject);
 %0A%09%7D%0A%7D%0A

delete .meta file if deleted file in unity