From 87007e806897f4d46ead4efa0aea5c67c45b4cd2 Mon Sep 17 00:00:00 2001 From: William JCM Date: Thu, 16 Jan 2020 01:21:47 +0100 Subject: [PATCH] Add staged M.A.S.S. deletion. --- GUI/EvtMainFrame.cpp | 8 ++++ GUI/EvtMainFrame.h | 1 + GUI/MainFrame.cpp | 5 +++ GUI/MainFrame.fbp | 73 +++++++++++++++++++++++++++++++++++++ GUI/MainFrame.h | 2 + MassManager/MassManager.cpp | 10 +++++ MassManager/MassManager.h | 2 + 7 files changed, 101 insertions(+) diff --git a/GUI/EvtMainFrame.cpp b/GUI/EvtMainFrame.cpp index 5f38a80..cbf17b7 100644 --- a/GUI/EvtMainFrame.cpp +++ b/GUI/EvtMainFrame.cpp @@ -203,6 +203,14 @@ void EvtMainFrame::stagingSelectionEvent(wxCommandEvent&) { updateCommandsState(); } +void EvtMainFrame::deleteStagedEvent(wxCommandEvent&) { + int selection = _stagingList->GetSelection(); + + if(selection != wxNOT_FOUND) { + _manager.deleteStagedMass(selection); + } +} + void EvtMainFrame::stagingButtonEvent(wxCommandEvent&) { wxExecute("explorer.exe " + Utility::Directory::toNativeSeparators(_manager.stagingAreaDirectory())); } diff --git a/GUI/EvtMainFrame.h b/GUI/EvtMainFrame.h index c7efaf3..73d357d 100644 --- a/GUI/EvtMainFrame.h +++ b/GUI/EvtMainFrame.h @@ -40,6 +40,7 @@ class EvtMainFrame: public MainFrame { void backupEvent(wxCommandEvent&); void openSaveDirEvent(wxCommandEvent&); void stagingSelectionEvent(wxCommandEvent&); + void deleteStagedEvent(wxCommandEvent&); void stagingButtonEvent(wxCommandEvent&); void installedSelectionEvent(wxListEvent&); void listColumnDragEvent(wxListEvent&); diff --git a/GUI/MainFrame.cpp b/GUI/MainFrame.cpp index eb3b10e..ca64edf 100644 --- a/GUI/MainFrame.cpp +++ b/GUI/MainFrame.cpp @@ -78,6 +78,9 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co _stagingList = new wxListBox( sbSizerStagingArea->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_NEEDED_SB|wxLB_SINGLE ); sbSizerStagingArea->Add( _stagingList, 1, wxALL|wxEXPAND, 5 ); + _deleteStagedButton = new wxButton( sbSizerStagingArea->GetStaticBox(), wxID_ANY, wxT("Delete staged M.A.S.S."), wxDefaultPosition, wxDefaultSize, 0 ); + sbSizerStagingArea->Add( _deleteStagedButton, 0, wxALL|wxEXPAND, 5 ); + _stagingAreaButton = new wxButton( sbSizerStagingArea->GetStaticBox(), wxID_ANY, wxT("Open staging area directory"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizerStagingArea->Add( _stagingAreaButton, 0, wxALL|wxEXPAND, 5 ); @@ -131,6 +134,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co _importButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::importEvent ), NULL, this ); _exportButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::exportEvent ), NULL, this ); _stagingList->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( MainFrame::stagingSelectionEvent ), NULL, this ); + _deleteStagedButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteStagedEvent ), NULL, this ); _stagingAreaButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::stagingButtonEvent ), NULL, this ); this->Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( MainFrame::gameCheckTimerEvent ) ); } @@ -145,6 +149,7 @@ MainFrame::~MainFrame() _importButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::importEvent ), NULL, this ); _exportButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::exportEvent ), NULL, this ); _stagingList->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( MainFrame::stagingSelectionEvent ), NULL, this ); + _deleteStagedButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteStagedEvent ), NULL, this ); _stagingAreaButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::stagingButtonEvent ), NULL, this ); this->Disconnect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( MainFrame::gameCheckTimerEvent ) ); diff --git a/GUI/MainFrame.fbp b/GUI/MainFrame.fbp index 727a02a..bd76bb0 100644 --- a/GUI/MainFrame.fbp +++ b/GUI/MainFrame.fbp @@ -694,6 +694,79 @@ stagingSelectionEvent + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Delete staged M.A.S.S. + + 0 + + 0 + + + 0 + + 1 + _deleteStagedButton + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + deleteStagedEvent + + 5 wxALL|wxEXPAND diff --git a/GUI/MainFrame.h b/GUI/MainFrame.h index bc9ccbc..69d6359 100644 --- a/GUI/MainFrame.h +++ b/GUI/MainFrame.h @@ -45,6 +45,7 @@ class MainFrame : public wxFrame wxButton* _importButton; wxButton* _exportButton; wxListBox* _stagingList; + wxButton* _deleteStagedButton; wxButton* _stagingAreaButton; wxStaticText* _riskLabel; wxStaticText* _gameStatusLabel; @@ -60,6 +61,7 @@ class MainFrame : public wxFrame virtual void importEvent( wxCommandEvent& event ) { event.Skip(); } virtual void exportEvent( wxCommandEvent& event ) { event.Skip(); } virtual void stagingSelectionEvent( wxCommandEvent& event ) { event.Skip(); } + virtual void deleteStagedEvent( wxCommandEvent& event ) { event.Skip(); } virtual void stagingButtonEvent( wxCommandEvent& event ) { event.Skip(); } virtual void gameCheckTimerEvent( wxTimerEvent& event ) { event.Skip(); } diff --git a/MassManager/MassManager.cpp b/MassManager/MassManager.cpp index 26801b8..db5bb82 100644 --- a/MassManager/MassManager.cpp +++ b/MassManager/MassManager.cpp @@ -471,6 +471,16 @@ auto MassManager::removeStagedMass(const std::string& filename) -> int { return -1; } +void MassManager::deleteStagedMass(int index) { + int i = 0; + for(auto it = _stagedMasses.begin(); it != _stagedMasses.end(); ++it, ++i) { + if(i == index) { + Utility::Directory::rm(Utility::Directory::join(_stagingAreaDirectory, it->first)); + break; + } + } +} + std::string MassManager::stagedMassName(int index) { int i = 0; for(const auto& mass_info : _stagedMasses) { diff --git a/MassManager/MassManager.h b/MassManager/MassManager.h index 2698a7e..01be6ab 100644 --- a/MassManager/MassManager.h +++ b/MassManager/MassManager.h @@ -74,6 +74,8 @@ class MassManager { auto updateStagedMass(const std::string& filename) -> int; auto removeStagedMass(const std::string& filename) -> int; + void deleteStagedMass(int index); + auto stagedMassName(int index) -> std::string; auto stagedMassName(const std::string& filename) -> std::string;