/// <include file='doc\ServiceProvider.uex' path='docs/doc[@for="ServiceProvider.Dispose"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual void Dispose()
 {
     if (serviceProvider != null)
     {
         serviceProvider = null;
     }
 }
 /// <include file='doc\ServiceProvider.uex' path='docs/doc[@for="ServiceProvider.NativeMethods.IObjectWithSite.SetSite"]/*' />
 /// <devdoc>
 ///     Sets the site object we will be using to resolve services.
 /// </devdoc>
 void NativeMethods.IObjectWithSite.SetSite(object pUnkSite)
 {
     if (pUnkSite is NativeMethods.IOleServiceProvider)
     {
         serviceProvider = (NativeMethods.IOleServiceProvider)pUnkSite;
     }
 }
        /// <include file='doc\VSDesignerLoader.uex' path='docs/doc[@for="VSDesignerLoader.CreateCodeLoader"]/*' />
        /// <devdoc>
        ///     Called to create the MCM loader.
        /// </devdoc>
        protected override CodeLoader CreateCodeLoader(TextBuffer buffer, IDesignerLoaderHost host)
        {
            CodeLoader loader = null;

            // Get the context object off of the hierarchy, and ask it for an IVSMDCodeDomProvider
            // instance.
            //
            IVsHierarchy hier = Hierarchy;

            if (hier is IVsProject)
            {
                NativeMethods.IOleServiceProvider oleProvider = (NativeMethods.IOleServiceProvider)((IVsProject)hier).GetItemContext(ItemId);

                if (oleProvider != null)
                {
                    ServiceProvider      contextProv     = new ServiceProvider(oleProvider);
                    IVSMDCodeDomProvider codeDomProvider = (IVSMDCodeDomProvider)contextProv.GetService(typeof(IVSMDCodeDomProvider));
                    if (codeDomProvider != null)
                    {
                        loader = new VsCodeDomLoader(this, hier, ItemId, (CodeDomProvider)codeDomProvider.CodeDomProvider, buffer, host);
                    }
                }
            }

            if (loader == null)
            {
                throw new NotSupportedException(SR.GetString(SR.DESIGNERLOADERNoLanguageSupport));
            }

            return(loader);
        }
        public virtual void Dispose()
        {
            Debug.Assert(componentCount == 0,
                         "All components should have been removed by now!");

            serviceProvider = null;
            site            = null;
        }
        //////////////////////////////////////////////////////////////////////
        // Methods

        public virtual void SetSite(object site)
        {
            Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "StyleBuilderFormContainer: SetSite");
            if (site == null)
            {
                serviceProvider = null;
                Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "StyleBuilderFormContainer: SetSite: Site is null");
                return;
            }

            if (site is NativeMethods.IOleServiceProvider)
            {
                serviceProvider = (NativeMethods.IOleServiceProvider)site;
                Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "StyleBuilderFormContainer: SetSite: Site is a valid IServiceProvider");
            }
        }
        /// <include file='doc\StyleBuilderSite.uex' path='docs/doc[@for="StyleBuilderSite.SetSite"]/*' />
        /// <devdoc>
        /// </devdoc>
        internal void SetSite(object site)
        {
            Debug.Assert((site != null) && (site is NativeMethods.IOleServiceProvider),
                         "Null site or non-IServiceProvider site passed to StyleBuilderSite");
            if ((site == null) || !(site is NativeMethods.IOleServiceProvider))
            {
                throw new COMException(String.Empty, NativeMethods.E_INVALIDARG);
            }

            Debug.Assert(this.site == null, "StyleBuilderSite already site'd");
            if (this.site != null)
            {
                throw new COMException(String.Empty, NativeMethods.E_UNEXPECTED);
            }

            this.site = (NativeMethods.IOleServiceProvider)site;
        }
 /// <include file='doc\StyleBuilderSite.uex' path='docs/doc[@for="StyleBuilderSite.Close"]/*' />
 /// <devdoc>
 /// </devdoc>
 public void Close()
 {
     site = null;
 }
        /// <include file='doc\DesignerEditorFactory.uex' path='docs/doc[@for="DesignerEditorFactory.CreateEditorInstance"]/*' />
        /// <devdoc>
        ///     Creates a new editor for the given pile of flags.
        /// </devdoc>
        public virtual int CreateEditorInstance(int vscreateeditorflags, string fileName, string physicalView,
                                                IVsHierarchy hierarchy, int itemid, object existingDocData,
                                                out object docView, out object docData,
                                                out string caption, out Guid cmdUIGuid)
        {
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            IVsTextStream textStream = null;          // the buffer we will use

            // We support a design view only
            //
            if (physicalView == null || !physicalView.Equals(physicalViewName))
            {
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "EditorFactory : Invalid physical view name.");
                throw new COMException("Invalid physical view", NativeMethods.E_NOTIMPL);
            }

            // perform parameter validation and initialization.
            //
            if (((vscreateeditorflags & (__VSCREATEEDITORFLAGS.CEF_OPENFILE | __VSCREATEEDITORFLAGS.CEF_SILENT)) == 0))
            {
                throw new ArgumentException("vscreateeditorflags");
            }

            docView = null;
            docData = null;
            caption = null;

            IVSMDDesignerService ds = (IVSMDDesignerService)serviceProvider.GetService(typeof(IVSMDDesignerService));

            if (ds == null)
            {
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "EditorFactory : No designer service.");
                throw new Exception(SR.GetString(SR.EDITORNoDesignerService, fileName));
            }

            // Create our doc data if we don't have an existing one.
            //
            if (existingDocData == null)
            {
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "EditorFactory : No existing doc data, creating one.");
                ILocalRegistry localRegistry = (ILocalRegistry)serviceProvider.GetService(typeof(ILocalRegistry));
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tobtained local registry");

                if (localRegistry == null)
                {
                    Debug.Fail("Shell did not offer local registry, so we can't create a text buffer.");
                    throw new COMException("Unable to create text buffer", NativeMethods.E_FAIL);
                }

                Debug.Assert(!(typeof(VsTextBuffer)).GUID.Equals(Guid.Empty), "EE has munched on text buffer guid.");

                try {
                    Guid guidTemp = typeof(IVsTextStream).GUID;
                    textStream = (IVsTextStream)localRegistry.CreateInstance(typeof(VsTextBuffer).GUID,
                                                                             null,
                                                                             ref guidTemp,
                                                                             NativeMethods.CLSCTX_INPROC_SERVER);
                }
                #if DEBUG
                catch (ExternalException ex) {
                    Guid SID_VsTextBuffer  = typeof(VsTextBuffer).GUID;
                    Guid IID_IVsTextStream = typeof(IVsTextStream).GUID;
                    Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tILocalRegistry.CreateInstance(" + SID_VsTextBuffer.ToString() + ", " + IID_IVsTextStream.ToString() + ") failed (hr=" + ex.ErrorCode.ToString() + ")");
                #else
                catch (Exception) {
                #endif
                    throw new COMException("Failed to create text buffer", NativeMethods.E_FAIL);
                }

                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tcreated text buffer");
            }
            else
            {
                Debug.Assert(existingDocData is IVsTextStream, "Existing doc data must implement IVsTextStream");
                textStream = (IVsTextStream)existingDocData;
            }

            // Create and initialize our code stream.
            //
            object loaderObj = ds.CreateDesignerLoader(ds.GetDesignerLoaderClassForFile(fileName));

            // Before we embark on creating the designer, we need to do a quick check
            // to see if this file can be designed.  If it can't be we will fail this
            // editor create, and the shell will go on to the next editor in the list.
            //
            Debug.Assert(loaderObj is DesignerLoader, "loader must inherit from DesignerLoader: " + loaderObj.GetType().FullName);
            Debug.Assert(loaderObj is IVSMDDesignerLoader, "code stream must implement IVSMDDesignerLoader: " + loaderObj.GetType().FullName);
            NativeMethods.IOleServiceProvider oleProvider = (NativeMethods.IOleServiceProvider)serviceProvider.GetService(typeof(NativeMethods.IOleServiceProvider));
            ((IVSMDDesignerLoader)loaderObj).Initialize(oleProvider, hierarchy, itemid, textStream);

            DesignerLoader loader = (DesignerLoader)loaderObj;

            if (existingDocData == null)
            {
                if (textStream is NativeMethods.IObjectWithSite)
                {
                    ((NativeMethods.IObjectWithSite)textStream).SetSite(site);
                    Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tsited text buffer");
                }
            }

            // Now slam the two together and make a designer
            //
            IVSMDDesigner designer = ds.CreateDesigner(oleProvider, loader);
            Debug.Assert(designer != null, "Designer service should have thrown if it had a problem.");

            // Now ask for the view and setup our out-parameters
            //
            int attrs = NativeMethods.GetFileAttributes(fileName);
            if ((attrs & NativeMethods.FILE_ATTRIBUTE_READONLY) != 0)
            {
                attrs = _READONLYSTATUS.ROSTATUS_ReadOnly;
            }
            else
            {
                attrs = _READONLYSTATUS.ROSTATUS_NotReadOnly;
            }

            docView   = designer.View;
            docData   = textStream;
            caption   = ((IVSMDDesignerLoader)loaderObj).GetEditorCaption(attrs);
            cmdUIGuid = designer.CommandGuid;

            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

            return(0);
        }
 /// <include file='doc\ServiceProvider.uex' path='docs/doc[@for="ServiceProvider.ServiceProvider1"]/*' />
 /// <devdoc>
 ///     Creates a new ServiceProvider object and uses the given interface to resolve
 ///     services.
 /// </devdoc>
 public ServiceProvider(object sp)
 {
     serviceProvider = (NativeMethods.IOleServiceProvider)sp;
 }
 /// <include file='doc\ServiceProvider.uex' path='docs/doc[@for="ServiceProvider.ServiceProvider"]/*' />
 /// <devdoc>
 ///     Creates a new ServiceProvider object and uses the given interface to resolve
 ///     services.
 /// </devdoc>
 internal ServiceProvider(NativeMethods.IOleServiceProvider sp)
 {
     serviceProvider = sp;
 }
Esempio n. 11
0
 public DesignerServiceProvider(NativeMethods.IOleServiceProvider sp) : base(sp)
 {
 }