예제 #1
0
        private void newFigures_Click(object sender, EventArgs e)
        {
            if (Earth3d.MainWindow.figureEditor != null)
            {
                if (Earth3d.MainWindow.figureEditor.SaveAndClose() != DialogResult.OK)
                {
                    return;
                }
                Earth3d.MainWindow.figureEditor = null;
            }

            SimpleInput input = new SimpleInput(Language.GetLocalizedText(515, "Figure Library Name"), Language.GetLocalizedText(238, "Name"), "", 32);
            bool        retry = false;

            do
            {
                if (input.ShowDialog() == DialogResult.OK)
                {
                    if (!File.Exists(Constellations.GetFigurePath(input.ResultText)))
                    {
                        int index = figureLibrary.Items.IndexOf(input.ResultText);
                        if (index > -1)
                        {
                            MessageBox.Show(Language.GetLocalizedText(516, "Name already exists, type a different name."), Language.GetLocalizedText(3, "Microsoft WorldWide Telescope"));
                            retry = true;
                        }
                        else
                        {
                            string validfileName = @"^[A-Za-z0-9_ ]*$";
                            if (input.ResultText.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || !UiTools.ValidateString(input.ResultText, validfileName))
                            {
                                MessageBox.Show(Language.GetLocalizedText(231, "A name can not contain any of the following characters:") + " \\ / : * ? \" < > |", "Constellation Figure Editor");
                                retry = true;
                            }
                            else
                            {
                                Constellations figures = new Constellations(input.ResultText);
                                figures.Save(input.ResultText);
                                figures = null;
                                figureLibrary.Items.Add(input.ResultText);
                                figureLibrary.SelectedIndex = figureLibrary.Items.IndexOf(input.ResultText);
                                Earth3d.MainWindow.ShowFigureEditorWindow(Earth3d.MainWindow.constellationsFigures);
                                retry = false;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(Language.GetLocalizedText(516, "Name already exists, type a different name."), Language.GetLocalizedText(3, "Microsoft WorldWide Telescope"));
                        retry = true;
                    }
                }
                else
                {
                    return;
                }
            } while (retry);
        }