Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions FlowBoard/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Windows.Graphics.Display;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;

namespace FlowBoard.Helpers
{
Expand Down Expand Up @@ -148,6 +149,24 @@ public static async Task<bool> IsFilePresent(string fileName)
return item != null;
}

public static async Task<string> 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<bool> SaveProjectAsync(Color canvasColor, InkCanvas inkCanvas, ProjectClass project, string PreviewName, bool IsSilent)
{
Expand Down
4 changes: 2 additions & 2 deletions FlowBoard/NewProjectPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
<TextBlock FontSize="24" FontWeight="SemiBold" Margin="0, 0, 0, 12">New Project</TextBlock>
<TextBlock FontWeight="SemiBold">Project Name:</TextBlock>
<toolkit:DropShadowPanel ShadowOpacity="0.4" OffsetX="4" CornerRadius="8" Margin="0, 12, 0, 16" OffsetY="4">
<TextBox x:Name="Name" Height="20" Width="340" PlaceholderText="New Project" Style="{ThemeResource GlowTextBox}"/>
<TextBox x:Name="Name" Height="20" Width="340" PlaceholderText="New Whiteboard" Style="{ThemeResource GlowTextBox}"/>
</toolkit:DropShadowPanel>
<TextBlock FontWeight="SemiBold">Canvas Background:</TextBlock>
<controls:BackgroundSelectorControl x:Name="Backgrounds" SelectedIndex="0" Margin="8, 12, 0, 12"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
<TextBlock x:Name="Status" Foreground="Red" Width="250" TextWrapping="WrapWholeWords" Margin="0, 0, 4, 0"/>
<Button IsEnabled="{x:Bind helpers:UIHelper.TextToBool(Name.Text), Mode=OneWay}" Width="80" Click="CreateProject_Click">Create</Button>
<Button Width="80" Click="CreateProject_Click">Create</Button>
</StackPanel>
</StackPanel>
</Grid>
Expand Down
10 changes: 8 additions & 2 deletions FlowBoard/NewProjectPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down