示例#1
0
        private void CreateDialog_Load(object sender, EventArgs e)
        {
            if (m_parent == null)
            {
                m_parent = new RootTreeNode();
            }
            foreach (var item in CreateFactoryAddonType.GetItems(m_parent))
            {
                if (!m_parent.AllowCreate(item.GroupName, item.Name))
                {
                    continue;
                }
                m_allItems.Add(item);
            }
            foreach (ICreateFactoryItem item in m_allItems)
            {
                Bitmap bmp = item.Bitmap;
                if (bmp != null)
                {
                    m_imageIndexes[item] = imageList2.Images.Count;
                    imageList2.Images.Add(item.Bitmap);
                }
                else
                {
                    m_imageIndexes[item] = -1;
                }
            }
            if (!ShowGroups)
            {
                if (m_selectGroup != null && m_selectItem == null)
                {
                    foreach (var item in m_allItems)
                    {
                        if (item.GroupName == m_selectGroup)
                        {
                            m_selectItem = item.Name;
                            break;
                        }
                    }
                }
                listView1_SelectedIndexChanged(sender, e);
                return;
            }
            foreach (ICreateFactoryItem item in m_allItems)
            {
                if (item.Name == null || item.GroupName == null)
                {
                    continue;
                }
                if (!m_parent.AllowCreate(item.GroupName, item.Name))
                {
                    continue;
                }
                if (!m_items.ContainsKey(item.GroupName))
                {
                    m_items[item.GroupName] = new List <ICreateFactoryItem>();
                    ListViewItem grp = lbxGroups.Items.Add(Texts.Get(item.Group));
                    grp.Name       = item.GroupName;
                    grp.ImageIndex = 0;
                }
                m_items[item.GroupName].Add(item);
            }
            int selgrp = 0;

            if (m_selectGroup != null)
            {
                int index = 0;
                foreach (ListViewItem item in lbxGroups.Items)
                {
                    if (item.Name == m_selectGroup)
                    {
                        selgrp = index;
                    }
                    index++;
                }
            }
            foreach (var it in m_items)
            {
                it.Value.SortByKey(i => new Tuple <int, string>(-i.Weight, Texts.Get(i.Title)));
            }
            if (selgrp < lbxGroups.Items.Count)
            {
                lbxGroups.Items[selgrp].Focused  = true;
                lbxGroups.Items[selgrp].Selected = true;
                listView1_SelectedIndexChanged(sender, e);
            }
            m_selectItem  = null;
            m_selectGroup = null;
        }