Skip to content

Commit

Permalink
Merge pull request #1141 from vktr/fix/delete-tracker-removes-torrent
Browse files Browse the repository at this point in the history
Fix delete key in trackers view removing torrent
  • Loading branch information
vktr committed Feb 25, 2021
2 parents 7222dde + af415b4 commit 243026c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 57 deletions.
3 changes: 0 additions & 3 deletions src/picotorrent/ui/ids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ namespace UI
ptID_EVT_SHOW_STATUS_BAR,
ptID_EVT_VIEW_PREFERENCES,

ptID_KEY_SELECT_ALL,
ptID_KEY_DELETE,
ptID_KEY_DELETE_FILES,
ptID_KEY_ADD_TORRENT,
ptID_KEY_ADD_MAGNET_LINK,
ptID_KEY_VIEW_HELP,
Expand Down
54 changes: 0 additions & 54 deletions src/picotorrent/ui/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ MainFrame::MainFrame(std::shared_ptr<Core::Environment> env, std::shared_ptr<Cor
// Keyboard accelerators
std::vector<wxAcceleratorEntry> entries =
{
wxAcceleratorEntry(wxACCEL_CTRL, int('A'), ptID_KEY_SELECT_ALL),
wxAcceleratorEntry(wxACCEL_CTRL, int('U'), ptID_KEY_ADD_MAGNET_LINK),
wxAcceleratorEntry(wxACCEL_CTRL, int('O'), ptID_KEY_ADD_TORRENT),
wxAcceleratorEntry(wxACCEL_NORMAL, WXK_DELETE, ptID_KEY_DELETE),
wxAcceleratorEntry(wxACCEL_SHIFT, WXK_DELETE, ptID_KEY_DELETE_FILES),
wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F1, ptID_KEY_VIEW_HELP),
};

Expand Down Expand Up @@ -260,57 +257,6 @@ MainFrame::MainFrame(std::shared_ptr<Core::Environment> env, std::shared_ptr<Cor
this->Bind(wxEVT_MENU, &MainFrame::OnFileAddMagnetLink, this, ptID_KEY_ADD_MAGNET_LINK);
this->Bind(wxEVT_MENU, &MainFrame::OnViewHelp, this, ptID_KEY_VIEW_HELP);

this->Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
{
wxDataViewItemArray items;
m_torrentList->GetSelections(items);

if (items.IsEmpty()) { return; }

for (wxDataViewItem& item : items)
{
m_torrentListModel->GetTorrentFromItem(item)->Remove();
}
},
ptID_KEY_DELETE);

this->Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
{
wxDataViewItemArray items;
m_torrentList->GetSelections(items);

if (items.IsEmpty()) { return; }

if (wxMessageBox(
i18n("confirm_remove_description"),
i18n("confirm_remove"),
wxOK | wxCANCEL | wxICON_INFORMATION,
m_parent) != wxOK) {
return;
}

for (wxDataViewItem& item : items)
{
m_torrentListModel->GetTorrentFromItem(item)->RemoveFiles();
}
},
ptID_KEY_DELETE_FILES);

this->Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
{
m_torrentList->SelectAll();
wxPostEvent(
this,
wxCommandEvent(wxEVT_DATAVIEW_SELECTION_CHANGED, ptID_MAIN_TORRENT_LIST));
},
ptID_KEY_SELECT_ALL);

m_taskBarIcon->Bind(wxEVT_MENU, &MainFrame::OnFileAddTorrent, this, ptID_EVT_ADD_TORRENT);
m_taskBarIcon->Bind(wxEVT_MENU, &MainFrame::OnFileAddMagnetLink, this, ptID_EVT_ADD_MAGNET_LINK);
m_taskBarIcon->Bind(wxEVT_MENU, [this](wxCommandEvent&) { this->Close(true); }, ptID_EVT_EXIT);
Expand Down
61 changes: 61 additions & 0 deletions src/picotorrent/ui/torrentlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,68 @@ TorrentListView::TorrentListView(wxWindow* parent, wxWindowID id, Models::Torren
// insert the "fake" column last, always
AppendColumn(new wxDataViewColumn(wxEmptyString, new wxDataViewTextRenderer(), TorrentListModel::Columns::_Max, 0, wxALIGN_CENTER, 0));

// Keyboard accelerators
std::vector<wxAcceleratorEntry> entries =
{
wxAcceleratorEntry(wxACCEL_CTRL, int('A'), ptID_KEY_SELECT_ALL),
wxAcceleratorEntry(wxACCEL_NORMAL, WXK_DELETE, ptID_KEY_DELETE),
wxAcceleratorEntry(wxACCEL_SHIFT, WXK_DELETE, ptID_KEY_DELETE_FILES),
};

this->SetAcceleratorTable(wxAcceleratorTable(static_cast<int>(entries.size()), entries.data()));

this->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &TorrentListView::ShowHeaderContextMenu, this);

this->Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
{
wxDataViewItemArray items;
this->GetSelections(items);

if (items.IsEmpty()) { return; }

for (wxDataViewItem& item : items)
{
m_model->GetTorrentFromItem(item)->Remove();
}
},
ptID_KEY_DELETE);

this->Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
{
wxDataViewItemArray items;
this->GetSelections(items);

if (items.IsEmpty()) { return; }

if (wxMessageBox(
i18n("confirm_remove_description"),
i18n("confirm_remove"),
wxOK | wxCANCEL | wxICON_INFORMATION,
m_parent) != wxOK) {
return;
}

for (wxDataViewItem& item : items)
{
m_model->GetTorrentFromItem(item)->RemoveFiles();
}
},
ptID_KEY_DELETE_FILES);

this->Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
{
this->SelectAll();
wxPostEvent(
GetParent(),
wxCommandEvent(wxEVT_DATAVIEW_SELECTION_CHANGED, this->GetId()));
},
ptID_KEY_SELECT_ALL);
}

TorrentListView::~TorrentListView()
Expand Down
7 changes: 7 additions & 0 deletions src/picotorrent/ui/torrentlistview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ namespace Models
virtual ~TorrentListView();

private:
enum
{
ptID_KEY_SELECT_ALL = wxID_HIGHEST,
ptID_KEY_DELETE,
ptID_KEY_DELETE_FILES,
};

void ShowHeaderContextMenu(wxCommandEvent&);

struct ColumnMetadata
Expand Down

0 comments on commit 243026c

Please sign in to comment.