Beispiel #1
0
        private string PromptForFileName()
        {
            var dialog = new FileNameDialog();
            var result = dialog.ShowDialog();

            return(result.HasValue && result.Value ? dialog.Input : string.Empty);
        }
Beispiel #2
0
        private void SaveAs(object sender, ExecutedRoutedEventArgs e)
        {
            FileNameDialog dialog = new FileNameDialog("", "Save As", "Please enter the name for the new file:");

FileNamePick:

            if (!((bool)dialog.ShowDialog()))
            {
                return;
            }
            else
            {
                if (dialog.FileName == "" || dialog.FileName == " " || dialog.FileName == "  ")
                {
                    MessageBox.Show("Invalid file name. File name cannot be blank.", "Invalid name picked", MessageBoxButton.OK, MessageBoxImage.Warning);
                    goto FileNamePick;
                }

                try
                {
                    if (!fileManager.SaveFileItemsToFile(new List <FileItem>(fileItems), dialog.FileName, false))
                    {
                        switch (MessageBox.Show("There already exists a file called " + dialog.FileName + ". Do you wish to overwrite it?", "File already exists", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.No))
                        {
                        case MessageBoxResult.Yes: fileManager.SaveFileItemsToFile(new List <FileItem>(fileItems), dialog.FileName, true); break;

                        case MessageBoxResult.Cancel:
                        case MessageBoxResult.None: return;

                        case MessageBoxResult.No:
                        {
                            dialog = new FileNameDialog(dialog.FileName, "Pick another name", "Please pick another name for the new file:");
                            goto FileNamePick;
                        }
                        }
                    }

                    saved                = true;
                    fileItems            = new ObservableCollection <FileItem>(fileManager.LoadFileItemsFromFile(dialog.FileName));
                    dataGrid.ItemsSource = null;
                    dataGrid.ItemsSource = fileItems;
                    Title                = (new FileInfo(dialog.FileName).Name) + " - RubikTimer Satistic files Editor";
                    ViewSuccessSave();
                }

                catch (Exception ex) { ViewFailSave(ex); }
            }
        }