public HResult RegisterEditorFactory(Guid guid, INiEditorFactory editorFactory)
        {
            try
            {
                if (editorFactory == null)
                {
                    throw new ArgumentNullException("editorFactory");
                }

                if (_factories.ContainsKey(guid))
                {
                    throw new InvalidOperationException(NeutralResources.EditorFactoryAlreadyRegistered);
                }

                _factories.Add(guid, editorFactory);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Example #2
0
        public HResult GetStandardEditorFactory(Guid? editorGuid, string document, out INiEditorFactory editorFactory, out Guid resolvedEditorGuid)
        {
            editorFactory = null;
            resolvedEditorGuid = Guid.Empty;

            try
            {
                if (editorGuid.HasValue == (document != null))
                    throw new ArgumentOutOfRangeException("editorGuid", NeutralResources.SpecifyEitherDocumentOrEditorGuid);

                var editorFactoryRegistry = (NiEditorFactoryRegistry)GetService(typeof(INiEditorFactoryRegistry));

                if (document != null)
                {
                    string extension = Path.GetExtension(document);

                    if (!String.IsNullOrEmpty(extension))
                    {
                        var activeProject = ((INiProjectManager)GetService(typeof(INiProjectManager))).ActiveProject;
                        ExtensionRegistration registration = null;

                        if (activeProject != null)
                        {
                            var projectGuid = (Guid?)activeProject.GetPropertyEx(NiHierarchyProperty.OwnerType);

                            if (projectGuid.HasValue)
                            {
                                IKeyedCollection<string, ExtensionRegistration> registry;
                                if (editorFactoryRegistry.ProjectRegistries.TryGetValue(projectGuid.Value, out registry))
                                    registry.TryGetValue(extension, out registration);
                            }
                        }

                        if (registration == null)
                            editorFactoryRegistry.DefaultRegistry.TryGetValue(extension, out registration);

                        if (registration != null)
                            editorGuid = registration.FactoryType;
                    }

                    if (!editorGuid.HasValue)
                    {
                        // If we cannot find an editor for the extension, we fall
                        // back to the default editor which opens the document as
                        // plain text.

                        editorGuid = new Guid(NiConstants.TextEditor);
                    }
                }

                if (!editorFactoryRegistry.TryGetEditorFactory(editorGuid.Value, out editorFactory))
                    return HResult.False;

                resolvedEditorGuid = editorGuid.Value;

                return HResult.OK;
            }
            catch (Exception ex)
            {
                return ErrorUtil.GetHResult(ex);
            }
        }
Example #3
0
 public HResult GetStandardEditorFactory(Guid? editorGuid, string document, out INiEditorFactory editorFactory)
 {
     Guid resolvedEditorFactory;
     return GetStandardEditorFactory(editorGuid, document, out editorFactory, out resolvedEditorFactory);
 }
Example #4
0
        public HResult GetStandardEditorFactory(Guid?editorGuid, string document, out INiEditorFactory editorFactory, out Guid resolvedEditorGuid)
        {
            editorFactory      = null;
            resolvedEditorGuid = Guid.Empty;

            try
            {
                if (editorGuid.HasValue == (document != null))
                {
                    throw new ArgumentOutOfRangeException("editorGuid", NeutralResources.SpecifyEitherDocumentOrEditorGuid);
                }

                var editorFactoryRegistry = (NiEditorFactoryRegistry)GetService(typeof(INiEditorFactoryRegistry));

                if (document != null)
                {
                    string extension = Path.GetExtension(document);

                    if (!String.IsNullOrEmpty(extension))
                    {
                        var activeProject = ((INiProjectManager)GetService(typeof(INiProjectManager))).ActiveProject;
                        ExtensionRegistration registration = null;

                        if (activeProject != null)
                        {
                            var projectGuid = (Guid?)activeProject.GetPropertyEx(NiHierarchyProperty.OwnerType);

                            if (projectGuid.HasValue)
                            {
                                IKeyedCollection <string, ExtensionRegistration> registry;
                                if (editorFactoryRegistry.ProjectRegistries.TryGetValue(projectGuid.Value, out registry))
                                {
                                    registry.TryGetValue(extension, out registration);
                                }
                            }
                        }

                        if (registration == null)
                        {
                            editorFactoryRegistry.DefaultRegistry.TryGetValue(extension, out registration);
                        }

                        if (registration != null)
                        {
                            editorGuid = registration.FactoryType;
                        }
                    }

                    if (!editorGuid.HasValue)
                    {
                        // If we cannot find an editor for the extension, we fall
                        // back to the default editor which opens the document as
                        // plain text.

                        editorGuid = new Guid(NiConstants.TextEditor);
                    }
                }

                if (!editorFactoryRegistry.TryGetEditorFactory(editorGuid.Value, out editorFactory))
                {
                    return(HResult.False);
                }

                resolvedEditorGuid = editorGuid.Value;

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Example #5
0
        public HResult GetStandardEditorFactory(Guid?editorGuid, string document, out INiEditorFactory editorFactory)
        {
            Guid resolvedEditorFactory;

            return(GetStandardEditorFactory(editorGuid, document, out editorFactory, out resolvedEditorFactory));
        }
Example #6
0
        private HResult OpenSpecificEditor(string document, Guid editorType, INiEditorFactory editorFactory, INiHierarchy hier, IServiceProvider serviceProvider, out INiWindowFrame windowFrame)
        {
            windowFrame = null;

            try
            {
                if (document == null)
                {
                    throw new ArgumentNullException("document");
                }
                if (editorFactory == null)
                {
                    throw new ArgumentNullException("editorFactory");
                }
                if (serviceProvider == null)
                {
                    throw new ArgumentNullException("serviceProvider");
                }

                OpenDocument openDocument;
                if (_openDocuments.TryGetValue(document, out openDocument))
                {
                    ErrorUtil.ThrowOnFailure(openDocument.WindowFrame.Show());
                    return(HResult.OK);
                }

                string        editorCaption;
                INiWindowPane windowPane;
                var           hr = editorFactory.CreateEditor(document, out editorCaption, out windowPane);

                if (ErrorUtil.Failure(hr))
                {
                    return(hr);
                }
                if (windowPane == null)
                {
                    return(HResult.False);
                }

                hr = windowPane.SetSite(serviceProvider);

                if (ErrorUtil.Failure(hr))
                {
                    return(hr);
                }

                hr = ((INiShell)GetService(typeof(INiShell))).CreateToolWindow(
                    windowPane,
                    NiDockStyle.Document,
                    NiToolWindowOrientation.Top,
                    out windowFrame
                    );

                if (ErrorUtil.Failure(hr))
                {
                    return(hr);
                }

                ErrorUtil.ThrowOnFailure(windowFrame.SetCaption(
                                             editorCaption ?? Path.GetFileName(document)
                                             ));

                hr = windowPane.Initialize();

                if (ErrorUtil.Failure(hr))
                {
                    return(hr);
                }

                var docData = windowPane as INiPersistDocData;

                if (docData == null)
                {
                    var textBufferProvider = windowPane as INiTextBufferProvider;

                    if (textBufferProvider != null)
                    {
                        INiTextBuffer textBuffer;
                        hr = textBufferProvider.GetTextBuffer(out textBuffer);

                        if (ErrorUtil.Failure(hr))
                        {
                            return(hr);
                        }

                        docData = textBuffer;
                    }
                }

                int rdtCooke = -1;

                if (docData != null)
                {
                    hr = docData.LoadDocData(document);
                    if (ErrorUtil.Failure(hr))
                    {
                        return(hr);
                    }

                    hr = ((INiRunningDocumentTable)GetService(typeof(INiRunningDocumentTable))).Register(
                        document, hier, docData, out rdtCooke
                        );
                    if (ErrorUtil.Failure(hr))
                    {
                        return(hr);
                    }
                }

                windowFrame.SetPropertyEx(NiFrameProperty.DocCookie, rdtCooke);
                windowFrame.SetPropertyEx(NiFrameProperty.DocView, windowPane);
                windowFrame.SetPropertyEx(NiFrameProperty.DocData, docData);
                windowFrame.SetPropertyEx(NiFrameProperty.Document, document);
                windowFrame.SetPropertyEx(NiFrameProperty.EditorType, editorType);
                windowFrame.SetPropertyEx(NiFrameProperty.Hierarchy, hier);
                windowFrame.SetPropertyEx(NiFrameProperty.Type, NiFrameType.Document);

                _openDocuments.Add(document, new OpenDocument(
                                       this,
                                       document,
                                       hier,
                                       windowFrame,
                                       rdtCooke,
                                       docData
                                       ));

                return(windowFrame.Show());
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
 public bool TryGetEditorFactory(Guid guid, out INiEditorFactory editorFactory)
 {
     return(_factories.TryGetValue(guid, out editorFactory));
 }