/// <summary> /// Marks a region of code for extraction. It pastes the correct comment characters for the /// file type at the top and bottom of the region. If the user has selected to add 'TODO' comments /// and the editor for this file type supports commenting regions, it will also prompt /// the user for a TODO comment and place that comment above the region of code to be /// marked for extraction. /// </summary> public void Exec(EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut) { try { // First, get ahold of the necessary items to get the data we need CommentPair comments = GetCurrentComments(); if (comments == null) { return; } // Get the document EnvDTE.EditPoint startPoint, endPoint; EnvDTE.TextDocument textDocument = m_applicationObject.ActiveDocument.Object("TextDocument") as EnvDTE.TextDocument; if (textDocument != null) { if (textDocument.Selection.BottomPoint.AtStartOfLine && textDocument.Selection.IsActiveEndGreater) { // People whom select a whole section of text often also get the first // not-character of the next line (because that's how windows mouse-selection // works!). They only want to go around the highlighted section... textDocument.Selection.CharLeft(true, 1); } textDocument.Selection.Insert(comments.BeginComment + "\n", (int)EnvDTE.vsInsertFlags.vsInsertFlagsInsertAtStart); textDocument.Selection.Insert("\n" + comments.EndComment, (int)EnvDTE.vsInsertFlags.vsInsertFlagsInsertAtEnd); // Store away the selection for use after the TODO comment // is added. Create new EditPoint objects here because they // cause the editor to keep track of the markers in the text, even // when the selection changes. startPoint = textDocument.Selection.TopPoint.CreateEditPoint(); endPoint = textDocument.Selection.BottomPoint.CreateEditPoint(); MaybeAddTodoComment(textDocument.Selection); // Restore the selection textDocument.Selection.MoveToPoint(startPoint, false); textDocument.Selection.MoveToPoint(endPoint, true); // Perform the selection hiding (code collapse) only if the editor is not // in auto-select mode and if the user has enabled it in the tools options // page for the academic toolset. This is done last because some language // services move the Top and Bottom points of the Selection around when // performing an outline. if (EditorSupportsHideSelection() && ((bool)((EnvDTE.Properties)m_applicationObject.get_Properties("Assignment Manager", "Code Extractor")).Item("Collapse").Value)) { textDocument.Selection.TopPoint.CreateEditPoint().OutlineSection(textDocument.Selection.BottomPoint); } } } catch (System.Exception /*e*/) { } }
public void Exec(EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut) { try { // Load the student My Courses homepage. Note that this will create a new browser if one // isn't already open, but will reuse the existing one, if one is. m_applicationObject.ItemOperations.Navigate(m_strHomePageUrl, EnvDTE.vsNavigateOptions.vsNavigateOptionsDefault); } catch (System.Exception) { } }