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 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 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 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(); }