private void Save_Click(object sender, EventArgs e) { using (var getName = new TextQueryDialog("Palette Name", "What do you want to name the palette?", string.Empty)) { if (getName.ShowDialog() != DialogResult.OK) { return; } _nutcrackerData.SavePalette(getName.Response, _getPalette.Invoke()); PopulatePalettes(); } }
private void cbEffectsPresets_SelectedIndexChanged(object sender, EventArgs e) { if (_ignoreIndexChange) return; var effectsCount = cbEffectsPresets.Items.Count; if (cbEffectsPresets.SelectedIndex < effectsCount - 1) { var effectData = _nutcrackerData.GetDataForEffect(cbEffectsPresets.SelectedItem.ToString()); if (effectData != null) { SetPreset(effectData); } return; } //todo: there is some work here to do. while (true) using (var textDialog = new TextQueryDialog("Preset name", "What do you want to name this preset?", "")) { if (textDialog.ShowDialog() != DialogResult.OK) { return; } var presetName = textDialog.Response; cbEffectsPresets.Items.Insert(effectsCount - 1, presetName); _ignoreIndexChange = true; cbEffectsPresets.SelectedIndex = cbEffectsPresets.FindStringExact(presetName); _ignoreIndexChange = false; SavePreset(presetName); return; } }
private void btnOk_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(_modelPath)) { using (var modelName = new TextQueryDialog("Model Name", "What would you like to name this model", "")) { var isDone = false; do { modelName.ShowDialog(); if (modelName.DialogResult != DialogResult.OK) { return; } var tempModelPath = Path.Combine(Paths.NutcrackerDataPath, modelName.Response + Vendor.NutcrakerModelExtension); if (File.Exists(tempModelPath)) { if ( MessageBox.Show("That model exists, do you want to overwrite the existing model?", "Overwrite?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { continue; } _modelPath = tempModelPath; isDone = true; } else { _modelPath = tempModelPath; isDone = true; } } while (!isDone); } } SaveModel(); }
private static string GetFileName(string fileType, string filePath, IList<string> extension, string defaultResponse, string buttonText) { var newName = string.Empty; var caption = string.Format("{0} name", fileType); var query = string.Format("What would you like to name this {0}?", fileType); using (var dialog = new TextQueryDialog(caption, query, defaultResponse, buttonText)) { var showDialog = true; while (showDialog) { if (dialog.ShowDialog() == DialogResult.OK) { newName = dialog.Response; showDialog = false; if (!extension.Aggregate(false, (current, ext) => current | File.Exists(Path.Combine(filePath, newName + ext)))) { continue; } var msg = String.Format("{0} with the name {1} exists. Overwrite this {0}?", fileType, newName); var overwriteResult = MessageBox.Show(msg, "Overwrite?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (overwriteResult) { case DialogResult.Yes: break; case DialogResult.No: newName = string.Empty; showDialog = true; break; case DialogResult.Cancel: newName = string.Empty; break; } } else { showDialog = false; } } } return newName; }
private string GetName(string heading, string prompt, string value) { var result = string.Empty; using (var groupNameDialog = new TextQueryDialog(heading, prompt, value)) { var validName = false; while (!validName) { groupNameDialog.ShowDialog(); validName = true; if (groupNameDialog.DialogResult != DialogResult.OK) { continue; } var response = groupNameDialog.Response; var msg = string.Empty; if (string.IsNullOrEmpty(response)) { msg = "A group must have a unique name and cannot be blank."; } else if (tvGroups.Nodes.Cast<TreeNode>().Any(n => n.Text == response)) { msg = String.Format("A group with the name {0} already exists and group names must be unique.", response); } else if (response.Contains(Group.GroupTextDivider) || response.Contains(",")) { msg = string.Format("A group name can not contain a {0} or a ,", Group.GroupTextDivider); } if (msg != String.Empty) { if (MessageBox.Show(msg + @"\nClick OK to try again.", @"Group Naming Error", MessageBoxButtons.OKCancel) != DialogResult.OK) { continue; } groupNameDialog.Response = value; validName = false; } else { result = response; } } } return result; }
private static void SaveRoutine(byte[,] buffer) { DialogResult result; var path = string.Empty; using (var dialog = new TextQueryDialog(Vendor.ProductName, Resources.RoutineNamePrompt, string.Empty)) { do { result = dialog.ShowDialog(); if (result != DialogResult.OK) { continue; } path = Path.Combine(Paths.RoutinePath, Path.GetFileNameWithoutExtension(dialog.Response) + Vendor.RoutineExtension); if (File.Exists(path)) { result = MessageBox.Show(Resources.OverwriteFilePrompt, Vendor.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); } } while (result == DialogResult.No); } if (result == DialogResult.Cancel) { return; } using (var writer = new StreamWriter(path)) { var rows = buffer.GetLength(Utils.IndexRowsOrHeight); var cols = buffer.GetLength(Utils.IndexColsOrWidth); for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { writer.Write(buffer[row, col].ToString(CultureInfo.InvariantCulture) + " "); } writer.WriteLine(); } } MessageBox.Show(string.Format(Resources.StringFormat_RoutineSaved, Path.GetFileNameWithoutExtension(path)), Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
private void toolStripButtonIntensity_Click(object sender, EventArgs e) { var result = 0; var isValid = false; var top = _selectedCells.Top; var left = _selectedCells.Left; var isSingleCell = (_selectedCells.Width == 1) && (_selectedCells.Height == 1); while (!isValid) { isValid = true; if (_actualLevels) { var initialValue = isSingleCell ? _sequence.EventValues[GetEventFromChannelNumber(top), left].ToString(CultureInfo.InvariantCulture) : @"255"; using (var dialog = new TextQueryDialog(Vendor.ProductName, Resources.IntensityLevelPrompt, initialValue)) { if (dialog.ShowDialog() != DialogResult.OK) { return; } if (!int.TryParse(dialog.Response, out result)) { MessageBox.Show(Resources.InvalidNumber, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); isValid = false; } if ((result >= Utils.Cell8BitMin) && (result <= Utils.Cell8BitMax)) { continue; } MessageBox.Show(Resources.InvalidValue, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); isValid = false; } } else { var initialValue = isSingleCell ? _sequence.EventValues[GetEventFromChannelNumber(top), left].ToPercentage().ToString(CultureInfo.InvariantCulture) : @"100"; using (var dialog = new TextQueryDialog(Vendor.ProductName, Resources.IntensityPercentPrompt, initialValue)) { if (dialog.ShowDialog() != DialogResult.OK) { return; } try { result = Convert.ToSingle(dialog.Response).ToValue(); if ((result >= Utils.Cell8BitMin) && (result <= Utils.Cell8BitMax)) { continue; } MessageBox.Show(Resources.InvalidPercentage, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); isValid = false; } catch { MessageBox.Show(Resources.InvalidNumber, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); isValid = false; } } } } AddUndoItem(_selectedCells, UndoOriginalBehavior.Overwrite, Resources.UndoText_Intensity); for (var row = top; row < _selectedCells.Bottom; row++) { var channel = GetEventFromChannelNumber(row); if (!_sequence.Channels[row].Enabled) { continue; } for (var col = _selectedCells.Left; col < _selectedCells.Right; col++) { _sequence.EventValues[channel, col] = (byte) result; } } _selectionRectangle.Width = 0; pictureBoxGrid.Invalidate(SelectionToRectangle()); }