From c0e88ec90e3a8717fa181efb07179e6c9ac06e67 Mon Sep 17 00:00:00 2001 From: William JCM Date: Sat, 13 Jun 2020 22:29:23 +0200 Subject: [PATCH] MainFrame: expose renaming in the UI. --- GUI/EvtMainFrame.cpp | 27 ++++++++++++++++ GUI/EvtMainFrame.h | 1 + GUI/MainFrame.cpp | 5 +++ GUI/MainFrame.fbp | 73 ++++++++++++++++++++++++++++++++++++++++++++ GUI/MainFrame.h | 2 ++ 5 files changed, 108 insertions(+) diff --git a/GUI/EvtMainFrame.cpp b/GUI/EvtMainFrame.cpp index ac4207f..1a3cff6 100644 --- a/GUI/EvtMainFrame.cpp +++ b/GUI/EvtMainFrame.cpp @@ -22,6 +22,8 @@ #include #include +#include "EvtNameChangeDialog.h" + #include "EvtMainFrame.h" using namespace Corrade; @@ -177,6 +179,30 @@ void EvtMainFrame::deleteEvent(wxCommandEvent&) { } } +void EvtMainFrame::renameMassEvent(wxCommandEvent&) { + const static std::string error_prefix = "Rename failed:\n\n"; + + EvtNameChangeDialog dialog{this}; + dialog.setName(*(_manager.massName(_installedListView->GetFirstSelected()))); + int result = dialog.ShowModal(); + + if(result == wxID_OK) { + switch(_manager.gameState()) { + case GameState::Unknown: + errorMessage(error_prefix + "For security reasons, renaming a M.A.S.S. is disabled if the game's status is unknown."); + break; + case GameState::NotRunning: + if(!_manager.renameMass(_installedListView->GetFirstSelected(), dialog.getName())) { + errorMessage(error_prefix + _manager.lastError()); + } + break; + case GameState::Running: + errorMessage(error_prefix + "Renaming a M.A.S.S. is disabled while the game is running."); + break; + } + } +} + void EvtMainFrame::backupEvent(wxCommandEvent&) { const static std::string error_prefix = "Backup failed:\n\n"; @@ -399,6 +425,7 @@ void EvtMainFrame::updateCommandsState() { _exportButton->Enable(selection != -1); _moveButton->Enable(selection != -1 && game_state != GameState::Running && hangar_state != HangarState::Empty && hangar_state != HangarState::Invalid); _deleteButton->Enable(selection != -1 && game_state != GameState::Running && hangar_state != HangarState::Empty); + _renameButton->Enable(selection != -1 && game_state != GameState::Running && hangar_state != HangarState::Empty); _deleteStagedButton->Enable(staged_selection != -1); } diff --git a/GUI/EvtMainFrame.h b/GUI/EvtMainFrame.h index 73d357d..9bfb90e 100644 --- a/GUI/EvtMainFrame.h +++ b/GUI/EvtMainFrame.h @@ -37,6 +37,7 @@ class EvtMainFrame: public MainFrame { void exportEvent(wxCommandEvent&); void moveEvent(wxCommandEvent&); void deleteEvent(wxCommandEvent&); + void renameMassEvent(wxCommandEvent&); void backupEvent(wxCommandEvent&); void openSaveDirEvent(wxCommandEvent&); void stagingSelectionEvent(wxCommandEvent&); diff --git a/GUI/MainFrame.cpp b/GUI/MainFrame.cpp index 1bc9a06..e9e3c85 100644 --- a/GUI/MainFrame.cpp +++ b/GUI/MainFrame.cpp @@ -37,6 +37,9 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co _deleteButton = new wxButton( sbSizerButtons->GetStaticBox(), wxID_ANY, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizerButtons->Add( _deleteButton, 1, wxALL|wxEXPAND, 5 ); + _renameButton = new wxButton( sbSizerButtons->GetStaticBox(), wxID_ANY, wxT("Rename"), wxDefaultPosition, wxDefaultSize, 0 ); + sbSizerButtons->Add( _renameButton, 1, wxALL|wxEXPAND, 5 ); + sbSizerInstalled->Add( sbSizerButtons, 0, wxEXPAND, 5 ); @@ -132,6 +135,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co // Connect Events _moveButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveEvent ), NULL, this ); _deleteButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteEvent ), NULL, this ); + _renameButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::renameMassEvent ), NULL, this ); _zipButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::backupEvent ), NULL, this ); _openSaveDirButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openSaveDirEvent ), NULL, this ); _importButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::importEvent ), NULL, this ); @@ -147,6 +151,7 @@ MainFrame::~MainFrame() // Disconnect Events _moveButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveEvent ), NULL, this ); _deleteButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteEvent ), NULL, this ); + _renameButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::renameMassEvent ), NULL, this ); _zipButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::backupEvent ), NULL, this ); _openSaveDirButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openSaveDirEvent ), NULL, this ); _importButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::importEvent ), NULL, this ); diff --git a/GUI/MainFrame.fbp b/GUI/MainFrame.fbp index 84e1c95..4d597ed 100644 --- a/GUI/MainFrame.fbp +++ b/GUI/MainFrame.fbp @@ -300,6 +300,79 @@ deleteEvent + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Rename + + 0 + + 0 + + + 0 + + 1 + _renameButton + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + renameMassEvent + + diff --git a/GUI/MainFrame.h b/GUI/MainFrame.h index 0b67bfb..c3fe3da 100644 --- a/GUI/MainFrame.h +++ b/GUI/MainFrame.h @@ -41,6 +41,7 @@ class MainFrame : public wxFrame wxListView* _installedListView; wxButton* _moveButton; wxButton* _deleteButton; + wxButton* _renameButton; wxButton* _zipButton; wxButton* _openSaveDirButton; wxButton* _importButton; @@ -58,6 +59,7 @@ class MainFrame : public wxFrame // Virtual event handlers, overide them in your derived class virtual void moveEvent( wxCommandEvent& event ) { event.Skip(); } virtual void deleteEvent( wxCommandEvent& event ) { event.Skip(); } + virtual void renameMassEvent( wxCommandEvent& event ) { event.Skip(); } virtual void backupEvent( wxCommandEvent& event ) { event.Skip(); } virtual void openSaveDirEvent( wxCommandEvent& event ) { event.Skip(); } virtual void importEvent( wxCommandEvent& event ) { event.Skip(); }