diff --git a/ChangeLog b/ChangeLog index e20c9a7fa..8a09c43df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,8 @@ on very small (<10^{-300}) probabilities. - The new subgame root computation fixes a bug which failed to detect subgames where the subgame root node is a member of an absent-minded infoset. (#584) +- Removed spurious warning in graphical interface when loading file as a command-line argument + (or also by clicking on a file in MSW, as that uses the command-line mechanism). (#801) ## [16.5.1] - unreleased diff --git a/src/gui/app.cc b/src/gui/app.cc index 1e5fafc48..e7fc195ba 100644 --- a/src/gui/app.cc +++ b/src/gui/app.cc @@ -66,8 +66,6 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas bool Application::OnInit() { - wxApp::OnInit(); - const wxBitmap bitmap(gambitbig_xpm); m_splashTimer.Start(); m_splash = new wxSplashScreen(MakeScaledSplashBitmap(bitmap, 0.45), @@ -84,26 +82,19 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas wxConfigBase::Get()->Read(_T("/General/CurrentDirectory"), &m_currentDir, _T("")); // Process command line arguments, if any. - for (int i = 1; i < wxApp::argc; i++) { - const AppLoadResult result = LoadFile(wxApp::argv[i]); + for (int i = 1; i < argc; i++) { + const AppLoadResult result = LoadFile(argv[i], nullptr); if (result == GBT_APP_OPEN_FAILED) { - wxMessageDialog dialog( - nullptr, wxT("Gambit could not open file '") + wxApp::argv[i] + wxT("' for reading."), - wxT("Unable to open file"), wxOK | wxICON_ERROR); - dialog.ShowModal(); + wxMessageBox(wxString::Format(_("Gambit could not open file for reading:\n%s"), argv[i]), + _("Unable to open file"), wxOK | wxICON_ERROR, nullptr); } else if (result == GBT_APP_PARSE_FAILED) { - wxMessageDialog dialog( - nullptr, wxT("File '") + wxApp::argv[i] + wxT("' is not in a format Gambit recognizes."), - wxT("Unable to read file"), wxOK | wxICON_ERROR); - dialog.ShowModal(); + wxMessageBox(wxString::Format(_("File is not in a format Gambit recognizes:\n%s"), argv[i]), + _("Unable to read file"), wxOK | wxICON_ERROR, nullptr); } } - if (m_documents.size() == 0) { - // If we don't have any game files -- whether because none were - // specified on the command line, or because those specified couldn't - // be read -- create a default document. + if (m_documents.empty()) { const Game efg = NewTree(); efg->NewPlayer()->SetLabel("Player 1"); efg->NewPlayer()->SetLabel("Player 2"); @@ -140,10 +131,12 @@ void Application::DismissSplash() m_splash = nullptr; } -AppLoadResult Application::LoadFile(const wxString &p_filename) +AppLoadResult Application::LoadFile(const wxString &p_filename, wxWindow *p_parent) { - std::ifstream infile((const char *)p_filename.mb_str()); + std::ifstream infile(p_filename.mb_str()); if (!infile.good()) { + wxMessageBox(_("Gambit could not open file for reading:\n") + p_filename, + _("Unable to open file"), wxOK | wxICON_ERROR, p_parent); return GBT_APP_OPEN_FAILED; } @@ -155,9 +148,7 @@ AppLoadResult Application::LoadFile(const wxString &p_filename) (void)new GameFrame(nullptr, doc); return GBT_APP_FILE_OK; } - else { - delete doc; - } + delete doc; try { const Game nfg = ReadGame(infile); @@ -165,11 +156,13 @@ AppLoadResult Application::LoadFile(const wxString &p_filename) m_fileHistory.AddFileToHistory(p_filename); m_fileHistory.Save(*wxConfigBase::Get()); doc = new GameDocument(nfg); - doc->SetFilename(wxT("")); + doc->SetFilename(""); (void)new GameFrame(nullptr, doc); return GBT_APP_FILE_OK; } catch (InvalidFileException &) { + wxMessageBox(_("File is not in a format Gambit recognizes:\n") + p_filename, + _("Unable to read file"), wxOK | wxICON_ERROR, p_parent); return GBT_APP_PARSE_FAILED; } } diff --git a/src/gui/app.h b/src/gui/app.h index 620895c5d..144f8472f 100644 --- a/src/gui/app.h +++ b/src/gui/app.h @@ -63,9 +63,10 @@ class Application final : public wxApp { } void RemoveMenu(wxMenu *p_menu) { m_fileHistory.RemoveMenu(p_menu); } - AppLoadResult LoadFile(const wxString &); + AppLoadResult LoadFile(const wxString &, wxWindow *); + ; #ifdef __WXMAC__ - void MacOpenFile(const wxString &filename) override { LoadFile(filename); } + void MacOpenFile(const wxString &filename) override { LoadFile(filename, nullptr); } #endif // __WXMAC__ //! diff --git a/src/gui/gameframe.cc b/src/gui/gameframe.cc index 6ce968979..dd7a2358f 100644 --- a/src/gui/gameframe.cc +++ b/src/gui/gameframe.cc @@ -649,20 +649,7 @@ void GameFrame::OnFileOpen(wxCommandEvent &) if (dialog.ShowModal() == wxID_OK) { const wxString filename = dialog.GetPath(); wxGetApp().SetCurrentDir(wxPathOnly(filename)); - - const AppLoadResult result = wxGetApp().LoadFile(filename); - if (result == GBT_APP_OPEN_FAILED) { - wxMessageDialog msgdialog( - this, wxT("Gambit could not open file '") + filename + wxT("' for reading."), - wxT("Unable to open file"), wxOK | wxICON_ERROR); - msgdialog.ShowModal(); - } - else if (result == GBT_APP_PARSE_FAILED) { - wxMessageDialog msgdialog( - this, wxT("File '") + filename + wxT("' is not in a format Gambit recognizes."), - wxT("Unable to read file"), wxOK | wxICON_ERROR); - msgdialog.ShowModal(); - } + wxGetApp().LoadFile(filename, this); } } @@ -903,20 +890,7 @@ void GameFrame::OnFileExit(wxCommandEvent &p_event) void GameFrame::OnFileMRUFile(wxCommandEvent &p_event) { const wxString filename = wxGetApp().GetHistoryFile(p_event.GetId() - wxID_FILE1); - const AppLoadResult result = wxGetApp().LoadFile(filename); - - if (result == GBT_APP_OPEN_FAILED) { - wxMessageDialog dialog(this, - wxT("Gambit could not open file '") + filename + wxT("' for reading."), - wxT("Unable to open file"), wxOK | wxICON_ERROR); - dialog.ShowModal(); - } - else if (result == GBT_APP_PARSE_FAILED) { - wxMessageDialog dialog( - this, wxT("File '") + filename + wxT("' is not in a format Gambit recognizes."), - wxT("Unable to read file"), wxOK | wxICON_ERROR); - dialog.ShowModal(); - } + wxGetApp().LoadFile(filename, this); } //----------------------------------------------------------------------