Fix incorrect check in Selective Sync that prevented folder changes to propagate...
[pithos-ms-client] / trunk / Pithos.Client.WPF / FileProperties / FilePropertiesViewModel.cs
index dfadea3..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,79 +266,51 @@ namespace Pithos.Client.WPF
                 NotifyOfPropertyChange(()=>SynchStatus);
             }
         }
-
-        private string _permissionName;
-        public string PermissionName
-        {
-            get { return _permissionName; }
-            set
-            {
-                _permissionName = value;
-                NotifyOfPropertyChange(()=>PermissionName);
-                NotifyOfPropertyChange(() => CanAddPermission);
-            }
-        }
-
+        
         private Permission _currentPermission;
         public Permission CurrentPermission
         {
             get { return _currentPermission; }
             set
-            {
-                _currentPermission = value;
-                PermissionName = CurrentPermission.UserName;
-                PermissionRead = CurrentPermission.Read;
+            {                
+                _currentPermission = (value==null)?new Permission() : value.Clone();
+                _currentPermission.PropertyChanged += (o, e) => NotifyOfPropertyChange(() => CanAddPermission);
 
                 NotifyOfPropertyChange(()=>CurrentPermission);
-                NotifyOfPropertyChange(() => PermissionName);
-            }
-        }
-
-
-        private bool _permissionRead=true;
-        public bool PermissionRead
-        {
-            get { return _permissionRead; }
-            set
-            {
-                _permissionRead = value;
-                NotifyOfPropertyChange(()=>PermissionRead);
-                NotifyOfPropertyChange(() => PermissionWrite);
-            }
-        }
-
-        public bool PermissionWrite
-        {
-            get
-            {
-                return !PermissionRead;
-            }
-            set
-            {
-                _permissionRead = !value;
-                NotifyOfPropertyChange(() => PermissionRead);
-                NotifyOfPropertyChange(()=>PermissionWrite);
+                NotifyOfPropertyChange(() => CanAddPermission);
             }
         }
 
         public bool CanAddPermission
         {
-            get { return !String.IsNullOrWhiteSpace(PermissionName); }
+            get { return !String.IsNullOrWhiteSpace(CurrentPermission.UserName); }
         }
 
         public void AddPermission()
         {
-            Permissions.Add(new Permission{Read=PermissionRead,UserName=PermissionName,Write=!PermissionRead});   
+            var existingPermission = Permissions.FirstOrDefault(perm => perm.UserName == CurrentPermission.UserName);
+            if (existingPermission==null)
+                Permissions.Add(CurrentPermission.Clone());
+            else
+            {
+                existingPermission.Read = CurrentPermission.Read;
+            }
         }
 
         public bool CanAddTag
         {
-            get { return CurrentTag!=null && !String.IsNullOrWhiteSpace(CurrentTag.Name); }
+            get { return !String.IsNullOrWhiteSpace(CurrentTag.Name); }
         }
 
         public void AddTag()
         {
-            Tags.Add(CurrentTag);   
+            var existingTag = Tags.FirstOrDefault(tag => tag.Name == CurrentTag.Name);           
+            if (existingTag == null)
+                Tags.Add(CurrentTag.Clone());
+            else
+            {
+                existingTag.Value = CurrentTag.Value;
+            }
         }
 
 
@@ -379,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)
@@ -398,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)
@@ -476,8 +451,11 @@ namespace Pithos.Client.WPF
             get { return _currentTag; }
             set
             {
-                _currentTag = value;
+                _currentTag = (value==null)?new MetaValue() : value.Clone();
+                _currentTag.PropertyChanged += (o, e) => NotifyOfPropertyChange(() => CanAddTag);
+
                 NotifyOfPropertyChange(()=>CurrentTag);
+                NotifyOfPropertyChange(() => CanAddTag);
             }
         }