diff options
| author | Ian C <ianc@noddybox.co.uk> | 2012-06-27 22:49:23 +0000 | 
|---|---|---|
| committer | Ian C <ianc@noddybox.co.uk> | 2012-06-27 22:49:23 +0000 | 
| commit | 2c39a1ef8c13bd8d0321f79b0ce2850d0a590b45 (patch) | |
| tree | 72ba36255d4aabe03c3d063f501248cc4680c79c /Noddybox.WindowsPhone.Silverlight/ViewModels | |
| parent | 1c036de8e527038f00b7ff07fc1ef4b80f23a846 (diff) | |
Done Save, Load and Delete dialogs.
Diffstat (limited to 'Noddybox.WindowsPhone.Silverlight/ViewModels')
| -rw-r--r-- | Noddybox.WindowsPhone.Silverlight/ViewModels/FileDialogViewModel.cs | 35 | ||||
| -rw-r--r-- | Noddybox.WindowsPhone.Silverlight/ViewModels/FileInfo.cs | 27 | 
2 files changed, 54 insertions, 8 deletions
| 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;
 | 
