예제 #1
0
        //~ Methods ..........................................................

        // ------------------------------------------------------
        /// <summary>
        /// Called when the Finish button is clicked in the wizard.
        /// </summary>
        /// <param name="e">
        /// An <code>EventArgs</code> object.
        /// </param>
        protected override void OnFinish(EventArgs e)
        {
            base.OnFinish(e);

            HierarchyItem projectItem     = page1.SelectedProject;
            string        suiteName       = page1.SuiteName;
            HierarchyItem headerUnderTest = page1.HeaderUnderTest;
            string        superclass      = page1.Superclass;
            bool          createSetUp     = page1.CreateSetUp;
            bool          createTearDown  = page1.CreateTearDown;

            VCCodeFunction[] functions = page2.SelectedFunctions;

            // Invoke the test suite generator to create the file and add it
            // to the project.

            TestSuiteGenerator generator = new TestSuiteGenerator(
                projectItem, suiteName, headerUnderTest, superclass,
                createSetUp, createTearDown, functions);

            generator.Generate();

            // Open the new test suite in the IDE.

            HierarchyItem suiteFile = generator.GeneratedSuiteFile;

            IVsProject     vsproj   = projectItem.Hierarchy as IVsProject;
            Guid           guidNull = Guid.Empty;
            IVsWindowFrame windowFrame;

            vsproj.OpenItem(suiteFile.ItemID, ref guidNull, IntPtr.Zero, out windowFrame);
        }
예제 #2
0
        /// <summary>
        /// Get the window frame associated with this location.
        /// </summary>
        /// <param name="openIfClosed">Should the frame be opened if it is not yet open?</param>
        /// <returns></returns>
        public IVsWindowFrame GetWindowFrame(bool openIfClosed)
        {
            Validate();

            IVsWindowFrame windowFrame = null;

            IVsUIShellOpenDocument doc = Common.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (doc != null)
            {
                IVsUIHierarchy uihier       = project as IVsUIHierarchy; // also works if project==null
                Guid           textViewGuid = new Guid(LogicalViewID.TextView);
                IVsWindowFrame frame;
                IVsUIHierarchy uiHierOpen;
                uint[]         itemIds = { 0 };
                int            open;
                //note: we explicitly only look at a *text* views belonging to the correct project
                // we do not want a designer form, or a view opened from another project that might
                // have been build using different settings. However, this code also works if the
                // project and itemid are unknown, but in that case we just pick the first best text
                // view.
                int hr = doc.IsDocumentOpen(uihier, itemId, FilePath, ref textViewGuid
                                            , 0, out uiHierOpen, itemIds, out frame, out open);
                //success
                if ((open != 0) && (frame != null) &&
                    (project == null || uihier == uiHierOpen) &&
                    (itemId == Nil || itemId == itemIds[0]))
                {
                    windowFrame = frame;
                }
                // failure: try to open it.
                else if (openIfClosed)
                {
                    if (ValidProject())
                    {
                        hr = project.OpenItem(itemId, ref textViewGuid, IntPtr.Zero, out frame);
                        if (hr == 0 && frame != null)
                        {
                            windowFrame = frame;
                        }
                    }
                    else
                    {
                        Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;
                        uint item;
                        hr = doc.OpenDocumentViaProject(FilePath, ref textViewGuid, out sp, out uiHierOpen, out item, out frame);
                        if (hr == 0 && frame != null)
                        {
                            project = uiHierOpen as IVsProject;
                            if (project != null)
                            {
                                itemId = item;
                            }
                            windowFrame = frame;
                        }
                    }
                }
            }
            return(windowFrame);
        }
예제 #3
0
        public IVsWindowFrame OpenItem(HierarchyNode child)
        {
            Guard.ArgumentNotNull(child, "child");

            Guid   logicalView     = VSConstants.LOGVIEWID_Primary;
            IntPtr existingDocData = IntPtr.Zero;
            int    hr = _project.OpenItem(child.ItemId, ref logicalView, existingDocData, out IVsWindowFrame windowFrame);

            Marshal.ThrowExceptionForHR(hr);
            return(windowFrame);
        }
예제 #4
0
        public void how_to_convert_MSBuild_Project_to_IVsProject()
        {
            // Say you got an MSBuild Project somehow.
            Microsoft.Build.Evaluation.Project project = this.MsBuildLibrary;

            IVsProject vsProject = project.Adapt().AsVsProject();

            Assert.IsNotNull(vsProject);

            // Use the VS project to open an item in a specific view, the designer, for example
            uint           itemId = 0;   // Get the item ID to open somehow, see other how-tos.
            IVsWindowFrame frame;
            Guid           viewId = VSConstants.LOGVIEWID.Designer_guid;

            vsProject.OpenItem(itemId, ref viewId, IntPtr.Zero, out frame);
        }
예제 #5
0
        public void how_to_convert_DTE_project_to_IVsProject()
        {
            // Say you got a DTE project somehow.
            EnvDTE.Project dteProject = this.DteLibrary;

            IVsProject vsProject = dteProject.Adapt().AsVsProject();

            Assert.IsNotNull(vsProject);

            // Use the VS project to open an item in a specific view, the designer, for example
            uint           itemId = 0;   // Get the item ID to open somehow, see other how-tos.
            IVsWindowFrame frame;
            Guid           viewId = VSConstants.LOGVIEWID.Designer_guid;

            vsProject.OpenItem(itemId, ref viewId, IntPtr.Zero, out frame);
        }
예제 #6
0
        int IVsProject.OpenItem(uint itemid, ref Guid rguidLogicalView, IntPtr punkDocDataExisting, out IVsWindowFrame ppWindowFrame)
        {
            if (_innerProject3 != null && IsHtmlFile(_innerVsHierarchy.GetItemName(itemid)))
            {
                // force HTML files opened w/o an editor type to be opened w/ our editor factory.
                Guid guid = GuidList.guidDjangoEditorFactory;
                return(_innerProject3.OpenItemWithSpecific(
                           itemid,
                           0,
                           ref guid,
                           null,
                           rguidLogicalView,
                           punkDocDataExisting,
                           out ppWindowFrame
                           ));
            }

            return(_innerProject.OpenItem(itemid, rguidLogicalView, punkDocDataExisting, out ppWindowFrame));
        }
예제 #7
0
        public int OpenItem(uint itemid, ref Guid rguidLogicalView, IntPtr punkDocDataExisting, out IVsWindowFrame ppWindowFrame)
        {
            if (_innerProject3 != null && IsJavaScriptFile(GetItemName(_innerVsHierarchy, itemid)))
            {
                // force .js files opened w/o an editor type to be opened w/ our editor factory.
                Guid guid = typeof(NodejsEditorFactory).GUID;
                Guid view = Guid.Empty;
                int  hr   = _innerProject3.OpenItemWithSpecific(
                    itemid,
                    0,
                    ref guid,
                    null,
                    rguidLogicalView,
                    punkDocDataExisting,
                    out ppWindowFrame
                    );
                return(hr);
            }

            return(_innerProject.OpenItem(itemid, rguidLogicalView, punkDocDataExisting, out ppWindowFrame));
        }
예제 #8
0
 int IVsProject.OpenItem(uint itemid, ref Guid rguidLogicalView, IntPtr punkDocDataExisting, out IVsWindowFrame ppWindowFrame)
 {
     return(_innerProject.OpenItem(itemid, rguidLogicalView, punkDocDataExisting, out ppWindowFrame));
 }
예제 #9
0
        // --------------------------------------------------------------
        // Editor control
        // --------------------------------------------------------------

        private void ShowSource(string emitter, string path, int line_no)
        {
            IVsUIShellOpenDocument od = (IVsUIShellOpenDocument)MsVsShell.Package.GetGlobalService(typeof(SVsUIShellOpenDocument));

            // not clear why lookup needs a string array; documentation does not mention returning
            // more than one path
            uint search_strategy = (uint)__VSRELPATHSEARCHFLAGS.RPS_UseAllSearchStrategies;

            String[] found_abs_paths = new String[1];
            int      res             = od.SearchProjectsForRelativePath(search_strategy, path, found_abs_paths);

            // if the whole path wasn't found, retry with just the filename
            String chosen_abs_path;

            if (res != VsConstants.S_OK)
            {
                int last_elem_pos = path.LastIndexOf('\\');
                if (last_elem_pos >= 0)
                {
                    string last_elem = path.Substring(last_elem_pos + 1);
                    res = od.SearchProjectsForRelativePath(search_strategy, last_elem, found_abs_paths);
                }
            }

            if (res == VsConstants.S_OK)
            {
                chosen_abs_path = found_abs_paths[0];
            }
            else
            {
                OutputString(System.String.Format("Unable to find source code in any project: path:'{0}' line:{1}", path, line_no));
                return;
            }

            // fetch a hierarchy for the absolute path
            IVsUIHierarchy hierarchy;
            UInt32         item_id;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider;
            Int32 in_proj;

            res = od.IsDocumentInAProject(chosen_abs_path, out hierarchy, out item_id, out provider, out in_proj);

            if (res != VsConstants.S_OK)
            {
                OutputString(System.String.Format("Unable to find project for source code: emitter: '{0}'", emitter));
                return;
            }

            if (in_proj == 0)
            {
                OutputString(System.String.Format("Unable to find source code in project: emitter: '{0}'", emitter));
                return;
            }

            // convert the hierarchy to a project, and open & show the source code document
            IVsProject     project = (IVsProject)hierarchy;
            IntPtr         DOCDATAEXISTING_UNKNOWN = (IntPtr)(int)-1;
            Guid           logical_view            = new Guid(LogicalViewID.Code);
            IVsWindowFrame frame;

            res = project.OpenItem(item_id, logical_view, DOCDATAEXISTING_UNKNOWN, out frame);

            if (res != VsConstants.S_OK)
            {
                OutputString(System.String.Format("Unable to open editor for source code: emitter: '{0}'", emitter));
                return;
            }

            frame.Show();

            // move the cursor to the correct line in the editor
            IVsTextView text_view = Microsoft.VisualStudio.Shell.VsShellUtilities.GetTextView(frame);

            if (text_view == null)
            {
                OutputString(System.String.Format("Unable to access editor for source code: emitter: '{0}'", emitter));
                return;
            }

            line_no = line_no - 1;
            res     = text_view.SetCaretPos(line_no, 0);
            if (res != VsConstants.S_OK)
            {
                OutputString(System.String.Format("Unable to set cursor to source code: emitter: '{0}'", emitter));
                return;
            }

            // and finally, centre the view on the source code line - ignore errors, it doesn't
            // matter that much
            text_view.CenterLines(line_no, 1);
        }
예제 #10
0
        public static void Open(this IVsProject project, VSConstants.VSITEMID itemId)
        {
            Guid view = Guid.Empty;

            project.OpenItem((uint)itemId, ref view, IntPtr.Zero, out IVsWindowFrame _);
        }