Example #1
0
        private void DeletePackClicked(object sender, EventArgs e)
        {
            Button but  = sender as Button;
            string name = but.Name.Substring(0, but.Name.Length - Constants.DeleteExt.Length);

            ConfirmDialog dialog = new ConfirmDialog(Dialogs.ConfirmDelete(name), "Delete " + name + " word pack?");

            dialog.ShowDialog(this);

            if (dialog.Cancelled || !dialog.Decision)
            {
                return;
            }

            if (!PackManager.Instance.Remove(name, true))
            {
                ErrorDialog error = new ErrorDialog(Dialogs.DeleteFail(name));
                error.ShowDialog(this);
            }

            m_packpanes[name].Controls.Clear();
            packPane.Controls.Remove(m_packpanes[name]);
            m_packpanes[name].Dispose();
            m_packpanes.Remove(name);
        }
Example #2
0
        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();
            }
        }
Example #3
0
        private void SaveAsClicked(object sender, EventArgs e)
        {
            NameEditor ne = new NameEditor(m_pack.Name + " Copy");

            ne.ShowDialog(this);

            if (ne.Cancelled)
            {
                return;
            }

            string name = ne.NameField.Trim();

            if (!Naming.IsValidName(name))
            {
                ErrorDialog er = new ErrorDialog(Dialogs.InvalidPackName(name ?? string.Empty));
                er.ShowDialog(this);
                return;
            }

            m_pack.Name = name;
            string filename = FolderPaths.WordPackDir + "\\" + name + "." + Constants.PackFileExt;

            if (File.Exists(filename))
            {
                ConfirmDialog cd = new ConfirmDialog(Dialogs.ReplacePack(name), "Replace pack?");
                cd.ShowDialog(this);

                if (cd.Cancelled || !cd.Decision)
                {
                    return;
                }
            }

            m_pack.Clear();
            m_pack.Add(textBox.Lines);

            if (!m_pack.SaveToFile(filename))
            {
                ErrorDialog er = new ErrorDialog(Dialogs.PackSaveFail);
                er.ShowDialog(this);
            }
            else
            {
                Changed = false;
            }
        }
Example #4
0
        private void OnFormClose(object sender, EventArgs e)
        {
            if (Changed)
            {
                ConfirmDialog d = new ConfirmDialog(Dialogs.SaveChanges, "Save changes?");
                d.ShowDialog(this);

                if (!d.Cancelled && d.Decision)
                {
                    m_pack.Clear();
                    m_pack.Add(textBox.Lines);

                    if (!m_pack.SaveToFile())
                    {
                        ErrorDialog er = new ErrorDialog(Dialogs.PackSaveFail);
                        er.ShowDialog(this);
                    }
                    else
                    {
                        PackManager.Instance[m_pack.Name] = m_pack;
                    }
                }
            }
        }