Esempio n. 1
0
        /// <summary>
        /// Function to include a file in the editor.
        /// </summary>
        /// <param name="file">File entry to include.</param>
        /// <returns>An editor file object linking the file to the the system.</returns>
        public static EditorFile IncludeItem(GorgonFileSystemFileEntry file)
        {
            ContentPlugIn plugIn = GetContentPlugInForFile(file.Extension);

            string plugInType = string.Empty;

            if (plugIn != null)
            {
                plugInType = plugIn.GetType().FullName;
            }


            var fileItem = new EditorFile(file.FullPath)
            {
                PlugInType = plugInType
            };

            if (plugIn != null)
            {
                using (Stream fileStream = file.OpenStream(false))
                {
                    plugIn.GetEditorFileAttributes(fileStream, fileItem.Attributes);
                }
            }

            EditorMetaDataFile.Files[fileItem.FilePath] = fileItem;

            return(fileItem);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        /// <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));
        }
Esempio n. 4
0
        /// <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();
        }