public CodeIssueOptionsDialog(InspectorResults act)
        {
            this.r = act;
            Build();
            HasSeparator = false;

            labelInspectionTitle.Text = r.Inspector.Title;
            var s = r.Inspector.GetSeverity();

            radiobuttonHide.Active       = s == Severity.None;
            radiobuttonError.Active      = s == Severity.Error;
            radiobuttonWarning.Active    = s == Severity.Warning;
            radiobuttonHint.Active       = s == Severity.Hint;
            radiobuttonSuggestion.Active = s == Severity.Suggestion;
            buttonOk.Clicked            += HandleClicked;
            buttonCancel.Clicked        += (sender, e) => Destroy();
            Response += (o, args) => {
                if (args.ResponseId == ResponseType.Close)
                {
                    Destroy();
                }
            };
        }
        public void PopulateFixes(Gtk.Menu menu, ref int items)
        {
            int  mnemonic = 1;
            bool gotImportantFix = false, addedSeparator = false;
            var  fixesAdded = new List <string> ();

            foreach (var fix_ in Fixes.OrderByDescending(i => Tuple.Create(IsAnalysisOrErrorFix(i), (int)i.Severity, GetUsage(i.IdString))))
            {
                // filter out code actions that are already resolutions of a code issue
                if (fixesAdded.Any(f => fix_.IdString.IndexOf(f, StringComparison.Ordinal) >= 0))
                {
                    continue;
                }
                fixesAdded.Add(fix_.IdString);
                if (IsAnalysisOrErrorFix(fix_))
                {
                    gotImportantFix = true;
                }
                if (!addedSeparator && gotImportantFix && !IsAnalysisOrErrorFix(fix_))
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    addedSeparator = true;
                }

                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                        : "  " + escapedLabel;
                var thisInstanceMenuItem = new MenuItem(label);
                thisInstanceMenuItem.Activated += new ContextActionRunner(fix, document, currentSmartTagBegin).Run;
                thisInstanceMenuItem.Activated += delegate {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(thisInstanceMenuItem);
                items++;
            }

            bool first             = true;
            var  settingsMenuFixes = Fixes
                                     .OfType <AnalysisContextActionProvider.AnalysisCodeAction> ()
                                     .Where(f => f.Result is InspectorResults)
                                     .GroupBy(f => ((InspectorResults)f.Result).Inspector);

            foreach (var analysisFixGroup_ in settingsMenuFixes)
            {
                var analysisFixGroup    = analysisFixGroup_;
                var arbitraryFixInGroup = analysisFixGroup.First();
                var ir = (InspectorResults)arbitraryFixInGroup.Result;

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }

                var subMenu = new Gtk.Menu();
                foreach (var analysisFix_ in analysisFixGroup)
                {
                    var analysisFix = analysisFix_;
                    if (analysisFix.SupportsBatchRunning)
                    {
                        var batchRunMenuItem = new Gtk.MenuItem(string.Format(GettextCatalog.GetString("Apply in file: {0}"), analysisFix.Title));
                        batchRunMenuItem.Activated += delegate {
                            ConfirmUsage(analysisFix.IdString);
                            menu.Destroy();
                        };
                        batchRunMenuItem.Activated += new ContextActionRunner(analysisFix, document, this.currentSmartTagBegin).BatchRun;
                        subMenu.Add(batchRunMenuItem);
                        subMenu.Add(new Gtk.SeparatorMenuItem());
                    }
                }

                var inspector = ir.Inspector;
                if (inspector.CanSuppressWithAttribute)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with attribute"));
                    menuItem.Activated += delegate {
                        inspector.SuppressWithAttribute(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableWithPragma)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                    menuItem.Activated += delegate {
                        inspector.DisableWithPragma(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableOnce)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable Once"));
                    menuItem.Activated += delegate {
                        inspector.DisableOnce(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableAndRestore)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and Restore"));
                    menuItem.Activated += delegate {
                        inspector.DisableAndRestore(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }
                var label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(ir.Inspector));
                var subMenuItem = new Gtk.MenuItem(label);

                var optionsMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure Rule"));
                optionsMenuItem.Activated += arbitraryFixInGroup.ShowOptions;

                optionsMenuItem.Activated += delegate {
                    menu.Destroy();
                };
                subMenu.Add(optionsMenuItem);
                subMenuItem.Submenu = subMenu;
                menu.Add(subMenuItem);
                items++;
            }
        }
Exemple #3
0
        public void PopulateFixes(Gtk.Menu menu, ref int items)
        {
            int mnemonic = 1;

            foreach (var fix_ in fixes.OrderByDescending(i => GetUsage(i.IdString)))
            {
                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                var thisInstanceMenuItem = new Gtk.MenuItem(label);
                thisInstanceMenuItem.Activated += new ContextActionRunner(fix, document, loc).Run;
                thisInstanceMenuItem.Activated += delegate {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(thisInstanceMenuItem);
                items++;
            }
            var first           = true;
            var alreadyInserted = new HashSet <BaseCodeIssueProvider> ();

            foreach (var analysisFix_ in fixes.OfType <AnalysisContextActionProvider.AnalysisCodeAction>().Where(f => f.Result is InspectorResults))
            {
                var analysisFix = analysisFix_;
                var ir          = analysisFix.Result as InspectorResults;
                if (ir == null)
                {
                    continue;
                }

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }
                if (alreadyInserted.Contains(ir.Inspector))
                {
                    continue;
                }
                alreadyInserted.Add(ir.Inspector);

                var subMenu = new Gtk.Menu();
                if (analysisFix.SupportsBatchRunning)
                {
                    var batchRunMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("Fix all in this file"));
                    batchRunMenuItem.Activated += delegate {
                        ConfirmUsage(analysisFix.IdString);
                        menu.Destroy();
                    };
                    batchRunMenuItem.Activated += new ContextActionRunner(analysisFix, document, loc).BatchRun;
                    subMenu.Add(batchRunMenuItem);
                    subMenu.Add(new Gtk.SeparatorMenuItem());
                }

                var inspector = ir.Inspector;
                if (inspector.CanDisableWithPragma)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                    menuItem.Activated += delegate {
                        inspector.DisableWithPragma(document, loc);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableOnce)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable once with comment"));
                    menuItem.Activated += delegate {
                        inspector.DisableOnce(document, loc);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableAndRestore)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and restore with comments"));
                    menuItem.Activated += delegate {
                        inspector.DisableAndRestore(document, loc);
                    };
                    subMenu.Add(menuItem);
                }
                var label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(ir.Inspector));
                var subMenuItem = new Gtk.MenuItem(label);

                var optionsMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure inspection severity"));
                optionsMenuItem.Activated += analysisFix.ShowOptions;
                optionsMenuItem.Activated += delegate {
                    menu.Destroy();
                };
                subMenu.Add(optionsMenuItem);
                subMenuItem.Submenu = subMenu;
                menu.Add(subMenuItem);
                items++;
            }

            foreach (var fix_ in fixes.Where(f => f.BoundToIssue != null))
            {
                var fix = fix_;
                foreach (var inspector_ in RefactoringService.GetInspectors(document.Editor.MimeType).Where(i => i.GetSeverity() != Severity.None))
                {
                    var inspector = inspector_;

                    if (inspector.IdString.IndexOf(fix.BoundToIssue.FullName, StringComparison.Ordinal) < 0)
                    {
                        continue;
                    }
                    if (first)
                    {
                        menu.Add(new Gtk.SeparatorMenuItem());
                        first = false;
                    }
                    if (alreadyInserted.Contains(inspector))
                    {
                        continue;
                    }
                    alreadyInserted.Add(inspector);

                    var      label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(inspector));
                    var      subMenuItem = new Gtk.MenuItem(label);
                    Gtk.Menu subMenu     = new Gtk.Menu();
                    if (inspector.CanSuppressWithAttribute)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with attribute"));
                        menuItem.Activated += delegate {
                            inspector.SuppressWithAttribute(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    if (inspector.CanDisableWithPragma)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                        menuItem.Activated += delegate {
                            inspector.DisableWithPragma(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    if (inspector.CanDisableOnce)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable once with comment"));
                        menuItem.Activated += delegate {
                            inspector.DisableOnce(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    if (inspector.CanDisableAndRestore)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and restore with comments"));
                        menuItem.Activated += delegate {
                            inspector.DisableAndRestore(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    var confItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure inspection severity"));
                    confItem.Activated += delegate {
                        MessageService.RunCustomDialog(new CodeIssueOptionsDialog(inspector), MessageService.RootWindow);
                        menu.Destroy();
                    };
                    subMenu.Add(confItem);

                    subMenuItem.Submenu = subMenu;
                    subMenu.ShowAll();
                    menu.Add(subMenuItem);
                    break;
                }

                items++;
            }
        }
Exemple #4
0
        public void PopulateFixes(Gtk.Menu menu, ref int items)
        {
            int  mnemonic = 1;
            bool gotImportantFix = false, addedSeparator = false;

            foreach (var fix_ in fixes.OrderByDescending(i => Tuple.Create(IsAnalysisOrErrorFix(i), (int)i.Severity, GetUsage(i.IdString))))
            {
                if (IsAnalysisOrErrorFix(fix_))
                {
                    gotImportantFix = true;
                }
                if (!addedSeparator && gotImportantFix && !IsAnalysisOrErrorFix(fix_))
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    addedSeparator = true;
                }

                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                var thisInstanceMenuItem = new Gtk.MenuItem(label);
                thisInstanceMenuItem.Activated += new ContextActionRunner(fix, document, loc).Run;
                thisInstanceMenuItem.Activated += delegate {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(thisInstanceMenuItem);
                items++;
            }

            bool first           = true;
            var  alreadyInserted = new HashSet <BaseCodeIssueProvider> ();

            foreach (var analysisFix_ in fixes.OfType <AnalysisContextActionProvider.AnalysisCodeAction>().Where(f => f.Result is InspectorResults))
            {
                var analysisFix = analysisFix_;
                var ir          = analysisFix.Result as InspectorResults;
                if (ir == null)
                {
                    continue;
                }

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }
                if (alreadyInserted.Contains(ir.Inspector))
                {
                    continue;
                }
                alreadyInserted.Add(ir.Inspector);

                var subMenu = new Gtk.Menu();
                if (analysisFix.SupportsBatchRunning)
                {
                    var batchRunMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("Fix all in this file"));
                    batchRunMenuItem.Activated += delegate {
                        ConfirmUsage(analysisFix.IdString);
                        menu.Destroy();
                    };
                    batchRunMenuItem.Activated += new ContextActionRunner(analysisFix, document, loc).BatchRun;
                    subMenu.Add(batchRunMenuItem);
                    subMenu.Add(new Gtk.SeparatorMenuItem());
                }

                var inspector = ir.Inspector;
                if (inspector.CanSuppressWithAttribute)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with attribute"));
                    menuItem.Activated += delegate {
                        inspector.SuppressWithAttribute(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableWithPragma)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                    menuItem.Activated += delegate {
                        inspector.DisableWithPragma(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableOnce)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable once with comment"));
                    menuItem.Activated += delegate {
                        inspector.DisableOnce(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableAndRestore)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and restore with comments"));
                    menuItem.Activated += delegate {
                        inspector.DisableAndRestore(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }
                var label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(ir.Inspector));
                var subMenuItem = new Gtk.MenuItem(label);

                var optionsMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure inspection"));
                optionsMenuItem.Activated += analysisFix.ShowOptions;
                optionsMenuItem.Activated += delegate {
                    menu.Destroy();
                };
                subMenu.Add(optionsMenuItem);
                subMenuItem.Submenu = subMenu;
                menu.Add(subMenuItem);
                items++;
            }
        }