コード例 #1
0
ファイル: EffectMenuBase.cs プロジェクト: cyberjaxx/OpenPDN
        private void PopulateMenu()
        {
            DropDownItems.Clear();

            if (EnableRepeatEffectMenuItem && LastEffect != null)
            {
                string      repeatFormat = PdnResources.GetString("Effects.RepeatMenuItem.Format");
                string      menuName     = string.Format(repeatFormat, LastEffect.Name);
                PdnMenuItem pmi          = new PdnMenuItem(menuName, LastEffect.Image, RepeatEffectMenuItem_Click)
                {
                    Name         = "RepeatEffect(" + LastEffect.GetType().FullName + ")",
                    ShortcutKeys = Keys.Control | Keys.F
                };
                DropDownItems.Add(pmi);

                ToolStripSeparator tss = new ToolStripSeparator();
                DropDownItems.Add(tss);
            }

            AddEffectsToMenu();

            Triple <Assembly, Type, Exception>[] errors = Effects.GetLoaderExceptions();

            for (int i = 0; i < errors.Length; ++i)
            {
                AppWorkspace.ReportEffectLoadError(errors[i]);
            }

            MenuPopulated = true;
        }
コード例 #2
0
ファイル: EffectMenuBase.cs プロジェクト: cyberjaxx/OpenPDN
        private void AddEffectsToMenu()
        {
            // Fill the menu with the effect names, and "..." if it is configurable
            EffectsCollection effectsCollection = Effects;

            Type[] effectTypes   = effectsCollection.Effects;
            bool   withShortcuts = EnableEffectShortcuts;

            List <Effect> newEffects = new List <Effect>();

            foreach (Type type in effectsCollection.Effects)
            {
                try
                {
                    ConstructorInfo ci     = type.GetConstructor(Type.EmptyTypes);
                    Effect          effect = (Effect)ci.Invoke(null);

                    if (FilterEffects(effect))
                    {
                        newEffects.Add(effect);
                    }
                }

                catch (Exception ex)
                {
                    // We don't want a DLL that can't be figured out to cause the app to crash
                    //continue;
                    AppWorkspace.ReportEffectLoadError(Triple.Create(type.Assembly, type, ex));
                }
            }

            newEffects.Sort((lhs, rhs) => string.Compare(lhs.Name, rhs.Name, true));

            List <string> subMenuNames = new List <string>();

            foreach (Effect effect in newEffects)
            {
                if (!string.IsNullOrEmpty(effect.SubMenuName))
                {
                    subMenuNames.Add(effect.SubMenuName);
                }
            }

            subMenuNames.Sort((lhs, rhs) => string.Compare(lhs, rhs, true));

            string lastSubMenuName = null;

            foreach (string subMenuName in subMenuNames)
            {
                if (subMenuName == lastSubMenuName)
                {
                    // skip duplicate names
                    continue;
                }

                PdnMenuItem subMenu = new PdnMenuItem(subMenuName, null, null);
                DropDownItems.Add(subMenu);
                lastSubMenuName = subMenuName;
            }

            foreach (Effect effect in newEffects)
            {
                AddEffectToMenu(effect, withShortcuts);
            }
        }