Modified preferences to save account additions/deletions only when the user save...
authorPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 1 Mar 2012 17:18:12 +0000 (19:18 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 1 Mar 2012 17:18:12 +0000 (19:18 +0200)
trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml
trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs
trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs

index 1686a72..dc93a5e 100644 (file)
                                     <ColumnDefinition Width="*"/>
                                     <ColumnDefinition Width="Auto"/>
                                 </Grid.ColumnDefinitions>
-                                <TextBox  Name="CurrentAccount_RootPath" Margin="5" HorizontalAlignment="Stretch" Grid.Column="0"/>
+                                <TextBox  Name="CurrentAccount_RootPath" Margin="5" HorizontalAlignment="Stretch" Grid.Column="0" IsEnabled="False"/>
                                 <Button Name="MoveAccountFolder" Content="Move ..." Width="60" Height="30" Grid.Column="1" />
                             </Grid>
                             <CheckBox Name="CurrentAccount_IsActive" Content="Account is Active" Grid.Column="1" Grid.Row="4" Margin="5"/>
index fbe78fe..48c7299 100644 (file)
@@ -278,12 +278,24 @@ namespace Pithos.Client.WPF.Preferences
 
         private void DoSave()
         {
-            Settings.Save();
             //SetStartupMode();            
 
+            //Ensure we save the settings changes first
             foreach (var account in _accountsToRemove)
             {
                 Settings.Accounts.Remove(account);
+            }
+
+            foreach (var account in _accountsToAdd)
+            {
+                Settings.Accounts.Add(account);    
+            }
+            
+            Settings.Save();
+
+
+            foreach (var account in _accountsToRemove)
+            {
                 Shell.RemoveMonitor(account.AccountName);
             }
 
@@ -320,8 +332,8 @@ namespace Pithos.Client.WPF.Preferences
         }
 */
 
-        
 
+        readonly List<AccountSettings> _accountsToAdd=new List<AccountSettings>();
        public void AddAccount()
        {
            var wizard = new AddAccountViewModel();
@@ -344,7 +356,7 @@ namespace Pithos.Client.WPF.Preferences
                                         RootPath = actualRootPath,
                                         IsActive=wizard.IsAccountActive
                                     };
-               Settings.Accounts.Add(newAccount);
+               _accountsToAdd.Add(newAccount);
                var accountVm = new AccountViewModel(newAccount);
                (Accounts as IProducerConsumerCollection<AccountViewModel>).TryAdd(accountVm);
                CurrentAccount = accountVm;
@@ -385,8 +397,6 @@ namespace Pithos.Client.WPF.Preferences
         readonly List<AccountSettings> _accountsToRemove = new List<AccountSettings>();
         public void RemoveAccount()
         {
-            var accountName = CurrentAccount.AccountName;
-
             Accounts.TryRemove(CurrentAccount);
             _accountsToRemove.Add(CurrentAccount.Account);
 
index d6a1e79..b06e8b8 100644 (file)
@@ -737,10 +737,13 @@ namespace Pithos.Client.WPF {
                                return;
 
                        var accountInfo=_accounts.FirstOrDefault(account => account.UserName == accountName);
-                       _accounts.TryRemove(accountInfo);
+            if (accountInfo != null)
+            {
+                _accounts.TryRemove(accountInfo);
+                _pollAgent.RemoveAccount(accountInfo);
+            }
 
-                   _pollAgent.RemoveAccount(accountInfo);
-                       PithosMonitor monitor;
+                   PithosMonitor monitor;
                        if (Monitors.TryRemove(accountName, out monitor))
                        {
                                monitor.Stop();