Skip to content

Commit

Permalink
Multi selection support, and add file open options in context menus.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexafluoride committed Aug 23, 2014
1 parent 8668181 commit cc9e9ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
8 changes: 4 additions & 4 deletions ByteFlood/UI/MainWindow.xaml
Expand Up @@ -79,12 +79,12 @@
<Button Content="Add RSS feed..." Height="26" HorizontalAlignment="Left" Margin="5,7,0,0" VerticalAlignment="Top" Width="94" Command="{StaticResource Commands.AddRssFeed}" />
<Button Content="Preferences" Height="26" HorizontalAlignment="Left" Margin="5,7,0,0" VerticalAlignment="Top" Width="75" Command="{StaticResource Commands.OpenPreferences}" />
</StackPanel>
<ListView Height="151" Margin="0,0,0,0" HorizontalAlignment="Stretch" BorderThickness="0,1,1,0" DockPanel.Dock="Top" VerticalAlignment="Top" Name="mainlist" Grid.Row="2" SelectionMode="Single" SelectionChanged="mainlist_SelectionChanged" MouseLeftButtonDown="mainlist_MouseLeftButtonDown">
<ListView Height="151" Margin="0,0,0,0" HorizontalAlignment="Stretch" BorderThickness="0,1,1,0" DockPanel.Dock="Top" VerticalAlignment="Top" Name="mainlist" Grid.Row="2" SelectionMode="Extended" SelectionChanged="mainlist_SelectionChanged" MouseLeftButtonDown="mainlist_MouseLeftButtonDown">
<ListView.Resources>
<ContextMenu x:Key="ItemContextMenu">
<MenuItem Header="Start" Click="StartSelectedTorrent" />
<MenuItem Header="Pause" Click="PauseSelectedTorrent" />
<MenuItem Header="Stop" Click="StopSelectedTorrent" />
<MenuItem Header="Start" Tag="Start" Click="OperationOnSelectedTorrents" />
<MenuItem Header="Pause" Tag="Pause" Click="OperationOnSelectedTorrents" />
<MenuItem Header="Stop" Tag="Stop" Click="OperationOnSelectedTorrents" />
<MenuItem Header="Open containing folder" Click="OpenSelectedTorrentLocation" />
<Separator />
<MenuItem Header="Change torrent options" Click="OpenTorrentProperties" />
Expand Down
33 changes: 30 additions & 3 deletions ByteFlood/UI/MainWindow.xaml.cs
Expand Up @@ -308,14 +308,14 @@ public void OpenSelectedFileLocation(object sender, RoutedEventArgs e)
return;
string filepath = t.Torrent.Torrent.Files[files_list.SelectedIndex].FullPath;
string dir = new System.IO.FileInfo(filepath).Directory.FullName;
Process.Start("explorer.exe", dir);
Process.Start("explorer.exe", "\"" + dir + "\"");
}
public void OpenSelectedTorrentLocation(object sender, RoutedEventArgs e)
{
TorrentInfo t;
if (!GetSelectedTorrent(out t))
return;
Process.Start("explorer.exe", t.SavePath);
Process.Start("explorer.exe", "\"" + t.SavePath + "\"");
}
public bool GetSelectedTorrent(out TorrentInfo ti)
{
Expand All @@ -324,7 +324,8 @@ public bool GetSelectedTorrent(out TorrentInfo ti)
return false;
ti = state.Torrents[mainlist.SelectedIndex];
return true;
}
}

#endregion

#region Commands
Expand Down Expand Up @@ -592,6 +593,32 @@ private void Window_StateChanged(object sender, EventArgs e)
if (this.WindowState == System.Windows.WindowState.Minimized)
ExecuteWindowBehavior(App.Settings.MinimizeBehavior);
}

private void OperationOnSelectedTorrents(object sender, RoutedEventArgs e)
{
TorrentInfo[] arr = new TorrentInfo[mainlist.SelectedItems.Count];
mainlist.SelectedItems.CopyTo(arr, 0);
if (arr.Length == 0)
return;
string tag = ((MenuItem)e.Source).Tag.ToString();
Action<TorrentInfo> f = new Action<TorrentInfo>(t => {});
switch (tag)
{
case "Start":
f = new Action<TorrentInfo>(t => t.Start());
break;
case "Pause":
f = new Action<TorrentInfo>(t => t.Pause());
break;
case "Stop":
f = new Action<TorrentInfo>(t => t.Stop());
break;
}
foreach (TorrentInfo ti in arr)
{
f(ti);
}
}

}
}

0 comments on commit cc9e9ec

Please sign in to comment.