Example #1
0
        public bool CanExecute(Command command)
        {
            try
            {
                bool result = false;

                if (this.dte != null)
                {
                    switch (command)
                    {
                    // These require a text selection.
                    case Command.SortLines:
                    case Command.Trim:
                    case Command.Statistics:
                    case Command.StreamText:
                    case Command.ExecuteText:
                    case Command.CheckSpelling:
                        result = new TextDocumentHandler(this.dte).HasNonEmptySelection;
                        break;

                    // These require a text selection for specific languages.
                    case Command.CommentSelection:
                    case Command.UncommentSelection:
                        result = CommentHandler.CanCommentSelection(this.dte, command == Command.CommentSelection);
                        break;

                    // These require a document using a supported language.
                    case Command.AddRegion:
                    case Command.CollapseAllRegions:
                    case Command.ExpandAllRegions:
                        result = RegionHandler.IsSupportedLanguage(this.ActiveLanguage);
                        break;

                    // These require an open document with a backing file on disk.
                    case Command.ExecuteFile:
                    case Command.ToggleReadOnly:
                        string fileName = this.GetDocumentFileName();
                        result = File.Exists(fileName);
                        break;

                    case Command.GenerateGuid:
                        result = new TextDocumentHandler(this.dte).CanSetSelectedText;
                        break;

                    case Command.ToggleFiles:
                        result = ToggleFilesHandler.IsSupportedLanguage(this.ActiveLanguage);
                        break;

                    case Command.ListAllProjectProperties:
                        result = ProjectHandler.GetSelectedProjects(this.dte, null);
                        break;

                    case Command.ViewBaseConverter:
                    case Command.ViewTasks:
                        result = true;
                        break;

                    case Command.SortMembers:
                        result = new MemberSorter(this.dte, false).CanFindMembers;
                        break;

                    case Command.AddToDoComment:
                        result = CommentHandler.CanAddToDoComment(this.dte);
                        break;
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                MainPackage.LogException(ex);
                throw;
            }
        }
Example #2
0
        public void Execute(Command command)
        {
            try
            {
                if (this.dte != null)
                {
                    switch (command)
                    {
                    case Command.AddRegion:
                        RegionHandler.AddRegion(this.dte, Options.SplitValues(this.package.Options.PredefinedRegions));
                        break;

                    case Command.CheckSpelling:
                        this.CheckSpelling();
                        break;

                    case Command.CollapseAllRegions:
                        RegionHandler.CollapseAllRegions(this.dte, this.ActiveLanguage, this.package);
                        break;

                    case Command.CommentSelection:
                    case Command.UncommentSelection:
                        CommentHandler.CommentSelection(this.dte, this.package, command == Command.CommentSelection);
                        break;

                    case Command.ExecuteFile:
                        this.ExecuteFile();
                        break;

                    case Command.ExecuteText:
                        this.ExecuteText();
                        break;

                    case Command.ExpandAllRegions:
                        RegionHandler.ExpandAllRegions(this.dte, this.ActiveLanguage);
                        break;

                    case Command.GenerateGuid:
                        this.GenerateGuid();
                        break;

                    case Command.ListAllProjectProperties:
                        ProjectHandler.ListAllProjectProperties(this.dte);
                        break;

                    case Command.SortLines:
                        this.SortLines();
                        break;

                    case Command.Statistics:
                        this.Statistics();
                        break;

                    case Command.StreamText:
                        this.StreamText();
                        break;

                    case Command.ToggleFiles:
                        ToggleFilesHandler toggleFilesHandler = new ToggleFilesHandler(this.dte, this.package);
                        toggleFilesHandler.ToggleFiles();
                        break;

                    case Command.ToggleReadOnly:
                        this.ToggleReadOnly();
                        break;

                    case Command.Trim:
                        this.Trim();
                        break;

                    case Command.ViewBaseConverter:
                        this.ViewToolWindow(typeof(BaseConverterWindow));
                        break;

                    case Command.SortMembers:
                        this.SortMembers();
                        break;

                    case Command.AddToDoComment:
                        CommentHandler.AddToDoComment(this.dte);
                        break;

                    case Command.ViewTasks:
                        this.ViewToolWindow(typeof(Tasks.TasksWindow));
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MainPackage.LogException(ex);
                throw;
            }
        }