Revision 7a804364

b/trunk/Pithos.Client.WPF/FileProperties/FilePropertiesView.xaml
90 90
                <TabItem Header="Metadata">
91 91
                    <StackPanel>
92 92
                        <StackPanel Orientation="Horizontal">
93
                            <TextBox x:Name="CurrentTag_Name" Width="150" Margin="5" Grid.Row="6"/>
94
                            <TextBox x:Name="CurrentTag_Value" Width="150" Margin="5" Grid.Row="6"/>
95
                            <Button x:Name="AddTag" Content="Add" Margin="5"/>
93
                            <TextBox x:Name="CurrentTag_Name" Width="145" Margin="5" Grid.Row="6"/>
94
                            <TextBox x:Name="CurrentTag_Value" Width="145" Margin="5" Grid.Row="6"/>
95
                            <Button x:Name="AddTag" Content="Update" Margin="5"/>
96 96
                        </StackPanel>
97 97
                        <DataGrid ItemsSource="{Binding Tags}" x:Name="Tags"
98
                    AutoGenerateColumns="False" GridLinesVisibility="None" IsReadOnly="True" >
98
                    AutoGenerateColumns="False" GridLinesVisibility="None" 
99
                                  IsReadOnly="False"
100
                                  CanUserDeleteRows="True"
101
                                  CanUserAddRows="False">
99 102
                            <DataGrid.Columns>
100
                                <DataGridTextColumn Binding="{Binding Name}" Header="Key" MinWidth="150" />
101
                                <DataGridTextColumn Binding="{Binding Value}" Header="Value"  MinWidth="100"/>
103
                                <DataGridTextColumn Binding="{Binding Name}" Header="Key" MinWidth="150" IsReadOnly="True"/>
104
                                <DataGridTextColumn Binding="{Binding Value}" Header="Value"  MinWidth="100" IsReadOnly="True"/>
102 105
                            </DataGrid.Columns>
103 106
                        </DataGrid>
107
                        <Button x:Name="DeleteTag" Content="Delete" 
108
                                Command="DataGrid.DeleteCommand" CommandTarget="{Binding ElementName=Tags}"
109
                                Style="{StaticResource ResourceKey=ButtonStyle}" HorizontalAlignment="Left" />
104 110
                    </StackPanel>
105 111
                </TabItem>
106 112
                <TabItem Header="Permissions">
107 113
                    <StackPanel>
108 114
                        <CheckBox x:Name="IsPublic" Content="Public" Margin="5"/>
109 115
                        <StackPanel Orientation="Horizontal">
110
                            <TextBox x:Name="PermissionName" Width="200" Margin="5" Grid.Row="6"/>
111
                            <RadioButton x:Name="PermissionRead" Content="Read" Margin="5" Grid.Row="7"/>
112
                            <RadioButton x:Name="PermissionWrite" Content="Write" Margin="5" Grid.Row="8"/>
113
                            <Button x:Name="AddPermission" Content="Add" Margin="5"/>
116
                            <TextBox x:Name="CurrentPermission_UserName" Width="195" Margin="5" Grid.Row="6"/>
117
                            <RadioButton x:Name="CurrentPermission_Read" Content="Read" Margin="5" Grid.Row="7"/>
118
                            <RadioButton x:Name="CurrentPermission_Write" Content="Write" Margin="5" Grid.Row="8"/>
119
                            <Button x:Name="AddPermission" Content="Update" Margin="5"/>
114 120
                        </StackPanel>
115 121
                        <TextBlock Margin="5" Visibility="{Binding Path=IsPublic,FallbackValue=Collapsed, Converter={StaticResource BoolToVisible}}">
116 122
                <Run Text="Public URL:" />
117 123
                <Run Text="{Binding PublicUrl,FallbackValue='http://someurl'}" />
118 124
                        </TextBlock>
119
                        <DataGrid x:Name="Permissions" AutoGenerateColumns="False" GridLinesVisibility="None" IsReadOnly="True" >
125
                        <DataGrid x:Name="Permissions" AutoGenerateColumns="False" GridLinesVisibility="None" 
126
                                  IsReadOnly="False" 
127
                                  CanUserDeleteRows="True"
128
                                  CanUserAddRows="False"
129
                                  >
120 130
                            <DataGrid.Columns>
121
                                <DataGridTextColumn Binding="{Binding UserName}" Header="Name"  MinWidth="150" />
122
                                <DataGridTextColumn Binding="{Binding Value}" Header="Permission"/>
131
                                <DataGridTextColumn Binding="{Binding UserName}" Header="Name"  MinWidth="150" IsReadOnly="True" />
132
                                <DataGridTextColumn Binding="{Binding Value}" Header="Permission" IsReadOnly="True"/>
123 133
                            </DataGrid.Columns>
124 134
                        </DataGrid>
135
                        <Button x:Name="DeletePermission" Content="Delete" 
136
                                Command="DataGrid.DeleteCommand" CommandTarget="{Binding ElementName=Permissions}"
137
                                Style="{StaticResource ResourceKey=ButtonStyle}" HorizontalAlignment="Left" />
125 138
                    </StackPanel>
126 139
                </TabItem>
127 140
                <!--<TabItem Header="Other">
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

  
b/trunk/Pithos.Client.WPF/FileProperties/MetaValue.cs
79 79
        }
80 80

  
81 81

  
82
        public MetaValue Clone()
83
        {
84
            return new MetaValue {Name = Name, Value = Value};
85
        }
82 86
    }
83 87
}
b/trunk/Pithos.Client.WPF/FileProperties/Permission.cs
58 58
            }
59 59
        }
60 60

  
61
        private bool _read;
61
        private bool _read=true;
62 62
        public bool Read
63 63
        {
64 64
            get { return _read; }
......
115 115
            
116 116
        }
117 117

  
118
        public Permission Clone()
119
        {
120
            return new Permission {UserName = UserName, Read = Read};
121
        }
118 122
    }
119 123
}

Also available in: Unified diff