summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2012-06-27 22:49:23 +0000
committerIan C <ianc@noddybox.co.uk>2012-06-27 22:49:23 +0000
commit2c39a1ef8c13bd8d0321f79b0ce2850d0a590b45 (patch)
tree72ba36255d4aabe03c3d063f501248cc4680c79c
parent1c036de8e527038f00b7ff07fc1ef4b80f23a846 (diff)
Done Save, Load and Delete dialogs.
-rw-r--r--Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml74
-rw-r--r--Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml.cs182
-rw-r--r--Noddybox.WindowsPhone.Silverlight/FileDialogEvent.cs41
-rw-r--r--Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml79
-rw-r--r--Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml.cs169
-rw-r--r--Noddybox.WindowsPhone.Silverlight/Noddybox.WindowsPhone.Silverlight.csproj15
-rw-r--r--Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml43
-rw-r--r--Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml.cs70
-rw-r--r--Noddybox.WindowsPhone.Silverlight/Themes/generic.xaml17
-rw-r--r--Noddybox.WindowsPhone.Silverlight/ViewModels/FileDialogViewModel.cs35
-rw-r--r--Noddybox.WindowsPhone.Silverlight/ViewModels/FileInfo.cs27
-rw-r--r--Noddybox.WindowsPhone.Test/App.xaml.cs19
-rw-r--r--Noddybox.WindowsPhone.Test/MainPage.xaml3
-rw-r--r--Noddybox.WindowsPhone.Test/MainPage.xaml.cs5
14 files changed, 742 insertions, 37 deletions
diff --git a/Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml b/Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml
new file mode 100644
index 0000000..3d09e02
--- /dev/null
+++ b/Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml
@@ -0,0 +1,74 @@
+<!-- This file is part of the Noddybox.WindowsPhone C# suite.
+
+ Noddybox.Emulation is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Noddybox.Emulation is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Noddybox.Emulation. If not, see<http://www.gnu.org/licenses/> .
+
+ Copyright (c) 2012 Ian Cowburn
+-->
+<UserControl x:Class="Noddybox.WindowsPhone.Silverlight.DeleteDialog"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:conv="clr-namespace:Noddybox.WindowsPhone.Silverlight.Converters"
+ mc:Ignorable="d"
+ FontFamily="{StaticResource PhoneFontFamilyNormal}"
+ FontSize="{StaticResource PhoneFontSizeNormal}"
+ Foreground="{StaticResource PhoneForegroundBrush}"
+ d:DesignHeight="480" d:DesignWidth="480">
+
+ <UserControl.Resources>
+ <conv:ConvertFolderFlag x:Key="ConvertFolderFlag" />
+ </UserControl.Resources>
+
+ <Grid x:Name="LayoutRoot">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="*" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ </Grid.RowDefinitions>
+ <TextBlock x:Name="titleText" Grid.Row="0"
+ Margin="4" FontWeight="Bold"
+ HorizontalAlignment="Center"/>
+ <TextBlock Grid.Row="1" Grid.ColumnSpan="2"
+ Text="{Binding Path, Mode=OneWay}" Margin="4"/>
+ <ListBox x:Name="fileList" Grid.Row="2"
+ ItemsSource="{Binding FileList, Mode=OneWay}"
+ SelectionMode="Multiple"
+ SelectionChanged="OnFileListSelection">
+ <ListBox.ItemTemplate>
+ <DataTemplate>
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="32" />
+ <ColumnDefinition Width="32" />
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+ <Image Grid.Column="0"
+ Source="{Binding IsFolder, Mode=OneWay, Converter={StaticResource ConvertFolderFlag}}"
+ VerticalAlignment="Center"
+ HorizontalAlignment="Center"
+ Height="32"/>
+ <TextBlock Grid.Column="2"
+ Text="{Binding Name, Mode=OneWay}" />
+ </Grid>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ </ListBox>
+ <Button x:Name="deleteButton" Grid.Row="3" Grid.Column="0" Content="Delete"
+ IsEnabled="False"
+ Click="OnDeleteButton"/>
+ </Grid>
+</UserControl>
diff --git a/Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml.cs b/Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml.cs
new file mode 100644
index 0000000..77fe1b4
--- /dev/null
+++ b/Noddybox.WindowsPhone.Silverlight/DeleteDialog.xaml.cs
@@ -0,0 +1,182 @@
+// This file is part of the Noddybox.WindowsPhone C# suite.
+//
+// Noddybox.Emulation is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Noddybox.Emulation is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Noddybox.Emulation. If not, see <http://www.gnu.org/licenses/>.
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using Noddybox.WindowsPhone.Silverlight.ViewModels;
+using System.ComponentModel;
+using System.IO.IsolatedStorage;
+
+namespace Noddybox.WindowsPhone.Silverlight
+{
+ public partial class DeleteDialog : UserControl
+ {
+ #region Private data
+
+ private FileDialogViewModel model;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Construct a save dialog.
+ /// </summary>
+ public DeleteDialog()
+ {
+ InitializeComponent();
+
+ if (!DesignerProperties.IsInDesignTool)
+ {
+ model = new FileDialogViewModel("/");
+ DataContext = model;
+ }
+ }
+
+ #endregion
+
+ #region Properties
+
+ private static void OnDummyDependency(DependencyObject d, DependencyPropertyChangedEventArgs e) {}
+
+ public static readonly DependencyProperty StartPathProperty =
+ DependencyProperty.Register("StartPath", typeof(string), typeof(DeleteDialog),
+ new PropertyMetadata("StartPath", new PropertyChangedCallback(DeleteDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty DeleteButtonTextProperty =
+ DependencyProperty.Register("OkButtonText", typeof(string), typeof(DeleteDialog),
+ new PropertyMetadata("DeleteButtonText", new PropertyChangedCallback(DeleteDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty TitleTextProperty =
+ DependencyProperty.Register("TitleText", typeof(string), typeof(DeleteDialog),
+ new PropertyMetadata("TitleText", new PropertyChangedCallback(DeleteDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty FileMaskProperty =
+ DependencyProperty.Register("FileMask", typeof(string), typeof(DeleteDialog),
+ new PropertyMetadata("FileMask", new PropertyChangedCallback(DeleteDialog.OnDummyDependency)));
+
+ /// <summary>
+ /// Set the file mask.
+ /// </summary>
+ public string FileMask
+ {
+ get {return (string)GetValue(FileMaskProperty);}
+ set
+ {
+ SetValue(FileMaskProperty, value);
+
+ if (!DesignerProperties.IsInDesignTool)
+ {
+ model.Mask = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Set the start path
+ /// </summary>
+ public string StartPath
+ {
+ get {return (string)GetValue(StartPathProperty);}
+ set
+ {
+ SetValue(StartPathProperty, value);
+
+ if (!DesignerProperties.IsInDesignTool)
+ {
+ model.Path = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Set the contents of the Delete button.
+ /// </summary>
+ public string DeleteButtonText
+ {
+ get {return (string)GetValue(DeleteButtonTextProperty);}
+ set
+ {
+ SetValue(DeleteButtonTextProperty, value);
+ deleteButton.Content = value;
+ }
+ }
+
+ /// <summary>
+ /// Set the contents of the Title bar.
+ /// </summary>
+ public string TitleText
+ {
+ get {return (string)GetValue(TitleTextProperty);}
+ set
+ {
+ SetValue(TitleTextProperty, value);
+ titleText.Text = value;
+ }
+ }
+
+ #endregion
+
+ #region Event handlers
+
+ private void OnDeleteButton(object sender, RoutedEventArgs e)
+ {
+ IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
+
+ foreach (FileInfo info in fileList.SelectedItems)
+ {
+ iso.DeleteFile(info.Path);
+ }
+
+ model.RefreshFileList();
+ deleteButton.IsEnabled = false;
+ }
+
+ private void OnFileListSelection(object sender, SelectionChangedEventArgs e)
+ {
+ if (e.AddedItems.Count > 0)
+ {
+ foreach (FileInfo info in e.AddedItems)
+ {
+ if (info.IsFolder)
+ {
+ model.FileSelected(info);
+ deleteButton.IsEnabled = false;
+ return;
+ }
+ }
+
+ deleteButton.IsEnabled = true;
+ }
+ else
+ {
+ deleteButton.IsEnabled = false;
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/Noddybox.WindowsPhone.Silverlight/FileDialogEvent.cs b/Noddybox.WindowsPhone.Silverlight/FileDialogEvent.cs
new file mode 100644
index 0000000..5533763
--- /dev/null
+++ b/Noddybox.WindowsPhone.Silverlight/FileDialogEvent.cs
@@ -0,0 +1,41 @@
+// This file is part of the Noddybox.WindowsPhone C# suite.
+//
+// Noddybox.Emulation is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Noddybox.Emulation is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Noddybox.Emulation. If not, see <http://www.gnu.org/licenses/>.
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+
+namespace Noddybox.WindowsPhone.Silverlight
+{
+ /// <summary>
+ /// Handles events from the file dialogs
+ /// </summary>
+ public class FileDialogEvent : EventArgs
+ {
+ /// <summary>
+ /// The full path of the selected or entered file.
+ /// </summary>
+ public string Path {get;set;}
+ }
+}
diff --git a/Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml b/Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml
new file mode 100644
index 0000000..e720d9c
--- /dev/null
+++ b/Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml
@@ -0,0 +1,79 @@
+<!-- This file is part of the Noddybox.WindowsPhone C# suite.
+
+ Noddybox.Emulation is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Noddybox.Emulation is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Noddybox.Emulation. If not, see<http://www.gnu.org/licenses/> .
+
+ Copyright (c) 2012 Ian Cowburn
+-->
+<UserControl x:Class="Noddybox.WindowsPhone.Silverlight.LoadDialog"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:conv="clr-namespace:Noddybox.WindowsPhone.Silverlight.Converters"
+ mc:Ignorable="d"
+ FontFamily="{StaticResource PhoneFontFamilyNormal}"
+ FontSize="{StaticResource PhoneFontSizeNormal}"
+ Foreground="{StaticResource PhoneForegroundBrush}"
+ d:DesignHeight="480" d:DesignWidth="480">
+
+ <UserControl.Resources>
+ <conv:ConvertFolderFlag x:Key="ConvertFolderFlag" />
+ </UserControl.Resources>
+
+ <Grid x:Name="LayoutRoot">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="*" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ </Grid.RowDefinitions>
+ <TextBlock x:Name="titleText" Grid.Row="0"
+ Margin="4" FontWeight="Bold"
+ HorizontalAlignment="Center"/>
+ <TextBlock Grid.Row="1" Grid.ColumnSpan="2"
+ Text="{Binding Path, Mode=OneWay}" Margin="4"/>
+ <ListBox x:Name="fileList" Grid.Row="2"
+ ItemsSource="{Binding FileList, Mode=OneWay}"
+ SelectionMode="Single"
+ SelectionChanged="OnFileListSelection">
+ <ListBox.ItemTemplate>
+ <DataTemplate>
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="32" />
+ <ColumnDefinition Width="32" />
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+ <Image Grid.Column="0"
+ Source="{Binding IsFolder, Mode=OneWay, Converter={StaticResource ConvertFolderFlag}}"
+ VerticalAlignment="Center"
+ HorizontalAlignment="Center"
+ Height="32"/>
+ <TextBlock Grid.Column="2"
+ Text="{Binding Name, Mode=OneWay}" />
+ </Grid>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ </ListBox>
+ <TextBox x:Name="fileName" Grid.Row="3"
+ Text="{Binding Filename, Mode=OneWay}"
+ IsEnabled="False"
+ InputScope="FileName"
+ TabIndex="-1" />
+ <Button x:Name="okButton" Grid.Row="4" Grid.Column="0" Content="Ok"
+ IsEnabled="{Binding IsFileSelected, Mode=OneWay}"
+ Click="OnOKButton"/>
+ </Grid>
+</UserControl>
diff --git a/Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml.cs b/Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml.cs
new file mode 100644
index 0000000..8524e7b
--- /dev/null
+++ b/Noddybox.WindowsPhone.Silverlight/LoadDialog.xaml.cs
@@ -0,0 +1,169 @@
+// This file is part of the Noddybox.WindowsPhone C# suite.
+//
+// Noddybox.Emulation is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Noddybox.Emulation is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Noddybox.Emulation. If not, see <http://www.gnu.org/licenses/>.
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using Noddybox.WindowsPhone.Silverlight.ViewModels;
+using System.ComponentModel;
+
+namespace Noddybox.WindowsPhone.Silverlight
+{
+ public partial class LoadDialog : UserControl
+ {
+ #region Private data
+
+ private FileDialogViewModel model;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Construct a save dialog.
+ /// </summary>
+ public LoadDialog()
+ {
+ InitializeComponent();
+
+ if (!DesignerProperties.IsInDesignTool)
+ {
+ model = new FileDialogViewModel("/");
+ DataContext = model;
+ }
+ }
+
+ #endregion
+
+ #region Properties
+
+ private static void OnDummyDependency(DependencyObject d, DependencyPropertyChangedEventArgs e) {}
+
+ public static readonly DependencyProperty StartPathProperty =
+ DependencyProperty.Register("StartPath", typeof(string), typeof(LoadDialog),
+ new PropertyMetadata("StartPath", new PropertyChangedCallback(LoadDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty OkButtonTextProperty =
+ DependencyProperty.Register("OkButtonText", typeof(string), typeof(LoadDialog),
+ new PropertyMetadata("OkButtonText", new PropertyChangedCallback(LoadDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty TitleTextProperty =
+ DependencyProperty.Register("TitleText", typeof(string), typeof(LoadDialog),
+ new PropertyMetadata("TitleText", new PropertyChangedCallback(LoadDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty FileMaskProperty =
+ DependencyProperty.Register("FileMask", typeof(string), typeof(LoadDialog),
+ new PropertyMetadata("FileMask", new PropertyChangedCallback(LoadDialog.OnDummyDependency)));
+
+ public delegate void FileDialogEventHandler(object sender, FileDialogEvent e);
+
+ /// <summary>
+ /// Event for users to subscribe to the pressing of the OK button.
+ /// </summary>
+ public event FileDialogEventHandler OkPressed;
+
+ /// <summary>
+ /// Set the file mask.
+ /// </summary>
+ public string FileMask
+ {
+ get {return (string)GetValue(FileMaskProperty);}
+ set
+ {
+ SetValue(FileMaskProperty, value);
+
+ if (!DesignerProperties.IsInDesignTool)
+ {
+ model.Mask = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Set the start path
+ /// </summary>
+ public string StartPath
+ {
+ get {return (string)GetValue(StartPathProperty);}
+ set
+ {
+ SetValue(StartPathProperty, value);
+
+ if (!DesignerProperties.IsInDesignTool)
+ {
+ model.Path = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Set the contents of the OK button.
+ /// </summary>
+ public string OkButtonText
+ {
+ get {return (string)GetValue(OkButtonTextProperty);}
+ set
+ {
+ SetValue(OkButtonTextProperty, value);
+ okButton.Content = value;
+ }
+ }
+
+ /// <summary>
+ /// Set the contents of the Title bar.
+ /// </summary>
+ public string TitleText
+ {
+ get {return (string)GetValue(TitleTextProperty);}
+ set
+ {
+ SetValue(TitleTextProperty, value);
+ titleText.Text = value;
+ }
+ }
+
+ #endregion
+
+ #region Event handlers
+
+ private void OnOKButton(object sender, RoutedEventArgs e)
+ {
+ if (OkPressed != null)
+ {
+ OkPressed(this, new FileDialogEvent() {Path = model.SelectedFile});
+ }
+ }
+
+ private void OnFileListSelection(object sender, SelectionChangedEventArgs e)
+ {
+ if (e.AddedItems.Count > 0)
+ {
+ model.FileSelected((FileInfo)e.AddedItems[0]);
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/Noddybox.WindowsPhone.Silverlight/Noddybox.WindowsPhone.Silverlight.csproj b/Noddybox.WindowsPhone.Silverlight/Noddybox.WindowsPhone.Silverlight.csproj
index 1726553..e4774d3 100644
--- a/Noddybox.WindowsPhone.Silverlight/Noddybox.WindowsPhone.Silverlight.csproj
+++ b/Noddybox.WindowsPhone.Silverlight/Noddybox.WindowsPhone.Silverlight.csproj
@@ -52,6 +52,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\ConvertFolderFlag.cs" />
+ <Compile Include="DeleteDialog.xaml.cs">
+ <DependentUpon>DeleteDialog.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="FileDialogEvent.cs" />
+ <Compile Include="LoadDialog.xaml.cs">
+ <DependentUpon>LoadDialog.xaml</DependentUpon>
+ </Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SaveDialog.xaml.cs">
<DependentUpon>SaveDialog.xaml</DependentUpon>
@@ -65,6 +72,14 @@
<Compile Include="ViewModels\FileDialogViewModel.cs" />
</ItemGroup>
<ItemGroup>
+ <Page Include="DeleteDialog.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
+ <Page Include="LoadDialog.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="SaveDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
diff --git a/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml b/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml
index ef45e68..708d8ef 100644
--- a/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml
+++ b/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml
@@ -1,4 +1,21 @@
-<UserControl x:Class="Noddybox.WindowsPhone.Silverlight.SaveDialog"
+<!-- This file is part of the Noddybox.WindowsPhone C# suite.
+
+ Noddybox.Emulation is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Noddybox.Emulation is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Noddybox.Emulation. If not, see<http://www.gnu.org/licenses/> .
+
+ Copyright (c) 2012 Ian Cowburn
+-->
+<UserControl x:Class="Noddybox.WindowsPhone.Silverlight.SaveDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -16,17 +33,17 @@
<Grid x:Name="LayoutRoot" >
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="1*" />
- <ColumnDefinition Width="1*" />
- </Grid.ColumnDefinitions>
- <TextBlock Grid.Row="0" Grid.ColumnSpan="2"
+ <TextBlock x:Name="titleText" Grid.Row="0"
+ Margin="4" FontWeight="Bold"
+ HorizontalAlignment="Center"/>
+ <TextBlock Grid.Row="1" Grid.ColumnSpan="2"
Text="{Binding Path, Mode=OneWay}" Margin="4"/>
- <ListBox x:Name="fileList" Grid.Row="1" Grid.ColumnSpan="2"
+ <ListBox x:Name="fileList" Grid.Row="2"
ItemsSource="{Binding FileList, Mode=OneWay}"
SelectionMode="Single"
SelectionChanged="OnFileListSelection">
@@ -41,19 +58,21 @@
<Image Grid.Column="0"
Source="{Binding IsFolder, Mode=OneWay, Converter={StaticResource ConvertFolderFlag}}"
VerticalAlignment="Center"
- HorizontalAlignment="Center" />
+ HorizontalAlignment="Center"
+ Height="32"/>
<TextBlock Grid.Column="2"
Text="{Binding Name, Mode=OneWay}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
- <TextBox x:Name="fileName" Grid.Row="2" Grid.ColumnSpan="2"
+ <TextBox x:Name="fileName" Grid.Row="3"
+ Text="{Binding Filename, Mode=TwoWay}"
+ InputScope="FileName"
+ TabIndex="-1"
KeyUp="OnFilenameKeyUp"/>
- <Button x:Name="okButton" Grid.Row="3" Grid.Column="0" Content="Ok"
+ <Button x:Name="okButton" Grid.Row="4" Grid.Column="0" Content="Ok"
IsEnabled="{Binding IsFileSelected, Mode=OneWay}"
Click="OnOKButton"/>
- <Button x:Name="cancelButton" Grid.Row="3" Grid.Column="1" Content="Cancel"
- Click="OnCancelButton"/>
</Grid>
</UserControl>
diff --git a/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml.cs b/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml.cs
index 8df7b73..8d8e515 100644
--- a/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml.cs
+++ b/Noddybox.WindowsPhone.Silverlight/SaveDialog.xaml.cs
@@ -62,16 +62,46 @@ namespace Noddybox.WindowsPhone.Silverlight
#region Properties
+ private static void OnDummyDependency(DependencyObject d, DependencyPropertyChangedEventArgs e) {}
+
public static readonly DependencyProperty StartPathProperty =
- DependencyProperty.Register("StartPath", typeof(string), typeof(SaveDialog), null);
- // new PropertyMetadata("StartPath", new PropertyChangedCallback(SaveDialog.OnStartPathChanged)));
+ DependencyProperty.Register("StartPath", typeof(string), typeof(SaveDialog),
+ new PropertyMetadata("StartPath", new PropertyChangedCallback(SaveDialog.OnDummyDependency)));
public static readonly DependencyProperty OkButtonTextProperty =
- DependencyProperty.Register("OkButtonText", typeof(string), typeof(SaveDialog), null);
- // new PropertyMetadata("StartPath", new PropertyChangedCallback(SaveDialog.OnStartPathChanged)));
+ DependencyProperty.Register("OkButtonText", typeof(string), typeof(SaveDialog),
+ new PropertyMetadata("OkButtonText", new PropertyChangedCallback(SaveDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty TitleTextProperty =
+ DependencyProperty.Register("TitleText", typeof(string), typeof(SaveDialog),
+ new PropertyMetadata("TitleText", new PropertyChangedCallback(SaveDialog.OnDummyDependency)));
+
+ public static readonly DependencyProperty FileMaskProperty =
+ DependencyProperty.Register("FileMask", typeof(string), typeof(SaveDialog),
+ new PropertyMetadata("FileMask", new PropertyChangedCallback(SaveDialog.OnDummyDependency)));
+
+ public delegate void FileDialogEventHandler(object sender, FileDialogEvent e);
+
+ /// <summary>
+ /// Event for users to subscribe to the pressing of the OK button.
+ /// </summary>
+ public event FileDialogEventHandler OkPressed;
- private static void OnStartPathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ /// <summary>
+ /// Set the file mask.
+ /// </summary>
+ public string FileMask
{
+ get {return (string)GetValue(FileMaskProperty);}
+ set
+ {
+ SetValue(FileMaskProperty, value);
+
+ if (!DesignerProperties.IsInDesignTool)
+ {
+ model.Mask = value;
+ }
+ }
}
/// <summary>
@@ -79,8 +109,11 @@ namespace Noddybox.WindowsPhone.Silverlight
/// </summary>
public string StartPath
{
- set
+ get {return (string)GetValue(StartPathProperty);}
+ set
{
+ SetValue(StartPathProperty, value);
+
if (!DesignerProperties.IsInDesignTool)
{
model.Path = value;
@@ -93,17 +126,25 @@ namespace Noddybox.WindowsPhone.Silverlight
/// </summary>
public string OkButtonText
{
- set
+ get {return (string)GetValue(OkButtonTextProperty);}
+ set
{
+ SetValue(OkButtonTextProperty, value);
+ okButton.Content = value;
}
}
/// <summary>
- /// Set the contents of the Cancel button.
+ /// Set the contents of the Title bar.
/// </summary>
- public string CancelButtonText
+ public string TitleText
{
- set {cancelButton.Content = value;}
+ get {return (string)GetValue(TitleTextProperty);}
+ set
+ {
+ SetValue(TitleTextProperty, value);
+ titleText.Text = value;
+ }
}
#endregion
@@ -112,15 +153,16 @@ namespace Noddybox.WindowsPhone.Silverlight
private void OnFilenameKeyUp(object sender, KeyEventArgs e)
{
+ fileList.SelectedItem = null;
model.Filename = fileName.Text;
}
private void OnOKButton(object sender, RoutedEventArgs e)
{
- }
-
- private void OnCancelButton(object sender, RoutedEventArgs e)
- {
+ if (OkPressed != null)
+ {
+ OkPressed(this, new FileDialogEvent() {Path = model.SelectedFile});
+ }
}
private void OnFileListSelection(object sender, SelectionChangedEventArgs e)
diff --git a/Noddybox.WindowsPhone.Silverlight/Themes/generic.xaml b/Noddybox.WindowsPhone.Silverlight/Themes/generic.xaml
index 74c1d9a..5ac753a 100644
--- a/Noddybox.WindowsPhone.Silverlight/Themes/generic.xaml
+++ b/Noddybox.WindowsPhone.Silverlight/Themes/generic.xaml
@@ -19,10 +19,23 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
- xmlns:local="clr-namespace:Silverlight">
+ xmlns:local="clr-namespace:Noddybox.WindowsPhone.Silverlight">
<Style TargetType="local:SaveDialog">
<Setter Property="StartPath" Value="/" />
<Setter Property="OkButtonText" Value="OK" />
- <Setter Property="CancelButtonText" Value="Cancel" />
+ <Setter Property="TitleText" Value="Select File To Save" />
+ <Setter Property="FileMask" Value="*" />
+ </Style>
+ <Style TargetType="local:LoadDialog">
+ <Setter Property="StartPath" Value="/" />
+ <Setter Property="OkButtonText" Value="OK" />
+ <Setter Property="TitleText" Value="Select File To Load" />
+ <Setter Property="FileMask" Value="*" />
+ </Style>
+ <Style TargetType="local:DeleteDialog">
+ <Setter Property="StartPath" Value="/" />
+ <Setter Property="DeleteButtonText" Value="Delete" />
+ <Setter Property="TitleText" Value="Select Files To Delete" />
+ <Setter Property="FileMask" Value="*" />
</Style>
</ResourceDictionary> \ No newline at end of file
diff --git a/Noddybox.WindowsPhone.Silverlight/ViewModels/FileDialogViewModel.cs b/Noddybox.WindowsPhone.Silverlight/ViewModels/FileDialogViewModel.cs
index afc8e63..0dd7e55 100644
--- a/Noddybox.WindowsPhone.Silverlight/ViewModels/FileDialogViewModel.cs
+++ b/Noddybox.WindowsPhone.Silverlight/ViewModels/FileDialogViewModel.cs
@@ -39,6 +39,7 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels
private string filename;
private string path;
private List<FileInfo> fileList;
+ private string mask;
#endregion
@@ -46,7 +47,7 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels
private void GetFileList()
{
- FileList = FileInfo.GetFiles(path);
+ FileList = FileInfo.GetFiles(path, Mask);
}
#endregion
@@ -94,11 +95,42 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels
}
}
+ /// <summary>
+ /// The file mask to use.
+ /// </summary>
+ public string Mask
+ {
+ get {return mask;}
+ set
+ {
+ SetValue(ref mask, value, "Mask");
+ Filename = String.Empty;
+ GetFileList();
+ }
+ }
+
#endregion
#region Public members
/// <summary>
+ /// Get the path of the selected file.
+ /// </summary>
+ public string SelectedFile
+ {
+ get {return path + Filename;}
+ }
+
+ /// <summary>
+ /// Refresh the current directory listing.
+ /// </summary>
+ public void RefreshFileList()
+ {
+ Filename = String.Empty;
+ GetFileList();
+ }
+
+ /// <summary>
/// Called when a file is selected.
/// </summary>
/// <param name="file">The selected file.</param>
@@ -149,6 +181,7 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels
/// <param name="startPath">The path to start selecting from.</param>
public FileDialogViewModel(string startPath)
{
+ Mask = "*";
path = startPath;
Filename = String.Empty;
GetFileList();
diff --git a/Noddybox.WindowsPhone.Silverlight/ViewModels/FileInfo.cs b/Noddybox.WindowsPhone.Silverlight/ViewModels/FileInfo.cs
index 3c680c7..9adb0f3 100644
--- a/Noddybox.WindowsPhone.Silverlight/ViewModels/FileInfo.cs
+++ b/Noddybox.WindowsPhone.Silverlight/ViewModels/FileInfo.cs
@@ -27,6 +27,7 @@ using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
namespace Noddybox.WindowsPhone.Silverlight.ViewModels
{
@@ -46,14 +47,20 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels
public string Name {get; private set;}
/// <summary>
+ /// The full path of the file.
+ /// </summary>
+ public string Path {get; private set;}
+
+ /// <summary>
/// Constructor.
/// </summary>
/// <param name="isFolder">Whether the file is a folder.</param>
/// <param name="name">The file name.</param>
- public FileInfo (bool isFolder, string name)
+ public FileInfo (bool isFolder, string name, string path)
{
IsFolder = isFolder;
Name = name;
+ Path = path;
}
/// <summary>
@@ -61,7 +68,7 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels
/// </summary>
/// <param name="folder">The folder to search, which must end with a "/". Uses root folder is empty or null.</param>
/// <returns>A list of the files and directories. A ".." directory is added if not the root folder.</returns>
- public static List<FileInfo> GetFiles(string folder)
+ public static List<FileInfo> GetFiles(string folder, string mask)
{
bool root = false;
List<FileInfo> flist = new List<FileInfo>();
@@ -79,19 +86,25 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels
if (!root)
{
- flist.Add(new FileInfo(true, ".."));
+ flist.Add(new FileInfo(true, "..", folder + ".."));
}
IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
- foreach (string s in iso.GetDirectoryNames(folder + "*"))
+ List<string> folders = new List<string>(iso.GetDirectoryNames(folder + "*"));
+ List<string> files = new List<string>(iso.GetFileNames(folder + mask));
+
+ folders.Sort();
+ files.Sort();
+
+ foreach (string s in folders)
{
- flist.Add(new FileInfo(true, s));
+ flist.Add(new FileInfo(true, s, folder + s));
}
- foreach (string s in iso.GetFileNames(folder + "*"))
+ foreach (string s in files)
{
- flist.Add(new FileInfo(false, s));
+ flist.Add(new FileInfo(false, s, folder + s));
}
return flist;
diff --git a/Noddybox.WindowsPhone.Test/App.xaml.cs b/Noddybox.WindowsPhone.Test/App.xaml.cs
index 139cae7..7fd87f0 100644
--- a/Noddybox.WindowsPhone.Test/App.xaml.cs
+++ b/Noddybox.WindowsPhone.Test/App.xaml.cs
@@ -12,6 +12,7 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
+using System.IO.IsolatedStorage;
namespace Noddybox.WindowsPhone.Test
{
@@ -57,6 +58,24 @@ namespace Noddybox.WindowsPhone.Test
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
+ IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
+
+ iso.CreateDirectory("/dir1");
+ iso.CreateDirectory("/dir1/sub1");
+ iso.CreateDirectory("/dir2");
+
+ for(int f = 1; f < 100; f++)
+ {
+ using (var s = iso.CreateFile(String.Format("/file{0}.{1}", f, (f%2) == 1 ? "txt":"bat")))
+ {
+ s.WriteByte(1);
+ }
+
+ using (var s = iso.CreateFile(String.Format("/dir1/file_foobar{0}.{1}", f, (f%2) == 1 ? "TXT":"bat")))
+ {
+ s.WriteByte(1);
+ }
+ }
}
// Code to execute when the application is launching (eg, from Start)
diff --git a/Noddybox.WindowsPhone.Test/MainPage.xaml b/Noddybox.WindowsPhone.Test/MainPage.xaml
index 8e80897..5d0d3fe 100644
--- a/Noddybox.WindowsPhone.Test/MainPage.xaml
+++ b/Noddybox.WindowsPhone.Test/MainPage.xaml
@@ -29,7 +29,8 @@
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
- <noddybox:SaveDialog />
+ <!--<noddybox:LoadDialog TitleText="Select File to Load" OkPressed="SaveDialog_OkPressed"/>-->
+ <noddybox:DeleteDialog TitleText="Select Files to Delete" />
</Grid>
</Grid>
diff --git a/Noddybox.WindowsPhone.Test/MainPage.xaml.cs b/Noddybox.WindowsPhone.Test/MainPage.xaml.cs
index 726cedc..7583388 100644
--- a/Noddybox.WindowsPhone.Test/MainPage.xaml.cs
+++ b/Noddybox.WindowsPhone.Test/MainPage.xaml.cs
@@ -20,5 +20,10 @@ namespace Noddybox.WindowsPhone.Test
{
InitializeComponent();
}
+
+ private void SaveDialog_OkPressed(object sender, Silverlight.FileDialogEvent e)
+ {
+ MessageBox.Show(e.Path);
+ }
}
} \ No newline at end of file