コード例 #1
0
ファイル: SceneView.cs プロジェクト: Banbury/duality
		private void EditorForm_ResourceRenamed(object sender, ResourceRenamedEventArgs e)
		{
			if (e.Path == Scene.CurrentPath) this.UpdateSceneLabel();

			if (!e.IsDirectory && !typeof(Prefab).IsAssignableFrom(e.ContentType)) return;
			this.UpdatePrefabLinkStatus(true);
		}
コード例 #2
0
ファイル: FileEventManager.cs プロジェクト: Banbury/duality
		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);
				});
			}
		}
コード例 #3
0
		private void FileEventManager_ResourceRenamed(object sender, ResourceRenamedEventArgs e)
		{
			NodeBase node = this.NodeFromPath(e.OldPath);
			bool registerRes = false;

			// Modify existing node
			if (node != null)
			{
				// If its a file, remove and add it again
				if (File.Exists(e.Path))
				{
					// Remove it
					this.UnregisterNodeTree(node);
					node.Parent.Nodes.Remove(node);

					// Register it
					registerRes = true;
				}
				// Otherwise: Rename node according to file
				else
				{
					this.UnregisterNodeTree(node);
					node.NodePath = e.Path;
					node.ApplyPathToName();
					this.RegisterNodeTree(node);
				}
			}
			// Register newly detected ressource file
			else if (this.NodeFromPath(e.Path) == null)
			{
				registerRes = true;
			}

			// If neccessary, check if the file is a ressource file and add it, if yes
			if (registerRes && Resource.IsResourceFile(e.Path))
			{
				node = this.ScanFile(e.Path);

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

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

			// Perform previously scheduled selection
			this.PerformScheduleSelect(Path.GetFullPath(e.Path));
		}
コード例 #4
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);
                });
            }
        }