From 1815d650dad12c16a4f3fba02847e451ba7222df Mon Sep 17 00:00:00 2001 From: Theodore Turocy Date: Sun, 15 Mar 2026 19:55:41 +0000 Subject: [PATCH 1/4] Remove call to wxApp::OnInit() which was creating spurious warnings when opening files on MSW. --- src/gui/app.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/gui/app.cc b/src/gui/app.cc index 1e5fafc48..918370ee6 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,23 @@ 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]); 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); + wxMessageDialog dialog(nullptr, + wxT("Gambit could not open file '") + argv[i] + wxT("' for reading."), + wxT("Unable to open file"), wxOK | wxICON_ERROR); dialog.ShowModal(); } else if (result == GBT_APP_PARSE_FAILED) { wxMessageDialog dialog( - nullptr, wxT("File '") + wxApp::argv[i] + wxT("' is not in a format Gambit recognizes."), + nullptr, wxT("File '") + argv[i] + wxT("' is not in a format Gambit recognizes."), wxT("Unable to read file"), wxOK | wxICON_ERROR); dialog.ShowModal(); } } - 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"); From 8b9e5db8f90bfa51768d0103bdf98b05092c4c4c Mon Sep 17 00:00:00 2001 From: Theodore Turocy Date: Sun, 15 Mar 2026 20:06:14 +0000 Subject: [PATCH 2/4] Minor improvements to error dialogs on failing to open file passed on command-line --- src/gui/app.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/gui/app.cc b/src/gui/app.cc index 918370ee6..b6a25a32e 100644 --- a/src/gui/app.cc +++ b/src/gui/app.cc @@ -85,16 +85,12 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas for (int i = 1; i < argc; i++) { const AppLoadResult result = LoadFile(argv[i]); if (result == GBT_APP_OPEN_FAILED) { - wxMessageDialog dialog(nullptr, - wxT("Gambit could not open file '") + 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 '") + 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); } } From d536156fc7b71bbaf965b6ce85c0dfd0f903c659 Mon Sep 17 00:00:00 2001 From: Theodore Turocy Date: Sun, 15 Mar 2026 20:24:56 +0000 Subject: [PATCH 3/4] Unify dialog boxes on file loading errors into one place. --- src/gui/app.cc | 16 +++++++++------- src/gui/app.h | 5 +++-- src/gui/gameframe.cc | 30 ++---------------------------- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/src/gui/app.cc b/src/gui/app.cc index b6a25a32e..e7fc195ba 100644 --- a/src/gui/app.cc +++ b/src/gui/app.cc @@ -83,7 +83,7 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas // Process command line arguments, if any. for (int i = 1; i < argc; i++) { - const AppLoadResult result = LoadFile(argv[i]); + const AppLoadResult result = LoadFile(argv[i], nullptr); if (result == GBT_APP_OPEN_FAILED) { wxMessageBox(wxString::Format(_("Gambit could not open file for reading:\n%s"), argv[i]), _("Unable to open file"), wxOK | wxICON_ERROR, nullptr); @@ -131,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; } @@ -146,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); @@ -156,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); } //---------------------------------------------------------------------- From b1facbecaff0d01dc922744dfe30b4dc7bda4325 Mon Sep 17 00:00:00 2001 From: Theodore Turocy Date: Sun, 15 Mar 2026 20:30:59 +0000 Subject: [PATCH 4/4] Unify dialog boxes on file loading errors into one place. --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) 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