[mapguide-commits] r6081 - in trunk/Tools/Maestro/Maestro.Base: Commands Commands/Conditions Commands/SiteExplorer UI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Aug 16 08:11:22 EDT 2011


Author: jng
Date: 2011-08-16 05:11:22 -0700 (Tue, 16 Aug 2011)
New Revision: 6081

Modified:
   trunk/Tools/Maestro/Maestro.Base/Commands/Conditions/NotConnectedConditionEvaluator.cs
   trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs
   trunk/Tools/Maestro/Maestro.Base/Commands/PreviewResourceCommand.cs
   trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DeleteSelectedItemsCommand.cs
   trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
Log:
#1784: More fixes for multi-site support


Modified: trunk/Tools/Maestro/Maestro.Base/Commands/Conditions/NotConnectedConditionEvaluator.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/Conditions/NotConnectedConditionEvaluator.cs	2011-08-16 10:37:14 UTC (rev 6080)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/Conditions/NotConnectedConditionEvaluator.cs	2011-08-16 12:11:22 UTC (rev 6081)
@@ -34,8 +34,7 @@
                 if (wb.ActiveSiteExplorer != null)
                 {
                     var items = wb.ActiveSiteExplorer.SelectedItems;
-                    if (items.Length == 1)
-                        return items[0].IsRoot;
+                    return (items.Length > 0);
                 }
             }
             return false;

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs	2011-08-16 10:37:14 UTC (rev 6080)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs	2011-08-16 12:11:22 UTC (rev 6081)
@@ -37,7 +37,8 @@
             var clip = ServiceRegistry.GetService<ClipboardService>();
             var omgr = ServiceRegistry.GetService<OpenResourceManager>();
             var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
-            var conn = connMgr.GetConnection(exp.ConnectionName);
+            var targetConnName = exp.ConnectionName;
+            var conn = connMgr.GetConnection(targetConnName);
 
             if (!clip.HasContent())
                 return;
@@ -57,67 +58,76 @@
             
             //.net FX 2.0 hack to compensate for lack of set collection
             Dictionary<string, string> folders = new Dictionary<string, string>();
+            var notPasted = new List<RepositoryItem>();
 
             foreach (var item in itemsToPaste)
             {
-                LoggingService.InfoFormatted(Properties.Resources.ClipboardAction, item.ClipboardState, item.ResourceId, folder.ResourceId);
-                
-                //Keep testing until we find a target resource identifier that 
-                //doesn't already exists. Note this would automatically guard against any resources in this folder
-                //that may already be open in an editor
-                var rid = new ResourceIdentifier(item.ResourceId);
-                var name = rid.IsFolder ? (rid.Name + "/") : (rid.Name + "." + rid.ResourceType.ToString());
-                var resId = folder.ResourceId + name;
-                int counter = 0;
-                while (conn.ResourceService.ResourceExists(resId))
+                if (item.ConnectionName == targetConnName) //From same connection
                 {
-                    counter++;
+                    LoggingService.InfoFormatted(Properties.Resources.ClipboardAction, item.ClipboardState, item.ResourceId, folder.ResourceId);
 
-                    if (rid.IsFolder)
+                    //Keep testing until we find a target resource identifier that 
+                    //doesn't already exists. Note this would automatically guard against any resources in this folder
+                    //that may already be open in an editor
+                    var rid = new ResourceIdentifier(item.ResourceId);
+                    var name = rid.IsFolder ? (rid.Name + "/") : (rid.Name + "." + rid.ResourceType.ToString());
+                    var resId = folder.ResourceId + name;
+                    int counter = 0;
+                    while (conn.ResourceService.ResourceExists(resId))
                     {
-                        resId = folder.ResourceId + rid.Name + " (" + counter + ")/";
+                        counter++;
+
+                        if (rid.IsFolder)
+                        {
+                            resId = folder.ResourceId + rid.Name + " (" + counter + ")/";
+                        }
+                        else
+                        {
+                            var rname = name.Substring(0, name.IndexOf("."));
+                            var type = name.Substring(name.IndexOf("."));
+                            rname += " (" + counter + ")";
+                            resId = folder.ResourceId + rname + type;
+                        }
                     }
-                    else
-                    {
-                        var rname = name.Substring(0, name.IndexOf("."));
-                        var type = name.Substring(name.IndexOf("."));
-                        rname += " (" + counter + ")";
-                        resId = folder.ResourceId + rname + type;
-                    }
-                }
 
-                if (item.ClipboardState == RepositoryItem.ClipboardAction.Copy)
-                {
-                    if (item.IsFolder)
+                    if (item.ClipboardState == RepositoryItem.ClipboardAction.Copy)
                     {
-                        conn.ResourceService.CopyFolderWithReferences(item.ResourceId, resId, null, null);
+                        if (item.IsFolder)
+                        {
+                            conn.ResourceService.CopyFolderWithReferences(item.ResourceId, resId, null, null);
+                        }
+                        else
+                        {
+                            conn.ResourceService.CopyResource(item.ResourceId, resId, false);
+                        }
                     }
-                    else
+                    else if (item.ClipboardState == RepositoryItem.ClipboardAction.Cut)
                     {
-                        conn.ResourceService.CopyResource(item.ResourceId, resId, false);
-                    }
-                }
-                else if (item.ClipboardState == RepositoryItem.ClipboardAction.Cut)
-                {
-                    if (!item.IsFolder)
-                    {
-                        if (omgr.IsOpen(item.ResourceId))
+                        if (!item.IsFolder)
                         {
-                            sourceItemsNotMoved.Add(item.ResourceId);
-                            continue;
+                            if (omgr.IsOpen(item.ResourceId))
+                            {
+                                sourceItemsNotMoved.Add(item.ResourceId);
+                                continue;
+                            }
                         }
+
+                        //TODO: Should we prompt? That may be equivalent to saying
+                        //"Shall I break your resources because you're moving" isn't it?
+                        var res = conn.ResourceService.MoveResourceWithReferences(item.ResourceId, resId, null, null);
+                        if (!res)
+                            LoggingService.InfoFormatted(Properties.Resources.MoveFailure, item.ResourceId, resId);
+                        else
+                            folders[item.Parent.ResourceId] = item.Parent.ResourceId;
                     }
-
-                    //TODO: Should we prompt? That may be equivalent to saying
-                    //"Shall I break your resources because you're moving" isn't it?
-                    var res = conn.ResourceService.MoveResourceWithReferences(item.ResourceId, resId, null, null);
-                    if (!res)
-                        LoggingService.InfoFormatted(Properties.Resources.MoveFailure, item.ResourceId, resId);
-                    else
-                        folders[item.Parent.ResourceId] = item.Parent.ResourceId;
                 }
+                else
+                {
+                    //TODO: Revisit later
+                    MessageService.ShowError("Copy/Pasting between connections is currently not implemented");
+                    return;
+                }
             }
-
             if (sourceItemsNotMoved.Count > 0)
                 MessageService.ShowMessage(string.Format(Properties.Resources.ItemsNotMovedDueToBeingOpen, Environment.NewLine + string.Join(Environment.NewLine, sourceItemsNotMoved.ToArray())));
 

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/PreviewResourceCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/PreviewResourceCommand.cs	2011-08-16 10:37:14 UTC (rev 6080)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/PreviewResourceCommand.cs	2011-08-16 12:11:22 UTC (rev 6081)
@@ -40,8 +40,9 @@
                 var exp = wb.ActiveSiteExplorer;
                 if (exp != null)
                 {
-                    var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
-                    var conn = connMgr.GetConnection(exp.ConnectionName);
+                    //var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+                    //var conn = connMgr.GetConnection(exp.ConnectionName);
+                    var conn = ed.Resource.CurrentConnection;
                     var launcher = ServiceRegistry.GetService<UrlLauncherService>();
 
                     //HACK: This is a bit dodgy as we assume we're dealing with the http

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DeleteSelectedItemsCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DeleteSelectedItemsCommand.cs	2011-08-16 10:37:14 UTC (rev 6080)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DeleteSelectedItemsCommand.cs	2011-08-16 12:11:22 UTC (rev 6081)
@@ -19,6 +19,7 @@
 #endregion
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 using ICSharpCode.Core;
 using Maestro.Base.Services;
@@ -44,6 +45,8 @@
                 var items = exp.SelectedItems;
                 if (items.Length > 0)
                 {
+                    //Ascertain the parent connection that requires refresh post-delete
+                    string connName = items.First().ConnectionName;
                     if (MessageService.AskQuestion(Properties.Resources.ConfirmDelete))
                     {
                         if (ConfirmDeleteOpenResources(items, omgr.OpenEditors))
@@ -77,9 +80,9 @@
                     //so we should get the same result
                     var parent = ResourceIdentifier.GetParentFolder(items[0].ResourceId);
                     if (parent == null) //root?
-                        exp.RefreshModel(null);
+                        exp.RefreshModel(connName);
                     else
-                        exp.RefreshModel(parent);
+                        exp.RefreshModel(connName, parent);
                 }
             }
         }

Modified: trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs	2011-08-16 10:37:14 UTC (rev 6080)
+++ trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs	2011-08-16 12:11:22 UTC (rev 6081)
@@ -139,7 +139,7 @@
 
                 //If this node is not initially expanded, we get NRE on refresh
                 ExpandNode(connectionName, resId);
-
+                
                 var path = _model.GetPathFromResourceId(connectionName, resId);
                 while (path == null)
                 {
@@ -157,7 +157,11 @@
                 trvResources.SelectedNode = node;
             }
             _model.Refresh();
-            trvResources.Root.Children[0].Expand();
+            if (!string.IsNullOrEmpty(resId))
+            {
+                SelectNode(connectionName, resId);
+            }
+            //trvResources.Root.Children[0].Expand();
         }
 
         private void trvResources_MouseDoubleClick(object sender, MouseEventArgs e)
@@ -351,10 +355,10 @@
             var nodes = e.Item as TreeNodeAdv[];
             if (nodes != null)
             {
-                List<ResourceIdentifier> rids = new List<ResourceIdentifier>();
+                List<RepositoryItem> rids = new List<RepositoryItem>();
                 foreach (var n in nodes)
                 {
-                    rids.Add(new ResourceIdentifier(((RepositoryItem)n.Tag).ResourceId));
+                    rids.Add((RepositoryItem)n.Tag);
                 }
                 trvResources.DoDragDrop(rids.ToArray(), DragDropEffects.All);
             }
@@ -362,7 +366,7 @@
 
         private void trvResources_DragDrop(object sender, DragEventArgs e)
         {
-            var data = e.Data.GetData(typeof(ResourceIdentifier[])) as ResourceIdentifier[];
+            var data = e.Data.GetData(typeof(RepositoryItem[])) as RepositoryItem[];
             if (data == null)
             {
                 //See if the mouse is currently over a node
@@ -382,25 +386,29 @@
                 {
                     string connectionName = RepositoryTreeModel.GetParentConnectionName(item);
                     string folderId = item.ResourceId;
-                    List<string> resIds = new List<string>();
-                    foreach (var n in data)
-                    {
-                        resIds.Add(n.ToString());
-                    }
 
                     //I think it's nice to ask for confirmation
-                    if (resIds.Count > 0)
+                    if (data.Length > 0)
                     {
                         if (!MessageService.AskQuestion(Properties.Resources.ConfirmMove))
                             return;
                     }
 
-                    string[] folders = MoveResources(connectionName, resIds, folderId);
+                    if (data.First().ConnectionName == connectionName)
+                    {
+                        string[] folders = MoveResourcesWithinConnection(connectionName, data.Select(x => x.ResourceId).ToArray(), folderId);
 
-                    foreach (var fid in folders)
+                        foreach (var fid in folders)
+                        {
+                            LoggingService.Info("Refreshing: " + fid + " on " + connectionName); //LOCALIZEME
+                            RefreshModel(connectionName, fid);
+                        }
+                    }
+                    else
                     {
-                        LoggingService.Info("Refreshing: " + fid);
-                        RefreshModel(fid);
+                        //TODO: Revisit later
+                        MessageService.ShowError("Moving resources between connections is currently not implemented");
+                        return;
                     }
                 }
             }
@@ -408,7 +416,7 @@
 
         private void trvResources_DragOver(object sender, DragEventArgs e)
         {
-            var data = e.Data.GetData(typeof(ResourceIdentifier[])) as ResourceIdentifier[];
+            var data = e.Data.GetData(typeof(RepositoryItem[])) as RepositoryItem[];
             if (data == null)
             {
                 SiteExplorerDragDropHandler.OnDragEnter(this, e);
@@ -442,7 +450,7 @@
             // (eg. Create a Feature Source from a dragged SDF file)
         }
 
-        private string [] MoveResources(string connectionName, ICollection<string> resIds, string folderId)
+        private string [] MoveResourcesWithinConnection(string connectionName, ICollection<string> resIds, string folderId)
         {
             var wb = Workbench.Instance;
             var notMovedToTarget = new List<string>();



More information about the mapguide-commits mailing list