Skip to content

Commit 6604668

Browse files
committed
feat: sftp & ftp support drag file to upload #393
1 parent 0fcfc2f commit 6604668

File tree

3 files changed

+69
-19
lines changed

3 files changed

+69
-19
lines changed

Ui/View/Host/ProtocolHosts/FileTransmitHost.xaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@
471471

472472

473473

474-
<Grid Grid.Row="2">
474+
<Border Grid.Row="2" BorderBrush="{StaticResource DefaultBorderBrush}" BorderThickness="0 2 0 0">
475475
<ListView x:Name="ListViewTransmitTasks"
476476
Background="{DynamicResource PrimaryMidBrush}"
477477
ItemsSource="{Binding TransmitTasks}"
@@ -614,7 +614,7 @@
614614
</DataTemplate>
615615
</ItemsControl.ItemTemplate>
616616
</ListView>
617-
</Grid>
617+
</Border>
618618

619619
<Grid Grid.Row="3" Height="30">
620620
<Grid.Style>
@@ -625,9 +625,6 @@
625625
<DataTrigger Binding="{Binding IoMessageLevel}" Value="-1">
626626
<Setter Property="Visibility" Value="Collapsed"></Setter>
627627
</DataTrigger>
628-
<DataTrigger Binding="{Binding IoMessageLevel}" Value="0">
629-
<Setter Property="Background" Value="{DynamicResource PrimaryMidBrush}"></Setter>
630-
</DataTrigger>
631628
<DataTrigger Binding="{Binding IoMessageLevel}" Value="1">
632629
<Setter Property="Background" Value="Yellow"></Setter>
633630
</DataTrigger>
@@ -640,6 +637,20 @@
640637
<TextBlock Margin="5 0" VerticalAlignment="Center" TextWrapping="WrapWithOverflow"
641638
Text="{Binding IoMessage}"
642639
Foreground="{DynamicResource PrimaryTextBrush}">
640+
<TextBlock.Resources>
641+
<Style TargetType="TextBlock">
642+
<Style.Triggers>
643+
<DataTrigger Binding="{Binding IoMessageLevel}" Value="1">
644+
<Setter Property="Foreground" Value="White"></Setter>
645+
<Setter Property="FontWeight" Value="Bold"></Setter>
646+
</DataTrigger>
647+
<DataTrigger Binding="{Binding IoMessageLevel}" Value="2">
648+
<Setter Property="Foreground" Value="White"></Setter>
649+
<Setter Property="FontWeight" Value="Bold"></Setter>
650+
</DataTrigger>
651+
</Style.Triggers>
652+
</Style>
653+
</TextBlock.Resources>
643654
</TextBlock>
644655
</Grid>
645656
</Grid>
@@ -652,8 +663,7 @@
652663

653664

654665

655-
<Grid
656-
Name="GridLoading" Visibility="{Binding GridLoadingVisibility}">
666+
<Grid Name="GridLoading" Visibility="{Binding GridLoadingVisibility}">
657667
<Grid Background="Black" Opacity="{Binding GridLoadingBgOpacity}"></Grid>
658668
<Control Style="{StaticResource BusyAnimationStyle}" Background="Transparent"/>
659669
</Grid>

Ui/View/Host/ProtocolHosts/FileTransmitHost.xaml.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
24
using System.Globalization;
35
using System.Linq;
46
using System.Windows;
57
using System.Windows.Controls;
68
using System.Windows.Data;
79
using System.Windows.Input;
10+
using System.Windows.Media;
811
using _1RM.Model;
912
using _1RM.Model.Protocol;
1013
using _1RM.Model.Protocol.Base;
1114
using _1RM.Model.Protocol.FileTransmit;
15+
using _1RM.Utils;
1216
using Shawn.Utils;
1317
using Shawn.Utils.Wpf;
1418
using Stylet;
@@ -55,6 +59,37 @@ private FileTransmitHost(ProtocolBase protocolServer) : base(protocolServer, fal
5559
TvFileList.ScrollIntoView(TvFileList.SelectedItem);
5660
}
5761
};
62+
63+
this.AllowDrop = true;
64+
this.DragEnter += OnDragEnter;
65+
this.Drop += OnDrop;
66+
}
67+
68+
private void OnDrop(object sender, DragEventArgs e)
69+
{
70+
try
71+
{
72+
var fileName = (e.Data.GetData(DataFormats.FileDrop) as System.Array)?.GetValue(0)?.ToString();
73+
if (fileName != null)
74+
this._vmRemote.DoUpload(new List<string>() { fileName });
75+
}
76+
catch (Exception ex)
77+
{
78+
MessageBoxHelper.ErrorAlert(ex.Message);
79+
}
80+
}
81+
82+
private void OnDragEnter(object sender, DragEventArgs e)
83+
{
84+
// 拖拽文件以上传
85+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
86+
{
87+
e.Effects = DragDropEffects.Copy;
88+
}
89+
else
90+
{
91+
e.Effects = DragDropEffects.None;
92+
}
5893
}
5994

6095
#region Base Interface

Ui/View/Host/ProtocolHosts/VmFileTransmitHost.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public RelayCommand CmdUploadClipboard
869869
}
870870
}
871871

872-
private void DoUpload(List<string> filePathList)
872+
public void DoUpload(List<string> filePathList)
873873
{
874874
var fis = new List<FileInfo>();
875875
var dis = new List<DirectoryInfo>();
@@ -964,7 +964,12 @@ public RelayCommand CmdDeleteTransmitTask
964964
private readonly CancellationTokenSource _consumingTransmitTaskCancellationTokenSource = new CancellationTokenSource();
965965

966966

967-
public double GridLoadingBgOpacity { get; set; } = 1;
967+
public double GridLoadingBgOpacity
968+
{
969+
get => _gridLoadingBgOpacity;
970+
set => _gridLoadingBgOpacity = value;
971+
}
972+
968973
private Visibility _gridLoadingVisibility = Visibility.Collapsed;
969974
public Visibility GridLoadingVisibility
970975
{
@@ -980,23 +985,21 @@ public Visibility GridLoadingVisibility
980985
}
981986
}
982987

983-
984-
985-
986-
988+
private int _ioMessageLevel = 0;
987989
/// <summary>
988990
/// level: 0 normal; 1 warning(yellow); 2 error(red);
989991
/// </summary>
990-
public int IoMessageLevel { get; set; } = 0;
992+
public int IoMessageLevel
993+
{
994+
get => _ioMessageLevel;
995+
set => SetAndNotifyIfChanged(ref _ioMessageLevel, value);
996+
}
997+
991998
private string _ioMessage = "";
992999
public string IoMessage
9931000
{
9941001
get => _ioMessage;
995-
set
996-
{
997-
SetAndNotifyIfChanged(ref _ioMessage, value);
998-
RaisePropertyChanged(nameof(IoMessageLevel));
999-
}
1002+
set => SetAndNotifyIfChanged(ref _ioMessage, value);
10001003
}
10011004

10021005

@@ -1083,6 +1086,8 @@ public ObservableCollection<RemoteItem> RemoteItems
10831086

10841087

10851088
private ObservableCollection<TransmitTask> _transmitTasks = new ObservableCollection<TransmitTask>();
1089+
private double _gridLoadingBgOpacity = 1;
1090+
10861091
public ObservableCollection<TransmitTask> TransmitTasks
10871092
{
10881093
get => _transmitTasks;

0 commit comments

Comments
 (0)