Ejemplo n.º 1
0
        public static void OpenDocument(ServiceProvider provider, string path)
        {
            IVsUIHierarchy hierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;
            IVsTextView    view;

            VsShell.OpenDocument(provider, path, out hierarchy, out itemID, out windowFrame, out view);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Here we simply host the visual studio core text editor.
        /// </summary>
        public virtual void CreateEditorInstance(uint createDocFlags, string moniker,
                                                 string physicalView, IVsHierarchy pHier, uint itemid, IntPtr existingDocData,
                                                 out IntPtr docView, out IntPtr docData, out string editorCaption,
                                                 out Guid cmdUI, out int cancelled)
        {
            string ext = Path.GetExtension(moniker).ToLower();

            if (ext.StartsWith("."))
            {
                ext = ext.Substring(1);
            }
            bool takeover = CheckAllFileTypes() && !this.IsRegisteredExtension(ext);

            if (takeover && !IsOurKindOfFile(moniker))
            {
                throw new System.Runtime.InteropServices.COMException("", (int)VsConstants.VS_E_UNSUPPORTEDFORMAT);
            }

            IVsTextLines buffer = null;

            if (existingDocData != IntPtr.Zero)
            {
                buffer = (IVsTextLines)Marshal.GetTypedObjectForIUnknown(existingDocData, typeof(IVsTextLines));
            }
            else
            {
                buffer = (IVsTextLines)VsShell.CreateInstance(this.site, ref VsConstants.CLSID_VsTextBuffer, ref VsConstants.IID_IVsTextLines, typeof(IVsTextLines));
            }

            IObjectWithSite objWithSite = (IObjectWithSite)buffer;

            objWithSite.SetSite(this.site.Unwrap());

            object window = CreateEditorView(moniker, buffer, physicalView, out editorCaption, out cmdUI);

            if (takeover)
            {
                Guid langSid = GetLanguageSID();
                if (langSid != Guid.Empty)
                {
                    buffer.SetLanguageServiceID(ref langSid);
                    IVsUserData vud = (IVsUserData)buffer;
                    vud.SetData(ref VsConstants.GUID_VsBufferDetectLangSID, false);
                }
                // todo: for some reason my commands are disabled when we go through this
                // code path...
            }

            docView = Marshal.GetIUnknownForObject(window);
            docData = Marshal.GetIUnknownForObject(buffer);

            // VS core editor is the primary command handler
            cancelled = 0;
        }
Ejemplo n.º 3
0
        public virtual object CreateEditorView(string moniker, IVsTextLines buffer, string physicalView, out string editorCaption, out Guid cmdUI)
        {
            IVsCodeWindow window = (IVsCodeWindow)VsShell.CreateInstance(this.site, ref VsConstants.CLSID_VsCodeWindow, ref VsConstants.IID_IVsCodeWindow, typeof(IVsCodeWindow));

            window.SetBuffer(buffer);
            window.SetBaseEditorCaption(null);
            window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption);

            Guid CMDUIGUID_TextEditor = new Guid(0x8B382828, 0x6202, 0x11d1, 0x88, 0x70, 0x00, 0x00, 0xF8, 0x75, 0x79, 0xD2);

            cmdUI = CMDUIGUID_TextEditor;
            return(window);
        }
Ejemplo n.º 4
0
        public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site)
        {
            this.site          = new ServiceProvider(site);
            this.editorFactory = CreateEditorFactory();
            if (this.editorFactory != null)
            {
                this.editorFactory.SetSite(site);
                Guid editorGuid        = this.editorFactory.GetType().GUID;
                IVsRegisterEditors vre = (IVsRegisterEditors)this.site.QueryService(VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
                vre.RegisterEditor(ref editorGuid, editorFactory, out this.editorFactoryCookie);
            }

            this.projectFactory = CreateProjectFactory();
            if (this.projectFactory != null)
            {
                this.projectFactory.SetSite(site);
                IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
                if (rpt != null)
                {
                    Guid projectType = this.projectFactory.GetType().GUID;
                    rpt.RegisterProjectType(ref projectType, this.projectFactory, out this.projectFactoryCookie);
                }
            }

            uint lcid = VsShell.GetProviderLocale(this.site);

            languageServices = new Hashtable();
            string          thisPackage = "{" + this.GetType().GUID.ToString() + "}";
            ServiceProvider thisSite    = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider) this);

            ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.QueryService(VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3));
            string          root          = null;

            if (localRegistry != null)
            {
                localRegistry.GetLocalRegistryRoot(out root);
            }
            using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
                if (rootKey != null)
                {
                    using (RegistryKey languages = rootKey.OpenSubKey("Languages\\Language Services")) {
                        if (languages != null)
                        {
                            foreach (string languageName in languages.GetSubKeyNames())
                            {
                                using (RegistryKey langKey = languages.OpenSubKey(languageName)) {
                                    object pkg = langKey.GetValue("Package");
                                    if (pkg is string && (string)pkg == thisPackage)
                                    {
                                        object guid = langKey.GetValue(null);
                                        if (guid is string)
                                        {
                                            Guid langGuid = new Guid((string)guid);
                                            if (!this.languageServices.Contains(langGuid.ToString()))
                                            {
                                                LanguageService svc = CreateLanguageService(ref langGuid);
                                                if (svc != null)
                                                {
                                                    svc.Init(thisSite, ref langGuid, lcid, GetFileExtensions(rootKey, (string)guid));
                                                    this.languageServices.Add(langGuid.ToString(), svc);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //register with ComponentManager for Idle processing
            this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager));
            if (componentID == 0)
            {
                OLECRINFO[] crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)OLECRF.olecrfNeedIdleTime |
                                   (uint)OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal |
                                     (uint)OLECADVF.olecadvfRedrawOff |
                                     (uint)OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                this.componentManager.FRegisterComponent(this, crinfo, out componentID);
            }
        }