示例#1
0
        /// <summary>
        /// If both the user has chosen in the Tools Options dialog to be prompted for a
        /// TODO comment *and* this language service supports a TODO comment, then we
        /// prompt them for their string, move the cursor around, add the text, and comment it.
        /// </summary>
        private void MaybeAddTodoComment(EnvDTE.TextSelection selection)
        {
            EnvDTE.Command  CommentSelection = null;
            EnvDTE.TaskList tl          = null;
            System.Object   emptyIn     = null;
            System.Object   emptyOut    = null;
            string          todoComment = null;
            TodoCommentForm input       = null;

            input = new TodoCommentForm();


            if (((bool)((EnvDTE.Properties)m_applicationObject.get_Properties("Assignment Manager", "Code Extractor")).Item("PromptForTodo").Value) &&
                ((CommentSelection = EditorSupportsCommentSelection()) != null) &&
                (input.ShowDialog() == System.Windows.Forms.DialogResult.OK))
            {
                todoComment = input.TodoComment;

                // Move the selection to be right before the commented region, add the new text,
                // and comment it.
                selection.MoveToPoint(selection.TopPoint, false);
                tl = m_applicationObject.Windows.Item(EnvDTE.Constants.vsWindowKindTaskList).Object as EnvDTE.TaskList;
                selection.Insert(tl.DefaultCommentToken + ": " + todoComment + "\n", (int)EnvDTE.vsInsertFlags.vsInsertFlagsInsertAtStart);
                m_applicationObject.Commands.Raise(CommentSelection.Guid, CommentSelection.ID, ref emptyIn, ref emptyOut);
            }
        }
        /// <summary>
        /// LoadTaskList delay-connects the object to VS7's task list. Note that it returns
        /// true if it manages to connect to the object and false if either it cannot connect
        /// to the object *or* if the DTE is is not-user-controlled-mode (i.e. ui is being
        /// suppressed!). It also hooks the navigate event so that we can actually the
        /// user's attempt to navigate to items.
        /// </summary>
        private bool LoadTaskList()
        {
            if (dte == null)
            {
                throw new System.InvalidOperationException();
            }

            try {
                if (dte.UserControl == false)
                {
                    return(false);
                }

                EnvDTE.TaskList tl   = dte.Windows.Item(EnvDTE.Constants.vsWindowKindTaskList).Object as EnvDTE.TaskList;
                EnvDTE.TaskItem item = null;
                if (tl == null)
                {
                    return(false);
                }

                taskItems = tl.TaskItems;

                tl.Parent.Visible = true;

                // Clear out any old entries
                int i, nItems = taskItems.Count;
                for (i = 1; i <= nItems; i++)
                {
                    item = taskItems.Item(i);
                    string cat    = item.Category;
                    string subcat = item.SubCategory;

                    // HACK: VS doesn't keep around subCategories.
                    if (item.Category == mainCategory)
                    {
                        try { item.Delete(); } catch (System.Exception) {}
                    }
                }

                // Register a connection point to handle the Navigated event (otherwise, no
                // navigation will be done when the user double-clicks on an item in the
                // task list!).
                TaskWindow.TaskListEvents evts = new TaskWindow.TaskListEvents(dte);
                dte.Events.get_TaskListEvents(mainCategory).TaskNavigated += new EnvDTE._dispTaskListEvents_TaskNavigatedEventHandler(evts.TaskNavigated);

                return(true);
            } catch (Exception /*e*/) {
                return(false);
            }
        }