删除原有的上 下,删 按钮方式的操作逻辑,改用拖动,和左键激活
This commit is contained in:
@@ -68,32 +68,30 @@
|
||||
Background="#F5F5F5"
|
||||
BorderBrush="{StaticResource PanelBorder}"
|
||||
BorderThickness="0,1,0,1">
|
||||
<Grid>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
|
||||
<Button
|
||||
Command="{Binding NewPipelineCommand}"
|
||||
Content="新建"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="新建流水线" />
|
||||
<Button
|
||||
Command="{Binding SavePipelineCommand}"
|
||||
Content="保存"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="保存当前流水线" />
|
||||
<Button
|
||||
Width="60"
|
||||
Command="{Binding SaveAsPipelineCommand}"
|
||||
Content="另存为"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="另存当前流水线" />
|
||||
<Button
|
||||
Width="52"
|
||||
Command="{Binding LoadPipelineCommand}"
|
||||
Content="加载"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="加载流水线" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
|
||||
<Button
|
||||
Command="{Binding NewPipelineCommand}"
|
||||
Content="新建"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="新建流水线" />
|
||||
<Button
|
||||
Command="{Binding SavePipelineCommand}"
|
||||
Content="保存"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="保存当前流水线" />
|
||||
<Button
|
||||
Width="60"
|
||||
Command="{Binding SaveAsPipelineCommand}"
|
||||
Content="另存为"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="另存当前流水线" />
|
||||
<Button
|
||||
Width="52"
|
||||
Command="{Binding LoadPipelineCommand}"
|
||||
Content="加载"
|
||||
Style="{StaticResource ToolbarBtn}"
|
||||
ToolTip="加载流水线" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<ListBox
|
||||
@@ -120,7 +118,6 @@
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="44" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Line
|
||||
@@ -176,54 +173,6 @@
|
||||
Foreground="#6E6E6E"
|
||||
Text="已启用" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
x:Name="NodeActions"
|
||||
Grid.Column="2"
|
||||
Margin="0,0,4,0"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal"
|
||||
Visibility="Collapsed">
|
||||
<Button
|
||||
Width="22"
|
||||
Height="22"
|
||||
Margin="1,0"
|
||||
Background="Transparent"
|
||||
BorderBrush="#CDCBCB"
|
||||
BorderThickness="1"
|
||||
Command="{Binding DataContext.MoveNodeUpCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
|
||||
CommandParameter="{Binding}"
|
||||
Content="上"
|
||||
Cursor="Hand"
|
||||
FontSize="10"
|
||||
ToolTip="上移" />
|
||||
<Button
|
||||
Width="22"
|
||||
Height="22"
|
||||
Margin="1,0"
|
||||
Background="Transparent"
|
||||
BorderBrush="#CDCBCB"
|
||||
BorderThickness="1"
|
||||
Command="{Binding DataContext.MoveNodeDownCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
|
||||
CommandParameter="{Binding}"
|
||||
Content="下"
|
||||
Cursor="Hand"
|
||||
FontSize="10"
|
||||
ToolTip="下移" />
|
||||
<Button
|
||||
Width="22"
|
||||
Height="22"
|
||||
Margin="1,0"
|
||||
Background="Transparent"
|
||||
BorderBrush="#E05050"
|
||||
BorderThickness="1"
|
||||
Command="{Binding DataContext.RemoveOperatorCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
|
||||
CommandParameter="{Binding}"
|
||||
Content="删"
|
||||
Cursor="Hand"
|
||||
FontSize="10"
|
||||
ToolTip="删除" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
<DataTemplate.Triggers>
|
||||
@@ -254,9 +203,6 @@
|
||||
<Setter TargetName="NodeContainer" Property="BorderBrush" Value="#7E9AB6" />
|
||||
<Setter TargetName="NodeContainer" Property="Opacity" Value="1" />
|
||||
</MultiDataTrigger>
|
||||
<Trigger SourceName="NodeRoot" Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="NodeActions" Property="Visibility" Value="Visible" />
|
||||
</Trigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XplorePlane.Models;
|
||||
using XplorePlane.ViewModels;
|
||||
@@ -90,9 +91,14 @@ namespace XplorePlane.Views
|
||||
}
|
||||
|
||||
_isInternalDragging = true;
|
||||
_suppressClickToggle = true;
|
||||
var data = new DataObject(PipelineNodeDragFormat, _draggedNode);
|
||||
DragDrop.DoDragDrop(PipelineListBox, data, DragDropEffects.Move);
|
||||
_suppressClickToggle = true;
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
_suppressClickToggle = false;
|
||||
ResetDragState();
|
||||
}), DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
private void OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
@@ -195,29 +201,11 @@ namespace XplorePlane.Views
|
||||
}
|
||||
|
||||
var oldIndex = vm.PipelineNodes.IndexOf(draggedNode);
|
||||
var targetIndex = GetDropTargetIndex(e.GetPosition(PipelineListBox));
|
||||
if (targetIndex < 0)
|
||||
{
|
||||
targetIndex = vm.PipelineNodes.Count - 1;
|
||||
}
|
||||
var insertionIndex = GetDropInsertionIndex(e.GetPosition(PipelineListBox), vm.PipelineNodes.Count);
|
||||
var newIndex = insertionIndex > oldIndex ? insertionIndex - 1 : insertionIndex;
|
||||
newIndex = Math.Max(0, Math.Min(newIndex, vm.PipelineNodes.Count - 1));
|
||||
|
||||
if (targetIndex >= oldIndex && targetIndex < vm.PipelineNodes.Count - 1)
|
||||
{
|
||||
var targetItem = GetItemAtPosition(e.GetPosition(PipelineListBox));
|
||||
if (targetItem != null)
|
||||
{
|
||||
var itemBounds = VisualTreeHelper.GetDescendantBounds(targetItem);
|
||||
var itemTopLeft = targetItem.TranslatePoint(new Point(0, 0), PipelineListBox);
|
||||
var itemMidY = itemTopLeft.Y + (itemBounds.Height / 2);
|
||||
if (e.GetPosition(PipelineListBox).Y > itemMidY)
|
||||
{
|
||||
targetIndex = Math.Min(targetIndex + 1, vm.PipelineNodes.Count - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetIndex = Math.Max(0, Math.Min(targetIndex, vm.PipelineNodes.Count - 1));
|
||||
if (oldIndex == targetIndex)
|
||||
if (oldIndex == newIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -225,16 +213,27 @@ namespace XplorePlane.Views
|
||||
vm.ReorderOperatorCommand.Execute(new PipelineReorderArgs
|
||||
{
|
||||
OldIndex = oldIndex,
|
||||
NewIndex = targetIndex
|
||||
NewIndex = newIndex
|
||||
});
|
||||
}
|
||||
|
||||
private int GetDropTargetIndex(Point position)
|
||||
private int GetDropInsertionIndex(Point position, int itemCount)
|
||||
{
|
||||
var item = GetItemAtPosition(position);
|
||||
return item == null
|
||||
? -1
|
||||
: PipelineListBox.ItemContainerGenerator.IndexFromContainer(item);
|
||||
if (item == null)
|
||||
{
|
||||
return itemCount;
|
||||
}
|
||||
|
||||
var targetIndex = PipelineListBox.ItemContainerGenerator.IndexFromContainer(item);
|
||||
if (targetIndex < 0)
|
||||
{
|
||||
return itemCount;
|
||||
}
|
||||
|
||||
var itemTop = item.TranslatePoint(new Point(0, 0), PipelineListBox).Y;
|
||||
var itemMid = itemTop + (item.ActualHeight / 2);
|
||||
return position.Y > itemMid ? targetIndex + 1 : targetIndex;
|
||||
}
|
||||
|
||||
private ListBoxItem GetItemAtPosition(Point position)
|
||||
@@ -274,7 +273,12 @@ namespace XplorePlane.Views
|
||||
var current = originalSource as DependencyObject;
|
||||
while (current != null)
|
||||
{
|
||||
if (current is ButtonBase || current is TextBoxBase || current is Selector || current is ScrollBar)
|
||||
if (current is ListBoxItem)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (current is ButtonBase || current is TextBoxBase || current is ScrollBar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user