Fix incorrect check in Selective Sync that prevented folder changes to propagate...
[pithos-ms-client] / trunk / Pithos.Client.WPF / FileProperties / FilePropertiesViewModel.cs
index dc0f098..fb75da7 100644 (file)
  * -----------------------------------------------------------------------
  */
 #endregion
-using System.Collections;
-using System.Collections.Concurrent;
+
 using System.Collections.ObjectModel;
-using System.Collections.Specialized;
 using System.ComponentModel.Composition;
-using System.Diagnostics;
 using System.Diagnostics.Contracts;
 using System.Drawing;
 using System.IO;
@@ -55,7 +52,6 @@ using System.Windows.Interop;
 using System.Windows.Media.Imaging;
 using Caliburn.Micro;
 using Pithos.Client.WPF.FileProperties;
-using Pithos.Client.WPF.Properties;
 using Pithos.Core;
 using Pithos.Interfaces;
 using Pithos.Network;
@@ -63,9 +59,7 @@ using Pithos.Network;
 namespace Pithos.Client.WPF
 {
     using System;
-    using System.Collections.Generic;
     using System.Linq;
-    using System.Text;
 
     /// <summary>
     /// TODO: Update summary.
@@ -272,62 +266,51 @@ namespace Pithos.Client.WPF
                 NotifyOfPropertyChange(()=>SynchStatus);
             }
         }
-
-        private string _permissionName;
-        public string PermissionName
-        {
-            get { return _permissionName; }
-            set
-            {
-                _permissionName = value;
-                NotifyOfPropertyChange(()=>PermissionName);
-            }
-        }
-
+        
         private Permission _currentPermission;
         public Permission CurrentPermission
         {
             get { return _currentPermission; }
             set
-            {
-                _currentPermission = value;
+            {                
+                _currentPermission = (value==null)?new Permission() : value.Clone();
+                _currentPermission.PropertyChanged += (o, e) => NotifyOfPropertyChange(() => CanAddPermission);
+
                 NotifyOfPropertyChange(()=>CurrentPermission);
+                NotifyOfPropertyChange(() => CanAddPermission);
             }
         }
 
-
-        private bool _permissionRead;
-        public bool PermissionRead
+        public bool CanAddPermission
         {
-            get { return _permissionRead; }
-            set
-            {
-                _permissionRead = value;
-                NotifyOfPropertyChange(()=>PermissionRead);
-                if (CurrentPermission != null)
-                {
-                    CurrentPermission.Read = value;
-                }
-            }
+            get { return !String.IsNullOrWhiteSpace(CurrentPermission.UserName); }
         }
-        public bool PermissionWrite
+
+        public void AddPermission()
         {
-            get { return CurrentPermission.Write; }
-            set
+            var existingPermission = Permissions.FirstOrDefault(perm => perm.UserName == CurrentPermission.UserName);
+            if (existingPermission==null)
+                Permissions.Add(CurrentPermission.Clone());
+            else
             {
-                CurrentPermission.Write = value;
-                NotifyOfPropertyChange(()=>PermissionWrite);
+                existingPermission.Read = CurrentPermission.Read;
             }
         }
 
-        public bool CanAddPermission
+        public bool CanAddTag
         {
-            get { return !String.IsNullOrWhiteSpace(PermissionName); }
+            get { return !String.IsNullOrWhiteSpace(CurrentTag.Name); }
         }
 
-        public void AddPermission()
+        public void AddTag()
         {
-            Permissions.Add(new Permission{Read=PermissionRead,UserName=PermissionName,Write=!PermissionRead});   
+            var existingTag = Tags.FirstOrDefault(tag => tag.Name == CurrentTag.Name);           
+            if (existingTag == null)
+                Tags.Add(CurrentTag.Clone());
+            else
+            {
+                existingTag.Value = CurrentTag.Value;
+            }
         }
 
 
@@ -362,8 +345,17 @@ namespace Pithos.Client.WPF
             _permissions = new ObservableCollection<Permission>();
             _permissions.CollectionChanged += (sender, evt) => { PermissionsChanged = true; };
             
+
+            CurrentPermission=new Permission();
+            CurrentTag=new MetaValue();
+
+
             Shell = shell;
             LocalFileName = localFileName;
+
+            var name=Path.GetFileName(localFileName);
+            DisplayName = String.Format("{0} File Properties", name);
+
             pithosFile.ContinueWith(t =>
             {
                 if (t.IsFaulted)
@@ -381,7 +373,7 @@ namespace Pithos.Client.WPF
 
         private void ShowError(AggregateException exception)
         {
-            MessageView view = null;
+            MessageView view;
             if (exception.InnerException is RetryException)
                 view = new MessageView(exception.InnerException as RetryException);
             else if (exception.InnerException is WebException)
@@ -453,6 +445,19 @@ namespace Pithos.Client.WPF
             }
         }
 
+        private MetaValue _currentTag;
+        public MetaValue CurrentTag
+        {
+            get { return _currentTag; }
+            set
+            {
+                _currentTag = (value==null)?new MetaValue() : value.Clone();
+                _currentTag.PropertyChanged += (o, e) => NotifyOfPropertyChange(() => CanAddTag);
+
+                NotifyOfPropertyChange(()=>CurrentTag);
+                NotifyOfPropertyChange(() => CanAddTag);
+            }
+        }
 
         private readonly ObservableCollection<MetaValue> _tags ;
         public ObservableCollection<MetaValue> Tags