// open child window to edit channel private void OnEdit(object sender, EventArgs e) { // get selected enty foreach (ListViewItem curItem in listView.SelectedItems) { int selectedChannel = Int32.Parse(curItem.SubItems[1].Text); // do not edit global items (this may happen at double click) if (channelList[selectedChannel].globalChannel) { break; } // diaplay edit box ChannelInfo channelInfo = new ChannelInfo(channelList[selectedChannel]); FormChannelSettingsEdit channelEdit = new FormChannelSettingsEdit(channelInfo, false); DialogResult dialogResult = channelEdit.ShowDialog(this); // update list view display in case of pressing OK if (dialogResult == DialogResult.OK) { // check for duplicate channel if (channelList.IsNewChannel(channelInfo, channelList[selectedChannel])) { // override the stored channel channelList[selectedChannel] = channelInfo; curItem.SubItems[2].Text = channelList[selectedChannel].link; curItem.SubItems[3].Text = channelList[selectedChannel].priority.ToString(); } else { MessageBox.Show( Resources.str_channelSettingsDuplicateLink, Resources.str_settingsFormErrorHeader, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // we just edit the first selection and skip the remaining ones break; } // we need to reselect an entry after this operation editButton.Enabled = false; deleteButton.Enabled = false; }
// open a child window to create a new channel private void OnNew(object sender, EventArgs e) { // create new enty ChannelInfo channelInfo = new ChannelInfo(); // set link if specified if (sender is String) { channelInfo.link = sender as String; } // diaplay edit box FormChannelSettingsEdit channelEdit = new FormChannelSettingsEdit(channelInfo, true); DialogResult dialogResult = channelEdit.ShowDialog(this); // if edit is confirmed, store the entry if (dialogResult == DialogResult.OK) { // check for duplicate channel if (channelList.IsNewChannel(channelInfo, null)) { // OK, let's add it channelList.Add(channelInfo); ListViewItem listItem = new ListViewItem(); listItem.SubItems.Add(listView.Items.Count.ToString()); listItem.SubItems.Add(channelInfo.link); listItem.SubItems.Add(channelInfo.priority.ToString()); listItem.StateImageIndex = Convert.ToInt16(channelInfo.globalChannel); listView.Items.Add(listItem); } else { MessageBox.Show( Resources.str_channelSettingsDuplicateLink, Resources.str_settingsFormErrorHeader, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // we need to reselect an entry after this operation editButton.Enabled = false; deleteButton.Enabled = false; }