Renamed root folders are added to the list of selective folders, as long as their...
authorpkanavos <pkanavos@gmail.com>
Tue, 3 Jul 2012 11:50:48 +0000 (14:50 +0300)
committerpkanavos <pkanavos@gmail.com>
Tue, 3 Jul 2012 11:50:48 +0000 (14:50 +0300)
trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs
trunk/Pithos.Core/Agents/PollAgent.cs

index 049384b..b9cbf78 100644 (file)
@@ -113,13 +113,9 @@ namespace Pithos.Client.WPF.Preferences
 \r
         [ImportingConstructor]\r
         public PreferencesViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shell, PithosSettings settings)\r
-            :this(windowManager,events,shell,settings,null)\r
         {\r
             this.DisplayName = "Pithos+ Preferences";\r
-        }\r
 \r
-        public PreferencesViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shell, PithosSettings settings, string currentTab)\r
-        {\r
             // ReSharper disable DoNotCallOverridableMethodsInConstructor\r
             //Caliburn.Micro uses DisplayName for the view's title\r
             DisplayName = "Pithos+ Preferences";\r
@@ -132,15 +128,7 @@ namespace Pithos.Client.WPF.Preferences
             \r
             Settings=settings;\r
             Accounts = new ObservableConcurrentCollection<AccountViewModel>();\r
-            if (settings.Accounts == null)\r
-            {\r
-                settings.Accounts=new AccountsCollection();\r
-                settings.Save();\r
-            }\r
-            var accountVMs = from account in settings.Accounts\r
-                             select new AccountViewModel(account);\r
-\r
-            Accounts.AddFromEnumerable(accountVMs);\r
+            \r
             \r
             var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);\r
             _shortcutPath = Path.Combine(startupPath, "Pithos.lnk");\r
@@ -148,7 +136,24 @@ namespace Pithos.Client.WPF.Preferences
 \r
             StartOnSystemStartup = File.Exists(_shortcutPath);\r
 \r
-            SelectedTab = currentTab;\r
+            //SelectedTab = currentTab;\r
+        }\r
+\r
+        protected override void OnViewLoaded(object view)\r
+        {\r
+            base.OnViewLoaded(view);\r
+            Settings.Reload();\r
+            Accounts.Clear();\r
+\r
+            if (Settings.Accounts == null)\r
+            {\r
+                Settings.Accounts = new AccountsCollection();\r
+                Settings.Save();\r
+            }\r
+            var accountVMs = from account in Settings.Accounts\r
+                             select new AccountViewModel(account);\r
+\r
+            Accounts.AddFromEnumerable(accountVMs);\r
         }\r
 \r
         private string _selectedTab="General";\r
@@ -232,7 +237,7 @@ namespace Pithos.Client.WPF.Preferences
         {\r
             //var monitor = Shell.Monitors[CurrentAccount.AccountKey];\r
             \r
-\r
+            \r
             var model = new SelectiveSynchViewModel(_events,CurrentAccount.Account,CurrentAccount.ApiKey,false);            \r
             if (_windowManager.ShowDialog(model) == true)\r
             {\r
index 85dccfa..940ed4c 100644 (file)
@@ -545,6 +545,8 @@ namespace Pithos.Core.Agents
                                                                 tuple.ObjectInfo.X_Object_Hash);\r
 \r
                                 StatusKeeper.StoreInfo(targetPath, tuple.ObjectInfo);\r
+\r
+                                AddRootFolderToSelectives(accountInfo, tuple, targetPath);\r
                             }\r
 \r
                             /*\r
@@ -555,7 +557,8 @@ namespace Pithos.Core.Agents
                     }\r
                 }\r
                 else\r
-                {\r
+                {                   \r
+\r
                     //Local changes found\r
 \r
                     //Server unchanged?\r
@@ -610,6 +613,8 @@ namespace Pithos.Core.Agents
                                 //Detect server moves\r
                                 var targetPath = MoveForServerMove(accountInfo, tuple);\r
                                 StatusKeeper.StoreInfo(targetPath, tuple.ObjectInfo);\r
+                                \r
+                                AddRootFolderToSelectives(accountInfo, tuple, targetPath);\r
                             }\r
                             else\r
                             {\r
@@ -653,6 +658,28 @@ namespace Pithos.Core.Agents
             }\r
         }\r
 \r
+        private void AddRootFolderToSelectives(AccountInfo accountInfo, StateTuple tuple, string targetPath)\r
+        {\r
+            //Also ensure that any newly created folders are added to the selectives, if the original folder was selected\r
+            var containerPath = Path.Combine(accountInfo.AccountPath, tuple.ObjectInfo.Container);\r
+\r
+            //If this is a root folder encountered for the first time\r
+            if (tuple.L == null && Directory.Exists(tuple.FileInfo.FullName) \r
+                && (tuple.FileInfo.FullName.IsAtOrDirectlyBelow(containerPath)))\r
+            {\r
+                \r
+                var relativePath = tuple.ObjectInfo.RelativeUrlToFilePath(accountInfo.UserName);\r
+                var initialPath = Path.Combine(accountInfo.AccountPath, relativePath);\r
+\r
+                var hasMoved = true;// !initialPath.Equals(targetPath);\r
+                if (hasMoved && Selectives.IsSelected(accountInfo, initialPath))\r
+                {\r
+                    Selectives.AddUri(accountInfo, tuple.ObjectInfo.Uri);\r
+                    Selectives.Save(accountInfo);\r
+                }\r
+            }\r
+        }\r
+\r
         private string MoveForServerMove(AccountInfo accountInfo, StateTuple tuple)\r
         {\r
             if (tuple.ObjectInfo == null)\r