Beispiel #1
0
 public VsAppShell()
 {
     Debug.Assert(_instance == null, "VsAppShell is a singleton and cannot be created twice");
     _instance = this;
     _services = new VsServiceManager(this);
     ConfigureServices();
 }
Beispiel #2
0
 public void ShowContextMenu(CommandId commandId, int x, int y, object commandTarget = null)
 {
     if (commandTarget == null)
     {
         var package = VsAppShell.EnsurePackageLoaded(RGuidList.RPackageGuid);
         if (package != null)
         {
             var sp          = (IServiceProvider)package;
             var menuService = (System.ComponentModel.Design.IMenuCommandService)sp
                               .GetService(typeof(System.ComponentModel.Design.IMenuCommandService));
             menuService.ShowContextMenu(new System.ComponentModel.Design.CommandID(commandId.Group, commandId.Id), x, y);
         }
     }
     else
     {
         var target = commandTarget as ICommandTarget;
         if (target == null)
         {
             throw new ArgumentException(Invariant($"{nameof(commandTarget)} must implement ICommandTarget"));
         }
         var pts = new POINTS[1];
         pts[0].x = (short)x;
         pts[0].y = (short)y;
         _uiShell.ShowContextMenu(0, commandId.Group, commandId.Id, pts, new CommandTargetToOleShim(null, target));
     }
 }
Beispiel #3
0
        private static void SetupTestInstance()
        {
            var      thisAssembly            = Assembly.GetExecutingAssembly().GetAssemblyPath();
            var      assemblyLoc             = Path.GetDirectoryName(thisAssembly);
            var      packageTestAssemblyPath = Path.Combine(assemblyLoc, "Microsoft.VisualStudio.R.Package.Test.dll");
            Assembly testAssembly            = null;

            // Catch exception when loading assembly since it is missing in non-test
            // environment but do throw when it is present but test types cannot be created.
            try {
                testAssembly = Assembly.LoadFrom(packageTestAssemblyPath);
            } catch (Exception) { }

            if (testAssembly != null)
            {
                var types   = testAssembly.GetTypes();
                var classes = types.Where(x => x.IsClass);

                var testshell = classes.FirstOrDefault(c => c.Name.Contains("VsAppShellTestSetup"));
                Debug.Assert(testshell != null);

                var mi = testshell.GetMethod("Setup", BindingFlags.Static | BindingFlags.Public);

                _instance = new VsAppShell(c => (VsServiceManager)mi.Invoke(null, new object[] { c }));
            }
            else
            {
                Debug.Fail("Unable to create VsAppShellTestSetup in Microsoft.VisualStudio.R.Package.Test.dll");
            }
        }