예제 #1
0
    // Bind to hotkey in the context of Text Editor
    // This will throw an error when running from the VCmd editor window but works once you have an open document active

    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        serviceProvider = package as System.IServiceProvider;
        SetSearchCurrentDocument(true);
        DTE.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
        DTE.ExecuteCommand("Edit.GoToSymbol");
    }
예제 #2
0
        private void ConfigurePackageServices()
        {
            var platformServices = new VsPlatformServices();

            var componentModel     = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));
            var compositionCatalog = new CompositionCatalog(componentModel.DefaultCompositionService, componentModel.DefaultExportProvider);
            var exportProvider     = componentModel.DefaultExportProvider;

            _services
            .AddService(componentModel)
            .AddService(componentModel.DefaultCompositionService)
            .AddService(exportProvider)
            .AddService(compositionCatalog)
            .AddService(new VsUIServices(this))
            .AddService(new VsPlotExportDialog(this))
            .AddService(platformServices)
            .AddService <IEditorSupport, VsEditorSupport>()
            .AddService <IImageService, ImageService>()
            .AddService(new REditorSettings(this))
            .AddService(new RMarkdownEditorSettings(this))
            .AddService <IStatusBar, VsStatusBar>()
            .AddService <RPackageToolWindowProvider>()
            .AddRComponentsServices()
            .AddWindowsRInterpretersServices()
            .AddWindowsHostClientServices()
            .AddWindowsRComponentsServices()
            .AddEditorServices()
            .AddWindowsContainerServices();
            // TODO: add more

            _application = new VsApplication(_services);
            _services.AddService(_application);
            _services.GetService <IRSettings>().LoadSettings();
        }
예제 #3
0
        public override T GetService <T>(Type type = null)
        {
            // First try internal services
            var service = base.GetService <T>(type);

            if (service == null)
            {
                // First try MEF
                service = _appShell.ExportProvider.GetExportedValueOrDefault <T>();
                if (service == null)
                {
                    // Now try VS services. Only allowed on UI thread.
                    _appShell.AssertIsOnMainThread();
                    if (_appShell.IsUnitTestEnvironment)
                    {
                        service = RPackage.Current.GetService(type ?? typeof(T)) as T;
                    }
                    else
                    {
                        service = VsPackage.GetGlobalService(type ?? typeof(T)) as T;
                    }
                }
            }
            return(service);
        }
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
        if (ts == null)
        {
            return;
        }
        EnvDTE.CodeFunction func = ts.ActivePoint.CodeElement[EnvDTE.vsCMElement.vsCMElementFunction] as EnvDTE.CodeFunction;
        if (func == null)
        {
            return;
        }

        string result = "";

        foreach (EnvDTE.CodeParameter i in func.Parameters)
        {
            if (result.Length > 0)
            {
                result += ", ";
            }
            result += i.Name;
        }
        ts.Text = "(" + result + ")";
    }
예제 #5
0
        private static Task <Action> GetInitializeTask()
        {
            var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));

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

            try
            {
                // HACK: Short cut to set the Powershell execution policy for this process to RemoteSigned.
                // This is so that we can initialize the PowerShell host and load our modules successfully.
                Environment.SetEnvironmentVariable(
                    "PSExecutionPolicyPreference", "RemoteSigned", EnvironmentVariableTarget.Process);
            }
            catch (SecurityException)
            {
                // ignore if user doesn't have permission to add process-level environment variable,
                // which is very rare.
            }

            var initializer = componentModel.GetService <IHostInitializer>();

            return(Task.Factory.StartNew(() =>
            {
                initializer.Start();
                return new Action(initializer.SetDefaultRunspace);
            }));
        }
예제 #6
0
 public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
 {
     serviceProvider = package as System.IServiceProvider;
     Microsoft.VisualStudio.Text.Editor.IWpfTextView textView      = GetTextView();
     Microsoft.VisualStudio.Text.SnapshotPoint       caretPosition = textView.Caret.Position.BufferPosition;
     textView.TextBuffer.Insert(caretPosition.Position, "sample code");
 }
예제 #7
0
 public virtual int Close()
 {
     this.site    = null;
     this.package = null;
     GC.Collect();
     return(0);
 }
 //! \brief ctor
 public CManager(Microsoft.VisualStudio.Shell.Package package, DTE2 applicationObject)
 {
     _doxManger              = this;
     this._package           = package;
     this._applicationObject = applicationObject;
     this._options           = new COptions(package);
 }
예제 #9
0
        protected ProjectFactory(Microsoft.VisualStudio.Shell.Package package)
        {
            this.package = package;
            this.site    = package;

            // Please be aware that this methods needs that ServiceProvider is valid, thus the ordering of calls in the ctor matters.
            this.buildEngine = Utilities.InitializeMsBuildEngine(this.buildEngine, this.site);
        }
예제 #10
0
        protected ProjectFactory(Microsoft.VisualStudio.Shell.Package package)
        {
            this.package = package;
            this.site = package;

            // Please be aware that this methods needs that ServiceProvider is valid, thus the ordering of calls in the ctor matters.
            this.buildEngine = Utilities.InitializeMsBuildEngine(this.buildEngine, this.site);
        }
        public CogaenEditProjectFactory(Microsoft.VisualStudio.Shell.Package package)
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
            this.package = package;
            this.site = package;

            // Please be aware that this methods needs that ServiceProvider is valid, thus the ordering of calls in the ctor matters.
            this.buildEngine = Utilities.InitializeMsBuildEngine(this.buildEngine, this.site);
        }
예제 #12
0
 public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
 {
     events       = DTE.Events;
     windowEvents = events.WindowEvents;
     windowEvents.WindowActivated += OnWindowActivated;
     System.IServiceProvider serviceProvider = package as System.IServiceProvider;
     statusBar = serviceProvider.GetService(
         typeof(Microsoft.VisualStudio.Shell.Interop.SVsStatusbar)) as
                 Microsoft.VisualStudio.Shell.Interop.IVsStatusbar;
 }
    public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        this.DTE     = DTE;
        events       = DTE.Events;
        windowEvents = events.WindowEvents;
        windowEvents.WindowActivated += OnWindowActivated;

        documentEvents = events.DocumentEvents;
        documentEvents.DocumentOpened += OnDocumentOpened;
    }
예제 #14
0
        /// <summary>
        /// Get the open solution.
        /// </summary>
        /// <returns></returns>
        private static Solution GetOpenSolution()
        {
            var dte = VsPackage.GetGlobalService(typeof(DTE)) as DTE;

            if (dte != null)
            {
                var openSolution = dte.Solution;
                return(openSolution);
            }
            else
            {
                return(null);
            }
        }
예제 #15
0
        private async Task <MSSolution> GetCurrentSolution()
        {
            var dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
            var solutionFullName = dte?.Solution.FullName;

            if (string.IsNullOrEmpty(solutionFullName))
            {
                throw new NoSolutionOpenException();
            }

            var msBuildWorkspace = MSBuildWorkspace.Create();

            return(await msBuildWorkspace.OpenSolutionAsync(solutionFullName));
        }
예제 #16
0
        public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
        {
            EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
            if (ts == null)
            {
                return;
            }
            var codeClass = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementClass]
                            as EnvDTE.CodeClass;

            if (codeClass == null)
            {
                return;
            }
            EnvDTE.Project project   = DTE.ActiveWindow.Project;
            var            resolutor = GetResolutionService(project, Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider);
            var            type      = resolutor.GetType(codeClass.FullName, true);
            var            bases     = new List <Type>();

            //var baseType = type.BaseType;
            //while (baseType != typeof(object) && baseType != null)
            //{
            //    bases.Add(baseType);
            //    baseType = baseType.BaseType;
            //}
            bases.Insert(0, type);

            var fields_list = new List <FieldInfo>();

            foreach (var type_base in bases)
            {
                var tmp = type_base.GetFields(
                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Default | BindingFlags.Instance);
                foreach (var fieldInfo in tmp)
                {
                    fields_list.Add(fieldInfo);
                }
            }
            var text = " //numero di fields = ' " + fields_list.Count + " '" + System.Environment.NewLine;

            foreach (var fieldInfo in fields_list)
            {
                var propName = fieldInfo.Name.Replace("_", "").Substring(0, 1).ToUpper() +
                               fieldInfo.Name.Replace("_", "").Substring(1);
                text += "public " + fieldInfo.FieldType + " " + propName + "{get{ return " + fieldInfo.Name + ";} set{  " + fieldInfo.Name + " = value ; RaisePropertyChanged( () => (" + fieldInfo.Name + ")); }}" + System.Environment.NewLine + System.Environment.NewLine;;
            }
            text = text.Replace("+", ".");
            System.Windows.Clipboard.SetText(text);
        }
예제 #17
0
        private System.Type GetTypeByName(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package, string name)
        {
            System.IServiceProvider serviceProvider = package as System.IServiceProvider;
            var typeService =
                serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Design.DynamicTypeService)) as
                Microsoft.VisualStudio.Shell.Design.DynamicTypeService;

            Microsoft.VisualStudio.Shell.Interop.IVsSolution sln =
                serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)) as
                Microsoft.VisualStudio.Shell.Interop.IVsSolution;

            Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hier;
            sln.GetProjectOfUniqueName(DTE.ActiveDocument.ProjectItem.ContainingProject.UniqueName, out hier);

            return(typeService.GetTypeResolutionService(hier).GetType(name, true));
        }
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        string propertyName = Microsoft.VisualBasic.Interaction.InputBox("Property name", "Create view model property [1/2]", "Foo", -1, -1);
        string propertyType = Microsoft.VisualBasic.Interaction.InputBox("Property type", "Create view model property [2/2]", "double", -1, -1);
        string fieldName    = "_" + System.Char.ToLower(propertyName[0]) + propertyName.Substring(1);

        EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
        ts.Text = $@"
    private {propertyType} {fieldName};
    public {propertyType} {propertyName}
    {{
       get {{ return {fieldName}; }}
       set {{ SetProperty(ref {fieldName}, value); }}
    }}
    ";
    }
예제 #19
0
        private static Task <Action> GetInitializeTask()
        {
            var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));

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

            var initializer = componentModel.GetService <IHostInitializer>();

            return(Task.Factory.StartNew(() => {
                initializer.Start();
                return new Action(initializer.SetDefaultRunspace);
            }));
        }
예제 #20
0
        private void showToolWindow()
        {
            var vsUiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
            var guid      = Guid.Parse(
                "e3bfb80d-d50a-4a85-bacd-64daca9095f7");                //This is the exact Guid declared by the DataTableVisualizerToolWindow
            var result = vsUiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFindFirst, ref guid,
                                                  out var windowFrame); // Find MyToolWindow

            if (result != VSConstants.S_OK)
            {
                result = vsUiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref guid,
                                                  out windowFrame); // Crate MyToolWindow if not found
            }
            if (result == VSConstants.S_OK)                         // Show MyToolWindow
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
        }
예제 #21
0
        private void SubmitAddRefStats()
        {
            DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            if (dte != null)
            {
                bool optOutOfStats = dte.GetOptOutStatsSetting();
                if (!optOutOfStats)
                {
                    var langName = typesHandler.RelativeTypesUrl.Substring(6);
                    Analytics.SubmitAnonymousAddReferenceUsage(langName);
                }
            }
            else
            {
                OutputWindowWriter.WriterWindow.WriteLine("Warning: Failed to resolve DTE");
            }
        }
예제 #22
0
        public override T GetService <T>(Type type = null)
        {
            type = type ?? typeof(T);

            if (type == typeof(ICoreShell))
            {
                return(_shell as T);
            }
            if (type == typeof(ExportProvider))
            {
                return(ExportProvider as T);
            }
            if (type == typeof(ICompositionService))
            {
                return(CompositionService as T);
            }
            if (type == typeof(ICompositionCatalog))
            {
                return((T)(ICompositionCatalog) new CompositionCatalog(CompositionService, ExportProvider));
            }

            // First try internal services
            var service = base.GetService <T>(type);

            if (service == null)
            {
                // First try MEF
                service = ExportProvider.GetExportedValueOrDefault <T>();
                if (service == null)
                {
                    // Now try VS services. Only allowed on UI thread.
                    if (TestEnvironment.Current != null)
                    {
                        service = RPackage.Current != null?RPackage.Current.GetService(type) as T : null;
                    }
                    else
                    {
                        service = VsPackage.GetGlobalService(type) as T;
                    }
                }
            }
            return(service);
        }
예제 #23
0
        private async Task AttemptLogErrorAsync(string message)
        {
            if (!ThreadHelper.CheckAccess())
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            }

            var outputWindow = (IVsOutputWindow)Package.GetGlobalService(typeof(SVsOutputWindow));

            if (outputWindow != null)
            {
                outputWindow.GetPane(VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid, out var pane);
                if (pane != null)
                {
                    pane.OutputString(message);
                    pane.Activate();
                }
            }
        }
        private async Task HandleChange(int delta)
        {
            if (ParticlesEnabled)
            {
                for (var i = 0; i < 10; i++)
                {
                    var explosion = new ExplosionParticle(_adornmentLayer,
                                                          (DTE)Package.GetGlobalService(typeof(DTE)),
                                                          _view.Caret.Top,
                                                          _view.Caret.Left);
                    var expl = explosion.Explode();

#pragma warning disable CS4014 // Don't care about return
                    Task.Run(() => expl);
#pragma warning restore CS4014
                }
            }
            if (ShakeEnabled)
            {
                await Shake(delta);
            }
        }
예제 #25
0
        private void Init()
        {
            dte = Package.GetGlobalService(typeof(DTE)) as DTE2;

            if (dte != null)
            {
                events = dte.Events as Events2;
                if (events != null)
                {
                    dteEvents                  = events.DTEEvents;
                    solutionEvents             = events.SolutionEvents;
                    dteEvents.OnBeginShutdown += ShutDown;
                    solutionEvents.Opened     += () => SwitchStartupDir("\n====== Solution opening Detected ======\n");
                }
            }

            terminalController.SetShell(optionMgr.Shell);

            terminalController.Init(GetProjectPath());

            terminalController.InvokeCmd("\n[Global Init Script ...]\n", optionMgr.getGlobalScript());
        }
예제 #26
0
        private void ConfigureServices()
        {
            var platformServices   = new VsPlatformServices();
            var telemetry          = new VsTelemetryService();
            var componentModel     = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));
            var loggingPermissions = new LoggingPermissions(platformServices, telemetry, new RegistryImpl());
            var settings           = new RToolsSettingsImplementation(this, new VsSettingsStorage(), loggingPermissions);
            var compositionCatalog = new CompositionCatalog(componentModel.DefaultCompositionService, componentModel.DefaultExportProvider);
            var exportProvider     = componentModel.DefaultExportProvider;

            _services
            .AddService(componentModel)
            .AddService(componentModel.DefaultCompositionService)
            .AddService(exportProvider)
            .AddService(compositionCatalog)
            .AddService(new VsMainThread())
            .AddService(new VsTaskService())
            .AddService(_idleTimeService)
            .AddService(new VsUIServices(this))
            .AddService(new SecurityService(this))
            .AddService(loggingPermissions)
            .AddService(new Logger(ApplicationName, Path.GetTempPath(), loggingPermissions))
            .AddService(platformServices)
            .AddService(settings)
            .AddService(new REditorSettings(new LanguageSettingsStorage(this, RGuidList.RLanguageServiceGuid, RGuidList.RPackageGuid, new string[] { RPackage.ProductName })))
            .AddService(new ImageService(exportProvider.GetExportedValue <IGlyphService>()))
            .AddService(new VsEditorSupport(this))
            .AddService(telemetry)
            .AddService(new FileSystem())
            .AddService(new ProcessServices())
            .AddService(new RegistryImpl())
            .AddService(new MicrosoftRClientInstaller())
            .AddWindowsRInterpretersServices()
            .AddWindowsHostClientServices();
            // TODO: add more

            settings.LoadSettings();
        }
예제 #27
0
        /// <summary>
        /// Brings up the browse folder dialog.
        /// </summary>
        /// <param name="sender">The browse button.</param>
        /// <param name="e">The <see cref="EventArgs"/> object that contains the event data.</param>
        private void OnBrowseButtonClick(object sender, EventArgs e)
        {
            // initialize the dialog to the current directory (if it exists)
            bool   overridePersistedInitialDirectory = false;
            string initialDirectory = null;

            if (Directory.Exists(FullPath))
            {
                initialDirectory = FullPath;
                overridePersistedInitialDirectory = true;
            }

            IntPtr      parentWindow    = Handle;
            Guid        persistenceSlot = typeof(FileBrowserTextBox).GUID;
            IVsUIShell2 shell           = (IVsUIShell2)Package.GetGlobalService(typeof(SVsUIShell));
            // show the dialog
            string path = shell.GetDirectoryViaBrowseDialog(parentWindow, persistenceSlot, "Select folder", initialDirectory, overridePersistedInitialDirectory);

            if (path != null)
            {
                if (MakeRelative && !string.IsNullOrEmpty(RootFolder))
                {
                    string rootFolder = Path.GetFullPath(RootFolder);
                    if (Directory.Exists(rootFolder))
                    {
                        if (!rootFolder.EndsWith(Path.DirectorySeparatorChar.ToString()) && !rootFolder.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
                        {
                            rootFolder = rootFolder + Path.DirectorySeparatorChar;
                        }

                        path = new Url(rootFolder).MakeRelative(new Url(path));
                    }
                }

                this.folderTextBox.Text = path;
            }
        }
예제 #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowDefinitionInILSpyCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        private ShowDefinitionInILSpyCommand(SpyDefinitionPackage package) : base(package, CommandId)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            this.package = package;

            //OleMenuCommandService commandService =
            //    this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            //if (commandService != null)
            //{
            //    var menuCommandID = new CommandID(ILSpyCommand.CommandSet, CommandId);
            //    var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
            //    commandService.AddCommand(menuItem);
            //}

            _dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));

            this.workspace = componentModel.GetService <VisualStudioWorkspace>() as VisualStudioWorkspace;
        }
예제 #29
0
        public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
        {
            EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
            if (ts == null)
            {
                return;
            }

            EnvDTE.CodeParameter codeParam = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementParameter] as EnvDTE.CodeParameter;
            if (codeParam == null)
            {
                return;
            }

            System.Type tClass     = GetTypeByName(DTE, package, codeParam.Type.AsFullName);
            string      properties = "";

            foreach (var p in tClass.GetProperties())
            {
                properties += codeParam.Name + "." + p.Name + System.Environment.NewLine;
            }
            System.Windows.Clipboard.SetText(properties);
            System.Windows.MessageBox.Show(properties);
        }
예제 #30
0
 protected MarkdownEditorFactory(Package package, bool promptEncodingOnLoad)
 {
     _package = package;
     _promptEncodingOnLoad = promptEncodingOnLoad;
 }
예제 #31
0
        static StringDictionary languageExtensions; // string -> language service guid.

        /// <include file='doc\EditorFactory.uex' path='docs/doc[@for="EditorFactory.EditorFactory"]/*' />
        public AnkhEditorFactory(Microsoft.VisualStudio.Shell.Package package)
        {
            this.package = package;
            this.site    = package;
        }
예제 #32
0
    Hashtable extensions; // registered

    public EditorFactory(Microsoft.VisualStudio.Shell.Package package){
      this.package = package; 
    }
예제 #33
0
 protected EditorFactory(Package package, bool promptEncodingOnLoad)
 {
     _package = package;
     _promptEncodingOnLoad = promptEncodingOnLoad;
 }
 private SnowParticle NewParticle()
 {
     return(new SnowParticle(_adornmentLayer,
                             (DTE)Package.GetGlobalService(typeof(DTE)),
                             particle => _explosionParticles.Add(particle)));
 }
예제 #35
0
 public virtual int Close(){      
   this.site = null;
   this.package = null;
   GC.Collect();
   return 0;
 }