コード例 #1
0
        /// <summary>
        /// Adds one or more files to the solution folder.
        /// </summary>
        public async Task <IEnumerable <File> > AddExistingFilesAsync(params string[] files)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsUIShell uiShell = await VS.Services.GetUIShellAsync();

            uiShell.GetDialogOwnerHwnd(out IntPtr hwndDlgOwner);

            GetItemInfo(out IVsHierarchy hierarchy, out _, out _);

            Guid rguidEditorType = Guid.Empty, rguidLogicalView = Guid.Empty;

            VSADDRESULT[] result   = new VSADDRESULT[1];
            IVsProject3   project3 = (IVsProject3)hierarchy;

            project3.AddItemWithSpecific(itemidLoc: (uint)VSConstants.VSITEMID.Root,
                                         dwAddItemOperation: VSADDITEMOPERATION.VSADDITEMOP_OPENFILE,
                                         pszItemName: "test",
                                         cFilesToOpen: (uint)files.Count(), //The name of the parameter is misleading, it's the number of files to process,
                                                                            //and whether to open in editor or not is determined by other flag
                                         rgpszFilesToOpen: files,
                                         hwndDlgOwner: hwndDlgOwner,
                                         grfEditorFlags: 0u, //We do not want to open in the editor
                                         rguidEditorType: ref rguidEditorType,
                                         pszPhysicalView: null,
                                         rguidLogicalView: ref rguidLogicalView,
                                         pResult: result);

            return(await File.FromFilesAsync(files));
        }
コード例 #2
0
        protected override void SetInnerProject(IntPtr innerIUnknown)
        {
            var inner = Marshal.GetObjectForIUnknown(innerIUnknown);

            // The reason why we keep a reference to those is that doing a QI after being
            // aggregated would do the AddRef on the outer object.
            _innerVsProjectFlavorCfgProvider = inner as IVsProjectFlavorCfgProvider;
            _innerProject     = inner as IVsProject;
            _innerProject3    = inner as IVsProject3;
            _innerVsHierarchy = inner as IVsHierarchy;

            if (serviceProvider == null)
            {
                serviceProvider = _site;
            }

            // Now let the base implementation set the inner object
            base.SetInnerProject(innerIUnknown);

            // Get access to the menu service used by FlavoredProjectBase. We
            // need to forward IOleCommandTarget functions to this object, since
            // we override the FlavoredProjectBase implementation with no way to
            // call it directory.
            // (This must run after we called base.SetInnerProject)
            _menuService = (IOleCommandTarget)((IServiceProvider)this).GetService(typeof(IMenuCommandService));
            if (_menuService == null)
            {
                throw new InvalidOperationException("Cannot initialize Web project");
            }
        }
コード例 #3
0
        public static IServiceProvider ToServiceProvider(Project project)
        {
            IVsProject3 vsProject = ToVsProject(project);

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider;
            ErrorHandler.ThrowOnFailure(vsProject.GetItemContext(VSConstants.VSITEMID_ROOT, out provider));

            return(new ServiceProvider(provider));
        }
コード例 #4
0
        public override int OnAfterRenameProject(IVsHierarchy hierarchy)
        {
            if (hierarchy == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            try
            {
                List <ProjectReferenceNode> projectReferences = this.GetProjectReferencesContainingThisProject(hierarchy);

                // Collect data that is needed to initialize the new project reference node.
                string projectRef;
                ErrorHandler.ThrowOnFailure(this.Solution.GetProjrefOfProject(hierarchy, out projectRef));

                object nameAsObject;
                ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Name, out nameAsObject));
                string projectName = (string)nameAsObject;

                string projectPath = String.Empty;

                IVsProject3 project = hierarchy as IVsProject3;

                if (project != null)
                {
                    ErrorHandler.ThrowOnFailure(project.GetMkDocument(VSConstants.VSITEMID_ROOT, out projectPath));
                    projectPath = Path.GetDirectoryName(projectPath);
                }

                // Remove and re add the node.
                foreach (ProjectReferenceNode projectReference in projectReferences)
                {
                    ProjectNode projectMgr = projectReference.ProjectManager;
                    projectReference.Remove(false);

                    IReferenceContainer refContainer = projectMgr.GetReferenceContainer();
                    if (refContainer == null)
                    {
                        continue;
                    }

                    VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA();
                    selectorData.type        = VSCOMPONENTTYPE.VSCOMPONENTTYPE_Project;
                    selectorData.bstrTitle   = projectName;
                    selectorData.bstrFile    = projectPath;
                    selectorData.bstrProjRef = projectRef;
                    refContainer.AddReferenceFromSelectorData(selectorData);
                }
            }
            catch (COMException e)
            {
                return(e.ErrorCode);
            }

            return(VSConstants.S_OK);
        }
コード例 #5
0
        void LoadXamlEditor()
        {
            //Guid editorGuid = new Guid("FA3CD31E-987B-443A-9B81-186104E8DAC1"); // XML Editor
            //Guid editorGuid = new Guid("DEE6CEF9-3BCA-449A-82A6-FC757D6956FB"); // XSD Editor
            //Guid editorGuid = new Guid("f11acc28-31d1-4c80-a34b-f4e09d3d753c"); // XAML UI Designer (TabbedViewEditorFactory)
            //Guid editorGuid = new Guid("a4f9ff65-a78c-4650-866d-5069cc4127cf"); // XAML Text Editor (XamlTabEditorFactory)
            Guid editorGuid = VSConstants.VsEditorFactoryGuid.TextEditor_guid;

            IVsWindowFrame frame;
            IVsProject3    vsProject   = (IVsProject3)_hierarchy;
            Guid           _emptyGuid  = Guid.Empty;
            uint           editorFlags = (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_UseEditor | (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen;

            ErrorHandler.ThrowOnFailure(
                vsProject.OpenItemWithSpecific(
                    _itemid,
                    editorFlags,
                    ref editorGuid,
                    _pszPhysicalView,
                    ref _emptyGuid,
                    _punkDocData,
                    out frame));

            IVsWindowFrame windowFrameOrig = GetFrame();

            Debug.Assert(windowFrameOrig != null);
            ErrorHandler.ThrowOnFailure(frame.SetProperty((int)__VSFPROPID2.VSFPROPID_ParentFrame, windowFrameOrig));
            ErrorHandler.ThrowOnFailure(frame.SetProperty((int)__VSFPROPID2.VSFPROPID_ParentHwnd, GetChildContainerHandle()));
            //ErrorHandler.ThrowOnFailure(frame.SetProperty((int)__VSFPROPID.VSFPROPID_pszPhysicalView, "MainFrame"));
            _subFrame = frame;
            var    IID_IVsCodeWindow = typeof(IVsCodeWindow).GUID;
            IntPtr intPtr;

            _subFrame.QueryViewInterface(ref IID_IVsCodeWindow, out intPtr);
            _subCodeWindow = Marshal.GetObjectForIUnknown(intPtr) as IVsCodeWindow;
            //ErrorHandler.ThrowOnFailure(((IVsWindowFrame2)frame).ActivateOwnerDockedWindow());

            /*
             * IVsTextView vsTextView;
             * ((IVsCodeWindow)_subCodeWindow).GetPrimaryView(out vsTextView);
             *
             * // Enable the "Quick Find" feature of Visual Studio:
             * EnableAutonomousFind(windowFrameOrig, vsTextView);
             * EnableAutonomousFind(_subFrame, vsTextView);
             *
             * foreach (Type theInterface in _subCodeWindow.GetType().GetInterfaces())
             * {
             *  string name = theInterface.Name;
             *  string toString = theInterface.ToString();
             * }
             */
        }
コード例 #6
0
        /// <summary>
        /// Converts an EnvDTE.Project to a Visual Studio project hierarchy.
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public static IVsProject3 ToVsProject(EnvDTE.Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            IVsProject3 vsProject = ToHierarchy(project) as IVsProject3;

            if (vsProject == null)
            {
                throw new ArgumentException("Project is not a recognized VS project.");
            }
            return(vsProject);
        }
コード例 #7
0
        // Token: 0x06000020 RID: 32 RVA: 0x00002608 File Offset: 0x00000808
        public static IVsProject3 ToVsProject(this Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            IVsProject3 vsProject = project.ToHierarchy() as IVsProject3;

            if (vsProject == null)
            {
                throw new ArgumentException("Project is not a VS project.");
            }
            return(vsProject);
        }
コード例 #8
0
ファイル: VsHelper.cs プロジェクト: vijumn/open-wssf-2015
        /// <summary>
        /// Toes the vs project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns></returns>
        public static IVsProject3 ToVSProject(EnvDTE.Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            IVsProject3 vsProject = ToHierarchy(project) as IVsProject3;

            if (vsProject == null)
            {
                throw new ArgumentException(Properties.Resources.ProjectIsNotVSProject);
            }

            return(vsProject);
        }
コード例 #9
0
ファイル: DjangoProject.cs プロジェクト: PeezoSlug/PTVS
        protected override void SetInnerProject(IntPtr innerIUnknown)
        {
            var inner = Marshal.GetObjectForIUnknown(innerIUnknown);

            // The reason why we keep a reference to those is that doing a QI after being
            // aggregated would do the AddRef on the outer object.
            _innerVsProjectFlavorCfgProvider = inner as IVsProjectFlavorCfgProvider;
            _innerProject     = inner as IVsProject;
            _innerProject3    = inner as IVsProject3;
            _innerVsHierarchy = inner as IVsHierarchy;

            // Ensure we have a service provider as this is required for menu items to work
            if (serviceProvider == null)
            {
                serviceProvider = _serviceProvider;
            }

            // Now let the base implementation set the inner object
            base.SetInnerProject(innerIUnknown);

            // Add our commands (this must run after we called base.SetInnerProject)
            _menuService = ((System.IServiceProvider) this).GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

#if !DJANGO_HTML_EDITOR
            try
            {
                var outputWindow = OutputWindowRedirector.GetGeneral(this);
                outputWindow.WriteErrorLine("NOTE: Django template support has been disabled in the editor due to a\r\n" +
                                            "compatibility issue and will be restored in a future update.");
                outputWindow.ShowAndActivate();

                var shell = ((System.IServiceProvider) this).GetService(typeof(SVsUIShell)) as IVsUIShell;
                if (shell != null)
                {
                    var windowGuid = new Guid("{34E76E81-EE4A-11D0-AE2E-00A0C90FFFC3}");
                    if (ErrorHandler.Succeeded(shell.FindToolWindow(0, ref windowGuid, out IVsWindowFrame wnd)) && wnd != null)
                    {
                        wnd.Show();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
            }
#endif
        }
コード例 #10
0
        public override int OnAfterRenameProject(IVsHierarchy hierarchy)
        {
            if (hierarchy == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            try
            {
                List <ProjectReferenceNode> projectReferences = this.GetProjectReferencesContainingThisProject(hierarchy);

                // Collect data that is needed to initialize the new project reference node.
                string projectRef;
                ErrorHandler.ThrowOnFailure(this.Solution.GetProjrefOfProject(hierarchy, out projectRef));

                object nameAsObject;
                ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Name, out nameAsObject));
                string projectName = (string)nameAsObject;

                string projectPath = String.Empty;

                if (hierarchy is IVsProject3)
                {
                    IVsProject3 project = (IVsProject3)hierarchy;

                    ErrorHandler.ThrowOnFailure(project.GetMkDocument(VSConstants.VSITEMID_ROOT, out projectPath));
                    projectPath = Path.GetDirectoryName(projectPath);
                }

                // Remove and re add the node.
                foreach (ProjectReferenceNode projectReference in projectReferences)
                {
                    ProjectNode projectMgr = projectReference.ProjectMgr;
                    projectReference.Remove(false);
                    ProjectReferenceNode newNode = new ProjectReferenceNode(projectMgr, projectName, projectPath, projectRef);
                    newNode.AddReference();
                }
            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception :" + e.Message);
                return(e.ErrorCode);
            }

            return(VSConstants.S_OK);
        }
コード例 #11
0
        /// <summary>
        /// Notifies a sink that the [bindable] property specified by dispID has changed.
        /// If dispID is DISPID_UNKNOWN, then multiple properties have changed together.
        /// The client (owner of the sink) should then retrieve the current value of each property of interest from the object that generated the notification.
        /// In our case we will care about the  VSLangProj80.VsProjPropId.VBPROJPROPID_FileName and update the changes in the parent project file.
        /// </summary>
        /// <param name="dispid">Dispatch identifier of the property that is about to change or DISPID_UNKNOWN if multiple properties are about to change.</param>
        public virtual void OnChanged(int dispid)
        {
            if (dispid == (int)VSLangProj80.VsProjPropId.VBPROJPROPID_FileName)
            {
                // Get the filename of the nested project. Inetead of asking the label on the nested we ask the filename, since the label might not yet been set.
                IVsProject3 nestedProject = this.nestedHierarchy as IVsProject3;

                if (nestedProject != null)
                {
                    string document;
                    nestedProject.GetMkDocument(VSConstants.VSITEMID_ROOT, out document);
                    this.RenameNestedProjectInParentProject(Path.GetFileNameWithoutExtension(document));

                    // We need to redraw the caption since for some reason, by intervining to the OnChanged event the Caption is not updated.
                    this.ReDraw(UIHierarchyElement.Caption);
                }
            }
        }
コード例 #12
0
ファイル: DjangoProject.cs プロジェクト: int19h/PTVS
        protected override void SetInnerProject(IntPtr innerIUnknown)
        {
            var inner = Marshal.GetObjectForIUnknown(innerIUnknown);

            // The reason why we keep a reference to those is that doing a QI after being
            // aggregated would do the AddRef on the outer object.
            _innerVsProjectFlavorCfgProvider = inner as IVsProjectFlavorCfgProvider;
            _innerProject     = inner as IVsProject;
            _innerProject3    = inner as IVsProject3;
            _innerVsHierarchy = inner as IVsHierarchy;

            // Ensure we have a service provider as this is required for menu items to work
            if (serviceProvider == null)
            {
                serviceProvider = _serviceProvider;
            }

            // Now let the base implementation set the inner object
            base.SetInnerProject(innerIUnknown);

            // Add our commands (this must run after we called base.SetInnerProject)
            _menuService = ((System.IServiceProvider) this).GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
        }
コード例 #13
0
        public override void GotoSource(VSOBJGOTOSRCTYPE gotoType)
        {
            // We do not support the "Goto Reference"
            if (VSOBJGOTOSRCTYPE.GS_REFERENCE == gotoType)
            {
                return;
            }

            // There is no difference between definition and declaration, so here we
            // don't check for the other flags.

            IVsWindowFrame frame        = null;
            IntPtr         documentData = FindDocDataFromRDT();

            try {
                // Now we can try to open the editor. We assume that the owner hierarchy is
                // a project and we want to use its OpenItem method.
                IVsProject3 project = _ownerHierarchy as IVsProject3;
                if (null == project)
                {
                    return;
                }
                Guid viewGuid = VSConstants.LOGVIEWID_Code;
                ErrorHandler.ThrowOnFailure(project.OpenItem(_fileId, ref viewGuid, documentData, out frame));
            } finally {
                if (IntPtr.Zero != documentData)
                {
                    Marshal.Release(documentData);
                    documentData = IntPtr.Zero;
                }
            }

            // Make sure that the document window is visible.
            ErrorHandler.ThrowOnFailure(frame.Show());

            // Get the code window from the window frame.
            object docView;

            ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView));
            IVsCodeWindow codeWindow = docView as IVsCodeWindow;

            if (null == codeWindow)
            {
                object docData;
                ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData));
                codeWindow = docData as IVsCodeWindow;
                if (null == codeWindow)
                {
                    return;
                }
            }

            // Get the primary view from the code window.
            IVsTextView textView;

            ErrorHandler.ThrowOnFailure(codeWindow.GetPrimaryView(out textView));

            // Set the cursor at the beginning of the declaration.
            ErrorHandler.ThrowOnFailure(textView.SetCaretPos(_sourceSpan.iStartLine, _sourceSpan.iStartIndex));
            // Make sure that the text is visible.
            TextSpan visibleSpan = new TextSpan();

            visibleSpan.iStartLine  = _sourceSpan.iStartLine;
            visibleSpan.iStartIndex = _sourceSpan.iStartIndex;
            visibleSpan.iEndLine    = _sourceSpan.iStartLine;
            visibleSpan.iEndIndex   = _sourceSpan.iStartIndex + 1;
            ErrorHandler.ThrowOnFailure(textView.EnsureSpanVisible(visibleSpan));
        }
コード例 #14
0
 internal XSharpEventBindingProvider(FileNode xsFile)
 {
     _xsFile  = xsFile;
     _project = xsFile.ProjectMgr;
 }
コード例 #15
0
ファイル: PythonWebProject.cs プロジェクト: zooba/PTVS
        protected override void SetInnerProject(IntPtr innerIUnknown) {
            var inner = Marshal.GetObjectForIUnknown(innerIUnknown);

            // The reason why we keep a reference to those is that doing a QI after being
            // aggregated would do the AddRef on the outer object.
            _innerVsProjectFlavorCfgProvider = inner as IVsProjectFlavorCfgProvider;
            _innerProject = inner as IVsProject;
            _innerProject3 = inner as IVsProject3;
            _innerVsHierarchy = inner as IVsHierarchy;

            if (serviceProvider == null) {
                serviceProvider = _site;
            }

            // Now let the base implementation set the inner object
            base.SetInnerProject(innerIUnknown);

            // Get access to the menu service used by FlavoredProjectBase. We
            // need to forward IOleCommandTarget functions to this object, since
            // we override the FlavoredProjectBase implementation with no way to
            // call it directory.
            // (This must run after we called base.SetInnerProject)
            _menuService = (IOleCommandTarget)((IServiceProvider)this).GetService(typeof(IMenuCommandService));
            if (_menuService == null) {
                throw new InvalidOperationException("Cannot initialize Web project");
            }
        }
コード例 #16
0
        private void TestImplicitNestedProjectReload(IServiceProvider sp, ProjectNode project, int dialogAnswer)
        {
            // Save everything.
            IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));

            solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project, 0);

            IVsProject3 nestedProject = Utilities.GetNestedHierarchy(project, "ANestedProject") as IVsProject3;

            if (nestedProject == null)
            {
                throw new InvalidOperationException("The nested project has not been loaded corectly");
            }

            string nestedProjectFileName = null;

            nestedProject.GetMkDocument(VSConstants.VSITEMID_ROOT, out nestedProjectFileName);

            if (nestedProjectFileName == null)
            {
                throw new InvalidOperationException("The nested project file name could not been retrieved corectly");
            }

            string resourceText = Utilities.GetResourceStringFromTheProjectAssembly("QueryReloadNestedProject");

            // Create the messageBoxListener Thread. This will bring up the reload of the nested project file.
            // In this scenario we will answer dialogAnswer. Also we rely on the exact messagebox text here.
            string message = String.Format(System.Globalization.CultureInfo.CurrentCulture, resourceText, nestedProjectFileName);

            DialogBoxPurger purger = new DialogBoxPurger(dialogAnswer, message);
            bool            result = false;

            try
            {
                purger.Start();
                this.AddReferenceExternallyToTheProjectFile(nestedProjectFileName);
            }
            finally
            {
                result = purger.WaitForDialogThreadToTerminate();
            }

            if (!result)
            {
                throw new InvalidOperationException("The messagebox for relaoding the nested project file has never popped up");
            }

            // Check to see if the nested project is there.
            EnvDTE.Project     projectDTE = Utilities.GetAutomationObject(project);
            EnvDTE.ProjectItem item       = projectDTE.ProjectItems.Item("ANestedProject");

            Assert.IsNotNull(item, "The nested project has not been loaded correctly.");
            EnvDTE.Project nestedAutomationProject = item.SubProject;

            // Now check to see if we can find the added reference
            VSLangProj.VSProject automationProject = nestedAutomationProject.Object as VSLangProj.VSProject;
            if (nestedAutomationProject == null)
            {
                throw new InvalidOperationException("The nested project is not a vs language project");
            }

            // Get references collection
            VSLangProj.References references = automationProject.References;

            IEnumerator enumerator = references.GetEnumerator();
            bool        found      = false;

            while (enumerator.MoveNext())
            {
                VSLangProj.Reference reference = enumerator.Current as VSLangProj.Reference;
                if (reference.Name == BuildEngineRef)
                {
                    found = true;
                }
            }

            if (dialogAnswer == NativeMethods.IDYES)
            {
                Assert.IsTrue(found, "The nested project file has not been reloaded correctly");
            }
            else
            {
                Assert.IsFalse(found, "The nested project file has been reloaded but was asked not to do that.");
            }
        }
コード例 #17
0
ファイル: SolutionToolbarPackage.cs プロジェクト: PavelPZ/REW
 void adjustAddFile(string fileName, IVsProject3 pro) {
   int pfFound; VSDOCUMENTPRIORITY[] pdwPriority = new VSDOCUMENTPRIORITY[1];
   int retVal; uint dirId, newFileId;
   //Microsoft.VisualStudio.VSConstants.VSITEMID 
   //if (!File.Exists(fileName)) throw new Exception();
   //retVal = pro.IsDocumentInProject(fileName, out pfFound, pdwPriority, out newFileId);
   //if (retVal != 0) return;
   //if (pfFound != 1) { 
   //}
   retVal = pro.IsDocumentInProject(fileName, out pfFound, pdwPriority, out newFileId);
   VSADDRESULT[] addResArr = new VSADDRESULT[1];
   string[] fnarr = new string[] { fileName };
   //retVal = pro.AddItem(newFileId, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, fileName, cFilesToOpen, fnarr, IntPtr.Zero, addResArr);
   //retVal = pro.AddItem(VSConstants.VSITEMID_ROOT, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, fileName, 1, fnarr, IntPtr.Zero, addResArr);
   retVal = pro.AddItem(newFileId, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, fileName, 1, fnarr, IntPtr.Zero, addResArr);
   if (retVal != 0) return;
   //retVal = pro.IsDocumentInProject(fileName, out pfFound, pdwPriority, out newFileId);
   //retVal = pro.IsDocumentInProject(fileName, out pfFound, pdwPriority, out newFileId);
   if (retVal != 0) return;
   Guid guid = Guid.Empty; IVsWindowFrame frame = null;
   retVal = pro.OpenItem(newFileId, ref guid, IntPtr.Zero, out frame);
   if (frame != null) frame.Show();
 }
コード例 #18
0
 internal NemerleEventBindingProvider(FileNode nFile)
 {
     _nFile   = nFile;
     _project = nFile.ProjectMgr;
 }
コード例 #19
0
 public IProjectNode Adapt(IVsProject3 from)
 {
     return(CreateNode((IVsHierarchy)from) as IProjectNode);
 }
コード例 #20
0
ファイル: VSHelpers.cs プロジェクト: dotnet/ef6tools
        private static void GetProjectAndFileInfoForPath(
            string originalPath, IServiceProvider serviceProvider, IVsSolution solution, out IVsHierarchy projectHierarchy,
            out Project project, out uint fileItemId, out bool isDocumentInProject)
        {
            var guid = Guid.Empty;
            IEnumHierarchies hierarchyEnum = null;

            fileItemId          = VSConstants.VSITEMID_NIL;
            projectHierarchy    = null;
            isDocumentInProject = false;
            project             = null;

            if (solution != null)
            {
                var hr = solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLPROJECTS, ref guid, out hierarchyEnum);
                if (NativeMethods.Succeeded(hr) && hierarchyEnum != null)
                {
                    hierarchyEnum.Reset();

                    uint numFetched = 1;
                    var  item       = new IVsHierarchy[1];

                    hierarchyEnum.Next(1, item, out numFetched);
                    while (numFetched == 1)
                    {
                        var vsProject = item[0] as IVsProject;
                        if (vsProject != null)
                        {
                            GetProjectAndFileInfoForPath(
                                vsProject, originalPath, out projectHierarchy, out project, out fileItemId, out isDocumentInProject);
                            if (isDocumentInProject)
                            {
                                break;
                            }
                        }
                        hierarchyEnum.Next(1, item, out numFetched);
                    }
                }
            }

            // didn't find a project, so check the misc files project
            if (project == null)
            {
                //
                // try not to create the Misc files project externally - in some rare cases it has caused Access violoations in VS (e.g., Dev10 Bug 864725).
                // So, only create this if we really need it.
                //
                IVsProject3 miscFilesProject = null;
                if (serviceProvider == null)
                {
                    miscFilesProject = GetMiscellaneousProject();
                }
                else
                {
                    miscFilesProject = GetMiscellaneousProject(serviceProvider);
                }

                if (miscFilesProject != null)
                {
                    GetProjectAndFileInfoForPath(
                        miscFilesProject, originalPath, out projectHierarchy, out project, out fileItemId, out isDocumentInProject);
                    if (project == null)
                    {
                        projectHierarchy = miscFilesProject as IVsHierarchy;
                        if (projectHierarchy != null)
                        {
                            project = GetProject(projectHierarchy);
                        }
                    }
                }
            }
        }
コード例 #21
0
ファイル: GetRevisionDlg.cs プロジェクト: perforce/P4VS
        // Get Revision button click
        private void newOKBtn_Click(object sender, EventArgs e)
        {
            bool        updateSolution = false;
            IVsSolution solution       = null;
            string      path           = _scm.SolutionFile;

            IList <IVsHierarchy> projectsUpdating    = new List <IVsHierarchy>();
            IList <string>       projectsClosed      = new List <string>();
            IList <Guid>         projectsGuidsClosed = new List <Guid>();

            if (_isSolutionIncluded)
            {
                // Figure out a better test

                //updateSolution = _scm.SyncFile(
                //    new P4.SyncFilesCmdOptions(P4.SyncFilesCmdFlags.Preview, 1),
                //    path);

                updateSolution = true;
            }
            if (updateSolution)
            {
                if (DialogResult.Cancel == MessageBox.Show(
                        Resources.GetRevisionDlg_UpdatingSlnWarninig,
                        Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                {
                    return;
                }
                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));

                P4VsProvider.Instance.SuppressConnection = true;

                if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                {
                    MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else if (P4VsProvider.Instance.SccService.SelectedNodes != null)
            {
                bool needToAsk = true;
                foreach (VSITEMSELECTION pItem in P4VsProvider.Instance.SccService.SelectedNodes)
                {
                    if ((pItem.itemid == VSConstants.VSITEMID_ROOT) && (P4VsProvider.Instance.SccService.IsProjectControlled(pItem.pHier)))
                    {
#if VS2008
                        if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                   Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                        {
                            return;
                        }
                        updateSolution = true;

                        solution = (IVsSolution)GetService(typeof(SVsSolution));

                        P4VsProvider.Instance.SuppressConnection = true;

                        if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                        {
                            MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
#else
                        IVsProject3 pProj = pItem.pHier as IVsProject3;
                        if (pProj != null)
                        {
                            if (needToAsk == true)
                            {
                                if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                           Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                                {
                                    return;
                                }
                                needToAsk = false;
                            }
                            projectsUpdating.Add(pItem.pHier);

                            if (solution == null)
                            {
                                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));
                            }
                            Guid projGuid;
                            solution.GetGuidOfProject(pItem.pHier, out projGuid);
                            projectsGuidsClosed.Add(projGuid);

                            if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, pItem.pHier, 0))
                            {
                                MessageBox.Show(Resources.Error_ClosingProject, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
#endif
                    }
                }
            }
            List <string> refreshItems = new List <string>();

            try
            {
                //change this to a better global validator
                int  test = 0;
                bool num  = int.TryParse(ValueTB.Text, out test);
                if (specifierRB.Checked == true &&
                    num == false &&
                    specifierCB.SelectedIndex == 0 &&
                    ValueTB.Text != "head" &&
                    ValueTB.Text != "have" &&
                    ValueTB.Text != "none"
                    )
                {
                    MessageBox.Show(string.Format(Resources.GetRevisionDlg_InvalidRevisionSpecifierWarninig, ValueTB.Text));
                    ValueTB.Text = string.Empty;
                    return;
                }
                ////////
                _files = new List <P4.FileSpec>();

                foreach (ListViewItem item in filesListView.Items)
                {
                    P4.FileSpec     file = new P4.FileSpec();
                    P4.FileMetaData fmd  = new P4.FileMetaData();
                    if (item.Text.EndsWith("/..."))
                    {
                        fmd.DepotPath = new P4.DepotPath(item.Text);
                    }
                    else
                    {
                        fmd = _scm.GetFileMetaData(item.Text);
                    }

                    if (fmd.LocalPath != null)
                    {
                        file.LocalPath = fmd.LocalPath;
                    }
                    if (fmd.ClientPath != null)
                    {
                        file.ClientPath = fmd.ClientPath;
                    }
                    if (fmd.DepotPath != null)
                    {
                        file.DepotPath = fmd.DepotPath;
                    }
                    _files.Add(file);
                    refreshItems.Add(item.Text.ToString());
                }

                P4.SyncFilesCmdFlags flags = new P4.SyncFilesCmdFlags();
                flags = P4.SyncFilesCmdFlags.None;
                if (forceChk.Checked == true)
                {
                    flags = P4.SyncFilesCmdFlags.Force;
                }

                P4.Options options = new P4.Options(flags, -1);

                // set up the list of paths with specifiers that we will sync to
                IList <P4.FileSpec> files = new List <P4.FileSpec>();
                //int idx = 0;

                if (specifierRB.Checked == true)
                {
                    // #revision
                    if (specifierCB.SelectedIndex == 0)
                    {
                        bool disconnectAfterSync = false;
                        int  number = 0;
                        bool isnum  = int.TryParse(Value, out number);
                        if (isnum == true)
                        {
                            if (number == 0)
                            {
                                if (_isSolutionIncluded)
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingSlnWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                    disconnectAfterSync = true;
                                }
                                else
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingProjWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                }
                            }
                        }
                        foreach (P4.FileSpec file in _files)
                        {
                            if (isnum == true)
                            {
                                // skip meta data check for rev 0 there is none, but we dtill want to allow
                                // this as a way to remove the local copy of the file, but still keep checking
                                // to make sure other bad revisions are not fetched such as file that was moved
                                if (number != 0)
                                {
                                    IList <P4.FileSpec> fs = new List <FileSpec>();
                                    file.Version = new P4.Revision(number);
                                    fs.Add(file);
                                    IList <P4.FileMetaData> fmd = _scm.GetFileMetaData(fs, null);
                                    if (fmd == null)
                                    {
                                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                                        {
                                            if (_files.Count == 1)
                                            {
                                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                            }
                                            P4VsOutputWindow.AppendMessage(_scm.Connection.Repository.Connection.LastResults.ErrorList[0].ToString());
                                        }
                                        continue;
                                    }
                                }
                                file.Version = new P4.Revision(number);
                            }
                            else if (Value == "head")
                            {
                                file.Version = new P4.HeadRevision();
                            }
                            else if (Value == "have")
                            {
                                file.Version = new P4.HaveRevision();
                            }
                            else if (Value == "none")
                            {
                                file.Version = new P4.NoneRevision();
                            }
                            files.Add(file);
                        }
                        if (files.Count > 0)
                        {
                            _scm.SyncFiles(options, files);
                        }
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        if (disconnectAfterSync)
                        {
                            P4VsProvider.Instance.SccService.Dispose();
                        }
                    }

                    // @workspace
                    if (specifierCB.SelectedIndex == 4)
                    {
                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.ClientNameVersion(Value.ToString());
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @date/time
                    if (specifierCB.SelectedIndex == 2)
                    {
                        DateTime value = dateTimePicker.Value;

                        string timestamp = value.Date.ToShortDateString() + ":" + value.TimeOfDay.ToString();

                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.DateTimeVersion(value);
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, _files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @changelist
                    if (specifierCB.SelectedIndex == 1)
                    {
                        if (changelistFilesChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.ChangelistIdVersion(Convert.ToInt16(Value)),
                                                                   new P4.ChangelistIdVersion(Convert.ToInt32(Value)));
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.ChangelistIdVersion(Convert.ToInt32(Value));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @label
                    if (specifierCB.SelectedIndex == 3)
                    {
                        if (removeChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.LabelNameVersion(Value.ToString());
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.LabelNameVersion(Value.ToString()),
                                                                   new P4.LabelNameVersion(Value.ToString()));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                }

                else if (getLatestRB.Checked == true)
                {
                    files = _files;
                    _scm.SyncFiles(options, files);
                    if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                    {
                        IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                        foreach (P4.P4ClientError error in errors)
                        {
                            if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                            {
                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                return;
                            }
                        }
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
            finally
            {
                if (updateSolution)
                {
                    if (path != null)
                    {
                        solution.OpenSolutionFile(0, path);
                    }
                    if (_scm.SccService != null)
                    {
                        _scm.SccService.ResetSelection();
                    }
                }
#if !VS2008
                else if (projectsUpdating.Count > 0)
                {
                    foreach (Guid projGuid in projectsGuidsClosed)
                    {
                        Guid rProjGuid = projGuid;

                        var vsSolution4 = (IVsSolution4)solution;
                        if (vsSolution4 != null)
                        {
                            int res = vsSolution4.ReloadProject(ref rProjGuid);
                        }
                    }
                }
#endif
                // now refresh the selected nodes' glyphs
                if (_scm.SccService != null)
                {
                    _scm.SccService.UpdateProjectGlyphs(refreshItems, true);
                }
            }
        }
コード例 #22
0
        protected override void SetInnerProject(IntPtr innerIUnknown) {
            var inner = Marshal.GetObjectForIUnknown(innerIUnknown);

            // The reason why we keep a reference to those is that doing a QI after being
            // aggregated would do the AddRef on the outer object.
            _innerProject = inner as IVsProject;
            _innerProject3 = inner as IVsProject3;
            _innerVsHierarchy = inner as IVsHierarchy;
            _innerVsProjectFlavorCfgProvider = inner as IVsProjectFlavorCfgProvider;

            // Ensure we have a service provider as this is required for menu items to work
            if (this.serviceProvider == null)
                this.serviceProvider = (System.IServiceProvider)this._package;

            // Now let the base implementation set the inner object
            base.SetInnerProject(innerIUnknown);

            // Add our commands (this must run after we called base.SetInnerProject)            
            _menuService = ((System.IServiceProvider)this).GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

        }
 internal PythonEventBindingProvider(PythonFileNode pyFile)
 {
     this.pyFile  = pyFile;
     this.project = pyFile.ProjectMgr;
 }
コード例 #24
0
 internal XSharpEventBindingProvider(FileNode xsFile)
 {
     _xsFile = xsFile;
     _project = xsFile.ProjectMgr;
 }
コード例 #25
0
 internal PythonEventBindingProvider(PythonFileNode pyFile)
 {
     this.pyFile = pyFile;
     this.project = pyFile.ProjectMgr;
 }
コード例 #26
0
 internal NemerleEventBindingProvider(FileNode nFile)
 {
     _nFile   = nFile;
     _project = nFile.ProjectMgr;
 }