From 2c39a1ef8c13bd8d0321f79b0ce2850d0a590b45 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 27 Jun 2012 22:49:23 +0000 Subject: Done Save, Load and Delete dialogs. --- .../ViewModels/FileDialogViewModel.cs | 35 +++++++++++++++++++++- .../ViewModels/FileInfo.cs | 27 ++++++++++++----- 2 files changed, 54 insertions(+), 8 deletions(-) (limited to 'Noddybox.WindowsPhone.Silverlight/ViewModels') 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 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,10 +95,41 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels } } + /// + /// The file mask to use. + /// + public string Mask + { + get {return mask;} + set + { + SetValue(ref mask, value, "Mask"); + Filename = String.Empty; + GetFileList(); + } + } + #endregion #region Public members + /// + /// Get the path of the selected file. + /// + public string SelectedFile + { + get {return path + Filename;} + } + + /// + /// Refresh the current directory listing. + /// + public void RefreshFileList() + { + Filename = String.Empty; + GetFileList(); + } + /// /// Called when a file is selected. /// @@ -149,6 +181,7 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels /// The path to start selecting from. 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 { @@ -45,15 +46,21 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels /// public string Name {get; private set;} + /// + /// The full path of the file. + /// + public string Path {get; private set;} + /// /// Constructor. /// /// Whether the file is a folder. /// The file name. - public FileInfo (bool isFolder, string name) + public FileInfo (bool isFolder, string name, string path) { IsFolder = isFolder; Name = name; + Path = path; } /// @@ -61,7 +68,7 @@ namespace Noddybox.WindowsPhone.Silverlight.ViewModels /// /// The folder to search, which must end with a "/". Uses root folder is empty or null. /// A list of the files and directories. A ".." directory is added if not the root folder. - public static List GetFiles(string folder) + public static List GetFiles(string folder, string mask) { bool root = false; List flist = new List(); @@ -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 folders = new List(iso.GetDirectoryNames(folder + "*")); + List files = new List(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; -- cgit v1.2.3