/// <summary> /// Initializes a new instance of the <see cref="ContentObject"/> class. /// </summary> /// <param name="settings">The settings for the content.</param> protected ContentObject(ContentSettings settings) { TypeDescriptor = new ContentTypeDescriptor(this); TypeDescriptor.Enumerate(GetType()); Dependencies = new ContentDependencies(); if (settings == null) { return; } Name = settings.Name; }
/// <summary> /// Function to create a new content object. /// </summary> /// <param name="plugIn">The plug-in used to create the object.</param> /// <returns>The content object or NULL if the content object was not created.</returns> public static ContentObject Create(ContentPlugIn plugIn) { if (plugIn == null) { throw new ArgumentNullException("plugIn"); } // Perform any set up required on the content. ContentSettings settings = plugIn.GetContentSettings(); if (settings != null) { if (!settings.PerformSetup()) { return(null); } settings.CreateContent = true; } return(CreateContentObjectInstance(plugIn, settings, null, true)); }
/// <summary> /// Function to create a content object interface. /// </summary> /// <param name="settings">The initial settings for the content.</param> /// <returns>A new content object interface.</returns> internal ContentObject CreateContentObject(ContentSettings settings) { return(OnCreateContentObject(settings ?? GetContentSettings())); }
/// <summary> /// Function to create a content object interface. /// </summary> /// <param name="settings">The initial settings for the content.</param> /// <returns>A new content object interface.</returns> protected abstract ContentObject OnCreateContentObject(ContentSettings settings);
/// <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); }