Ability to Drag and drop proxies

This commit is contained in:
ForlaxPy
2019-06-15 07:51:04 -07:00
parent 3cbd367b39
commit 446fc39297
2 changed files with 31 additions and 6 deletions
+5 -5
View File
@@ -25,7 +25,7 @@
<RowDefinition Height="80" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Top Grid -->
<Grid Grid.Column="0" Grid.Row="0">
<Grid.ColumnDefinitions>
@@ -33,7 +33,7 @@
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
@@ -54,12 +54,12 @@
</DockPanel>
</Grid>
<!-- Check Button -->
<Button x:Name="checkButton" Grid.Column="1" Grid.Row="0" Margin="5" Content="CHECK" Click="checkButton_Click" />
<!-- Proxies List View -->
<ListView x:Name="proxiesListView" Grid.Column="0" Grid.Row="1" Foreground="{DynamicResource ForegroundMain}" Background="Transparent" ItemsSource="{Binding Path=ProxyList}" SelectionMode="Extended" BorderThickness="1" VirtualizingPanel.IsVirtualizing="True">
<ListView x:Name="proxiesListView" Grid.Column="0" Grid.Row="1" Foreground="{DynamicResource ForegroundMain}" Background="Transparent" ItemsSource="{Binding Path=ProxyList}" SelectionMode="Extended" BorderThickness="1" VirtualizingPanel.IsVirtualizing="True" AllowDrop="True" Drop="ProxyListViewDrop">
<!-- Show Headers by overriding the default style -->
<ListView.Style>
@@ -150,7 +150,7 @@
</Trigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.ItemsPanel>
+26 -1
View File
@@ -98,7 +98,7 @@ namespace OpenBullet
break;
}
}
App.Current.Dispatcher.Invoke(() =>
{
Globals.LogInfo(Components.ProxyManager, "Check completed, re-enabling the UI");
@@ -212,6 +212,31 @@ namespace OpenBullet
}
#endregion
private void ProxyListViewDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files.Where(x => x.EndsWith(".txt")).ToArray())
{
try
{
if ((file.ToLower()).Contains("http"))
AddProxies(file, ProxyType.Http, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
else if ((file.ToLower()).Contains("socks4"))
AddProxies(file, ProxyType.Socks4, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
else if ((file.ToLower()).Contains("socks4a"))
AddProxies(file, ProxyType.Socks4a, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
else if ((file.ToLower()).Contains("socks5"))
AddProxies(file, ProxyType.Socks5, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
else
Globals.LogError(Components.ProxyManager, "Failed to parse proxies type from file name");
}
catch { }
}
}
}
public void AddProxies(string fileName, ProxyType type, List<string> lines)
{
List<string> fromFile = new List<string>();