Exemple #1
0
        private void DesignView(int itemId, string viewName)
        {
            Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider = DataViewHierarchyAccessor.ServiceProvider as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
            IVsUIShell     shell = DataViewHierarchyAccessor.ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IVsUIHierarchy hier  = DataViewHierarchyAccessor.Hierarchy;
            IVsWindowFrame frame;

            if (shell != null)
            {
                ViewDesignerDoc form    = new ViewDesignerDoc(itemId, DataViewHierarchyAccessor, viewName);
                IntPtr          formptr = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(form);
                Guid            empty   = Guid.Empty;
                FakeHierarchy   fake    = new FakeHierarchy(form, hier);

                int code = shell.CreateDocumentWindow(
                    0, // (uint)(__VSCREATEDOCWIN.CDW_fCreateNewWindow | __VSCREATEDOCWIN.CDW_RDTFLAGS_MASK) | (uint)(_VSRDTFLAGS.RDT_CanBuildFromMemory | _VSRDTFLAGS.RDT_NonCreatable | _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_DontAddToMRU),
                    form.Name, fake, (uint)itemId, formptr, formptr, ref empty, null, ref guidViewDesignContext, provider, "", form.Caption, null, out frame);

                if (frame != null)
                {
                    object ret;
                    int    prop = (int)__VSFPROPID.VSFPROPID_Caption;

                    code = frame.GetProperty(prop, out ret);

                    code = frame.Show();
                }
            }
        }
        private IVsWindowFrame CreateDocWindow(
            Project project,
            string documentName,
            IVsHierarchy hier,
            uint itemId)
        {
            uint windowFlags =
                (uint)_VSRDTFLAGS.RDT_DontAddToMRU |
                (uint)_VSRDTFLAGS.RDT_DontSaveAs;

            var solutionManager = ServiceLocator.GetInstance <ISolutionManager>();
            var nugetProject    = solutionManager.GetNuGetProject(project.Name);

            var uiContextFactory = ServiceLocator.GetInstance <INuGetUIContextFactory>();
            var uiContext        = uiContextFactory.Create(this, new [] { nugetProject });

            var uiFactory    = ServiceLocator.GetInstance <INuGetUIFactory>();
            var uiController = uiFactory.Create(uiContext, _uiProjectContext);

            var model = new PackageManagerModel(uiController, uiContext);
            var vsWindowSearchHostfactory = ServiceLocator.GetGlobalService <SVsWindowSearchHostFactory, IVsWindowSearchHostFactory>();
            var control        = new PackageManagerControl(model, Settings, vsWindowSearchHostfactory);
            var windowPane     = new PackageManagerWindowPane(control);
            var ppunkDocView   = Marshal.GetIUnknownForObject(windowPane);
            var ppunkDocData   = Marshal.GetIUnknownForObject(model);
            var guidEditorType = Guid.Empty;
            var guidCommandUI  = Guid.Empty;
            var caption        = String.Format(
                CultureInfo.CurrentCulture,
                Resx.Label_NuGetWindowCaption,
                project.Name // **** myDoc.Target.Name);
                );

            IVsWindowFrame windowFrame;
            IVsUIShell     uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            int            hr      = uiShell.CreateDocumentWindow(
                windowFlags,
                documentName,
                (IVsUIHierarchy)hier,
                itemId,
                ppunkDocView,
                ppunkDocData,
                ref guidEditorType,
                null,
                ref guidCommandUI,
                null,
                caption,
                string.Empty,
                null,
                out windowFrame);

            ErrorHandler.ThrowOnFailure(hr);
            return(windowFrame);
        }
        private IVsWindowFrame CreateDocWindowForSolution()
        {
            // TODO: Need to wait until solution is loaded

            IVsWindowFrame windowFrame = null;
            IVsSolution    solution    = ServiceLocator.GetInstance <IVsSolution>();
            IVsUIShell     uiShell     = (IVsUIShell)GetService(typeof(SVsUIShell));
            uint           windowFlags =
                (uint)_VSRDTFLAGS.RDT_DontAddToMRU |
                (uint)_VSRDTFLAGS.RDT_DontSaveAs;

            var context         = ServiceLocator.GetInstance <VsPackageManagerContext>();
            var currentSolution = context.GetCurrentSolution();

            if (!currentSolution.Projects.Any())
            {
                // there are no supported projects.
                MessageHelper.ShowWarningMessage(VsResources.NoSupportedProjectsInSolution, Resources.ErrorDialogBoxTitle);
                return(windowFrame);
            }

            var myDoc          = new PackageManagerModel(context.SourceManager, currentSolution);
            var NewEditor      = new PackageManagerWindowPane(myDoc, ServiceLocator.GetInstance <IUserInterfaceService>());
            var ppunkDocView   = Marshal.GetIUnknownForObject(NewEditor);
            var ppunkDocData   = Marshal.GetIUnknownForObject(myDoc);
            var guidEditorType = PackageManagerEditorFactory.EditorFactoryGuid;
            var guidCommandUI  = Guid.Empty;
            var caption        = String.Format(
                CultureInfo.CurrentCulture,
                Resx.Resources.Label_NuGetWindowCaption,
                myDoc.Target.Name);
            var documentName = _dte.Solution.FullName;
            int hr           = uiShell.CreateDocumentWindow(
                windowFlags,
                documentName,
                (IVsUIHierarchy)solution,
                (uint)VSConstants.VSITEMID.Root,
                ppunkDocView,
                ppunkDocData,
                ref guidEditorType,
                null,
                ref guidCommandUI,
                null,
                caption,
                string.Empty,
                null,
                out windowFrame);

            ErrorHandler.ThrowOnFailure(hr);
            return(windowFrame);
        }
        private IVsWindowFrame CreateDocWindow(
            Project project,
            string documentName,
            IVsHierarchy hier,
            uint itemId)
        {
            uint windowFlags =
                (uint)_VSRDTFLAGS.RDT_DontAddToMRU |
                (uint)_VSRDTFLAGS.RDT_DontSaveAs;

            var context = ServiceLocator.GetInstance <VsPackageManagerContext>();
            var myDoc   = new PackageManagerModel(
                context.SourceManager,
                context.GetCurrentVsSolution().GetProject(project));

            var NewEditor      = new PackageManagerWindowPane(myDoc, ServiceLocator.GetInstance <IUserInterfaceService>());
            var ppunkDocView   = Marshal.GetIUnknownForObject(NewEditor);
            var ppunkDocData   = Marshal.GetIUnknownForObject(myDoc);
            var guidEditorType = PackageManagerEditorFactory.EditorFactoryGuid;
            var guidCommandUI  = Guid.Empty;
            var caption        = String.Format(
                CultureInfo.CurrentCulture,
                Resx.Resources.Label_NuGetWindowCaption,
                myDoc.Target.Name);

            IVsWindowFrame windowFrame;
            IVsUIShell     uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            int            hr      = uiShell.CreateDocumentWindow(
                windowFlags,
                documentName,
                (IVsUIHierarchy)hier,
                itemId,
                ppunkDocView,
                ppunkDocData,
                ref guidEditorType,
                null,
                ref guidCommandUI,
                null,
                caption,
                string.Empty,
                null,
                out windowFrame);

            ErrorHandler.ThrowOnFailure(hr);
            return(windowFrame);
        }
Exemple #5
0
        private async Task <IVsWindowFrame> CreateDocWindowAsync(UnconfiguredProject unconfiguredProject, string documentName, IVsHierarchy hierarchy, uint itemId)
        {
            var windowFlags = _VSRDTFLAGS.RDT_DontAddToMRU | _VSRDTFLAGS.RDT_DontAutoOpen;
            var model       = new WindowModel(project, targetUIs, lockService, threadHandler);
            await model.LoadFromProject();

            var            control    = new Control(model);
            var            windowPane = new WindowPane(control);
            var            editorType = Guid.Empty;
            var            commandUI  = Guid.Empty;
            var            caption    = $"{model.Name} Deploy Rules";
            IVsWindowFrame frame;
            var            docView = IntPtr.Zero;
            var            docData = IntPtr.Zero;
            var            hr      = 0;

            try
            {
                docView = Marshal.GetIUnknownForObject(windowPane);
                docData = Marshal.GetIUnknownForObject(model);
                hr      = uiShell.CreateDocumentWindow((uint)windowFlags, documentName, (IVsUIHierarchy)hierarchy, itemId,
                                                       docView, docData, ref editorType, null, ref commandUI, null, caption, string.Empty, null, out frame);
            }
            finally
            {
                if (docView != IntPtr.Zero)
                {
                    Marshal.Release(docView);
                }
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }
            ErrorHandler.ThrowOnFailure(hr);
            return(frame);
        }
        private async Task<IVsWindowFrame> CreateDocWindowForSolutionAsync()
        {
            IVsWindowFrame windowFrame = null;
            IVsSolution solution = ServiceLocator.GetInstance<IVsSolution>();
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            uint windowFlags =
                (uint)_VSRDTFLAGS.RDT_DontAddToMRU |
                (uint)_VSRDTFLAGS.RDT_DontSaveAs;

            var solutionManager = ServiceLocator.GetInstance<ISolutionManager>();

            if (!solutionManager.IsSolutionAvailable)
            {
                throw new InvalidOperationException(Strings.SolutionIsNotSaved);
            }

            var projects = solutionManager.GetNuGetProjects();
            if (!projects.Any())
            {
                // NOTE: The menu 'Manage NuGet Packages For Solution' will be disabled in this case.
                // But, it is possible, that, before NuGetPackage is loaded in VS, the menu is enabled and used.
                // For once, this message will be shown. Once the package is loaded, the menu will get disabled as appropriate
                MessageHelper.ShowWarningMessage(Resources.NoSupportedProjectsInSolution, Resources.ErrorDialogBoxTitle);
                return null;
            }

            // load packages.config. This makes sure that an exception will get thrown if there
            // are problems with packages.config, such as duplicate packages. When an exception
            // is thrown, an error dialog will pop up and this doc window will not be created.
            foreach (var project in projects)
            {
                await project.GetInstalledPackagesAsync(CancellationToken.None);
            }

            var uiContextFactory = ServiceLocator.GetInstance<INuGetUIContextFactory>();
            var uiContext = uiContextFactory.Create(this, projects);

            var uiFactory = ServiceLocator.GetInstance<INuGetUIFactory>();
            var uiController = uiFactory.Create(uiContext, _uiProjectContext);

            var solutionName = (string)_dte.Solution.Properties.Item("Name").Value;
            var model = new PackageManagerModel(uiController, uiContext, isSolution: true, editorFactoryGuid: GuidList.guidNuGetEditorType);
            model.SolutionName = solutionName;
            var vsWindowSearchHostfactory = ServiceLocator.GetGlobalService<SVsWindowSearchHostFactory, IVsWindowSearchHostFactory>();
            var vsShell = ServiceLocator.GetGlobalService<SVsShell, IVsShell4>();
            var control = new PackageManagerControl(model, Settings, vsWindowSearchHostfactory, vsShell, _outputConsoleLogger);
            var windowPane = new PackageManagerWindowPane(control);
            var guidEditorType = GuidList.guidNuGetEditorType;
            var guidCommandUI = Guid.Empty;
            var caption = Resx.Label_SolutionNuGetWindowCaption;
            var documentName = _dte.Solution.FullName;

            IntPtr ppunkDocView = IntPtr.Zero;
            IntPtr ppunkDocData = IntPtr.Zero;
            int hr = 0;

            try
            {
                ppunkDocView = Marshal.GetIUnknownForObject(windowPane);
                ppunkDocData = Marshal.GetIUnknownForObject(model);
                hr = uiShell.CreateDocumentWindow(
                    windowFlags,
                    documentName,
                    (IVsUIHierarchy)solution,
                    (uint)VSConstants.VSITEMID.Root,
                    ppunkDocView,
                    ppunkDocData,
                    ref guidEditorType,
                    null,
                    ref guidCommandUI,
                    null,
                    caption,
                    string.Empty,
                    null,
                    out windowFrame);
            }
            finally
            {
                if (ppunkDocView != IntPtr.Zero)
                {
                    Marshal.Release(ppunkDocData);
                }

                if (ppunkDocData != IntPtr.Zero)
                {
                    Marshal.Release(ppunkDocView);
                }
            }

            ErrorHandler.ThrowOnFailure(hr);
            return windowFrame;
        }
        private async Task<IVsWindowFrame> CreateDocWindowAsync(
            Project project,
            string documentName,
            IVsHierarchy hier,
            uint itemId)
        {
            uint windowFlags =
                (uint)_VSRDTFLAGS.RDT_DontAddToMRU |
                (uint)_VSRDTFLAGS.RDT_DontSaveAs;

            var solutionManager = ServiceLocator.GetInstance<ISolutionManager>();

            if (!solutionManager.IsSolutionAvailable)
            {
                throw new InvalidOperationException(Strings.SolutionIsNotSaved);
            }

            var nugetProject = solutionManager.GetNuGetProject(EnvDTEProjectUtility.GetCustomUniqueName(project));

            // If we failed to generate a cache entry in the solution manager something went wrong.
            if (nugetProject == null)
            {
                throw new InvalidOperationException(
                    string.Format(Resources.ProjectHasAnInvalidNuGetConfiguration, project.Name));
            }

            // load packages.config. This makes sure that an exception will get thrown if there
            // are problems with packages.config, such as duplicate packages. When an exception
            // is thrown, an error dialog will pop up and this doc window will not be created.
            var installedPackages = await nugetProject.GetInstalledPackagesAsync(CancellationToken.None);

            var uiContextFactory = ServiceLocator.GetInstance<INuGetUIContextFactory>();
            var uiContext = uiContextFactory.Create(this, new[] { nugetProject });

            var uiFactory = ServiceLocator.GetInstance<INuGetUIFactory>();
            var uiController = uiFactory.Create(uiContext, _uiProjectContext);

            var model = new PackageManagerModel(uiController, uiContext, isSolution: false, editorFactoryGuid: GuidList.guidNuGetEditorType);
            var vsWindowSearchHostfactory = ServiceLocator.GetGlobalService<SVsWindowSearchHostFactory, IVsWindowSearchHostFactory>();
            var vsShell = ServiceLocator.GetGlobalService<SVsShell, IVsShell4>();
            var control = new PackageManagerControl(model, Settings, vsWindowSearchHostfactory, vsShell, _outputConsoleLogger);
            var windowPane = new PackageManagerWindowPane(control);
            var guidEditorType = GuidList.guidNuGetEditorType;
            var guidCommandUI = Guid.Empty;
            var caption = String.Format(
                CultureInfo.CurrentCulture,
                Resx.Label_NuGetWindowCaption,
                project.Name);

            IVsWindowFrame windowFrame;
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

            IntPtr ppunkDocView = IntPtr.Zero;
            IntPtr ppunkDocData = IntPtr.Zero;
            int hr = 0;

            try
            {
                ppunkDocView = Marshal.GetIUnknownForObject(windowPane);
                ppunkDocData = Marshal.GetIUnknownForObject(model);
                hr = uiShell.CreateDocumentWindow(
                    windowFlags,
                    documentName,
                    (IVsUIHierarchy)hier,
                    itemId,
                    ppunkDocView,
                    ppunkDocData,
                    ref guidEditorType,
                    null,
                    ref guidCommandUI,
                    null,
                    caption,
                    string.Empty,
                    null,
                    out windowFrame);
            }
            finally
            {
                if (ppunkDocView != IntPtr.Zero)
                {
                    Marshal.Release(ppunkDocData);
                }

                if (ppunkDocData != IntPtr.Zero)
                {
                    Marshal.Release(ppunkDocView);
                }
            }

            ErrorHandler.ThrowOnFailure(hr);
            return windowFrame;
        }
        private IVsWindowFrame CreateDocWindowForSolution()
        {
            // TODO: Need to wait until solution is loaded
            IVsWindowFrame windowFrame = null;
            IVsSolution    solution    = ServiceLocator.GetInstance <IVsSolution>();
            IVsUIShell     uiShell     = (IVsUIShell)GetService(typeof(SVsUIShell));
            uint           windowFlags =
                (uint)_VSRDTFLAGS.RDT_DontAddToMRU |
                (uint)_VSRDTFLAGS.RDT_DontSaveAs;

            var solutionManager = ServiceLocator.GetInstance <ISolutionManager>();
            var projects        = solutionManager.GetNuGetProjects();

            if (!projects.Any())
            {
                // there are no supported projects.
                // TODO: MessageHelper.ShowWarningMessage(
                //    Resx.NoSupportedProjectsInSolution, Resources.ErrorDialogBoxTitle);
                return(null);
            }

            var uiContextFactory = ServiceLocator.GetInstance <INuGetUIContextFactory>();
            var uiContext        = uiContextFactory.Create(this, projects);

            var uiFactory    = ServiceLocator.GetInstance <INuGetUIFactory>();
            var uiController = uiFactory.Create(uiContext, _uiProjectContext);

            var solutionName = (string)_dte.Solution.Properties.Item("Name").Value;
            var model        = new PackageManagerModel(uiController, uiContext);

            model.SolutionName = solutionName;
            var vsWindowSearchHostfactory = ServiceLocator.GetGlobalService <SVsWindowSearchHostFactory, IVsWindowSearchHostFactory>();
            var control        = new PackageManagerControl(model, Settings, vsWindowSearchHostfactory);
            var windowPane     = new PackageManagerWindowPane(control);
            var ppunkDocView   = Marshal.GetIUnknownForObject(windowPane);
            var ppunkDocData   = Marshal.GetIUnknownForObject(model);
            var guidEditorType = Guid.Empty;
            var guidCommandUI  = Guid.Empty;
            var caption        = String.Format(
                CultureInfo.CurrentCulture,
                Resx.Label_NuGetWindowCaption,
                solutionName);
            var documentName = _dte.Solution.FullName;
            int hr           = uiShell.CreateDocumentWindow(
                windowFlags,
                documentName,
                (IVsUIHierarchy)solution,
                (uint)VSConstants.VSITEMID.Root,
                ppunkDocView,
                ppunkDocData,
                ref guidEditorType,
                null,
                ref guidCommandUI,
                null,
                caption,
                string.Empty,
                null,
                out windowFrame);

            ErrorHandler.ThrowOnFailure(hr);
            return(windowFrame);
        }