1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.Collections.Specialized;
9 
10 using StringList = System.Collections.Generic.List<string>;
11 
12 namespace ResourceTrans
13 {
14     public partial class MismatchForm : Form
15     {
16         private int origCheckedCount;
17         private int transCheckedCount;
18         private bool doneInitializing = false;
19         private StringList newStrings = null;
20         private StringList newTransStrings = null;
21 
updateEnabled()22         private void updateEnabled()
23         {
24             bool enabled = false;
25 
26             if (origCheckedCount == transCheckedCount)
27             {
28                 enabled = true;
29             }
30             okButton.Enabled = enabled;
31         }
32 
MismatchForm(StringList origStrings, StringList transStrings)33         public MismatchForm(StringList origStrings, StringList transStrings)
34         {
35             InitializeComponent();
36             for (int i = 0; i < origStrings.Count; i++)
37             {
38                 origListBox.Items.Add(origStrings[i], true);
39             }
40             for (int i = 0; i < transStrings.Count; i++)
41             {
42                 transListBox.Items.Add(transStrings[i], true);
43             }
44             origCheckedCount = origStrings.Count;
45             transCheckedCount = transStrings.Count;
46             doneInitializing = true;
47             updateEnabled();
48         }
49 
getStrings(out StringList orig, out StringList trans)50         public bool getStrings(out StringList orig, out StringList trans)
51         {
52             if (newStrings != null && newTransStrings != null)
53             {
54                 orig = newStrings;
55                 trans = newTransStrings;
56                 return true;
57             }
58             else
59             {
60                 orig = null;
61                 trans = null;
62                 return false;
63             }
64         }
65 
getStrings(CheckedListBox listBox, ref StringList strings)66         private void getStrings(CheckedListBox listBox, ref StringList strings)
67         {
68             int i;
69 
70             for (i = 0; i < listBox.Items.Count; i++)
71             {
72                 if (listBox.GetItemChecked(i))
73                 {
74 					String itemText = listBox.Items[i].ToString();
75 					strings.Add(itemText);
76                 }
77             }
78         }
79 
okButton_Click(object sender, EventArgs e)80         private void okButton_Click(object sender, EventArgs e)
81         {
82             newStrings = new StringList();
83             newTransStrings = new StringList();
84             getStrings(origListBox, ref newStrings);
85             getStrings(transListBox, ref newTransStrings);
86         }
87 
listBox_ItemCheck(object sender, ItemCheckEventArgs e)88         private void listBox_ItemCheck(object sender, ItemCheckEventArgs e)
89         {
90             if (doneInitializing)
91             {
92                 int delta = -1;
93 
94                 if (e.NewValue == CheckState.Checked)
95                 {
96                     delta = 1;
97                 }
98                 if (sender == origListBox)
99                 {
100                     origCheckedCount += delta;
101                 }
102                 else
103                 {
104                     transCheckedCount += delta;
105                 }
106                 updateEnabled();
107             }
108         }
109     }
110 }