private void FocusTorrentSearchBoxShortcut(object sender, KeyEventArgs e) { if ((e.Control && e.KeyCode == Keys.F)) { SearchTorrentListTextBox.Focus(); } }
// load list of torrents from active session private async Task RefreshTorrentList() { DialogResult dialogResult; bool doContinue = true; // warn user current selection will be lost if (TorrentFileListTreeView.TotalFilesSelected != 0) { dialogResult = MessageBox.Show("Refreshing the torrent list will cause the current file selection to be lost.\r\n\r\nDo you want to continue?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.No) { doContinue = false; } } if (doContinue) { // update UI state on continue PagesTabControl.SelectedIndex = 0; SearchTorrentListTextBox.Clear(); TorrentFileListTreeView.TotalFilesSelected = 0; TorrentFileListTreeView.TotalFiles = 0; SelectedTorrentLabel.Text = "Selected torrent: None selected"; SelectedFileCountLabel.Text = "Selected files: 0 (total file count not yet known)"; TorrentTabPage.Text = "Torrents"; FilesTabPage.Text = "Files"; TorrentFileListTreeView.Nodes.Clear(); TorrentsListView.Items.Clear(); FileNamesOldNewListView.Items.Clear(); Globals.TorrentsInfo.Clear(); Globals.SelectedTorrent = null; Globals.SelectedTorrentFiles.Clear(); RenameButton.Enabled = false; RefreshTorrentListButton.Enabled = false; RefreshTorrentListButton.Text = "Waiting (10)"; TimeOutTimer.Start(); ToggleLoadingPanels(true); // retrieve torrents list List <TorrentInfo> torrentsInfo = await Task.Run(() => Globals.SessionHandler.GetTorrents()); TimeOutTimer.Stop(); TimeOutTimer.Tag = Properties.Settings.Default.MaxRequestDuration; // handle list response if (torrentsInfo != null) { if (torrentsInfo.Count == 0) { MessageBox.Show("The host returned 0 torrents.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { List <FriendlyTorrentInfo> globalTorrentsInfo = new List <FriendlyTorrentInfo>(); List <ListViewItem> torrentLVItems = new List <ListViewItem>(); TorrentsListView.BeginUpdate(); foreach (TorrentInfo torrent in torrentsInfo) { FriendlyTorrentInfo fTorrentInfo = new FriendlyTorrentInfo(torrent); globalTorrentsInfo.Add(fTorrentInfo); var torrentLVItem = new ListViewItem(new[] { fTorrentInfo.QueuePosition, fTorrentInfo.Name, fTorrentInfo.Status, fTorrentInfo.Size, fTorrentInfo.Progress }) { Tag = fTorrentInfo.Torrent }; torrentLVItems.Add(torrentLVItem); } TorrentsListView.Items.AddRange(torrentLVItems.ToArray()); TorrentsListView.EndUpdate(); Globals.TorrentsInfo = globalTorrentsInfo; } } else { MessageBox.Show("The torrent list could not be retrieved.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error); } allItems.Clear(); allItems.AddRange(TorrentsListView.Items.Cast <ListViewItem>()); ToggleLoadingPanels(false); RefreshTorrentListButton.Text = "Refresh Torrent List"; TorrentTabPage.Text = $"Torrents ({Globals.TorrentsInfo.Count})"; RefreshTorrentListButton.Enabled = true; SearchTorrentListTextBox.Focus(); } }