//-------------------------------------------------------------- /// <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; }
//-------------------------------------------------------------- /// <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 }; }
/// <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; }
//-------------------------------------------------------------- /// <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, }; }
//-------------------------------------------------------------- /// <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, }; }
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(); }
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); }
/// <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); }
/// <inheritdoc/> protected override Document OnCreate(DocumentType documentType) { return new ModelDocument(_editor, documentType); }
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); } }
//-------------------------------------------------------------- #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(); }
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; }
//-------------------------------------------------------------- /// <inheritdoc/> protected override Document OnCreate(DocumentType documentType) { var document = new TextDocument(_editor, documentType); TextIntelliSense.EnableIntelliSense(document); return document; }
/// <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);
/// <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);
//-------------------------------------------------------------- /// <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); }
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(); } }
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; }