Beispiel #1
0
        public void Load(IServiceProvider serviceProvider)
        {
            PluginFactory.Register(new CecilStudioPlugin(this));

            _sp  = serviceProvider;
            _wm  = GetService <IWindowManager>();
            _ab  = GetService <IAssemblyBrowser>();
            _cbm = GetService <IBarManager>();
            _am  = GetService <IAssemblyManager>();

            // Main Window
            _items         = new List <UIContext>();
            ReflexilWindow = new Forms.ReflexilWindow();
            var window = _wm.Windows.Add(ReflexilWindowId, ReflexilWindow, ReflexilWindowText);

            window.Image = BasePlugin.ReflexilImage;

            // Main button
            _items.Add(new ButtonUIContext(_cbm.Bars[BarNames.Toolbar]));
            _items.Add(new ButtonUIContext(_cbm.Bars[BarNames.Toolbar], ReflexilButtonText, MainButtonClick,
                                           BasePlugin.ReflexilImage));

            using (var browserimages = new ImageList())
            {
                browserimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBrowserImages());
                browserimages.TransparentColor = Color.Green;

                using (var barimages = new ImageList())
                {
                    barimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBarImages());

                    // Menus
                    var typemenu        = AddMenu(BarNames.TypeDefinitionBrowser.ToString());
                    var assemblymenu    = AddMenu(BarNames.AssemblyDefinitionBrowser.ToString());
                    var assemblyrefmenu = AddMenu(BarNames.AssemblyNameReferenceBrowser.ToString());
                    var modulemenu      = AddMenu(BarNames.ModuleDefinitionBrowser.ToString());
                    var methodmenu      = AddMenu(BarNames.MethodDefinitionBrowser.ToString());
                    var fieldmenu       = AddMenu(BarNames.FieldDefinitionBrowser.ToString());
                    var propertymenu    = AddMenu(BarNames.PropertyDefinitionBrowser.ToString());
                    var eventmenu       = AddMenu(BarNames.EventDefinitionBrowser.ToString());

                    var allmenus = new UIContext[]
                    { typemenu, assemblymenu, assemblyrefmenu, modulemenu, methodmenu, fieldmenu, propertymenu, eventmenu };
                    var membersmenus = new UIContext[] { assemblyrefmenu, typemenu, methodmenu, fieldmenu, propertymenu, eventmenu };

                    // Type declaration menu
                    _items.Add(new SubMenuUIContext(typemenu, "Inject constructor", (sender, e) => Inject(InjectType.Constructor),
                                                    browserimages.Images[(int)EBrowserImages.PublicConstructor]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject event", (sender, e) => Inject(InjectType.Event),
                                                    browserimages.Images[(int)EBrowserImages.PublicEvent]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject field", (sender, e) => Inject(InjectType.Field),
                                                    browserimages.Images[(int)EBrowserImages.PublicField]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject method", (sender, e) => Inject(InjectType.Method),
                                                    browserimages.Images[(int)EBrowserImages.PublicMethod]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject property", (sender, e) => Inject(InjectType.Property),
                                                    browserimages.Images[(int)EBrowserImages.PublicProperty]));
                    _items.Add(new SubMenuUIContext(typemenu));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner class", (sender, e) => Inject(InjectType.Class),
                                                    browserimages.Images[(int)EBrowserImages.PublicClass]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner enum", (sender, e) => Inject(InjectType.Enum),
                                                    browserimages.Images[(int)EBrowserImages.PublicEnum]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner interface", (sender, e) => Inject(InjectType.Interface),
                                                    browserimages.Images[(int)EBrowserImages.PublicInterface]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner struct", (sender, e) => Inject(InjectType.Struct),
                                                    browserimages.Images[(int)EBrowserImages.PublicStructure]));

                    // Shared subitems for Assembly/Module
                    foreach (var menu in new[] { assemblymenu, modulemenu })
                    {
                        _items.Add(new SubMenuUIContext(menu, "Inject assembly reference",
                                                        (sender, e) => Inject(InjectType.AssemblyReference), browserimages.Images[(int)EBrowserImages.LinkedAssembly]));
                        _items.Add(new SubMenuUIContext(menu, "Inject class", (sender, e) => Inject(InjectType.Class),
                                                        browserimages.Images[(int)EBrowserImages.PublicClass]));
                        _items.Add(new SubMenuUIContext(menu, "Inject enum", (sender, e) => Inject(InjectType.Enum),
                                                        browserimages.Images[(int)EBrowserImages.PublicEnum]));
                        _items.Add(new SubMenuUIContext(menu, "Inject interface", (sender, e) => Inject(InjectType.Interface),
                                                        browserimages.Images[(int)EBrowserImages.PublicInterface]));
                        _items.Add(new SubMenuUIContext(menu, "Inject struct", (sender, e) => Inject(InjectType.Struct),
                                                        browserimages.Images[(int)EBrowserImages.PublicStructure]));
                        _items.Add(new SubMenuUIContext(menu));
                        _items.Add(new SubMenuUIContext(menu, "Obfuscator search...", SearchObfuscator, barimages.Images[(int)EBarImages.Search]));
                        _items.Add(new SubMenuUIContext(menu, "Reload", ReloadAssembly, barimages.Images[(int)EBarImages.Reload]));
                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));
                        _items.Add(new SubMenuUIContext(menu, "Save as...", SaveAssembly, barimages.Images[(int)EBarImages.Save]));
                        _items.Add(new SubMenuUIContext(menu, "Verify", VerifyAssembly, barimages.Images[(int)EBarImages.Check]));
                    }

                    // Shared subitems for renaming/deleting
                    foreach (var uiContext in membersmenus)
                    {
                        var menu = (MenuUIContext)uiContext;
                        if (menu == typemenu)
                        {
                            _items.Add(new SubMenuUIContext(menu));
                        }

                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));
                        _items.Add(new SubMenuUIContext(menu, "Delete", DeleteItem, barimages.Images[(int)EBarImages.Delete]));
                    }

                    _items.AddRange(allmenus);
                }
            }

            // Main events
            _ab.ActiveItemChanged += ActiveItemChanged;

            ReflexilWindow.HandleItem(_ab.ActiveItem);
        }