1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Data;
|
---|
5 | using System.Drawing;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.PluginInfrastructure;
|
---|
10 | using HeuristicLab.Common.Resources;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Optimizer {
|
---|
14 | internal partial class NewItemDialog : Form {
|
---|
15 | private bool initialized;
|
---|
16 | private List<IItem> items;
|
---|
17 |
|
---|
18 | private IItem item;
|
---|
19 | public IItem Item {
|
---|
20 | get { return item; }
|
---|
21 | }
|
---|
22 |
|
---|
23 | public NewItemDialog() {
|
---|
24 | initialized = false;
|
---|
25 | items = new List<IItem>();
|
---|
26 | item = null;
|
---|
27 | InitializeComponent();
|
---|
28 | }
|
---|
29 |
|
---|
30 | private void NewItemDialog_Load(object sender, EventArgs e) {
|
---|
31 | if (!initialized) {
|
---|
32 | SetListViewDisplayStyleCheckBoxes();
|
---|
33 |
|
---|
34 | var categories = from t in ApplicationManager.Manager.GetTypes(typeof(IItem))
|
---|
35 | where CreatableAttribute.IsCreatable(t)
|
---|
36 | orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t) ascending
|
---|
37 | group t by CreatableAttribute.GetCategory(t) into c
|
---|
38 | select c;
|
---|
39 |
|
---|
40 | itemsListView.SmallImageList = new ImageList();
|
---|
41 | foreach (var category in categories) {
|
---|
42 | ListViewGroup group = new ListViewGroup(category.Key);
|
---|
43 | itemsListView.Groups.Add(group);
|
---|
44 | foreach (var creatable in category) {
|
---|
45 | IItem i = (IItem)Activator.CreateInstance(creatable);
|
---|
46 | items.Add(i);
|
---|
47 | ListViewItem item = new ListViewItem(new string[] { i.ItemName, i.ItemDescription}, group);
|
---|
48 | itemsListView.SmallImageList.Images.Add(i.ItemImage);
|
---|
49 | item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
50 | item.Tag = i;
|
---|
51 | itemsListView.Items.Add(item);
|
---|
52 | }
|
---|
53 | }
|
---|
54 | initialized = true;
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | private void NewItemDialog_Shown(object sender, EventArgs e) {
|
---|
59 | item = null;
|
---|
60 | }
|
---|
61 |
|
---|
62 | private void itemTypesListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
63 | okButton.Enabled = itemsListView.SelectedItems.Count == 1;
|
---|
64 | }
|
---|
65 |
|
---|
66 | private void okButton_Click(object sender, EventArgs e) {
|
---|
67 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
68 | item = (IItem)((IItem)itemsListView.SelectedItems[0].Tag).Clone();
|
---|
69 | DialogResult = DialogResult.OK;
|
---|
70 | Close();
|
---|
71 | }
|
---|
72 | }
|
---|
73 | private void itemTypesListView_DoubleClick(object sender, EventArgs e) {
|
---|
74 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
75 | item = (IItem)((IItem)itemsListView.SelectedItems[0].Tag).Clone();
|
---|
76 | DialogResult = DialogResult.OK;
|
---|
77 | Close();
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | private void showIconsCheckBox_Click(object sender, EventArgs e) {
|
---|
82 | itemsListView.View = View.SmallIcon;
|
---|
83 | SetListViewDisplayStyleCheckBoxes();
|
---|
84 | }
|
---|
85 | private void showDetailsCheckBox_Click(object sender, EventArgs e) {
|
---|
86 | itemsListView.View = View.Details;
|
---|
87 | SetListViewDisplayStyleCheckBoxes();
|
---|
88 | for (int i = 0; i < itemsListView.Columns.Count; i++)
|
---|
89 | itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
90 | }
|
---|
91 | private void SetListViewDisplayStyleCheckBoxes() {
|
---|
92 | showIconsCheckBox.Checked = itemsListView.View == View.SmallIcon;
|
---|
93 | showDetailsCheckBox.Checked = itemsListView.View == View.Details;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|