コード例 #1
0
ファイル: DocumentManager.cs プロジェクト: vestild/nemerle
        /// <summary>
        /// Rename document in the running document table from oldName to newName.
        /// </summary>
        /// <param name="provider">The service provider.</param>
        /// <param name="oldName">Full path to the old name of the document.</param>		
        /// <param name="newName">Full path to the new name of the document.</param>		
        /// <param name="newItemId">The new item id of the document</param>		
        public static void RenameDocument(IServiceProvider site, string oldName, string newName, uint newItemId)
        {
            if(site == null)
            {
                throw new ArgumentNullException("site");
            }

            if(String.IsNullOrEmpty(oldName))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "oldName");
            }

            if(String.IsNullOrEmpty(newName))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "newName");
            }

            if(newItemId == VSConstants.VSITEMID_NIL)
            {
                throw new ArgumentNullException("newItemId");
            }

            IVsRunningDocumentTable pRDT = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if(pRDT == null || doc == null) return;

            IVsHierarchy pIVsHierarchy;
            uint itemId;
            IntPtr docData;
            uint uiVsDocCookie;
            ErrorHandler.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie));

            if(docData != IntPtr.Zero)
            {
                try
                {
                    IntPtr pUnk = Marshal.GetIUnknownForObject(pIVsHierarchy);
                    Guid iid = typeof(IVsHierarchy).GUID;
                    IntPtr pHier;
                    Marshal.QueryInterface(pUnk, ref iid, out pHier);
                    try
                    {
                        ErrorHandler.ThrowOnFailure(pRDT.RenameDocument(oldName, newName, pHier, newItemId));
                    }
                    finally
                    {
                        if(pHier != IntPtr.Zero)
                            Marshal.Release(pHier);
                        if(pUnk != IntPtr.Zero)
                            Marshal.Release(pUnk);
                    }
                }
                finally
                {
                    Marshal.Release(docData);
                }
            }
        }
コード例 #2
0
ファイル: TextViewFilter.cs プロジェクト: wenh123/PTVS
        public TextViewFilter(IServiceProvider serviceProvider, IVsTextView vsTextView) {
            var compModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
            _vsEditorAdaptersFactoryService = compModel.GetService<IVsEditorAdaptersFactoryService>();
            _debugger = (IVsDebugger)serviceProvider.GetService(typeof(IVsDebugger));

            vsTextView.GetBuffer(out _vsTextLines);
            _wpfTextView = _vsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);

            ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _next));
        }
コード例 #3
0
 public TextInformationManager(IServiceProvider serviceProvider, IComponentModel componentModel)
 {
     this.serviceProvider = serviceProvider;
     this.componentModel = componentModel;
     fontAndColorStorage = (IVsFontAndColorStorage) serviceProvider.GetService(typeof (SVsFontAndColorStorage));
     fontAndColorUtilities = fontAndColorStorage as IVsFontAndColorUtilities;
     fontAndColorCache = (IVsFontAndColorCacheManager)serviceProvider.GetService(typeof(SVsFontAndColorCacheManager));
     textManager = (IVsTextManager) serviceProvider.GetService(typeof (SVsTextManager));
     editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
     textStructureNavigatorSelectorService = componentModel.GetService<ITextStructureNavigatorSelectorService>();
     classicationFormatMapService = componentModel.GetService<IClassificationFormatMapService>();
     classificationAggregatorService = componentModel.GetService<IClassifierAggregatorService>();
 }
コード例 #4
0
ファイル: TextManager.cs プロジェクト: aesire/VsVim
 internal TextManager(
     IVsAdapter adapter,
     ITextDocumentFactoryService textDocumentFactoryService,
     ITextBufferFactoryService textBufferFactoryService,
     ISharedService sharedService,
     SVsServiceProvider serviceProvider)
 {
     _vsAdapter = adapter;
     _serviceProvider = serviceProvider;
     _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
     _textDocumentFactoryService = textDocumentFactoryService;
     _textBufferFactoryService = textBufferFactoryService;
     _runningDocumentTable = _serviceProvider.GetService<SVsRunningDocumentTable, IVsRunningDocumentTable>();
     _sharedService = sharedService;
 }
コード例 #5
0
        public IdleManager(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;

            _compMgr = new Lazy <IOleComponentManager>(() =>
                                                       (IOleComponentManager)serviceProvider?.GetService(typeof(SOleComponentManager))
                                                       );

            _compId = new Lazy <uint>(() => {
                var compMgr = _compMgr.Value;
                if (compMgr == null)
                {
                    return(VSConstants.VSCOOKIE_NIL);
                }
                uint compId;
                OLECRINFO[] crInfo          = new OLECRINFO[1];
                crInfo[0].cbSize            = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crInfo[0].grfcrf            = (uint)_OLECRF.olecrfNeedIdleTime;
                crInfo[0].grfcadvf          = (uint)0;
                crInfo[0].uIdleTimeInterval = 0;
                if (ErrorHandler.Failed(compMgr.FRegisterComponent(this, crInfo, out compId)))
                {
                    return(VSConstants.VSCOOKIE_NIL);
                }
                return(compId);
            });
        }
コード例 #6
0
ファイル: Utilities.cs プロジェクト: bnavarma/ScalaTools
        /// <summary>
        /// Use this instead of VsShellUtilities.ShowMessageBox because VSU uses ThreadHelper which
        /// uses a private interface that can't be mocked AND goes to the global service provider.
        /// </summary>
        public static int ShowMessageBox(IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton) {
            IVsUIShell uiShell = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            Debug.Assert(uiShell != null, "Could not get the IVsUIShell object from the services exposed by this serviceprovider");
            if (uiShell == null) {
                throw new InvalidOperationException();
            }

            Guid emptyGuid = Guid.Empty;
            int result = 0;

            serviceProvider.GetUIThread().Invoke(() => {
                ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                    0,
                    ref emptyGuid,
                    title,
                    message,
                    null,
                    0,
                    msgButton,
                    defaultButton,
                    icon,
                    0,
                    out result));
            });
            return result;
        }
コード例 #7
0
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.EmptyTaskList"]/*' />
        /// <devdoc>
        /// Empty the task list.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
        public static int EmptyTaskList(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentException("serviceProvider");
            }

            IVsTaskList taskList = serviceProvider.GetService(typeof(IVsTaskList)) as IVsTaskList;

            if (taskList == null)
            {
                throw new InvalidOperationException();
            }

            IVsEnumTaskItems enumTaskItems;
            int result = VSConstants.S_OK;
            try
            {
                ErrorHandler.ThrowOnFailure(taskList.EnumTaskItems(out enumTaskItems));

                if (enumTaskItems == null)
                {
                    throw new InvalidOperationException();
                }

                // Retrieve the task item text and check whether it is equal with one that supposed to be thrown.

                uint[] fetched = new uint[1];
                do
                {
                    IVsTaskItem[] taskItems = new IVsTaskItem[1];

                    result = enumTaskItems.Next(1, taskItems, fetched);

                    if (fetched[0] == 1)
                    {
                        IVsTaskItem2 taskItem = taskItems[0] as IVsTaskItem2;
                        if (taskItem != null)
                        {
                            int canDelete;
                            ErrorHandler.ThrowOnFailure(taskItem.CanDelete(out canDelete));
                            if (canDelete == 1)
                            {
                                ErrorHandler.ThrowOnFailure(taskItem.OnDeleteTask());
                            }
                        }
                    }

                } while (result == VSConstants.S_OK && fetched[0] == 1);

            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
                result = e.ErrorCode;
            }

            return result;
        }
コード例 #8
0
ファイル: TextManager.cs プロジェクト: praveennet/VsVim
 internal TextManager(
     IVsAdapter adapter,
     SVsServiceProvider serviceProvider)
 {
     _adapter = adapter;
     _serviceProvider = serviceProvider;
     _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
     _table = new RunningDocumentTable(_serviceProvider);
 }
コード例 #9
0
        protected AbstractObjectBrowserLibraryManager(string languageName, Guid libraryGuid, IServiceProvider serviceProvider)
            : base(libraryGuid, serviceProvider)
        {
            _languageName = languageName;

            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
            this.Workspace = componentModel.GetService<VisualStudioWorkspace>();
            this.Workspace.WorkspaceChanged += OnWorkspaceChanged;
        }
コード例 #10
0
ファイル: Utilities.cs プロジェクト: Boddlnagg/VisualRust
        /// <summary>
        /// Look in the registry under the current hive for the path
        /// of MSBuild
        /// </summary>
        /// <returns></returns>

        /// <summary>
        /// Is Visual Studio in design mode.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns>true if visual studio is in design mode</returns>
        public static bool IsVisualStudioInDesignMode(IServiceProvider site) {
            Utilities.ArgumentNotNull("site", site);

            IVsMonitorSelection selectionMonitor = site.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
            uint cookie = 0;
            int active = 0;
            Guid designContext = VSConstants.UICONTEXT_DesignMode;
            ErrorHandler.ThrowOnFailure(selectionMonitor.GetCmdUIContextCookie(ref designContext, out cookie));
            ErrorHandler.ThrowOnFailure(selectionMonitor.IsCmdUIContextActive(cookie, out active));
            return active != 0;
        }
コード例 #11
0
        protected AbstractObjectBrowserLibraryManager(string languageName, Guid libraryGuid, __SymbolToolLanguage preferredLanguage, IServiceProvider serviceProvider)
            : base(libraryGuid, serviceProvider)
        {
            _languageName = languageName;
            _preferredLanguage = preferredLanguage;

            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
            this.Workspace = componentModel.GetService<VisualStudioWorkspace>();
            this.LibraryService = this.Workspace.Services.GetLanguageServices(languageName).GetService<ILibraryService>();
            this.Workspace.WorkspaceChanged += OnWorkspaceChanged;
        }
コード例 #12
0
ファイル: solutionlistener.cs プロジェクト: zooba/wix3
        protected SolutionListener(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            this.solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;

            Debug.Assert(this.solution != null, "Could not get the IVsSolution object from the services exposed by this project");

            if (this.solution == null)
            {
                throw new InvalidOperationException();
            }
        }
コード例 #13
0
ファイル: Utilities.cs プロジェクト: Boddlnagg/VisualRust
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="Utilities.IsInAutomationFunction"]/*' />
        /// <devdoc>
        /// Is an extensibility object executing an automation function.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns>true if the extensiblity object is executing an automation function.</returns>
        public static bool IsInAutomationFunction(IServiceProvider serviceProvider) {
            Utilities.ArgumentNotNull("serviceProvider", serviceProvider);

            IVsExtensibility3 extensibility = serviceProvider.GetService(typeof(EnvDTE.IVsExtensibility)) as IVsExtensibility3;

            if (extensibility == null) {
                throw new InvalidOperationException();
            }
            int inAutomation = 0;
            ErrorHandler.ThrowOnFailure(extensibility.IsInAutomationFunction(out inAutomation));
            return inAutomation != 0;
        }
コード例 #14
0
        public GoToDefinitionFilterProvider([Import(typeof(SVsServiceProvider))] System.IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;

            var dte = serviceProvider.GetService(typeof(SDTE)) as DTE;
            var events = dte.Events as Events2;
            if (events != null)
            {
                this.solutionEvents = events.SolutionEvents;
                this.solutionEvents.AfterClosing += Cleanup;
            }
        }
コード例 #15
0
ファイル: ForumCommandTarget.cs プロジェクト: rsdn/janus
		public IDisposable SubscribeForumCommandStatusChanged(
			IServiceProvider provider, Action handler)
		{
			var activeForumSvc = provider.GetService<IActiveForumService>();
			if (activeForumSvc != null)
			{
				CodeJam.Extensibility.EventHandler<IActiveForumService> statusUpdater = sender => handler();
				activeForumSvc.ActiveForumChanged += statusUpdater;
				return Disposable.Create(
					() => activeForumSvc.ActiveForumChanged -= statusUpdater);
			}
			return Disposable.Empty;
		}
コード例 #16
0
ファイル: TextManager.cs プロジェクト: ericbock/VsVim
 internal TextManager(
     IVsAdapter adapter,
     ITextDocumentFactoryService textDocumentFactoryService,
     ITextBufferFactoryService textBufferFactoryService,
     SVsServiceProvider serviceProvider)
 {
     _vsAdapter = adapter;
     _serviceProvider = serviceProvider;
     _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
     _textDocumentFactoryService = textDocumentFactoryService;
     _textBufferFactoryService = textBufferFactoryService;
     _table = new RunningDocumentTable(_serviceProvider);
 }
コード例 #17
0
ファイル: CopyrightEditor.cs プロジェクト: nicknow/nHydrate
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            var edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

            var popupUI = new CopyrightForm();

            popupUI.Copyright = (string)value;
            if (edSvc.ShowDialog(popupUI) == System.Windows.Forms.DialogResult.OK)
            {
                value = popupUI.Copyright;
                context.OnComponentChanged();
            }
            return(value);
        }
コード例 #18
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                SortingEditorControl edtorControl = new SortingEditorControl(edSvc, value);

                edSvc.DropDownControl(edtorControl);

                return(edtorControl.Result);
            }
            return(value);
        }
コード例 #19
0
        internal CommandExecutionWatcher(IServiceProvider serviceProvider)
        {
            Validate.IsNotNull(serviceProvider, "serviceProvider");
            this.serviceProvider = serviceProvider;

            var rpct = (IVsRegisterPriorityCommandTarget)this.serviceProvider.GetService(typeof(SVsRegisterPriorityCommandTarget));
            if (rpct != null)
            {
                // We can ignore the return code here as there really isn't anything reasonable we could do to deal with failure,
                // and it is essentially a no-fail method.
                rpct.RegisterPriorityCommandTarget(dwReserved: 0U, pCmdTrgt: this, pdwCookie: out this.priorityCommandTargetCookie);
            }
            this.macroRecorder = (IRecorderPrivate)serviceProvider.GetService(typeof(IRecorder));
        }
コード例 #20
0
ファイル: Utilities.cs プロジェクト: ugurlu2001/CodePlex
        /// <summary>
        /// Search the registry fir the tool path for MSBuild.
        /// </summary>
        public static string GetMsBuildPath(IServiceProvider serviceProvider, string msbuildVersion)
        {
            string registryPath;

            if (serviceProvider == null)
            {
                return(String.Empty);
            }

            ILocalRegistry3 localRegistry = serviceProvider.GetService(typeof(SLocalRegistry)) as ILocalRegistry3;

            if (localRegistry == null)
            {
                return(String.Empty);
            }

            // first, we need the registry hive currently in use
            ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out registryPath));
            // now that we have it, append the subkey we are interested in to it
            if (!registryPath.EndsWith("\\"))
            {
                registryPath += '\\';
            }
            registryPath += "MSBuild";
            // finally, get the value from the registry
            string msBuildPath = null;

            using (Microsoft.Win32.RegistryKey vsKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath, false))
            {
                msBuildPath = (string)vsKey.GetValue("MSBuildBinPath", null);
            }
            if (!string.IsNullOrEmpty(msBuildPath))
            {
                return(msBuildPath);
            }

            // The path to MSBuild was not found in the VisualStudio's registry hive, so try to
            // find it in the new MSBuild hive.
            registryPath = string.Format(CultureInfo.InvariantCulture, "Software\\Microsoft\\MSBuild\\ToolsVersions\\{0}", msbuildVersion);
            using (Microsoft.Win32.RegistryKey msbuildKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath, false))
            {
                msBuildPath = (string)msbuildKey.GetValue("MSBuildToolsPath", null);
            }
            if (string.IsNullOrEmpty(msBuildPath))
            {
                string error = SR.GetString(SR.ErrorMsBuildRegistration);
                throw new FileLoadException(error);
            }
            return(msBuildPath);
        }
コード例 #21
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            var edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

            var entity  = (context.Instance as EntityShape).ModelElement as Entity;
            var popupUI = new SecurityFunctionForm();

            popupUI.Entity = entity;
            if (edSvc.ShowDialog(popupUI) == System.Windows.Forms.DialogResult.OK)
            {
                context.OnComponentChanged();
            }
            return(value);
        }
コード例 #22
0
        // Displays the UI for value selection.
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                //DateTimeFormatControl supsubControl = new DateTimeFormatControl(edSvc, value);
                //edSvc.DropDownControl(supsubControl);
                ItemInputForm frm = new ItemInputForm(false, value);
                edSvc.ShowDialog(frm);
                return(frm.Value);
            }
            return(value);
        }
コード例 #23
0
        private IEnumerable <ITextBuffer> GetDocumentTextBuffers(DocumentLoad documentLoad)
        {
            var list = new List <ITextBuffer>();

            foreach (var docCookie in _runningDocumentTable.GetRunningDocumentCookies())
            {
                if (documentLoad == DocumentLoad.RespectLazy && isLazyLoaded(docCookie))
                {
                    continue;
                }

                if (_vsAdapter.GetTextBufferForDocCookie(docCookie).TryGetValue(out ITextBuffer buffer))
                {
                    list.Add(buffer);
                }
            }

            return(list);

            bool isLazyLoaded(uint documentCookie)
            {
                try
                {
                    if (_runningDocumentTable4 is null)
                    {
                        _runningDocumentTable4 = _serviceProvider.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable4>();
                    }

                    var flags = (_VSRDTFLAGS4)_runningDocumentTable4.GetDocumentFlags(documentCookie);
                    return(0 != (flags & _VSRDTFLAGS4.RDT_PendingInitialization));
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
コード例 #24
0
        public int DebugLaunch(uint flags)
        {
            VsDebugTargetInfo2[] targets;
            int hr = QueryDebugTargets(out targets);

            if (ErrorHandler.Failed(hr))
            {
                return(hr);
            }

            flags |= (uint)__VSDBGLAUNCHFLAGS140.DBGLAUNCH_ContainsStartupTask;

            VsDebugTargetInfo4[] appPackageDebugTarget = new VsDebugTargetInfo4[1];
            int targetLength = (int)Marshal.SizeOf(typeof(VsDebugTargetInfo4));

            appPackageDebugTarget[0].AppPackageLaunchInfo.AppUserModelID = DeployAppUserModelID;
            appPackageDebugTarget[0].AppPackageLaunchInfo.PackageMoniker = DeployPackageMoniker;

            appPackageDebugTarget[0].dlo                   = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AppPackageDebug;
            appPackageDebugTarget[0].LaunchFlags           = flags;
            appPackageDebugTarget[0].bstrRemoteMachine     = targets[0].bstrRemoteMachine;
            appPackageDebugTarget[0].bstrExe               = targets[0].bstrExe;
            appPackageDebugTarget[0].bstrArg               = targets[0].bstrArg;
            appPackageDebugTarget[0].bstrCurDir            = targets[0].bstrCurDir;
            appPackageDebugTarget[0].bstrEnv               = targets[0].bstrEnv;
            appPackageDebugTarget[0].dwProcessId           = targets[0].dwProcessId;
            appPackageDebugTarget[0].pStartupInfo          = IntPtr.Zero; //?
            appPackageDebugTarget[0].guidLaunchDebugEngine = targets[0].guidLaunchDebugEngine;
            appPackageDebugTarget[0].dwDebugEngineCount    = targets[0].dwDebugEngineCount;
            appPackageDebugTarget[0].pDebugEngines         = targets[0].pDebugEngines;
            appPackageDebugTarget[0].guidPortSupplier      = targets[0].guidPortSupplier;

            appPackageDebugTarget[0].bstrPortName        = targets[0].bstrPortName;
            appPackageDebugTarget[0].bstrOptions         = targets[0].bstrOptions;
            appPackageDebugTarget[0].fSendToOutputWindow = targets[0].fSendToOutputWindow;
            appPackageDebugTarget[0].pUnknown            = targets[0].pUnknown;
            appPackageDebugTarget[0].guidProcessLanguage = targets[0].guidProcessLanguage;
            appPackageDebugTarget[0].project             = this.project;

            // Pass the debug launch targets to the debugger
            System.IServiceProvider sp        = this.project as System.IServiceProvider;
            IVsDebugger4            debugger4 = (IVsDebugger4)sp.GetService(typeof(SVsShellDebugger));

            VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[1];

            debugger4.LaunchDebugTargets4(1, appPackageDebugTarget, results);

            return(VSConstants.S_OK);
        }
コード例 #25
0
        /// <include file='doc\ExpansionProvider.uex' path='docs/doc[@for="ExpansionProvider.DisplayExpansionBrowser"]/*' />
        public virtual bool DisplayExpansionBrowser(IVsTextView view, string prompt, string[] types, bool includeNullType, string[] kinds, bool includeNullKind)
        {
            if (this.expansionActive)
            {
                this.EndTemplateEditing(true);
            }

            if (this.source.IsCompletorActive)
            {
                this.source.DismissCompletor();
            }

            this.view = view;
            IServiceProvider site    = this.source.LanguageService.Site;
            IVsTextManager2  textmgr = site.GetService(typeof(SVsTextManager)) as IVsTextManager2;

            if (textmgr == null)
            {
                return(false);
            }

            IVsExpansionManager exmgr;

            textmgr.GetExpansionManager(out exmgr);
            Guid languageSID = this.source.LanguageService.GetLanguageServiceGuid();
            int  hr          = 0;

            if (exmgr != null)
            {
                hr = exmgr.InvokeInsertionUI(view,                               // pView
                                             this,                               // pClient
                                             languageSID,                        // guidLang
                                             types,                              // bstrTypes
                                             (types == null) ? 0 : types.Length, // iCountTypes
                                             includeNullType ? 1 : 0,            // fIncludeNULLType
                                             kinds,                              // bstrKinds
                                             (kinds == null) ? 0 : kinds.Length, // iCountKinds
                                             includeNullKind ? 1 : 0,            // fIncludeNULLKind
                                             prompt,                             // bstrPrefixText
                                             ">"                                 //bstrCompletionChar
                                             );
                if (NativeMethods.Succeeded(hr))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #26
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService  svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            Dictionary <string, object> v   = value as Dictionary <string, object>;

            if (svc != null && v != null)
            {
                using (FrmObjEditor form = new FrmObjEditor(v))
                {
                    form.ShowDialog();
                    v = form.Value.Prop;
                }
            }
            return(v); // can also replace the wrapper object here
        }
コード例 #27
0
        public FileChangeManager(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            this.fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));

            if (this.fileChangeService == null)
            {
                // VS is in bad state, since the SVsFileChangeEx could not be proffered.
                throw new InvalidOperationException();
            }
        }
コード例 #28
0
        internal CommandExecutionWatcher(IServiceProvider serviceProvider)
        {
            Validate.IsNotNull(serviceProvider, "serviceProvider");
            this.serviceProvider = serviceProvider;

            var rpct = (IVsRegisterPriorityCommandTarget)this.serviceProvider.GetService(typeof(SVsRegisterPriorityCommandTarget));

            if (rpct != null)
            {
                // We can ignore the return code here as there really isn't anything reasonable we could do to deal with failure,
                // and it is essentially a no-fail method.
                rpct.RegisterPriorityCommandTarget(dwReserved: 0U, pCmdTrgt: this, pdwCookie: out this.priorityCommandTargetCookie);
            }
            this.macroRecorder = (IRecorderPrivate)serviceProvider.GetService(typeof(IRecorder));
        }
コード例 #29
0
        internal static CommonProjectNode GetStartupProject(System.IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                Debug.Assert(false, "No service provider");
                return(null);
            }
            var buildMgr = (IVsSolutionBuildManager)serviceProvider.GetService(typeof(IVsSolutionBuildManager));

            if (buildMgr != null && ErrorHandler.Succeeded(buildMgr.get_StartupProject(out var hierarchy)) && hierarchy != null)
            {
                return(hierarchy.GetProject().GetCommonProject());
            }
            return(null);
        }
コード例 #30
0
 /// <summary>
 ///     Create a new XML model provider.
 /// </summary>
 public VSXmlModelProvider(IServiceProvider services, IXmlDesignerPackage xmlDesignerPackage)
 {
     Debug.Assert(services != null);
     Debug.Assert(xmlDesignerPackage != null);
     _xmlDesignerPackage = xmlDesignerPackage;
     _services = services;
     if (_xmlStore == null)
     {
         var xmlEditorService = (XmlEditorService)services.GetService(
             typeof(XmlEditorService));
         _xmlStore = xmlEditorService.CreateXmlStore();
         _xmlStore.EditingScopeCompleted += OnXmlModelTransactionCompleted;
         _xmlStore.UndoRedoCompleted += OnXmlModelUndoRedoCompleted;
     }
 }
コード例 #31
0
        /// <summary>
        /// Invoke the property page help in response to an end-user request.
        /// </summary>
        /// <param name="pszHelpDir"></param>
        public void Help(string pszHelpDir)
        {
            System.IServiceProvider iPropertyPageSite =
                this.PropertyPageSite as System.IServiceProvider;
            if (iPropertyPageSite != null)
            {
                Microsoft.VisualStudio.VSHelp.Help service = iPropertyPageSite.GetService(
                    typeof(Microsoft.VisualStudio.VSHelp.Help)) as Microsoft.VisualStudio.VSHelp.Help;

                if (service != null)
                {
                    service.DisplayTopicFromF1Keyword(this.HelpKeyword);
                }
            }
        }
コード例 #32
0
 /// <summary>
 ///     Create a new XML model provider.
 /// </summary>
 public VSXmlModelProvider(IServiceProvider services, IXmlDesignerPackage xmlDesignerPackage)
 {
     Debug.Assert(services != null);
     Debug.Assert(xmlDesignerPackage != null);
     _xmlDesignerPackage = xmlDesignerPackage;
     _services           = services;
     if (_xmlStore == null)
     {
         var xmlEditorService = (XmlEditorService)services.GetService(
             typeof(XmlEditorService));
         _xmlStore = xmlEditorService.CreateXmlStore();
         _xmlStore.EditingScopeCompleted += OnXmlModelTransactionCompleted;
         _xmlStore.UndoRedoCompleted     += OnXmlModelUndoRedoCompleted;
     }
 }
コード例 #33
0
ファイル: PropertyGridUI.cs プロジェクト: zhangrl/Hunter3
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                // 可以打开任何特定的对话框
                OpenFileDialog dialog = new OpenFileDialog();
                if (dialog.ShowDialog().Equals(DialogResult.OK))
                {
                    return(dialog.FileName);
                }
            }
            return(value);
        }
コード例 #34
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                RepCustomXRRichText.RichTextEditorForm frm = new RepCustomXRRichText.RichTextEditorForm();

                frm.richTextBox1.Rtf = (context.Instance as XRRichText).Rtf;
                edSvc.ShowDialog(frm);
                return(frm.richTextBox1.Rtf);
            }

            return(value);
        }
コード例 #35
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService IFService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            Color4?color = value as Color4?;

            if (IFService != null)
            {
                using (ColorDialog form = new ColorDialog())
                {
                    form.ShowDialog();
                    color = form.Color;
                }
            }
            return(color);
        }
コード例 #36
0
 /// <summary>
 /// Sets the help context into the help service for this property page.
 /// </summary>
 private void SetHelpContext()
 {
     if (this.pageSite != null)
     {
         System.IServiceProvider sp = this.pageSite as System.IServiceProvider;
         if (sp != null)
         {
             IHelpService helpService = sp.GetService(typeof(IHelpService)) as IHelpService;
             if (helpService != null)
             {
                 helpService.AddContextAttribute("Keyword", String.Empty, HelpKeywordType.F1Keyword);
             }
         }
     }
 }
コード例 #37
0
ファイル: Utilities.cs プロジェクト: nathan8299/XSharpPublic
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="Utilities.IsInAutomationFunction"]/*' />
        /// <devdoc>
        /// Is an extensibility object executing an automation function.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns>true if the extensibility object is executing an automation function.</returns>
        public static bool IsInAutomationFunction(IServiceProvider serviceProvider)
        {
            Utilities.ArgumentNotNull("serviceProvider", serviceProvider);

            IVsExtensibility3 extensibility = serviceProvider.GetService(typeof(EnvDTE.IVsExtensibility)) as IVsExtensibility3;

            if (extensibility == null)
            {
                throw new InvalidOperationException();
            }
            int inAutomation = 0;

            ErrorHandler.ThrowOnFailure(extensibility.IsInAutomationFunction(out inAutomation));
            return(inAutomation != 0);
        }
コード例 #38
0
        internal static void OpenVsWebBrowser(System.IServiceProvider serviceProvider, string url)
        {
            serviceProvider.GetUIThread().Invoke(() => {
                var web = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (web == null)
                {
                    OpenWebBrowser(url);
                    return;
                }

                IVsWindowFrame frame;
                ErrorHandler.ThrowOnFailure(web.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out frame));
                frame.Show();
            });
        }
コード例 #39
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context,
                                         System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc =
                (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                VehicleTypeControl vehicleTypeControl = new VehicleTypeControl((TypeOfVehicle)value);
                vehicleTypeControl.Size = vehicleTypeControl.Image.Size;
                edSvc.DropDownControl(vehicleTypeControl);
                return(vehicleTypeControl.CurrentType);
            }
            return(value);
        }
コード例 #40
0
        public static string GetVsMainVersion(IServiceProvider serviceProvider)
        {
            const string defaultMainVersion = "15.0";

            try
            {
                var dte = (DTE)serviceProvider.GetService(typeof(DTE));
                return(dte?.Version ?? defaultMainVersion);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(defaultMainVersion);
            }
        }
コード例 #41
0
        /// <summary>
        /// Opens the find symbols dialog with a list of results.  This is done by requesting
        /// that VS does a search against our library GUID.  Our library then responds to
        /// that request by extracting the prvoided symbol list out and using that for the
        /// search results.
        /// </summary>
        private void ShowFindSymbolsDialog(string expr, IVsNavInfo symbols)
        {
            // ensure our library is loaded so find all references will go to our library
            _serviceProvider.GetService(typeof(IPythonLibraryManager));

            if (!string.IsNullOrEmpty(expr))
            {
                var findSym = (IVsFindSymbol)_serviceProvider.GetService(typeof(SVsObjectSearch));
                VSOBSEARCHCRITERIA2 searchCriteria = new VSOBSEARCHCRITERIA2();
                searchCriteria.eSrchType   = VSOBSEARCHTYPE.SO_ENTIREWORD;
                searchCriteria.pIVsNavInfo = symbols;
                searchCriteria.grfOptions  = (uint)_VSOBSEARCHOPTIONS2.VSOBSO_LISTREFERENCES;
                searchCriteria.szName      = expr;

                Guid guid = Guid.Empty;
                //  new Guid("{a5a527ea-cf0a-4abf-b501-eafe6b3ba5c6}")
                ErrorHandler.ThrowOnFailure(findSym.DoSearch(new Guid(CommonConstants.LibraryGuid), new VSOBSEARCHCRITERIA2[] { searchCriteria }));
            }
            else
            {
                var statusBar = (IVsStatusbar)_serviceProvider.GetService(typeof(SVsStatusbar));
                statusBar.SetText("The caret must be on valid expression to find all references.");
            }
        }
コード例 #42
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            FormTextInput form = new FormTextInput();

            form.tbxText.Text = value as string;

            IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (svc.ShowDialog(form) == DialogResult.OK)
            {
                value = form.tbxText.Text;
            }

            return(value);
        }
コード例 #43
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                SelTableForm frm = new SelTableForm();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    return(frm.m_SelTable.Code);
                }
            }

            return(value);
        }
コード例 #44
0
 ///--------------------------------------------------------------------------------------------
 /// <summary>
 /// Initialize and listen to debug mode changes
 /// </summary>
 ///--------------------------------------------------------------------------------------------
 internal void AdviseDebugger()
 {
     System.IServiceProvider sp = _site as System.IServiceProvider;
     if (sp != null)
     {
         _debugger = sp.GetService <IVsDebugger, IVsDebugger>();
         if (_debugger != null)
         {
             _debugger.AdviseDebuggerEvents(this, out _debuggerCookie);
             DBGMODE[] dbgMode = new DBGMODE[1];
             _debugger.GetMode(dbgMode);
             ((IVsDebuggerEvents)this).OnModeChange(dbgMode[0]);
         }
     }
 }
コード例 #45
0
        static void Main(string[] args)
        {
            IServiceCollection services = new ServiceCollection();

            System.IServiceProvider di = services.AddTransient <Car>()
                                         .AddTransient <Engine>(s => new Engine(5))
                                         .BuildServiceProvider();

            Car car = di.GetService <Car>();

            // or
            car = ActivatorUtilities.CreateInstance <Car>(di);

            System.Console.WriteLine(car.Engine.HorsePowers);
        }
コード例 #46
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (svc != null)
            {
                IBaseNode baseNode = context.Instance as IBaseNode;
                if (baseNode != null)
                {
                    using (DataConnectionForm frm = new DataConnectionForm(baseNode))
                    {
                        IDataPersistence dp = getDataPersistence(baseNode);
                        if (dp != null)
                        {
                            IDecisionTree tree     = baseNode.Tree;
                            List <string> Elements = new List <string>();
                            foreach (string reference in dp.DataConnections)
                            {
                                IBaseNode node = tree.GetNodeByReference(reference);
                                if (node != null)
                                {
                                    Elements.Add(node.Name);
                                }
                            }
                            frm.Elements = Elements;

                            if (svc.ShowDialog(frm) == DialogResult.OK)
                            {
                                List <string> result    = new List <string>();
                                IBaseNode     dataNodes = tree.RootNode.GetNode(eNodeType.DataObjects);
                                foreach (string name in frm.Elements)
                                {
                                    IBaseNode dc = dataNodes.GetNode(name);
                                    if (dc != null)
                                    {
                                        result.Add(dc.Reference);
                                    }
                                }

                                value = result.ToArray();
                            }
                        }
                    }
                }
            }

            return(value);
        }
コード例 #47
0
        /// <summary>
        /// Called when we want to edit the value of a property.  Brings up the Glyph Editor control.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (edSvc != null && value is ArrayList)
            {
                GlyphEditor glyphEditor = new GlyphEditor();
                glyphEditor.Glyphs = value as ArrayList;

                if (edSvc.ShowDialog(glyphEditor) == DialogResult.OK)
                {
                    return(new ArrayList(glyphEditor.Glyphs));
                }
            }

            return(value);
        }
コード例 #48
0
ファイル: FileChangeManager.cs プロジェクト: borota/JTVS
        /// <summary>
        /// Overloaded ctor.
        /// </summary>
        /// <param name="nodeParam">An instance of a project item.</param>
        internal FileChangeManager(IServiceProvider serviceProvider)
        {
            #region input validation
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            #endregion

            this.fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));

            if (this.fileChangeService == null)
            {
                // VS is in bad state, since the SVsFileChangeEx could not be proffered.
                throw new InvalidOperationException();
            }
        }
コード例 #49
0
		public AdapterCommand(IVsTextView adapter, System.IServiceProvider provider, Guid menuGroup, uint cmdID, Action commandEvent, Func<bool> queryEvent = null)
		{
			this.provider = provider;
			this.menuGroup = menuGroup;
			this.cmdID = cmdID;
			this.commandEvent = commandEvent;
			this.queryEvent = queryEvent ?? (() => true);

			var mcs = provider.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
			if (mcs != null)
				mcs.AddCommand(menuGroup, (int)cmdID, commandEvent, cmd => {
					cmd.Visible = cmd.Enabled = this.queryEvent();
				});

			Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
			{
				ErrorHandler.ThrowOnFailure(adapter.AddCommandFilter(this, out nextCommandTarget));
			}), DispatcherPriority.ApplicationIdle, null);
		}
コード例 #50
0
        /// <summary>
        /// Attaches events for invoking Statement completion 
        /// </summary>
        public IntellisenseController(IntellisenseControllerProvider provider, ITextView textView, IServiceProvider serviceProvider) {
            _textView = textView;
            _provider = provider;
            _editOps = provider._EditOperationsFactory.GetEditorOperations(textView);
            _incSearch = provider._IncrementalSearch.GetIncrementalSearch(textView);
            _textView.MouseHover += TextViewMouseHover;
            _serviceProvider = serviceProvider;
            if (textView.TextBuffer.IsPythonContent()) {
                try {
                    _expansionClient = new ExpansionClient(textView, provider._adaptersFactory, provider._ServiceProvider);
                    var textMgr = (IVsTextManager2)_serviceProvider.GetService(typeof(SVsTextManager));
                    textMgr.GetExpansionManager(out _expansionMgr);
                } catch (ArgumentException) {
                    // No expansion client for this buffer, but we can continue without it
                }
            }

            textView.Properties.AddProperty(typeof(IntellisenseController), this);  // added so our key processors can get back to us
            _textView.Closed += TextView_Closed;
        }
コード例 #51
0
ファイル: ViewFilter.cs プロジェクト: svick/visualfsharp
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="TextTipData.TextTipData"]/*' />
        internal TextTipData(IServiceProvider site)
        {
            if (site == null)
                throw new System.ArgumentNullException("site");

            //this.textView = view;
            // Create our method tip window (through the local registry)
            Type t = typeof(IVsTextTipWindow);
            Guid riid = t.GUID;

            Guid clsid = typeof(VsTextTipWindowClass).GUID;
            Microsoft.VisualStudio.Shell.Package pkg = (Microsoft.VisualStudio.Shell.Package)site.GetService(typeof(Microsoft.VisualStudio.Shell.Package));
            if (pkg == null) {
                throw new NullReferenceException(typeof(Microsoft.VisualStudio.Shell.Package).FullName);
            }
            this.textTipWindow = (IVsTextTipWindow)pkg.CreateInstance(ref clsid, ref riid, t);
            if (this.textTipWindow == null)
                NativeHelpers.RaiseComError(NativeMethods.E_FAIL);
            else
                NativeMethods.ThrowOnFailure(textTipWindow.SetTextTipData(this));
        }
コード例 #52
0
        public XamlTextViewCreationListener(
            [Import(typeof(SVsServiceProvider))] System.IServiceProvider services,
            ICommandHandlerServiceFactory commandHandlerServiceFactory,
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
            IXamlDocumentAnalyzerService analyzerService,
            VisualStudioWorkspaceImpl vsWorkspace)
        {
            _serviceProvider = services;
            _commandHandlerService = commandHandlerServiceFactory;
            _editorAdaptersFactory = editorAdaptersFactoryService;
            _vsWorkspace = vsWorkspace;
            _rdt = new Lazy<RunningDocumentTable>(() => new RunningDocumentTable(_serviceProvider));
            _vsSolution = (IVsSolution)_serviceProvider.GetService(typeof(SVsSolution));

            AnalyzerService = analyzerService;

            uint solutionEventsCookie;
            if (ErrorHandler.Succeeded(_vsSolution.AdviseSolutionEvents(this, out solutionEventsCookie)))
            {
                _solutionEventsCookie = solutionEventsCookie;
            }
        }
コード例 #53
0
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.OpenDocument"]/*' />
        /// <devdoc>
        /// Open document using the appropriate project. 
        /// </devdoc>
        /// <param name="provider">The service provider.</param>
        /// <param name="fullPath">Full path to the document.</param>
        /// <param name="logicalView">GUID identifying the logical view.</param>
        /// <param name="hierarchy">Reference to the IVsUIHierarchy interface of the project that contains the Open document.</param>
        /// <param name="itemID"> Reference to the hierarchy item identifier of the document in the project.</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the document.</param>
        public static void OpenDocument(IServiceProvider provider, string fullPath, Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame)
        {
            windowFrame = null;
            itemID = VSConstants.VSITEMID_NIL;
            hierarchy = null;

            if (provider == null)
            {
                throw new ArgumentException("provider");
            }

            if (String.IsNullOrEmpty(fullPath))
            {
                throw new ArgumentException("fullPath");
            }

            //open document
            if (!IsDocumentOpen(provider, fullPath, logicalView, out hierarchy, out itemID, out windowFrame))
            {
                IVsUIShellOpenDocument shellOpenDoc = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (shellOpenDoc != null)
                {
                    IOleServiceProvider psp;
                    uint itemid;
                    ErrorHandler.ThrowOnFailure(shellOpenDoc.OpenDocumentViaProject(fullPath, ref logicalView, out psp, out hierarchy, out itemid, out windowFrame));
                }
            }
            if (windowFrame != null)
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
        }
コード例 #54
0
ファイル: EditorFactory.cs プロジェクト: hesam/SketchSharp
        static StringDictionary GetLanguageExtensions(IServiceProvider site) {
            if (EditorFactory.languageExtensions != null)
                return EditorFactory.languageExtensions;

            StringDictionary extensions = new StringDictionary();
            ILocalRegistry3 localRegistry = site.GetService(typeof(SLocalRegistry)) as ILocalRegistry3;
            string root = null;
            if (localRegistry != null) {
                NativeMethods.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out root));
            }
            using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
                if (rootKey != null) {

                    string relpath = "Languages\\File Extensions";
                    using (RegistryKey key = rootKey.OpenSubKey(relpath, false)) {
                        if (key != null) {
                            foreach (string ext in key.GetSubKeyNames()) {
                                using (RegistryKey extkey = key.OpenSubKey(ext, false)) {
                                    if (extkey != null) {
                                        string fe = ext;
                                        string guid = extkey.GetValue(null) as string; // get default value
                                        if (!extensions.ContainsKey(fe)) {
                                            extensions.Add(fe, guid);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return EditorFactory.languageExtensions = extensions;
        }
コード例 #55
0
ファイル: EditorFactory.cs プロジェクト: hesam/SketchSharp
        static Hashtable GetEditors(IServiceProvider site) {
            if (EditorFactory.editors != null)
                return EditorFactory.editors;

            Hashtable editors = new Hashtable();
            ILocalRegistry3 localRegistry = site.GetService(typeof(SLocalRegistry)) as ILocalRegistry3;
            string root = null;
            if (localRegistry == null) {
                return editors;
            }
            NativeMethods.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out root));
            using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
                if (rootKey != null) {
                    RegistryKey editorsKey = rootKey.OpenSubKey("Editors", false);
                    if (editorsKey != null) {
                        using (editorsKey) {
                            foreach (string editorGuid in editorsKey.GetSubKeyNames()) {
                                Guid guid = GetGuid(editorGuid);
                                using (RegistryKey editorKey = editorsKey.OpenSubKey(editorGuid, false)) {
                                    object value = editorKey.GetValue(null);
                                    string name = (value != null) ? value.ToString() : editorGuid.ToString();
                                    RegistryKey extensions = editorKey.OpenSubKey("Extensions", false);
                                    if (extensions != null) {
                                        foreach (string s in extensions.GetValueNames()) {
                                            if (!string.IsNullOrEmpty(s)) {
                                                EditorInfo ei = new EditorInfo();
                                                ei.name = name;
                                                ei.guid = guid;
                                                object obj = extensions.GetValue(s);
                                                if (obj is int) {
                                                    ei.priority = (int)obj;
                                                }
                                                string ext = (s == "*") ? s : "." + s;
                                                AddEditorInfo(editors, ext.ToLowerInvariant(), ei);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return EditorFactory.editors = editors;
        }
コード例 #56
0
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.IsDocumentOpen"]/*' />
        /// <devdoc>
        /// Determine if a document is opened with a given logical view.  
        /// </devdoc>
        /// <param name="provider">The service provider.</param>
        /// <param name="fullPath">Full path to the document</param>
        /// <param name="logicalView">GUID identifying the logical view. If logicalView is set to Guid.Empty, it will return true if any view is open.</param>
        /// <param name="hierarchy">Reference to the IVsUIHierarchy interface of the project that contains the Open document</param>
        /// <param name="itemID"> Reference to the hierarchy item identifier of the document in the project</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the document</param>
        /// <returns>true if the document is open with the given logical view</returns>
        public static bool IsDocumentOpen(IServiceProvider provider, string fullPath, Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame)
        {
            windowFrame = null;
            itemID = VSConstants.VSITEMID_NIL;
            hierarchy = null;

            if (provider == null)
            {
                throw new ArgumentException("provider");
            }

            if (String.IsNullOrEmpty(fullPath))
            {
                throw new ArgumentException("fullPath");
            }

            //open document
            IVsUIShellOpenDocument shellOpenDoc = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IVsRunningDocumentTable pRDT = provider.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;
            if (pRDT != null && shellOpenDoc != null)
            {
                IntPtr punkDocData = IntPtr.Zero;
                uint docCookie;
                uint[] pitemid = new uint[1];
                IVsHierarchy ppIVsHierarchy;
                try
                {
                    ErrorHandler.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out ppIVsHierarchy, out pitemid[0], out punkDocData, out docCookie));
                    int pfOpen;
                    uint flags = (logicalView == Guid.Empty) ? (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView : 0;
                    ErrorHandler.ThrowOnFailure(shellOpenDoc.IsDocumentOpen((IVsUIHierarchy)ppIVsHierarchy, pitemid[0], fullPath, ref logicalView, flags, out hierarchy, pitemid, out windowFrame, out pfOpen));
                    if (windowFrame != null)
                    {
                        itemID = pitemid[0];
                        return (pfOpen == 1);
                    }
                }
                finally
                {
                    if (punkDocData != IntPtr.Zero)
                    {
                        Marshal.Release(punkDocData);
                    }
                }
            }
            return false;
        }
コード例 #57
0
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.IsInAutomationFunction"]/*' />
        /// <devdoc>
        /// Is an extensibility object executing an automation function.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns>true if the extensiblity object is executing an automation function.</returns>
        public static bool IsInAutomationFunction(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentException("serviceProvider");
            }

            IVsExtensibility extensibility = serviceProvider.GetService(typeof(IVsExtensibility)) as IVsExtensibility;

            if (extensibility == null)
            {
                throw new InvalidOperationException();
            }

            return (extensibility.IsInAutomationFunction() == 0) ? false : true;
        }
コード例 #58
0
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.IsSolutionBuilding"]/*' />
        /// <devdoc>
        /// Is current solution building or deploying
        /// </devdoc>
        /// <param name="serviceProvider">The service provider</param>
        /// <returns>true if solution is building or deploying.</returns>
        public static bool IsSolutionBuilding(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentException("serviceProvider");
            }

            IVsSolutionBuildManager solutionBuildManager = serviceProvider.GetService(typeof(IVsSolutionBuildManager)) as IVsSolutionBuildManager;

            if (solutionBuildManager == null)
            {
                throw new InvalidOperationException();
            }

            int returnValueAsInteger = 0;
            ErrorHandler.ThrowOnFailure(solutionBuildManager.QueryBuildManagerBusy(out returnValueAsInteger));
            return (returnValueAsInteger == 1);
        }
コード例 #59
0
ファイル: DocumentManager.cs プロジェクト: sharwell/MPFProj10
        /// <summary>
        /// Updates the caption for all windows associated to the document.
        /// </summary>
        /// <param name="site">The service provider.</param>
        /// <param name="caption">The new caption.</param>
        /// <param name="docData">The IUnknown interface to a document data object associated with a registered document.</param>
        public static void UpdateCaption(IServiceProvider site, string caption, IntPtr docData)
        {
            if(site == null)
            {
                throw new ArgumentNullException("site");
            }

            if(String.IsNullOrEmpty(caption))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "caption");
            }

            IVsUIShell uiShell = site.GetService(typeof(SVsUIShell)) as IVsUIShell;

            // We need to tell the windows to update their captions.
            IEnumWindowFrames windowFramesEnum;
            ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out windowFramesEnum));
            IVsWindowFrame[] windowFrames = new IVsWindowFrame[1];
            uint fetched;
            while(windowFramesEnum.Next(1, windowFrames, out fetched) == VSConstants.S_OK && fetched == 1)
            {
                IVsWindowFrame windowFrame = windowFrames[0];
                object data;
                ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out data));
                IntPtr ptr = Marshal.GetIUnknownForObject(data);
                try
                {
                    if(ptr == docData)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, caption));
                    }
                }
                finally
                {
                    if(ptr != IntPtr.Zero)
                    {
                        Marshal.Release(ptr);
                    }
                }
            }
        }
コード例 #60
0
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.LaunchDebugger"]/*' />
        /// <devdoc>
        /// Launch the debugger.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="info">A reference to a VsDebugTargetInfo object.</param>
        public static void LaunchDebugger(IServiceProvider serviceProvider, VsDebugTargetInfo info)
        {
            Debug.Assert(serviceProvider != null, "Cannot launch the debugger on an empty service provider");
            if (serviceProvider == null)
            {
                throw new ArgumentException("serviceProvider");
            }

            info.cbSize = (uint)Marshal.SizeOf(info);
            IntPtr ptr = Marshal.AllocCoTaskMem((int)info.cbSize);
            Marshal.StructureToPtr(info, ptr, false);
            try
            {
                IVsDebugger d = serviceProvider.GetService(typeof(IVsDebugger)) as IVsDebugger;
                Debug.Assert(d != null, "Could not retrieve IVsDebugger from " + serviceProvider.GetType().Name);

                if (d == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(d.LaunchDebugTargets(1, ptr));
            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
        }