Пример #1
0
 /// <summary>
 /// Adds a new list view item representation of the key in/out
 /// </summary>
 /// <param name="zStream">The stream to read the key definitions from</param>
 /// <returns></returns>
 private void AddListViewItems(FileStream zStream)
 {
     listViewKeys.Items.Clear();
     while (zStream.Position < zStream.Length)
     {
         var zKeyDef = new IOPairDefinition(zStream);
         var zItem   = new ListViewItem(new string[] {
             zKeyDef.GetInputString(),
             zKeyDef.GetOutputString()
         });
         zItem.Tag = zKeyDef;
         listViewKeys.Items.Add(zItem);
     }
 }
Пример #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var zInput  = (IODefinition)txtKeyIn.Tag;
            var zOutput = getCurrentOutputDefinition();

            if (null == zInput || null == zOutput)
            {
                MessageBox.Show(this, "Please specify both an input and output key.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            zInput.Flags = GetFlags(zInput, FlagsFromEnum.Input);

            var zPairDef = new IOPairDefinition(zInput, zOutput);

            // TODO: is it worth keeping a hashset of these to cut the time from o(n) to o(1)?
            // verify this is not already defined
            foreach (ListViewItem zListItem in listViewKeys.Items)
            {
                var zKeyOldDef = (IOPairDefinition)zListItem.Tag;
                if (zPairDef.GetHashCode() != zKeyOldDef.GetHashCode())
                {
                    continue;
                }

                MessageBox.Show(this, "Duplicate inputs are not allowed!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var zItem = new ListViewItem(new string[] {
                zPairDef.GetInputString(),
                zPairDef.GetOutputString()
            });

            zItem.Tag = zPairDef;
            listViewKeys.Items.Add(zItem);
            listViewKeys.SelectedItems.Clear();
            zItem.Selected = true;
            MarkDirty();
        }