private static readonly object _syncLock = new object(); // Synchronization object. #endregion #region Properties. /// <summary> /// Property to set or return a dependency by name. /// </summary> /// <remarks>Setting a dependency to NULL (Nothing in VB.Net) will remove it from the collection.</remarks> public Dependency this[EditorFile file, string type] { get { return(_dependencies[file, type]); } set { _dependencies[file, type] = value; } }
/// <summary> /// Function to return a related plug-in for the given editor file. /// </summary> /// <param name="file">Editor file to evaluate.</param> /// <returns>The plug-in for the editor file.</returns> public static ContentPlugIn GetContentPlugInForFile(EditorFile file) { if ((file == null) || (string.IsNullOrWhiteSpace(file.PlugInType))) { return(null); } ContentPlugIn plugIn; PlugIns.ContentPlugIns.TryGetValue(file.PlugInType, out plugIn); return(plugIn); }
/// <summary> /// Function to discard a cached dependency object. /// </summary> /// <param name="file">The file associated with the dependency.</param> /// <param name="type">The type of dependency.</param> public void DiscardDependencyObject(EditorFile file, string type) { Dependency dependency; if (!TryGetValue(file, type, out dependency)) { return; } var disposer = _cachedDependencies[dependency] as IDisposable; if (disposer != null) { disposer.Dispose(); } _cachedDependencies.Remove(dependency); }
/// <summary> /// Function to try and retrieve a dependency with the specified file and type. /// </summary> /// <param name="file">Editor file for the dependency.</param> /// <param name="type">Type of dependency.</param> /// <param name="value">The dependency, if found. NULL (Nothing in VB.Net) if not.</param> /// <returns>TRUE if found, FALSE if not.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="file"/> or the <paramref name="type"/> parameters are NULL (Nothing in VB.Net).</exception> /// <exception cref="ArgumentException">Thrown when the <paramref name="type"/> parameter is empty.</exception> public bool TryGetValue(EditorFile file, string type, out Dependency value) { if (file == null) { throw new ArgumentNullException("file"); } if (type == null) { throw new ArgumentNullException("type"); } if (string.IsNullOrWhiteSpace(type)) { throw new ArgumentException(APIResources.GOREDIT_ERR_PARAMETER_MUST_NOT_BE_EMPTY, "type"); } return(_dependencies.TryGetValue(new DependencyKey(file, type), out value)); }
/// <summary> /// Initializes a new instance of the <see cref="DependencyKey"/> struct. /// </summary> /// <param name="file">The editor file.</param> /// <param name="type">The type.</param> public DependencyKey(EditorFile file, string type) { if (file == null) { throw new ArgumentNullException("file"); } if (type == null) { throw new ArgumentNullException("type"); } if (string.IsNullOrWhiteSpace(type)) { throw new ArgumentException(APIResources.GOREDIT_ERR_PARAMETER_MUST_NOT_BE_EMPTY, "type"); } File = file; Type = type; }
/// <summary> /// Function to determine if the collection contains a dependency with the specified name and type. /// </summary> /// <param name="file">The dependency file.</param> /// <param name="type">Type of the dependency.</param> /// <returns>TRUE if found, FALSE if not.</returns> public bool Contains(EditorFile file, string type = null) { return(!string.IsNullOrWhiteSpace(type) ? _dependencies.ContainsKey(new DependencyKey(file, type)) : this.Any(item => item.EditorFile == file)); }
/// <summary> /// Function to return the files that are linked to the specified file. /// </summary> /// <param name="file">The file to look up.</param> /// <returns>A list of files that are linked to the specified file.</returns> public static IList <EditorFile> GetFileLinks(EditorFile file) { return(Files .Where(item => item.DependsOn.Contains(file)) .ToArray()); }
/// <summary> /// Function to determine if the specified file is linked to another. /// </summary> /// <param name="file">File to check.</param> /// <returns>TRUE if a link is found, FALSE if not.</returns> public static bool HasFileLinks(EditorFile file) { return(Files.Any(item => item.DependsOn.Contains(file))); }
/// <summary> /// Function to determine if the collection contains a dependency with the specified name and type. /// </summary> /// <param name="file">The dependency file.</param> /// <param name="type">Type of the dependency.</param> /// <returns>TRUE if found, FALSE if not.</returns> public bool Contains(EditorFile file, string type = null) { return(_dependencies.Contains(file, type)); }
/// <summary> /// Function to remove the dependency with the specified file and type from the list. /// </summary> /// <param name="file">File associated with the dependency.</param> /// <param name="type">Type of dependency.</param> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="file"/> or the <paramref name="type"/> parameter is NULL (Nothing in VB.Net).</exception> /// <exception cref="System.ArgumentException">Thrown when the <paramref name="type"/> parameter is empty.</exception> public void Remove(EditorFile file, string type) { DiscardDependencyObject(file, type); _dependencies[file, type] = null; }
/// <summary> /// Function to load content data from the file system. /// </summary> /// <param name="editorFile">The editor file data.</param> /// <param name="file">The file system file that contains the content data.</param> /// <param name="plugIn">The plug-in used to open the file.</param> /// <param name="reload">TRUE to just reload the file, FALSE to do a complete load of the content.</param> public static void Load(EditorFile editorFile, GorgonFileSystemFileEntry file, ContentPlugIn plugIn, bool reload = false) { ContentObject content; if (file == null) { throw new ArgumentNullException("file"); } if (!reload) { ContentSettings settings = plugIn.GetContentSettings(); // Get default settings. if (settings != null) { // Assign the name from the file. settings.Name = file.Name; settings.CreateContent = false; } content = CreateContentObjectInstance(plugIn, settings, editorFile, false); Debug.Assert(_currentContentObject != null, "Content should not be NULL!"); } else { content = Current; } // Load the content dependencies if any exist. // Check for dependencies. if ((editorFile != null) && (editorFile.DependsOn.Count > 0)) { var missingDependencies = new List <string>(); try { LoadDependencies(content, content.EditorFile, missingDependencies); } catch { content.Dependencies.Clear(); throw; } if ((missingDependencies.Count > 0) && (DependencyNotFound != null)) { DependencyNotFound(file.Name, missingDependencies); } } if (!reload) { LoadContentPane(content); } // Load in the content data. using (Stream stream = file.OpenStream(false)) { content.Read(stream); } ContentFile = file; content.OnContentReady(); }
/// <summary> /// Function to create a content object instance. /// </summary> /// <param name="plugIn">The plug-in to use when creating the content.</param> /// <param name="settings">Settings to pass to the content.</param> /// <param name="editorFile">Editor file that holds the content.</param> /// <param name="recordDefaults">TRUE to record the default property values for the content, FALSE to treat as new property values.</param> /// <returns>The new content object.</returns> private static ContentObject CreateContentObjectInstance(ContentPlugIn plugIn, ContentSettings settings, EditorFile editorFile, bool recordDefaults) { ContentObject content = plugIn.CreateContentObject(settings); content.OnCloseCurrent = CloseCurrentContent; content.OnRenameContent = RenameCurrentContent; content.OnPropertyRefreshed = ContentPropertyRefreshed; content.OnChanged = ContentPropertyChanged; content.OnReload = contentItem => { if ((Current == null) || (contentItem != Current)) { return; } Load(editorFile, ContentFile, plugIn, true); }; content.OnCommit = contentItem => { if ((Current == null) || (contentItem != Current)) { return; } // Save the content and its metadata. Save(); }; if ((content.HasProperties) && (recordDefaults)) { content.SetDefaults(); } content.ImageEditor = plugIn.GetRegisteredImageEditor(); if ((content.ImageEditor != null) && (string.IsNullOrWhiteSpace(PlugIns.DefaultImageEditorPlugIn))) { PlugIns.DefaultImageEditorPlugIn = content.ImageEditor.Name; } content.EditorFile = editorFile; if (content.EditorFile != null) { // Indicate that this content is linked to another piece of content. content.HasOwner = EditorMetaDataFile.HasFileLinks(editorFile); } return(content); }