Beispiel #1
0
        void IPackage.Load(IServiceProvider serviceProvider)
        {
            // Set this early so it is easily referenced
            myServiceProvider = serviceProvider;

            IAssemblyBrowser assemblyBrowser = (IAssemblyBrowser)serviceProvider.GetService(typeof(IAssemblyBrowser));

            assemblyBrowser.ActiveItemChanged += new EventHandler(OnActiveItemChanged);
            myLastActiveItem  = assemblyBrowser.ActiveItem;
            myAssemblyBrowser = assemblyBrowser;
            ILanguageManager languageManager = (ILanguageManager)serviceProvider.GetService(typeof(ILanguageManager));

            myLanguageManager = languageManager;
            myConfiguration   = new PLiXConfiguration(this);
            languageManager.ActiveLanguageChanged += new EventHandler(OnActiveLanguageChanged);
            ILanguage language = new PLiXLanguage((ITranslatorManager)serviceProvider.GetService(typeof(ITranslatorManager)), myConfiguration);

            languageManager.RegisterLanguage(language);
            myLanguage = language;

            // Add our PLiX menu item, activated when the plix language is active
            ICommandBarManager commandBarManager = (ICommandBarManager)serviceProvider.GetService(typeof(ICommandBarManager));
            ICommandBar        menuBar           = commandBarManager.CommandBars["MenuBar"];
            ICommandBarMenu    topMenu           = menuBar.Items.InsertMenu(menuBar.Items.Count - 1, "PLiXLanguageOptions", "PLi&X");

            topMenu.Visible   = false;
            topMenu.DropDown += new EventHandler(OnOpenTopMenu);

            ICommandBarItemCollection menuItems = topMenu.Items;

            myExampleLanguageMenu = menuItems.AddMenu("PLiXExampleLanguage", "&Example Language");
            menuItems.AddSeparator();
            myExpandCurrentNamespaceDeclarationButton = menuItems.AddButton("E&xpand Current Namespace Declaration", new EventHandler(OnExpandCurrentNamespaceDeclaration));
            myExpandCurrentTypeDeclarationButton      = menuItems.AddButton("E&xpand Current Type Declaration", new EventHandler(OnExpandCurrentTypeDeclaration));
            (myFullyExpandTypeDeclarationsCheckBox = menuItems.AddCheckBox("Ex&pand All Type Declarations")).Click += new EventHandler(OnFullyExpandTypeDeclarationsChanged);
            menuItems.AddSeparator();
            (myDisplayContextDataTypeQualifierCheckBox = menuItems.AddCheckBox("Display Context Type &Qualifier")).Click += new EventHandler(OnDisplayContextDataTypeQualifierChanged);
            ICommandBarMenu callStaticOptionsMenu = menuItems.AddMenu("PLiXStaticCallOptions", "&Static Call Options");

            menuItems = callStaticOptionsMenu.Items;
            (myExplicitStaticCallCheckBox = menuItems.AddCheckBox("&Explicit")).Click += new EventHandler(OnExplicitStaticCallCheckBoxChanged);
            (myImplicitCurrentTypeStaticCallCheckBox = menuItems.AddCheckBox("Implicit (&Current Type)")).Click += new EventHandler(OnImplicitCurrentTypeStaticCallCheckBoxChanged);
            (myImplicitBaseTypesStaticCallCheckBox = menuItems.AddCheckBox("Implicit (&Base Types)")).Click     += new EventHandler(OnImplicitBaseTypesStaticCallCheckBoxChanged);
            myTopMenu = topMenu;

            ICommandBarControl appRefresh1 = GetCommandbarControl(commandBarManager, "ToolBar", "Application.Refresh");

            if (appRefresh1 != null)
            {
                appRefresh1.Click += new EventHandler(OnApplicationRefresh);
            }
            ICommandBarControl appRefresh2 = GetCommandbarControl(commandBarManager, "View", "Application.Refresh");

            if (appRefresh2 != null && appRefresh2 != appRefresh1)
            {
                appRefresh2.Click += new EventHandler(OnApplicationRefresh);
            }
            //DumpMenus(commandBarManager);
        }
Beispiel #2
0
        /// <summary>
        /// Synchronize the example language sub menu with the current set of languages.
        /// Unfortunately, there is no add/remove event when languages are added and removed,
        /// and the DropDown event does not fire on submenus, so we need to synchronize here.
        /// </summary>
        private void OnOpenTopMenu(object sender, EventArgs e)
        {
            ICommandBarItemCollection exampleItems = myExampleLanguageMenu.Items;
            ILanguageCollection       languages    = myLanguageManager.Languages;
            ILanguage         selectedLanguage     = myConfiguration.ExampleLanguage;
            PLiXConfiguration plixConfig           = (PLiXConfiguration)myConfiguration;
            object            activeItem           = myAssemblyBrowser.ActiveItem;
            bool activeItemIsTypeDeclaration       = activeItem is ITypeDeclaration;
            bool activeItemIsNamespaceDeclaration  = !activeItemIsTypeDeclaration && activeItem is INamespace;
            bool alreadyExpandedCurrentType        = plixConfig.FullyExpandCurrentTypeDeclaration;
            bool alwaysExpandTypes = alreadyExpandedCurrentType ? false : myConfiguration.FullyExpandTypeDeclarations;

            if (activeItemIsNamespaceDeclaration)
            {
                myExpandCurrentNamespaceDeclarationButton.Visible = true;
                myExpandCurrentNamespaceDeclarationButton.Enabled = !plixConfig.FullyExpandCurrentNamespaceDeclaration;
            }
            else
            {
                myExpandCurrentNamespaceDeclarationButton.Visible = false;
            }
            if (activeItemIsTypeDeclaration)
            {
                myExpandCurrentTypeDeclarationButton.Visible = !alwaysExpandTypes;
                myExpandCurrentTypeDeclarationButton.Enabled = !alreadyExpandedCurrentType;
            }
            else
            {
                myExpandCurrentTypeDeclarationButton.Visible = false;
            }
            myFullyExpandTypeDeclarationsCheckBox.Checked     = alwaysExpandTypes;
            myDisplayContextDataTypeQualifierCheckBox.Checked = plixConfig.DisplayContextDataTypeQualifier;
            StaticCallRenderingOption staticRender = plixConfig.StaticCallRenderingOption;

            myExplicitStaticCallCheckBox.Checked            = staticRender == StaticCallRenderingOption.Explicit;
            myImplicitCurrentTypeStaticCallCheckBox.Checked = staticRender == StaticCallRenderingOption.ImplicitCurrentType;
            myImplicitBaseTypesStaticCallCheckBox.Checked   = staticRender == StaticCallRenderingOption.ImplicitBaseTypes;
            int itemsCount = exampleItems.Count;
            ICommandBarCheckBox currentItem;

            if (itemsCount == 0)
            {
                currentItem         = exampleItems.AddCheckBox("None");
                currentItem.Checked = selectedLanguage == null;
                currentItem.Click  += new EventHandler(OnExampleLanguageClick);
                ++itemsCount;
            }
            else
            {
                currentItem = (ICommandBarCheckBox)exampleItems[0];
                if (currentItem.Checked ^ (selectedLanguage == null))
                {
                    currentItem.Checked = selectedLanguage == null;
                }
            }

            int languagesCount   = languages.Count;
            int currentItemIndex = 1;             // None is at the zero position

            for (int iLanguage = 0; iLanguage < languagesCount; ++iLanguage)
            {
                ILanguage currentLanguage = languages[iLanguage];
                bool      isChecked       = currentLanguage == selectedLanguage;
                string    languageName    = currentLanguage.Name;
                if (currentLanguage != myLanguage && !languageName.StartsWith("IL"))
                {
                    if (currentItemIndex >= itemsCount)
                    {
                        currentItem       = exampleItems.AddCheckBox(languageName);
                        currentItem.Value = currentLanguage;
                        if (isChecked)
                        {
                            currentItem.Checked = true;
                        }
                        currentItem.Click += new EventHandler(OnExampleLanguageClick);
                        // No need to adjust currentItemIndex here, we'll continue to add to the end of the list
                    }
                    else
                    {
                        currentItem = (ICommandBarCheckBox)exampleItems[currentItemIndex];
                        ILanguage testLanguage = (ILanguage)currentItem.Value;
                        if (testLanguage == currentLanguage)
                        {
                            ++currentItemIndex;
                            if (currentItem.Checked ^ isChecked)
                            {
                                currentItem.Checked = isChecked;
                            }
                            continue;
                        }
                        else
                        {
                            // If the testLanguage appears later in the language list, then we need
                            // to insert the new language here. Otherwise, we need to remove the
                            // existing item.
                            int matchingLanguage = iLanguage + 1;
                            for (; matchingLanguage < languagesCount; ++matchingLanguage)
                            {
                                if (testLanguage == languages[matchingLanguage])
                                {
                                    break;
                                }
                            }
                            if (matchingLanguage < languagesCount)
                            {
                                // The language at this item will match later. Insert the currentLanguage at this position
                                currentItem       = exampleItems.InsertCheckBox(currentItemIndex, languageName);
                                currentItem.Value = currentLanguage;
                                if (isChecked)
                                {
                                    currentItem.Checked = true;
                                }
                                currentItem.Click += new EventHandler(OnExampleLanguageClick);
                                ++itemsCount;
                                ++currentItemIndex;
                            }
                            else
                            {
                                // The item needs to be removed
                                exampleItems.Remove(currentItem);
                                --itemsCount;
                            }
                        }
                    }
                }
            }
            // Remove any remaining items that we didn't match with a language
            if (currentItemIndex < itemsCount)
            {
                for (int i = itemsCount - 1; i >= currentItemIndex; --i)
                {
                    exampleItems.RemoveAt(i);
                }
            }
        }