Revision 7a804364 trunk/Pithos.Client.WPF/FileProperties/FilePropertiesViewModel.cs

b/trunk/Pithos.Client.WPF/FileProperties/FilePropertiesViewModel.cs
39 39
 * -----------------------------------------------------------------------
40 40
 */
41 41
#endregion
42
using System.Collections;
43
using System.Collections.Concurrent;
42

  
44 43
using System.Collections.ObjectModel;
45
using System.Collections.Specialized;
46 44
using System.ComponentModel.Composition;
47
using System.Diagnostics;
48 45
using System.Diagnostics.Contracts;
49 46
using System.Drawing;
50 47
using System.IO;
......
55 52
using System.Windows.Media.Imaging;
56 53
using Caliburn.Micro;
57 54
using Pithos.Client.WPF.FileProperties;
58
using Pithos.Client.WPF.Properties;
59 55
using Pithos.Core;
60 56
using Pithos.Interfaces;
61 57
using Pithos.Network;
......
63 59
namespace Pithos.Client.WPF
64 60
{
65 61
    using System;
66
    using System.Collections.Generic;
67 62
    using System.Linq;
68
    using System.Text;
69 63

  
70 64
    /// <summary>
71 65
    /// TODO: Update summary.
......
272 266
                NotifyOfPropertyChange(()=>SynchStatus);
273 267
            }
274 268
        }
275

  
276
        private string _permissionName;
277
        public string PermissionName
278
        {
279
            get { return _permissionName; }
280
            set
281
            {
282
                _permissionName = value;
283
                NotifyOfPropertyChange(()=>PermissionName);
284
                NotifyOfPropertyChange(() => CanAddPermission);
285
            }
286
        }
287

  
269
        
288 270
        private Permission _currentPermission;
289 271
        public Permission CurrentPermission
290 272
        {
291 273
            get { return _currentPermission; }
292 274
            set
293
            {
294
                _currentPermission = value;
295
                PermissionName = CurrentPermission.UserName;
296
                PermissionRead = CurrentPermission.Read;
275
            {                
276
                _currentPermission = (value==null)?new Permission() : value.Clone();
277
                _currentPermission.PropertyChanged += (o, e) => NotifyOfPropertyChange(() => CanAddPermission);
297 278

  
298 279
                NotifyOfPropertyChange(()=>CurrentPermission);
299
                NotifyOfPropertyChange(() => PermissionName);
300
            }
301
        }
302

  
303

  
304
        private bool _permissionRead=true;
305
        public bool PermissionRead
306
        {
307
            get { return _permissionRead; }
308
            set
309
            {
310
                _permissionRead = value;
311
                NotifyOfPropertyChange(()=>PermissionRead);
312
                NotifyOfPropertyChange(() => PermissionWrite);
313
            }
314
        }
315

  
316
        public bool PermissionWrite
317
        {
318
            get
319
            {
320
                return !PermissionRead;
321
            }
322
            set
323
            {
324
                _permissionRead = !value;
325
                NotifyOfPropertyChange(() => PermissionRead);
326
                NotifyOfPropertyChange(()=>PermissionWrite);
280
                NotifyOfPropertyChange(() => CanAddPermission);
327 281
            }
328 282
        }
329 283

  
330 284
        public bool CanAddPermission
331 285
        {
332
            get { return !String.IsNullOrWhiteSpace(PermissionName); }
286
            get { return !String.IsNullOrWhiteSpace(CurrentPermission.UserName); }
333 287
        }
334 288

  
335 289
        public void AddPermission()
336 290
        {
337
            Permissions.Add(new Permission{Read=PermissionRead,UserName=PermissionName,Write=!PermissionRead});   
291
            var existingPermission = Permissions.FirstOrDefault(perm => perm.UserName == CurrentPermission.UserName);
292
            if (existingPermission==null)
293
                Permissions.Add(CurrentPermission.Clone());
294
            else
295
            {
296
                existingPermission.Read = CurrentPermission.Read;
297
            }
338 298
        }
339 299

  
340 300
        public bool CanAddTag
341 301
        {
342
            get { return CurrentTag!=null && !String.IsNullOrWhiteSpace(CurrentTag.Name); }
302
            get { return !String.IsNullOrWhiteSpace(CurrentTag.Name); }
343 303
        }
344 304

  
345 305
        public void AddTag()
346 306
        {
347
            Tags.Add(CurrentTag);   
307
            var existingTag = Tags.FirstOrDefault(tag => tag.Name == CurrentTag.Name);           
308
            if (existingTag == null)
309
                Tags.Add(CurrentTag.Clone());
310
            else
311
            {
312
                existingTag.Value = CurrentTag.Value;
313
            }
348 314
        }
349 315

  
350 316

  
......
379 345
            _permissions = new ObservableCollection<Permission>();
380 346
            _permissions.CollectionChanged += (sender, evt) => { PermissionsChanged = true; };
381 347
            
348

  
349
            CurrentPermission=new Permission();
350
            CurrentTag=new MetaValue();
351

  
352

  
382 353
            Shell = shell;
383 354
            LocalFileName = localFileName;
384 355
            pithosFile.ContinueWith(t =>
......
398 369

  
399 370
        private void ShowError(AggregateException exception)
400 371
        {
401
            MessageView view = null;
372
            MessageView view;
402 373
            if (exception.InnerException is RetryException)
403 374
                view = new MessageView(exception.InnerException as RetryException);
404 375
            else if (exception.InnerException is WebException)
......
476 447
            get { return _currentTag; }
477 448
            set
478 449
            {
479
                _currentTag = value;
450
                _currentTag = (value==null)?new MetaValue() : value.Clone();
451
                _currentTag.PropertyChanged += (o, e) => NotifyOfPropertyChange(() => CanAddTag);
452

  
480 453
                NotifyOfPropertyChange(()=>CurrentTag);
454
                NotifyOfPropertyChange(() => CanAddTag);
481 455
            }
482 456
        }
483 457

  

Also available in: Unified diff