Esempio n. 1
0
 private static void Resource_ResourceSaved(object sender, Duality.ResourceEventArgs e)
 {
     if (string.IsNullOrEmpty(e.Path))
     {
         return;                                                 // Ignore Resources without a path.
     }
     if (e.IsDefaultContent)
     {
         return;                                                         // Ignore default content
     }
     editorJustSavedRes.Add(Path.GetFullPath(e.Path));
 }
        public void When_a_non_script_resource_is_created_Then_dont_run()
        {
            var logCountBeforeRunning = Log.LogData.Data.Count();

            var resource = new Prefab();
            resource.Save("test.prefab.res");
            var eventArgs = new ResourceEventArgs("test.prefab.res");

            _scriptResourceEvents.OnResourceCreated(this, eventArgs);

            Assert.AreEqual(logCountBeforeRunning, Log.LogData.Data.Count());
        }
Esempio n. 3
0
 private void FileEventManager_ResourceDeleted(object sender, ResourceEventArgs e)
 {
     // Remove lost Resource file
     NodeBase node = this.NodeFromPath(e.Path);
     if (node != null)
     {
         this.UnregisterNodeTree(node);
         node.Parent.Nodes.Remove(node);
     }
 }
Esempio n. 4
0
        private void FileEventManager_ResourceCreated(object sender, ResourceEventArgs e)
        {
            bool alreadyAdded = this.NodeFromPath(e.Path) != null; // Don't add Resources that are already present.

            if (!alreadyAdded)
            {
                // Register newly detected Resource file
                if (File.Exists(e.Path) && Resource.IsResourceFile(e.Path))
                {
                    NodeBase newNode = this.ScanFile(e.Path);

                    Node parentNode = this.NodeFromPath(Path.GetDirectoryName(e.Path));
                    if (parentNode == null) parentNode = this.folderModel.Root;

                    this.InsertNodeSorted(newNode, parentNode);
                    this.RegisterNodeTree(newNode);
                    newNode.NotifyVisible();
                }
                // Add new directory tree
                else if (e.IsDirectory)
                {
                    // Actually, only add the directory itsself. Each file will trigger its own ResourceCreated event
                    DirectoryNode newNode = new DirectoryNode(e.Path);
                    //NodeBase newNode = this.ScanDirectory(e.Path);

                    Node parentNode = this.NodeFromPath(Path.GetDirectoryName(e.Path));
                    if (parentNode == null) parentNode = this.folderModel.Root;

                    this.InsertNodeSorted(newNode, parentNode);
                    this.RegisterNodeTree(newNode);
                    newNode.NotifyVisible();
                }
            }

            // Perform previously scheduled selection
            this.PerformScheduleSelect(Path.GetFullPath(e.Path));
        }
Esempio n. 5
0
		private void FileEventManager_ResourceChanged(object sender, ResourceEventArgs e)
		{
			if (e.IsResource) this.OnResourceModified(e.Content);
		}
Esempio n. 6
0
 private void DualityEditorApp_ResourceDeleted(object sender, ResourceEventArgs e)
 {
     if (!e.IsDirectory && !typeof(Prefab).IsAssignableFrom(e.ContentType)) return;
     this.UpdatePrefabLinkStatus(true);
 }
Esempio n. 7
0
 private void DualityEditorApp_ResourceCreated(object sender, ResourceEventArgs e)
 {
     if (e.IsDirectory || typeof(Prefab).IsAssignableFrom(e.ContentType))
     {
         this.UpdatePrefabLinkStatus(true);
     }
     this.UpdateSceneLabel(); // In case we save the Scene for the first time
 }
Esempio n. 8
0
		private void Resource_ResourceSaved(object sender, ResourceEventArgs e)
		{
			// If a Resources modified state changes, invalidate
			this.folderView.Invalidate();
		}
Esempio n. 9
0
		private static void ProcessDataDirEvents()
		{
			List<ResourceRenamedEventArgs> renameEventBuffer = null;

			// Process events
			while (dataDirEventBuffer.Count > 0)
			{
				FileSystemEventArgs e = FetchFileSystemEvent(dataDirEventBuffer, DualityApp.DataDirectory);
				if (e == null) continue;

				// Determine whether we're dealing with a directory
				bool isDirectory = Directory.Exists(e.FullPath);
				{
					// If this is a deletion, nothing exists anymore, rely on metadata instead.
					DeletedEventArgsExt de = e as DeletedEventArgsExt;
					if (de != null && de.IsDirectory)
						isDirectory = true;
				}

				if (e.ChangeType == WatcherChangeTypes.Changed)
				{
					// Ignore stuff saved by the editor itself
					if (IsPathEditorModified(e.FullPath))
						continue;

					if (Resource.IsResourceFile(e.FullPath) || isDirectory)
					{
						ContentRef<Resource> resRef = new ContentRef<Resource>(null, e.FullPath);

						// Unregister outdated resources, if modified outside the editor
						if (!isDirectory && ContentProvider.HasContent(e.FullPath))
						{
							bool isCurrentScene = resRef.Is<Scene>() && Scene.Current == resRef.Res;
							if (isCurrentScene || DualityEditorApp.IsResourceUnsaved(e.FullPath))
							{
								DialogResult result = MessageBox.Show(
									String.Format(Properties.GeneralRes.Msg_ConfirmReloadResource_Text, e.FullPath), 
									Properties.GeneralRes.Msg_ConfirmReloadResource_Caption, 
									MessageBoxButtons.YesNo,
									MessageBoxIcon.Exclamation);
								if (result == DialogResult.Yes)
								{
									string curScenePath = Scene.CurrentPath;
									ContentProvider.RemoveContent(e.FullPath);
									if (isCurrentScene) Scene.SwitchTo(ContentProvider.RequestContent<Scene>(curScenePath), true);
								}
							}
							else
								ContentProvider.RemoveContent(e.FullPath);
						}

						if (ResourceModified != null)
							ResourceModified(null, new ResourceEventArgs(e.FullPath, isDirectory));
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Created)
				{
					if (File.Exists(e.FullPath))
					{
						// Register newly detected Resource file
						if (Resource.IsResourceFile(e.FullPath))
						{
							if (ResourceCreated != null)
								ResourceCreated(null, new ResourceEventArgs(e.FullPath, false));
						}
					}
					else if (Directory.Exists(e.FullPath))
					{
						// Register newly detected Resource directory
						if (ResourceCreated != null)
							ResourceCreated(null, new ResourceEventArgs(e.FullPath, true));
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Deleted)
				{
					// Is it a Resource file or just something else?
					if (Resource.IsResourceFile(e.FullPath) || isDirectory)
					{
						ResourceEventArgs args = new ResourceEventArgs(e.FullPath, isDirectory);

						// Organize the Source/Media directory accordingly
						DeleteSourceMediaFile(args);

						// Unregister no-more existing resources
						if (isDirectory)	ContentProvider.RemoveContentTree(args.Path);
						else				ContentProvider.RemoveContent(args.Path);

						if (ResourceDeleted != null)
							ResourceDeleted(null, args);
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Renamed)
				{
					// Is it a Resource file or just something else?
					RenamedEventArgs re = e as RenamedEventArgs;
					ResourceRenamedEventArgs args = new ResourceRenamedEventArgs(re.FullPath, re.OldFullPath, isDirectory);
					if (Resource.IsResourceFile(e.FullPath) || isDirectory)
					{
						// Determine which Source / Media files would belong to this Resource - before moving it
						string[] oldMediaPaths = PreMoveSourceMediaFile(args);;

						// Rename content registerations
						if (isDirectory)	ContentProvider.RenameContentTree(args.OldPath, args.Path);
						else				ContentProvider.RenameContent(args.OldPath, args.Path);

						// Query skipped paths
						bool isEmptyDir = isDirectory && !Directory.EnumerateFileSystemEntries(args.Path).Any();
						bool isSkippedPath = isEmptyDir;
						if (!isSkippedPath && BeginGlobalRename != null)
						{
							BeginGlobalRenameEventArgs beginGlobalRenameArgs = new BeginGlobalRenameEventArgs(args.Path, args.OldPath, isDirectory);
							BeginGlobalRename(null, beginGlobalRenameArgs);
							isSkippedPath = beginGlobalRenameArgs.Cancel;
						}

						if (!isSkippedPath)
						{
							// Buffer rename event to perform the global rename for all at once.
							if (renameEventBuffer == null) renameEventBuffer = new List<ResourceRenamedEventArgs>();
							renameEventBuffer.Add(args);
						}

						if (ResourceRenamed != null)
							ResourceRenamed(null, args);

						if (!isSkippedPath)
						{
							// Organize the Source/Media directory accordingly
							MoveSourceMediaFile(args, oldMediaPaths);
						}
					}
				}
			}

			// If required, perform a global rename operation in all existing content
			if (renameEventBuffer != null)
			{
				// Don't do it now - schedule it for the main form event loop so we don't block here.
				DualityEditorApp.MainForm.BeginInvoke((Action)delegate() {
					ProcessingBigTaskDialog taskDialog = new ProcessingBigTaskDialog( 
						Properties.GeneralRes.TaskRenameContentRefs_Caption, 
						Properties.GeneralRes.TaskRenameContentRefs_Desc, 
						async_RenameContentRefs, renameEventBuffer);
					taskDialog.ShowDialog(DualityEditorApp.MainForm);
				});
			}
		}
Esempio n. 10
0
		private void FileEventManager_ResourceModified(object sender, ResourceEventArgs e)
		{
			if (!e.IsResource) return;
			this.glControl.Invalidate();
		}
        public void When_a_non_resources_is_created_Then_dont_throw()
        {
            var eventArgs = new ResourceEventArgs(new ContentRef<Resource>());

            Assert.DoesNotThrow(() => _scriptResourceEvents.OnResourceCreated(this, eventArgs));
        }
        public void When_script_with_no_sourcePath_is_deleted_Then_use_generated_source_path_name()
        {
            var resourceEventArgs = new ResourceEventArgs(CreateContentRef(GetCSScriptText(), "Path\\test"));
            resourceEventArgs.Content.Res.SourcePath = null;

            _sourceFilePathGenerator.Setup(m => m.GenerateSourceFilePath(It.IsAny<ContentRef<Resource>>(), It.IsAny<string>())).Returns(@"Path\test (2).cs");
            _projectEditorMock.Setup(m => m.RemoveScriptFromProject(@"Path\test (2)", It.IsAny<string>(), It.IsAny<string>()));

            _scriptResourceEvents.OnResourceDeleting(null, resourceEventArgs);

            _projectEditorMock.VerifyAll();
        }
        public void When_non_resource_is_deleted_Then_dont_throw()
        {
            var eventArgs = new ResourceEventArgs(new ContentRef<Resource>());

            Assert.DoesNotThrow(() => _scriptResourceEvents.OnResourceDeleting(this, eventArgs));
        }
Esempio n. 14
0
		private static void DeleteSourceMediaFile(ResourceEventArgs deleteEvent)
		{
			if (deleteEvent.IsResource)
			{
				IList<string> mediaPaths = GetSourceMediaPaths(deleteEvent.Content.Res);
				for (int i = 0; i < mediaPaths.Count; i++)
				{
					if (File.Exists(mediaPaths[i]))
					{
						RecycleBin.SendSilent(mediaPaths[i]);
						PathHelper.DeleteEmptyDirectory(Path.GetDirectoryName(mediaPaths[i]), true);
					}
				}
			}
			else if (deleteEvent.IsDirectory)
			{
				string mediaPath = Path.Combine(
					EditorHelper.SourceMediaDirectory, 
					PathHelper.MakeFilePathRelative(deleteEvent.Path, DualityApp.DataDirectory));

				if (Directory.Exists(mediaPath))
				{
					RecycleBin.SendSilent(mediaPath);
					PathHelper.DeleteEmptyDirectory(Path.GetDirectoryName(mediaPath), true);
				}
			}
		}
Esempio n. 15
0
 private void FileEventManager_ResourceModified(object sender, ResourceEventArgs e)
 {
     // If a Prefab has been modified, update its appearance
     if (e.IsResource && e.Content.Is<Duality.Resources.Prefab>())
     {
         ResourceNode modifiedNode = this.NodeFromPath(e.Content.Path) as ResourceNode;
         if (modifiedNode != null) modifiedNode.UpdateImage();
     }
 }
Esempio n. 16
0
 private void EditorForm_ResourceModified(object sender, ResourceEventArgs e)
 {
     if (!e.IsResource) return;
     if (!e.Content.IsLoaded) return;
     if (this.propertyGrid.Selection.Contains(e.Content.Res))
     {
         // To force updating all probably generated previews, reselect everything
         object[] obj = this.propertyGrid.Selection.ToArray();
         this.propertyGrid.SelectObject(null);
         this.propertyGrid.SelectObjects(obj, false, 100);
     }
     else
     {
         // A (minimalistic) regular update - just in case
         this.propertyGrid.UpdateFromObjects(100);
     }
 }
Esempio n. 17
0
		private static void ProcessDataDirEvents()
		{
			List<ResourceRenamedEventArgs> renameEventBuffer = null;

			// Process events
			while (dataDirEventBuffer.Count > 0)
			{
				FileSystemEventArgs e = FetchFileSystemEvent(dataDirEventBuffer, dataDirWatcher.Path);
				if (e == null) continue;

				if (e.ChangeType == WatcherChangeTypes.Changed)
				{
					ResourceEventArgs args = new ResourceEventArgs(e.FullPath);
					bool justSaved = editorJustSavedRes.Contains(Path.GetFullPath(e.FullPath));
					// Ignore stuff saved by the editor itself
					if (!justSaved && (Resource.IsResourceFile(e.FullPath) || args.IsDirectory))
					{
						// Unregister outdated resources, if modified outside the editor
						if (!args.IsDirectory && ContentProvider.IsContentAvailable(args.Path))
						{
							bool isCurrentScene = args.Content.Is<Scene>() && Scene.Current == args.Content.Res;
							if (isCurrentScene || DualityEditorApp.IsResourceUnsaved(e.FullPath))
							{
								DialogResult result = MessageBox.Show(
									String.Format(EditorRes.GeneralRes.Msg_ConfirmReloadResource_Text, e.FullPath), 
									EditorRes.GeneralRes.Msg_ConfirmReloadResource_Caption, 
									MessageBoxButtons.YesNo,
									MessageBoxIcon.Exclamation);
								if (result == DialogResult.Yes)
								{
									string curScenePath = Scene.CurrentPath;
									ContentProvider.RemoveContent(args.Path);
									if (isCurrentScene) Scene.Current = ContentProvider.RequestContent<Scene>(curScenePath).Res;
								}
							}
							else
								ContentProvider.RemoveContent(args.Path);
						}

						if (ResourceModified != null) ResourceModified(null, args);
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Created)
				{
					if (File.Exists(e.FullPath))
					{
						// Register newly detected ressource file
						if (Resource.IsResourceFile(e.FullPath))
						{
							if (ResourceCreated != null)
								ResourceCreated(null, new ResourceEventArgs(e.FullPath));
						}
						// Import non-ressource file
						else
						{
							bool abort = false;

							if (FileImportProvider.IsImportFileExisting(e.FullPath))
							{
								DialogResult result = MessageBox.Show(
									String.Format(EditorRes.GeneralRes.Msg_ImportConfirmOverwrite_Text, e.FullPath), 
									EditorRes.GeneralRes.Msg_ImportConfirmOverwrite_Caption, 
									MessageBoxButtons.YesNo, 
									MessageBoxIcon.Warning);
								abort = result == DialogResult.No;
							}

							if (!abort)
							{
								bool importedSuccessfully = FileImportProvider.ImportFile(e.FullPath);
								if (!importedSuccessfully)
								{
									MessageBox.Show(
										String.Format(EditorRes.GeneralRes.Msg_CantImport_Text, e.FullPath), 
										EditorRes.GeneralRes.Msg_CantImport_Caption, 
										MessageBoxButtons.OK, 
										MessageBoxIcon.Error);
								}
								abort = !importedSuccessfully;
							}
						}
					}
					else if (Directory.Exists(e.FullPath))
					{
						// Register newly detected ressource directory
						if (ResourceCreated != null)
							ResourceCreated(null, new ResourceEventArgs(e.FullPath));
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Deleted)
				{
					// Is it a Resource file or just something else?
					ResourceEventArgs args = new ResourceEventArgs(e.FullPath);
					if (Resource.IsResourceFile(e.FullPath) || args.IsDirectory)
					{

						// Unregister no-more existing resources
						if (args.IsDirectory)	ContentProvider.RemoveContentTree(args.Path);
						else					ContentProvider.RemoveContent(args.Path);

						if (ResourceDeleted != null)
							ResourceDeleted(null, args);
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Renamed)
				{
					// Is it a Resource file or just something else?
					RenamedEventArgs re = e as RenamedEventArgs;
					ResourceRenamedEventArgs args = new ResourceRenamedEventArgs(re.FullPath, re.OldFullPath);
					if (Resource.IsResourceFile(e.FullPath) || args.IsDirectory)
					{
						// Rename content registerations
						if (args.IsDirectory)	ContentProvider.RenameContentTree(args.OldPath, args.Path);
						else					ContentProvider.RenameContent(args.OldPath, args.Path);

						// Query skipped paths
						bool isSkippedPath = false;
						if (BeginGlobalRename != null)
						{
							BeginGlobalRenameEventArgs beginGlobalRenameArgs = new BeginGlobalRenameEventArgs(args.Path, args.OldPath);
							BeginGlobalRename(null, beginGlobalRenameArgs);
							isSkippedPath = beginGlobalRenameArgs.Cancel;
						}

						if (!isSkippedPath)
						{
							// Buffer rename event to perform the global rename for all at once.
							if (renameEventBuffer == null) renameEventBuffer = new List<ResourceRenamedEventArgs>();
							renameEventBuffer.Add(args);
						}

						if (ResourceRenamed != null) ResourceRenamed(null, args);
					}
				}
			}

			// If required, perform a global rename operation in all existing content
			if (renameEventBuffer != null)
			{
				// Don't do it now - schedule it for the main form event loop so we don't block here.
				DualityEditorApp.MainForm.BeginInvoke((Action)delegate() {
					ProcessingBigTaskDialog taskDialog = new ProcessingBigTaskDialog( 
						EditorRes.GeneralRes.TaskRenameContentRefs_Caption, 
						EditorRes.GeneralRes.TaskRenameContentRefs_Desc, 
						async_RenameContentRefs, renameEventBuffer);
					taskDialog.ShowDialog(DualityEditorApp.MainForm);
				});
			}
		}