Ejemplo n.º 1
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="TextureDocument"/> class.
        /// </summary>
        /// <param name="editor">The editor.</param>
        /// <param name="documentType">The type of the document.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="editor"/> or <paramref name="documentType"/> is <see langword="null"/>.
        /// </exception>
        internal TextureDocument(IEditorService editor, DocumentType documentType)
            : base(editor, documentType)
        {
            _graphicsService = editor.Services.GetInstance<IGraphicsService>().ThrowIfMissing();
            _monoGameService = editor.Services.GetInstance<IMonoGameService>().ThrowIfMissing();
            _propertiesService = editor.Services.GetInstance<IPropertiesService>().WarnIfMissing();

            Editor.ActiveDockTabItemChanged += OnEditorDockTabItemChanged;
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="TextDocumentFactory"/> class.
        /// </summary>
        /// <param name="editor">The editor.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="editor"/> is <see langword="null"/>.
        /// </exception>
        public TextDocumentFactory(IEditorService editor)
            : base("Text Editor")
        {
            if (editor == null)
                throw new ArgumentNullException(nameof(editor));

            _editor = editor;

            // ----- Initialize supported document types.
            // Text Files (*.txt)
            var textDocumentType = new DocumentType(
                name: "Text file",
                factory: this,
                icon: MultiColorGlyphs.Document,
                fileExtensions: new[] { ".txt" },
                isCreatable: true,
                isLoadable: true,
                isSavable: true,
                priority: 10);

            // XML Files (*.XML)
            var xmlDocumentType = new DocumentType(
                name: "XML file",
                factory: this,
                icon: MultiColorGlyphs.DocumentXml,
                fileExtensions: new[] { ".xml" },
                isCreatable: false,
                isLoadable: true,
                isSavable: true,
                priority: 0);

            // All Files (*.*)
            var anyDocumentType = new DocumentType(
                name: AnyDocumentTypeName,
                factory: this,
                icon: null,
                fileExtensions: new[] { ".*" },
                isCreatable: false,
                isLoadable: true,
                isSavable: true,
                priority: 0);

            DocumentTypes = new[]
            {
                textDocumentType,
                xmlDocumentType,
                anyDocumentType
            };
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public Document New(DocumentType documentType)
        {
            if (documentType == null)
                throw new ArgumentNullException(nameof(documentType));
            if (!documentType.IsCreatable)
                throw new NotSupportedException(Invariant($"Creating new documents of type \"{documentType.Name}\" is not supported."));

            Logger.Info(CultureInfo.InvariantCulture, "Creating new document of type \"{0}\".", documentType.Name);

            var document = documentType.Factory.Create(documentType);
            if (document != null)
            {
                var viewModel = document.CreateViewModel();
                Editor.ActivateItem(viewModel);
            }

            return document;
        }
Ejemplo n.º 4
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="TextureDocumentFactory" /> class.
        /// </summary>
        /// <param name="editor">The editor.</param>
        public TextureDocumentFactory(IEditorService editor)
            : base("Texture Viewer")
        {
            if (editor == null)
                throw new ArgumentNullException(nameof(editor));

            _editor = editor;

            // ----- Initialize supported document types.
            // Textures
            var textureDocumentType = new DocumentType(
                name: "Texture",
                factory: this,
                icon: MultiColorGlyphs.Image,
                fileExtensions: new[]
                {
                    ".bmp", ".dds", ".gif", ".ico", ".jpg", ".jpeg", ".png", ".tga", ".tif",
                    ".jxr", ".hdp", ".wdp" // HD Photo
                },
                isCreatable: false,
                isLoadable: true,
                isSavable: false,
                priority: 10);

            _processedTextureDocumentType = new DocumentType(
                name: "Texture, processed",
                factory: this,
                icon: MultiColorGlyphs.Image,
                fileExtensions: new[]
                {
                    ".xnb"
                },
                isCreatable: false,
                isLoadable: true,
                isSavable: false,
                priority: 10);

            DocumentTypes = new[]
            {
                textureDocumentType,
                _processedTextureDocumentType,
            };
        }
Ejemplo n.º 5
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ModelDocumentFactory" /> class.
        /// </summary>
        /// <param name="editor">The editor.</param>
        public ModelDocumentFactory(IEditorService editor)
            : base("Model Viewer")
        {
            if (editor == null)
                throw new ArgumentNullException(nameof(editor));

            _editor = editor;

            // ----- Initialize supported document types.
            var modelDocumentType = new DocumentType(
                name: "3D model",
                factory: this,
                icon: MultiColorGlyphs.Model,
                fileExtensions: new[]
                {
                    ".dae", ".fbx", ".x"
                },
                isCreatable: false,
                isLoadable: true,
                isSavable: false,
                priority: 10);

            _processedModelDocumentType = new DocumentType(
                name: "3D model, processed",
                factory: this,
                icon: MultiColorGlyphs.Model,
                fileExtensions: new[]
                {
                    ".xnb"
                },
                isCreatable: false,
                isLoadable: true,
                isSavable: false,
                priority: 10);

            DocumentTypes = new[]
            {
                modelDocumentType,
                _processedModelDocumentType,
            };
        }
Ejemplo n.º 6
0
        public TextDocument(IEditorService editor, DocumentType documentType)
            : base(editor, documentType)
        {
            // Optional services:
            _searchService = editor.Services.GetInstance<ISearchService>().WarnIfMissing();
            _propertiesService = editor.Services.GetInstance<IPropertiesService>().WarnIfMissing();

            AvalonEditDocument = new AvalonEditDocument();
            SelectionMarkers = new TextSegmentCollection<Marker>();
            SearchMarkers = new TextSegmentCollection<Marker>();
            ErrorMarkers = new TextSegmentCollection<Marker>();

            InitializeSearch();

            // The UndoStack indicates whether changes were made to the document.
            AvalonEditDocument.UndoStack.PropertyChanged += OnUndoStackChanged;
            AvalonEditDocument.TextChanged += OnTextChanged;

            Editor.ActiveDockTabItemChanged += OnEditorDockTabItemChanged;

            BeginInvokeUpdateProperties();
        }
Ejemplo n.º 7
0
        protected Document(IEditorService editor, DocumentType documentType)
        {
            if (!WindowsHelper.IsInDesignMode)
            {
                if (editor == null)
                    throw new ArgumentNullException(nameof(editor));

                Editor = editor;
                _documentExtension = editor.Extensions.OfType<DocumentExtension>().FirstOrDefault().ThrowIfMissing();
            }

            if (documentType == null)
                throw new ArgumentNullException(nameof(documentType));

            DocumentType = documentType;
            _fileDialogFilter = DocumentHelper.GetFilterString(new[] { documentType });
            _fileDialogFilterIndex = 1;
            _viewModels = new ObservableCollection<DocumentViewModel>();
            ViewModels = new ReadOnlyObservableCollection<DocumentViewModel>(_viewModels);

            _documentExtension?.RegisterDocument(this);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new document of the specified type.
        /// </summary>
        /// <param name="documentType">The type of the document.</param>
        /// <returns>
        /// The newly created document if successful; otherwise, <see langword="null"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="documentType"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The document type belongs to a different factory.
        /// </exception>
        internal Document Create(DocumentType documentType)
        {
            if (documentType == null)
                throw new ArgumentNullException(nameof(documentType));
            if (documentType.Factory != this)
                throw new ArgumentException("The document type belongs to a different factory.");

            return OnCreate(documentType);
        }
Ejemplo n.º 9
0
 /// <inheritdoc/>
 protected override Document OnCreate(DocumentType documentType)
 {
     return new ModelDocument(_editor, documentType);
 }
Ejemplo n.º 10
0
        private void OnNewDocument(DocumentType documentType)
        {
            Logger.Info(CultureInfo.InvariantCulture, "Creating new document of type \"{0}\".", documentType.Name);

            var document = _documentExtension.New(documentType);

            if (_toolBarSplitButton != null && document != null)
            {
                // Select last recently used document type in toolbar.
                _toolBarSplitButton.SelectedItem = _toolBarSplitButton.Items
                                                                      .Select(menuItem => menuItem.CommandItem)
                                                                      .FirstOrDefault(commandItem => commandItem.CommandParameter == documentType);
            }
        }
Ejemplo n.º 11
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="ModelDocument"/> class.
        /// </summary>
        /// <param name="editor">The editor.</param>
        /// <param name="documentType">The type of the document.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="editor"/> or <paramref name="documentType"/> is <see langword="null"/>.
        /// </exception>
        internal ModelDocument(IEditorService editor, DocumentType documentType)
          : base(editor, documentType)
        {
            _modelsExtension = editor.Extensions.OfType<ModelsExtension>().FirstOrDefault().ThrowIfMissing();
            _useDigitalRuneGraphics = _modelsExtension.UseDigitalRuneGraphics;

            var services = Editor.Services;
            _documentService = services.GetInstance<IDocumentService>().ThrowIfMissing();
            _statusService = services.GetInstance<IStatusService>().ThrowIfMissing();
            _outputService = services.GetInstance<IOutputService>().ThrowIfMissing();
            _animationService = services.GetInstance<IAnimationService>().ThrowIfMissing();
            _monoGameService = services.GetInstance<IMonoGameService>().ThrowIfMissing();
            _outlineService = services.GetInstance<IOutlineService>().WarnIfMissing();
            _propertiesService = services.GetInstance<IPropertiesService>().WarnIfMissing();
            _errorService = services.GetInstance<IErrorService>().WarnIfMissing();

            Editor.ActiveDockTabItemChanged += OnEditorDockTabItemChanged;

            UpdateProperties();
            UpdateOutline();
        }
Ejemplo n.º 12
0
        private static string GetUntitledName(IDocumentService documentService, DocumentType documentType)
        {
            if (documentService == null)
                throw new ArgumentNullException(nameof(documentService));
            if (documentType == null)
                throw new ArgumentNullException(nameof(documentType));

            string name;
            bool nameAlreadyUsed;
            string extension = documentType.FileExtensions.FirstOrDefault() ?? string.Empty;

            int lastUntitledNumber;
            _lastUntitledNumbers.TryGetValue(extension, out lastUntitledNumber);

            do
            {
                // Use ascending numbering for untitled documents, e.g. "Untitled3.fx".
                lastUntitledNumber++;
                name = "Untitled" + lastUntitledNumber + extension;

                // Check if name is already in use:
                nameAlreadyUsed = false;
                foreach (Document document in documentService.Documents)
                {
                    string documentName = document.IsUntitled
                                        ? document._untitledName   // Important: Use field to avoid endless loops.
                                        : Path.GetFileName(document.Uri.LocalPath);
                    if (name == documentName)
                    {
                        nameAlreadyUsed = true;
                        break;
                    }
                }
            } while (nameAlreadyUsed);

            _lastUntitledNumbers[extension] = lastUntitledNumber;

            return name;
        }
Ejemplo n.º 13
0
        //--------------------------------------------------------------
        /// <inheritdoc/>
        protected override Document OnCreate(DocumentType documentType)
        {
            var document = new TextDocument(_editor, documentType);

            TextIntelliSense.EnableIntelliSense(document);

            return document;
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a new document of the specified type.
 /// </summary>
 /// <param name="documentType">Type of the document.</param>
 /// <returns>
 /// The newly created document if successful; otherwise, <see langword="null"/>.
 /// </returns>
 /// <remarks>
 /// When this method is called, it is guaranteed that <paramref name="documentType"/> is
 /// not <see langword="null"/> and that it is a document type of this factory.
 /// </remarks>
 protected abstract Document OnCreate(DocumentType documentType);
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a new document of the specified type.
 /// </summary>
 /// <param name="documentType">Type of the document.</param>
 /// <returns>
 /// The newly created document if successful; otherwise, <see langword="null"/>.
 /// </returns>
 /// <remarks>
 /// When this method is called, it is guaranteed that <paramref name="documentType"/> is
 /// not <see langword="null"/> and that it is a document type of this factory.
 /// </remarks>
 protected abstract Document OnCreate(DocumentType documentType);
Ejemplo n.º 16
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ShaderDocumentFactory" /> class.
        /// </summary>
        /// <param name="editor">The editor.</param>
        public ShaderDocumentFactory(IEditorService editor)
            : base("Shader Editor")
        {
            if (editor == null)
                throw new ArgumentNullException(nameof(editor));

            _editor = editor;

            // ----- Initialize supported document types.
            // HLSL Effect Files (*.fx, *.fxh)
            var fxDocumentType = new DocumentType(
                name: FxFile,
                factory: this,
                icon: MultiColorGlyphs.DocumentEffect,
                fileExtensions: new[] { ".fx", ".fxh" },
                isCreatable: true,
                isLoadable: true,
                isSavable: true,
                priority: 10);

            // Cg File (*.cg)
            var cgDocumentType = new DocumentType(
                name: CgFile,
                factory: this,
                icon: MultiColorGlyphs.DocumentEffect,
                fileExtensions: new[] { ".cg", ".cgh" },
                isCreatable: false,
                isLoadable: true,
                isSavable: true,
                priority: 10);

            // Cg Effect Files (*.cgfx)
            var cgFXDocumentType = new DocumentType(
                name: CgFXFile,
                factory: this,
                icon: MultiColorGlyphs.DocumentEffect,
                fileExtensions: new[] { ".cgfx" },
                isCreatable: false,
                isLoadable: true,
                isSavable: true,
                priority: 10);

            // All Effect Files (*.fx, *.cgfx)
            var anyDocumentType = new DocumentType(
                name: "All effect files",
                factory: this,
                icon: null,
                fileExtensions: new[] { ".fx", ".fxh", ".cg", ".cgh", ".cgfx" },
                isCreatable: false,
                isLoadable: true,
                isSavable: true,
                priority: 10);

            DocumentTypes = new[]
            {
                fxDocumentType,
                cgDocumentType,
                cgFXDocumentType,
                anyDocumentType
            };

            _filter = DocumentHelper.GetFilterString(DocumentTypes);
        }
Ejemplo n.º 17
0
 private static ShaderIntelliSense SelectIntelliSense(DocumentType documentType)
 {
     switch (documentType.Name)
     {
         case FxFile:
             return new HlslIntelliSense();
         case CgFile:
         case CgFXFile:
             return new CgIntelliSense();
         default:
             Logger.Warn("Unknown document type. Selecting IntelliSense provider for DirectX 10 HLSL.");
             return new HlslIntelliSense();
     }
 }
Ejemplo n.º 18
0
        protected override Document OnCreate(DocumentType documentType)
        {
            // Create a text document.
            var document = new TextDocument(_editor, documentType)
            {
                FileDialogFilter = _filter,
            };

            switch (documentType.FileExtensions.First())
            {
                case ".fx":
                case ".fxh":
                    document.FileDialogFilterIndex = 1;
                    break;
                case ".cg":
                case ".cgh":
                    document.FileDialogFilterIndex = 2;
                    break;
                case ".cgfx":
                    document.FileDialogFilterIndex = 3;
                    break;
                default:
                    document.FileDialogFilterIndex = 1;
                    break;
            }

            // Register event handler that enables IntelliSense on every view which is
            // added to the document.
            ((INotifyCollectionChanged)document.ViewModels).CollectionChanged += OnViewModelsChanged;

            return document;
        }