Index: Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs =================================================================== diff -u -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 -rc5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2 --- Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision c5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2) @@ -79,6 +79,7 @@ { Text = mapPointData => DotSpatialResources.MapData_Point_data_label, Image = mapPointData => DotSpatialResources.PointsIcon, + CanDrag = (mapPointData, parentData) => true, CanCheck = mapPointData => true, IsChecked = mapPointData => mapPointData.IsVisible, OnNodeChecked = MapPointDataOnNodeChecked @@ -88,6 +89,7 @@ { Text = mapLineData => DotSpatialResources.MapData_Line_data_label, Image = mapLineData => DotSpatialResources.LineIcon, + CanDrag = (mapLineData, parentData) => true, CanCheck = mapLineData => true, IsChecked = mapLineData => mapLineData.IsVisible, OnNodeChecked = MapLineDataOnNodeChecked @@ -97,6 +99,7 @@ { Text = mapPolygonData => DotSpatialResources.MapData_Polygon_data_label, Image = mapPolygonData => DotSpatialResources.AreaIcon, + CanDrag = (mapPolygonData, parentData) => true, CanCheck = mapPolygonData => true, IsChecked = mapPolygonData => mapPolygonData.IsVisible, OnNodeChecked = MapPolygonDataOnNodeChecked @@ -106,7 +109,10 @@ { Text = mapDataCollection => DotSpatialResources.General_Map, Image = mapDataCollection => GuiResources.folder, - ChildNodeObjects = mapDataCollection => mapDataCollection.List.Reverse().Cast().ToArray() + ChildNodeObjects = mapDataCollection => mapDataCollection.List.Reverse().Cast().ToArray(), + CanDrop = BaseMapCanDrop, + CanInsert = BaseMapCanInsert, + OnDrop = BaseMapOnDrop }); } @@ -140,5 +146,29 @@ } #endregion + + # region MapDataCollection + + private static bool BaseMapCanDrop(object draggedData, object targetData) + { + return draggedData is MapData; + } + + private static bool BaseMapCanInsert(object draggedData, object targetData) + { + return draggedData is MapData; + } + + private static void BaseMapOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) + { + var mapData = (MapData)droppedData; + var target = (MapDataCollection)newParentData; + + target.List.Remove(mapData); + target.List.Insert(target.List.Count - position, mapData); // Note: target is the same as the previous parent in this case + target.NotifyObservers(); + } + + # endregion } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendView.cs =================================================================== diff -u -rae6c53b67bd2ae5e49606b31fd1575eecc58620d -rc5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2 --- Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendView.cs (.../LegendView.cs) (revision ae6c53b67bd2ae5e49606b31fd1575eecc58620d) +++ Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendView.cs (.../LegendView.cs) (revision c5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2) @@ -118,22 +118,22 @@ # region ChartData - private void PointDataOnNodeChecked(PointData pointData, object parentData) + private static void PointDataOnNodeChecked(PointData pointData, object parentData) { PointBasedChartDataOnNodeChecked(pointData, parentData); } - private void LineDataOnNodeChecked(LineData lineData, object parentData) + private static void LineDataOnNodeChecked(LineData lineData, object parentData) { PointBasedChartDataOnNodeChecked(lineData, parentData); } - private void AreaDataOnNodeChecked(AreaData areaData, object parentData) + private static void AreaDataOnNodeChecked(AreaData areaData, object parentData) { PointBasedChartDataOnNodeChecked(areaData, parentData); } - private void PointBasedChartDataOnNodeChecked(PointBasedChartData pointBasedChartData, object parentData) + private static void PointBasedChartDataOnNodeChecked(PointBasedChartData pointBasedChartData, object parentData) { pointBasedChartData.IsVisible = !pointBasedChartData.IsVisible; pointBasedChartData.NotifyObservers(); @@ -149,22 +149,17 @@ # region ChartDataCollection - private bool BaseChartCanDrop(object draggedData, object targetData) + private static bool BaseChartCanDrop(object draggedData, object targetData) { - if (draggedData is ChartData) - { - return true; - } - - return false; + return draggedData is ChartData; } - private bool BaseChartCanInsert(object draggedData, object targetData) + private static bool BaseChartCanInsert(object draggedData, object targetData) { return draggedData is ChartData; } - private void BaseChartOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) + private static void BaseChartOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) { var chartData = (ChartData) droppedData; var target = (ChartDataCollection) newParentData; Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -r61f3b606ba0003553fe583462bab6e493043be5e -rc5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 61f3b606ba0003553fe583462bab6e493043be5e) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision c5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2) @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; @@ -47,9 +49,6 @@ Assert.IsNull(info.IsChecked); Assert.IsNull(info.OnNodeChecked); Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); } [Test] @@ -101,5 +100,145 @@ mocks.VerifyAll(); } + + [Test] + public void CanDrop_SourceNodeTagIsNoMapData_ReturnsFalse() + { + // Setup + var mapDataCollection = mocks.StrictMock(new List()); + + mocks.ReplayAll(); + + // Call + var canDrop = info.CanDrop(new object(), mapDataCollection); + + // Assert + Assert.IsFalse(canDrop); + + mocks.VerifyAll(); + } + + [Test] + public void CanDrop_SourceNodeTagIsMapData_ReturnsTrue() + { + // Setup + var mapData = mocks.StrictMock(); + var mapDataCollection = mocks.StrictMock(new List()); + + mocks.ReplayAll(); + + // Call + var canDrop = info.CanDrop(mapData, mapDataCollection); + + // Assert + Assert.IsTrue(canDrop); + + mocks.VerifyAll(); + } + + [Test] + public void CanInsert_SourceNodeTagIsNoMapData_ReturnsFalse() + { + // Setup + var mapDataCollection = mocks.StrictMock(new List()); + + mocks.ReplayAll(); + + // Call + var canInsert = info.CanInsert(new object(), mapDataCollection); + + // Assert + Assert.IsFalse(canInsert); + + mocks.VerifyAll(); + } + + [Test] + public void CanInsert_SourceNodeTagIsMapData_ReturnsTrue() + { + // Setup + var mapData = mocks.StrictMock(); + var mapDataCollection = mocks.StrictMock(new List()); + + mocks.ReplayAll(); + + // Call + var canInsert = info.CanInsert(mapData, mapDataCollection); + + // Assert + Assert.IsTrue(canInsert); + + mocks.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void OnDrop_MapDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + var mapData1 = mocks.StrictMock(); + var mapData2 = mocks.StrictMock(); + var mapData3 = mocks.StrictMock(); + var mapDataCollection = mocks.StrictMock(new List + { + mapData1, + mapData2, + mapData3 + }); + + var treeViewControlMock = mocks.StrictMock(); + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + mapDataCollection.Attach(observer); + + // Call + info.OnDrop(mapData1, mapDataCollection, mapDataCollection, position, treeViewControlMock); + + // Assert + var reversedIndex = 2 - position; + Assert.AreSame(mapData1, mapDataCollection.List.ElementAt(reversedIndex)); + + mocks.VerifyAll(); // UpdateObserver should be called + } + + [Test] + [TestCase(-50)] + [TestCase(-1)] + [TestCase(3)] + [TestCase(50)] + public void OnDrop_MapDataMovedToPositionOutsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + var mapData1 = mocks.StrictMock(); + var mapData2 = mocks.StrictMock(); + var mapData3 = mocks.StrictMock(); + var mapDataCollection = mocks.StrictMock(new List + { + mapData1, + mapData2, + mapData3 + }); + + mapDataCollection.Attach(observer); + + var treeViewControlMock = mocks.StrictMock(); + + mocks.ReplayAll(); + + // Call + TestDelegate test = () => info.OnDrop(mapData1, mapDataCollection, mapDataCollection, position, treeViewControlMock); + + // Assert + Assert.Throws(test); + + mocks.VerifyAll(); // UpdateObserver should be not called + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs =================================================================== diff -u -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 -rc5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision c5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2) @@ -44,7 +44,6 @@ Assert.IsNull(info.OnNodeRenamed); Assert.IsNull(info.CanRemove); Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanDrag); Assert.IsNull(info.CanDrop); Assert.IsNull(info.CanInsert); Assert.IsNull(info.OnDrop); @@ -153,5 +152,23 @@ mocks.VerifyAll(); } + + [Test] + public void CanDrag_Always_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + mocks.ReplayAll(); + + // Call + var canDrag = info.CanDrag(lineData, null); + + // Assert + Assert.IsTrue(canDrag); + + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs =================================================================== diff -u -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 -rc5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision c5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2) @@ -44,7 +44,6 @@ Assert.IsNull(info.OnNodeRenamed); Assert.IsNull(info.CanRemove); Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanDrag); Assert.IsNull(info.CanDrop); Assert.IsNull(info.CanInsert); Assert.IsNull(info.OnDrop); @@ -153,5 +152,23 @@ mocks.VerifyAll(); } + + [Test] + public void CanDrag_Always_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var pointData = mocks.StrictMock(Enumerable.Empty()); + + mocks.ReplayAll(); + + // Call + var canDrag = info.CanDrag(pointData, null); + + // Assert + Assert.IsTrue(canDrag); + + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs =================================================================== diff -u -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 -rc5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision c5b9900d1cc5bd7eb5ecc0727d1949fb21f486a2) @@ -44,7 +44,6 @@ Assert.IsNull(info.OnNodeRenamed); Assert.IsNull(info.CanRemove); Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanDrag); Assert.IsNull(info.CanDrop); Assert.IsNull(info.CanInsert); Assert.IsNull(info.OnDrop); @@ -153,5 +152,23 @@ mocks.VerifyAll(); } + + [Test] + public void CanDrag_Always_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var polygonData = mocks.StrictMock(Enumerable.Empty()); + + mocks.ReplayAll(); + + // Call + var canDrag = info.CanDrag(polygonData, null); + + // Assert + Assert.IsTrue(canDrag); + + mocks.VerifyAll(); + } } } \ No newline at end of file