private void buttonAddController_Click(object sender, EventArgs e) { List<KeyValuePair<string, object>> outputModules = new List<KeyValuePair<string, object>>(); foreach (KeyValuePair<Guid, string> kvp in ApplicationServices.GetAvailableModules<IControllerModuleInstance>()) { outputModules.Add(new KeyValuePair<string, object>(kvp.Value, kvp.Key)); } Common.Controls.ListSelectDialog addForm = new Common.Controls.ListSelectDialog("Add Controller", (outputModules)); if (addForm.ShowDialog() == DialogResult.OK) { IModuleDescriptor moduleDescriptor = ApplicationServices.GetModuleDescriptor((Guid)addForm.SelectedItem); string name = moduleDescriptor.TypeName; ControllerFactory controllerFactory = new ControllerFactory(); OutputController oc = (OutputController)controllerFactory.CreateDevice((Guid)addForm.SelectedItem, name); VixenSystem.OutputControllers.Add(oc); // In the case of a controller that has a form, the form will not be shown // until this event handler completes. To make sure it's in a visible state // before evaluating if it's running or not, we're calling DoEvents. // I hate DoEvents calls, so if you know of a better way... Application.DoEvents(); // select the new controller, and then repopulate the list -- it will make sure the currently // displayed controller is selected. _PopulateFormWithController(oc); _PopulateControllerList(); //We added a controller so set the _changesMade to true _changesMade = true; } }
private void buttonAddController_Click(object sender, EventArgs e) { List <KeyValuePair <string, object> > outputModules = new List <KeyValuePair <string, object> >(); foreach (KeyValuePair <Guid, string> kvp in ApplicationServices.GetAvailableModules <IControllerModuleInstance>()) { outputModules.Add(new KeyValuePair <string, object>(kvp.Value, kvp.Key)); } Common.Controls.ListSelectDialog addForm = new Common.Controls.ListSelectDialog("Add Controller", (outputModules)); if (addForm.ShowDialog() == DialogResult.OK) { IModuleDescriptor moduleDescriptor = ApplicationServices.GetModuleDescriptor((Guid)addForm.SelectedItem); string name = moduleDescriptor.TypeName; ControllerFactory controllerFactory = new ControllerFactory(); OutputController oc = (OutputController)controllerFactory.CreateDevice((Guid)addForm.SelectedItem, name); VixenSystem.OutputControllers.Add(oc); // In the case of a controller that has a form, the form will not be shown // until this event handler completes. To make sure it's in a visible state // before evaluating if it's running or not, we're calling DoEvents. // I hate DoEvents calls, so if you know of a better way... Application.DoEvents(); // select the new controller, and then repopulate the list -- it will make sure the currently // displayed controller is selected. _PopulateFormWithController(oc); _PopulateControllerList(); //We added a controller so set the _changesMade to true _changesMade = true; } }
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"); } } }
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"); } } }