Skip to content

Commit 32c0a97

Browse files
authored
Fix spurious graphical interface warning on loading games on command line (#801)
When launching the graphical interface via the command line and passing a filename (or filenames) as arguments, a spurious warning on unexpected arguments was generated. This has been corrected, and the dialog boxes shown on failing to load a file have been tidied up a bit.
1 parent 43ba14c commit 32c0a97

4 files changed

Lines changed: 22 additions & 52 deletions

File tree

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
on very small (<10^{-300}) probabilities.
1919
- The new subgame root computation fixes a bug which failed to detect subgames where the subgame
2020
root node is a member of an absent-minded infoset. (#584)
21+
- Removed spurious warning in graphical interface when loading file as a command-line argument
22+
(or also by clicking on a file in MSW, as that uses the command-line mechanism). (#801)
2123

2224
## [16.5.1] - unreleased
2325

src/gui/app.cc

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas
6666

6767
bool Application::OnInit()
6868
{
69-
wxApp::OnInit();
70-
7169
const wxBitmap bitmap(gambitbig_xpm);
7270
m_splashTimer.Start();
7371
m_splash = new wxSplashScreen(MakeScaledSplashBitmap(bitmap, 0.45),
@@ -84,26 +82,19 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas
8482
wxConfigBase::Get()->Read(_T("/General/CurrentDirectory"), &m_currentDir, _T(""));
8583

8684
// Process command line arguments, if any.
87-
for (int i = 1; i < wxApp::argc; i++) {
88-
const AppLoadResult result = LoadFile(wxApp::argv[i]);
85+
for (int i = 1; i < argc; i++) {
86+
const AppLoadResult result = LoadFile(argv[i], nullptr);
8987
if (result == GBT_APP_OPEN_FAILED) {
90-
wxMessageDialog dialog(
91-
nullptr, wxT("Gambit could not open file '") + wxApp::argv[i] + wxT("' for reading."),
92-
wxT("Unable to open file"), wxOK | wxICON_ERROR);
93-
dialog.ShowModal();
88+
wxMessageBox(wxString::Format(_("Gambit could not open file for reading:\n%s"), argv[i]),
89+
_("Unable to open file"), wxOK | wxICON_ERROR, nullptr);
9490
}
9591
else if (result == GBT_APP_PARSE_FAILED) {
96-
wxMessageDialog dialog(
97-
nullptr, wxT("File '") + wxApp::argv[i] + wxT("' is not in a format Gambit recognizes."),
98-
wxT("Unable to read file"), wxOK | wxICON_ERROR);
99-
dialog.ShowModal();
92+
wxMessageBox(wxString::Format(_("File is not in a format Gambit recognizes:\n%s"), argv[i]),
93+
_("Unable to read file"), wxOK | wxICON_ERROR, nullptr);
10094
}
10195
}
10296

103-
if (m_documents.size() == 0) {
104-
// If we don't have any game files -- whether because none were
105-
// specified on the command line, or because those specified couldn't
106-
// be read -- create a default document.
97+
if (m_documents.empty()) {
10798
const Game efg = NewTree();
10899
efg->NewPlayer()->SetLabel("Player 1");
109100
efg->NewPlayer()->SetLabel("Player 2");
@@ -140,10 +131,12 @@ void Application::DismissSplash()
140131
m_splash = nullptr;
141132
}
142133

143-
AppLoadResult Application::LoadFile(const wxString &p_filename)
134+
AppLoadResult Application::LoadFile(const wxString &p_filename, wxWindow *p_parent)
144135
{
145-
std::ifstream infile((const char *)p_filename.mb_str());
136+
std::ifstream infile(p_filename.mb_str());
146137
if (!infile.good()) {
138+
wxMessageBox(_("Gambit could not open file for reading:\n") + p_filename,
139+
_("Unable to open file"), wxOK | wxICON_ERROR, p_parent);
147140
return GBT_APP_OPEN_FAILED;
148141
}
149142

@@ -155,21 +148,21 @@ AppLoadResult Application::LoadFile(const wxString &p_filename)
155148
(void)new GameFrame(nullptr, doc);
156149
return GBT_APP_FILE_OK;
157150
}
158-
else {
159-
delete doc;
160-
}
151+
delete doc;
161152

162153
try {
163154
const Game nfg = ReadGame(infile);
164155

165156
m_fileHistory.AddFileToHistory(p_filename);
166157
m_fileHistory.Save(*wxConfigBase::Get());
167158
doc = new GameDocument(nfg);
168-
doc->SetFilename(wxT(""));
159+
doc->SetFilename("");
169160
(void)new GameFrame(nullptr, doc);
170161
return GBT_APP_FILE_OK;
171162
}
172163
catch (InvalidFileException &) {
164+
wxMessageBox(_("File is not in a format Gambit recognizes:\n") + p_filename,
165+
_("Unable to read file"), wxOK | wxICON_ERROR, p_parent);
173166
return GBT_APP_PARSE_FAILED;
174167
}
175168
}

src/gui/app.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ class Application final : public wxApp {
6363
}
6464
void RemoveMenu(wxMenu *p_menu) { m_fileHistory.RemoveMenu(p_menu); }
6565

66-
AppLoadResult LoadFile(const wxString &);
66+
AppLoadResult LoadFile(const wxString &, wxWindow *);
67+
;
6768
#ifdef __WXMAC__
68-
void MacOpenFile(const wxString &filename) override { LoadFile(filename); }
69+
void MacOpenFile(const wxString &filename) override { LoadFile(filename, nullptr); }
6970
#endif // __WXMAC__
7071

7172
//!

src/gui/gameframe.cc

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -649,20 +649,7 @@ void GameFrame::OnFileOpen(wxCommandEvent &)
649649
if (dialog.ShowModal() == wxID_OK) {
650650
const wxString filename = dialog.GetPath();
651651
wxGetApp().SetCurrentDir(wxPathOnly(filename));
652-
653-
const AppLoadResult result = wxGetApp().LoadFile(filename);
654-
if (result == GBT_APP_OPEN_FAILED) {
655-
wxMessageDialog msgdialog(
656-
this, wxT("Gambit could not open file '") + filename + wxT("' for reading."),
657-
wxT("Unable to open file"), wxOK | wxICON_ERROR);
658-
msgdialog.ShowModal();
659-
}
660-
else if (result == GBT_APP_PARSE_FAILED) {
661-
wxMessageDialog msgdialog(
662-
this, wxT("File '") + filename + wxT("' is not in a format Gambit recognizes."),
663-
wxT("Unable to read file"), wxOK | wxICON_ERROR);
664-
msgdialog.ShowModal();
665-
}
652+
wxGetApp().LoadFile(filename, this);
666653
}
667654
}
668655

@@ -903,20 +890,7 @@ void GameFrame::OnFileExit(wxCommandEvent &p_event)
903890
void GameFrame::OnFileMRUFile(wxCommandEvent &p_event)
904891
{
905892
const wxString filename = wxGetApp().GetHistoryFile(p_event.GetId() - wxID_FILE1);
906-
const AppLoadResult result = wxGetApp().LoadFile(filename);
907-
908-
if (result == GBT_APP_OPEN_FAILED) {
909-
wxMessageDialog dialog(this,
910-
wxT("Gambit could not open file '") + filename + wxT("' for reading."),
911-
wxT("Unable to open file"), wxOK | wxICON_ERROR);
912-
dialog.ShowModal();
913-
}
914-
else if (result == GBT_APP_PARSE_FAILED) {
915-
wxMessageDialog dialog(
916-
this, wxT("File '") + filename + wxT("' is not in a format Gambit recognizes."),
917-
wxT("Unable to read file"), wxOK | wxICON_ERROR);
918-
dialog.ShowModal();
919-
}
893+
wxGetApp().LoadFile(filename, this);
920894
}
921895

922896
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)