private void buttonGenerateSubmarks_Click(object sender, EventArgs e)
{
if (listViewMarks.SelectedItems.Count < 2) {
MessageBox.Show("Select at least two marks to generate times between.", "Need more marks");
return;
}
Common.Controls.TextDialog prompt = new Common.Controls.TextDialog("Break each interval into how many equal segments?");
if (prompt.ShowDialog() == DialogResult.OK) {
int divisions;
if (int.TryParse(prompt.Response, out divisions)) {
DialogResult newCollectionResult = MessageBox.Show("Do you want to put the new marks into a different collection?", "Add to new collection?", MessageBoxButtons.YesNoCancel);
if (newCollectionResult == DialogResult.Cancel) {
return;
}
List<TimeSpan> sourceTimes = new List<TimeSpan>();
foreach (ListViewItem item in listViewMarks.SelectedItems) {
sourceTimes.Add((TimeSpan)item.Tag);
}
sourceTimes.Sort();
List<TimeSpan> newTimes = new List<TimeSpan>();
for (int i = 1; i < sourceTimes.Count; i++) {
TimeSpan interval = TimeSpan.FromTicks((sourceTimes[i] - sourceTimes[i - 1]).Ticks / divisions);
for (int j = 0; j < divisions; j++) {
newTimes.Add(sourceTimes[i - 1] + TimeSpan.FromTicks(interval.Ticks * j));
}
}
newTimes.Add(sourceTimes.Last());
MarkCollection destination = _displayedCollection;
if (newCollectionResult == DialogResult.Yes) {
List<KeyValuePair<string, object>> options = new List<KeyValuePair<string, object>>();
foreach (MarkCollection mc in MarkCollections) {
options.Add(new KeyValuePair<string, object>(mc.Name, mc));
}
Common.Controls.ListSelectDialog selector = new Common.Controls.ListSelectDialog("Destination Mark Collection?", options);
if (selector.ShowDialog() == DialogResult.OK) {
destination = selector.SelectedItem as MarkCollection;
}
}
foreach (TimeSpan time in newTimes) {
if (!destination.Marks.Contains(time))
destination.Marks.Add(time);
}
destination.Marks.Sort();
if (destination == _displayedCollection) {
PopulateMarkListFromMarkCollection(_displayedCollection);
}
UpdateMarkCollectionInList(destination);
} else {
MessageBox.Show("Error parsing number: please enter a whole number for the number of divisions.", "Error parsing number");
}
}
}