Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [17.0.0-beta.2] - unreleased

### Added
- The "Open existing game" button on the GUI's welcome screen now has a dropdown listing the most
recently opened games. (#1108)
- Details on bifurcations found and actions taken to resolve them (by perturbation) are now reported
by `nash.logit_solve` (and related functions) (#186)

Expand Down
36 changes: 33 additions & 3 deletions src/gui/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#endif // WX_PRECOMP
#include <wx/artprov.h>
#include <wx/display.h>
#include <wx/filename.h>
#include <wx/image.h>

#include "games.h"
Expand Down Expand Up @@ -183,9 +184,17 @@ AppLoadResult Application::LoadFile(const wxString &p_filename, wxWindow *p_pare

switch (result) {
case GameDocument::LoadResult::OpenFailed:
FileErrorDialog(p_parent, _("Unable to open file"),
_("Gambit could not open this file for reading."), p_filename)
.ShowModal();
if (!wxFileName::FileExists(p_filename) && ForgetRecentFile(p_filename)) {
FileErrorDialog(p_parent, _("File not found"), _("This file no longer exists."),
p_filename + "\n\n" +
_("It has been removed from the list of recent games."))
.ShowModal();
}
else {
FileErrorDialog(p_parent, _("Unable to open file"),
_("Gambit could not open this file for reading."), p_filename)
.ShowModal();
}
return AppLoadResult::OpenFailed;

case GameDocument::LoadResult::ParseFailed:
Expand All @@ -210,6 +219,27 @@ AppLoadResult Application::LoadFile(const wxString &p_filename, wxWindow *p_pare
}
}

std::vector<wxString> Application::GetRecentFiles() const
{
std::vector<wxString> files;
for (size_t i = 0; i < m_fileHistory.GetCount(); i++) {
files.push_back(m_fileHistory.GetHistoryFile(i));
}
return files;
}

bool Application::ForgetRecentFile(const wxString &p_filename)
{
for (size_t i = 0; i < m_fileHistory.GetCount(); i++) {
if (m_fileHistory.GetHistoryFile(i) == p_filename) {
m_fileHistory.RemoveFileFromHistory(i);
m_fileHistory.Save(*wxConfigBase::Get());
return true;
}
}
return false;
}

void Application::SetCurrentDir(const wxString &p_dir)
{
m_currentDir = p_dir;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef GAMBIT_GUI_APP_H
#define GAMBIT_GUI_APP_H

#include <vector>

#include <wx/wx.h>
#include <wx/config.h> // for wxConfig
#include <wx/docview.h> // for wxFileHistory
Expand Down Expand Up @@ -50,6 +52,8 @@ class Application final : public wxApp {
bool OnInit() override;
void DismissSplash();
void OnSplashDismissTimer(wxTimerEvent &) { DismissSplash(); }
//! Drop `p_filename` from the recently-used list; returns whether it was there.
bool ForgetRecentFile(const wxString &p_filename);

wxDECLARE_EVENT_TABLE();

Expand All @@ -61,6 +65,8 @@ class Application final : public wxApp {
void SetCurrentDir(const wxString &p_dir);

wxString GetHistoryFile(int index) const { return m_fileHistory.GetHistoryFile(index); }
//! The recently-used files, most recent first.
std::vector<wxString> GetRecentFiles() const;
void AddMenu(wxMenu *p_menu)
{
m_fileHistory.UseMenu(p_menu);
Expand Down
Loading
Loading