diff --git a/FlowBoard/Helpers/FileHelper.cs b/FlowBoard/Helpers/FileHelper.cs index 3684424..ac2fcbb 100644 --- a/FlowBoard/Helpers/FileHelper.cs +++ b/FlowBoard/Helpers/FileHelper.cs @@ -18,6 +18,7 @@ using Windows.Graphics.Display; using System.Runtime.InteropServices.WindowsRuntime; using System.Collections.ObjectModel; +using System.Text.RegularExpressions; namespace FlowBoard.Helpers { @@ -148,6 +149,24 @@ public static async Task IsFilePresent(string fileName) return item != null; } + public static async Task GetSequentialNewWhiteboardFilename() + { + Regex rx = new Regex(@"(New Whiteboard$|New Whiteboard \(([0-9]+)\)$)"); + + int highestNumber = -1; + var items = await ApplicationData.Current.LocalFolder.GetItemsAsync(); + foreach (var item in items) + { + foreach (Match match in rx.Matches(item.Name)) + { + highestNumber = match.Groups[2].Length == 0 ? 0 : int.Parse(match.Groups[2].Value); + } + } + + string postfix = highestNumber < 0 ? "" : " (" + (highestNumber + 1).ToString() + ")"; + return "New Whiteboard" + postfix; + } + // Save the project + add it to the most recently used list + get a preview image public static async Task SaveProjectAsync(Color canvasColor, InkCanvas inkCanvas, ProjectClass project, string PreviewName, bool IsSilent) { diff --git a/FlowBoard/NewProjectPage.xaml b/FlowBoard/NewProjectPage.xaml index 891a2bb..614ee5f 100644 --- a/FlowBoard/NewProjectPage.xaml +++ b/FlowBoard/NewProjectPage.xaml @@ -42,13 +42,13 @@ New Project Project Name: - + Canvas Background: - + diff --git a/FlowBoard/NewProjectPage.xaml.cs b/FlowBoard/NewProjectPage.xaml.cs index ba76b35..58dc403 100644 --- a/FlowBoard/NewProjectPage.xaml.cs +++ b/FlowBoard/NewProjectPage.xaml.cs @@ -40,9 +40,15 @@ private async void CreateProject_Click(object sender, RoutedEventArgs e) await Task.Run(() => CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { + string fileName = Name.Text; + if (fileName == "") + { + fileName = await FileHelper.GetSequentialNewWhiteboardFilename(); + } + try { - if (await FileHelper.IsFilePresent(Name.Text)) + if (Name.Text != "" && await FileHelper.IsFilePresent(fileName)) { Ring.Visibility = Visibility.Collapsed; Content.Opacity = 1; @@ -58,7 +64,7 @@ await Task.Run(() => Status.Text = "Invalid project name"; return; } - bool success = await FileHelper.CreateProjectAsync(Name.Text, UIHelper.IndexToColor(Backgrounds.SelectedIndex).Color); + bool success = await FileHelper.CreateProjectAsync(fileName, UIHelper.IndexToColor(Backgrounds.SelectedIndex).Color); if(!success) { Ring.Visibility = Visibility.Collapsed;