/// <summary> /// Constructs a new word pack by deep copying data from another object. /// </summary> /// <remarks> /// The name of the new word pack will be <paramref name="w"/> + " Copy" so that it may be saved to file /// without colliding with the coppied objects' file. /// </remarks> /// <param name="w"> /// The word pack to copy from. /// </param> public WordPack(WordPack w) { Name = w.Name + " Copy"; m_words = new List <string>(w.Count); for (int i = 0; i < w.Count; i++) { m_words.Add(new string( w.m_words[i].ToCharArray())); } }
private void ImportClicked(object sender, EventArgs e) { if (importDialog.ShowDialog(this) == DialogResult.OK) { foreach (string file in importDialog.FileNames) { string packname = Path.GetFileNameWithoutExtension(file); if (PackManager.Instance.Contains(packname)) { ConfirmDialog confirm = new ConfirmDialog(Dialogs.ReplacePack(packname)); confirm.ShowDialog(this); if (confirm.Cancelled || !confirm.Decision) { return; } if (!PackManager.Instance.Remove(packname, true)) { ErrorDialog er = new ErrorDialog(Dialogs.PackDeleteFail(packname)); er.ShowDialog(this); return; } } string filename = packname + "." + Constants.PackFileExt; string filepath = FolderPaths.WordPackDir + "\\" + filename; try { File.Copy(file, filepath, true); } catch (ArgumentException argex) { ErrorDialog er = new ErrorDialog(Dialogs.ImportError(file, argex)); er.ShowDialog(this); } catch { ErrorDialog er = new ErrorDialog(Dialogs.ImportError(file)); er.ShowDialog(this); } if (!PackManager.Instance.Add(WordPack.FromName(packname), true)) { ErrorDialog er = new ErrorDialog(Dialogs.PackAddFail(packname)); er.ShowDialog(this); } } CreatePackUI(); } }
/// <summary> /// Returns a new word pack loaded from the given file path. /// </summary> /// <param name="path"> /// The path to load the word pack from. /// </param> /// <returns> /// The word pack loaded from <paramref name="path"/> on success, otherwise null. /// </returns> public static WordPack FromFile(string path) { WordPack w = new WordPack(); if (!w.LoadFromFile(path)) { return(null); } return(w); }
public PackEditor(WordPack pack = null) { InitializeComponent(); m_nameeditor = new NameEditor(); FormClosed += new FormClosedEventHandler(OnFormClose); try { CurrentPack = pack; } catch { ErrorDialog er = new ErrorDialog("Unable to create new pack."); er.ShowDialog(this); throw new InvalidOperationException(); } }
private void CreatePackUI() { ClearPacksUI(); foreach (var pair in PackManager.Instance) { WordPack pack = pair.Value; Panel pan = new Panel { Name = pack.Name + Constants.PanelExt, Size = new Size(190, 29) }; Button del = new Button { Name = pack.Name + Constants.DeleteExt, Size = new Size(23, 23), Text = "-" }; del.Click += DeletePackClicked; Button name = new Button { Name = pack.Name + Constants.EditExt, Size = new Size(102, 23), Text = pack.Name }; name.Click += EditPackClicked; Button add = new Button { Name = pack.Name + Constants.AddExt, Size = new Size(23, 23), Text = "+" }; add.Click += AddPackClicked; pan.Controls.Add(del); del.Location = new Point(3, 3); pan.Controls.Add(name); name.Location = new Point(32, 3); pan.Controls.Add(add); add.Location = new Point(140, 3); m_packpanes.Add(pack.Name, pan); packPane.Controls.Add(m_packpanes[pack.Name]); } }
private void OpenPackEditor(WordPack pack = null) { if (m_editor == null || m_editor.IsDisposed) { m_editor = new PackEditor(pack); } else { m_editor.CurrentPack = pack; } if (!m_editor.IsDisposed) { m_editor.ShowDialog(this); } if (!LoadPacks()) { Close(); } }
private void GenerateClicked(object sender, EventArgs e) { generateBox.Text = Constants.GeneratingText; if (m_packstack.Count > 0) { List <string> list = new List <string>(m_packstack.Count); foreach (string packname in m_packstack) { WordPack pack = PackManager.Instance[packname]; list.Add(pack[m_random.Next(0, pack.Count)]); } generateBox.Lines = list.ToArray(); } else { generateBox.Text = Constants.EmptyStackText; } }