private void btnRename_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count == 0) { MessageBox.Show("Please select a model to change its name."); return; } string mdName = listView.SelectedItems[0].SubItems[0].Text; string newName = PromptInput.PromptString("Rename Model", "Please enter a new model name:", mdName, 200); if (newName != null) { foreach (var f in Directory.EnumerateFiles(DataModeling.workDir, mdName + ".*")) { File.Move(f, f.Replace(mdName, newName)); } string chkFile = null; string chkFilePath = DataModeling.workDir + newName + ".chk"; using (var sr = new StreamReader(chkFilePath)) chkFile = sr.ReadToEnd(); using (var sw = new StreamWriter(chkFilePath)) sw.Write(chkFile.Replace(mdName, newName)); RefreshList(); } }
public static string PromptString(string title, string msg, string defaultValue, int winWidth) { PromptInput prompt = new PromptInput(title, msg, defaultValue); if (winWidth > 0) { prompt.Width = winWidth; } string str = null; if (prompt.ShowDialog() == DialogResult.OK) { str = prompt.inputTextBox.Text; } prompt.Dispose(); return(str); }