Skip to content

Commit

Permalink
Merge pull request #1804 from nicolasnoble/favorites
Browse files Browse the repository at this point in the history
Save/Restore file dialogs favorites.
  • Loading branch information
nicolasnoble authored Nov 19, 2024
2 parents ffc32ac + f06ba3c commit 33b7ec3
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/core/psxemulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class Emulator {
typedef SettingPath<TYPESTRING("EXP1BrowsePath")> SettingEXP1BrowsePath;
typedef Setting<bool, TYPESTRING("PIOConnected")> SettingPIOConnected;
typedef SettingPath<TYPESTRING("MapBrowsePath")> SettingMapBrowsePath;
typedef SettingVector<std::string, TYPESTRING("OpenDialogFavorites")> SettingOpenDialogFavorites;

Settings<SettingMcd1, SettingMcd2, SettingBios, SettingPpfDir, SettingPsxExe, SettingXa, SettingSpuIrq,
SettingBnWMdec, SettingScaler, SettingAutoVideo, SettingVideo, SettingFastBoot, SettingDebugSettings,
Expand All @@ -198,7 +199,7 @@ class Emulator {
SettingGLErrorReportingSeverity, SettingFullCaching, SettingHardwareRenderer, SettingShownAutoUpdateConfig,
SettingAutoUpdate, SettingMSAA, SettingLinearFiltering, SettingKioskMode, SettingMcd1Pocketstation,
SettingMcd2Pocketstation, SettingBiosBrowsePath, SettingEXP1Filepath, SettingEXP1BrowsePath,
SettingPIOConnected, SettingMapBrowsePath>
SettingPIOConnected, SettingMapBrowsePath, SettingOpenDialogFavorites>
settings;
class PcsxConfig {
public:
Expand Down
16 changes: 16 additions & 0 deletions src/gui/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ void PCSX::GUI::openUrl(std::string_view url) {
}
#endif

PCSX::GUI::GUI(std::vector<std::string>& favorites)
: m_listener(g_system->m_eventBus),
m_typedDebugger(settings.get<ShowTypedDebugger>().value, favorites),
m_memcardManager(settings.get<ShowMemcardManager>().value, favorites),
m_assembly(settings.get<ShowAssembly>().value, favorites),
m_openIsoFileDialog(l_("Open Disk Image"), favorites),
m_openBinaryDialog(l_("Open Binary"), favorites),
m_openArchiveDialog(l_("Open Archive"), favorites),
m_selectBiosDialog(l_("Select BIOS"), favorites),
m_selectEXP1Dialog(l_("Select EXP1"), favorites),
m_isoBrowser(settings.get<ShowIsoBrowser>().value, favorites),
m_pioCart(settings.get<ShowPIOCartConfig>().value, favorites) {
assert(g_gui == nullptr);
g_gui = this;
}

using json = nlohmann::json;

static std::function<void(const char*)> s_imguiUserErrorFunctor = nullptr;
Expand Down
25 changes: 11 additions & 14 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ class GUI final : public UI {
GUI *m_gui = nullptr;
};
std::vector<std::string> getGLerrors() { return std::move(m_glErrors); }
GUI() : m_listener(g_system->m_eventBus) {
assert(g_gui == nullptr);
g_gui = this;
}
GUI(std::vector<std::string> &favorites);
~GUI() {
assert(g_gui == this);
g_gui = nullptr;
Expand Down Expand Up @@ -374,20 +371,20 @@ class GUI final : public UI {
MemoryEditorWrapper m_vramEditor = {this, settings.get<ShowVRAMEditor>().value,
settings.get<VRAMEditorAddr>().value};
Widgets::MemoryObserver m_memoryObserver = {settings.get<ShowMemoryObserver>().value};
Widgets::TypedDebugger m_typedDebugger = {settings.get<ShowTypedDebugger>().value};
Widgets::TypedDebugger m_typedDebugger;
Widgets::Patches m_patches = {settings.get<ShowPatches>().value};
Widgets::MemcardManager m_memcardManager = {settings.get<ShowMemcardManager>().value};
Widgets::MemcardManager m_memcardManager;
Widgets::Registers m_registers = {settings.get<ShowRegisters>().value};
Widgets::Assembly m_assembly = {settings.get<ShowAssembly>().value};
Widgets::Assembly m_assembly;
Widgets::Disassembly m_disassembly = {settings.get<ShowDisassembly>().value};
Widgets::FileDialog<> m_openIsoFileDialog = {l_("Open Disk Image")};
Widgets::FileDialog<> m_openBinaryDialog = {l_("Open Binary")};
Widgets::FileDialog<> m_openArchiveDialog = {l_("Open Archive")};
Widgets::FileDialog<> m_selectBiosDialog = {l_("Select BIOS")};
Widgets::FileDialog<> m_selectEXP1Dialog = {l_("Select EXP1")};
Widgets::FileDialog<> m_openIsoFileDialog;
Widgets::FileDialog<> m_openBinaryDialog;
Widgets::FileDialog<> m_openArchiveDialog;
Widgets::FileDialog<> m_selectBiosDialog;
Widgets::FileDialog<> m_selectEXP1Dialog;
Widgets::NamedSaveStates m_namedSaveStates = {settings.get<ShowNamedSaveStates>().value};
Widgets::Breakpoints m_breakpoints = {settings.get<ShowBreakpoints>().value};
Widgets::IsoBrowser m_isoBrowser = {settings.get<ShowIsoBrowser>().value};
Widgets::IsoBrowser m_isoBrowser;

bool m_showCfg = false;
bool m_showUiCfg = false;
Expand All @@ -408,7 +405,7 @@ class GUI final : public UI {

Widgets::CallStacks m_callstacks = {settings.get<ShowCallstacks>().value};

Widgets::PIOCart m_pioCart = {settings.get<ShowPIOCartConfig>().value};
Widgets::PIOCart m_pioCart;
Widgets::SIO1 m_sio1 = {settings.get<ShowSIO1>().value};

Widgets::GPULogger m_gpuLogger{settings.get<ShowGPULogger>().value};
Expand Down
6 changes: 4 additions & 2 deletions src/gui/widgets/assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <set>
#include <string>
#include <string_view>
#include <vector>

#include "core/disr3000a.h"
#include "core/r3000a.h"
Expand All @@ -42,7 +43,8 @@ namespace Widgets {

class Assembly : private Disasm {
public:
Assembly(bool& show) : m_show(show), m_listener(g_system->m_eventBus) {
Assembly(bool& show, std::vector<std::string>& favorites)
: m_show(show), m_listener(g_system->m_eventBus), m_symbolsFileDialog(l_("Load Symbols"), favorites) {
m_listener.listen<Events::GUI::JumpToPC>([this](const auto& event) { m_jumpToPC = event.pc; });
memset(m_jumpAddressString, 0, sizeof(m_jumpAddressString));
}
Expand All @@ -60,7 +62,7 @@ class Assembly : private Disasm {
int m_numColumns = 4;
char m_jumpAddressString[20];
uint32_t m_previousPC = 0;
FileDialog<> m_symbolsFileDialog = {l_("Load Symbols")};
FileDialog<> m_symbolsFileDialog;
std::vector<std::pair<uint32_t, uint32_t>> m_arrows;

// Disasm section
Expand Down
13 changes: 13 additions & 0 deletions src/gui/widgets/filedialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ void PCSX::Widgets::FileDialogBase::setDeleteTexture() {
glDeleteTextures(1, &texID);
};
}

void PCSX::Widgets::FileDialogBase::restoreFavorites() {
for (const auto& fav : m_favorites) {
AddFavorite(fav);
}
}

void PCSX::Widgets::FileDialogBase::saveFavorites() {
m_favorites.clear();
for (const auto& fav : GetFavorites()) {
m_favorites.push_back(fav);
}
}
11 changes: 10 additions & 1 deletion src/gui/widgets/filedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,31 @@ namespace Widgets {
class FileDialogBase : protected ifd::FileDialog {
public:
virtual void* CreateTexture(uint8_t* data, int w, int h, char fmt) override;
FileDialogBase(std::vector<std::string>& favorites) : ifd::FileDialog(), m_favorites(favorites) {}

protected:
void setDeleteTexture();
void restoreFavorites();
void saveFavorites();

private:
std::vector<std::string>& m_favorites;
};

enum class FileDialogMode { Open, MultiSelect, Save };

template <FileDialogMode mode = FileDialogMode::Open>
class FileDialog : public FileDialogBase {
public:
FileDialog(std::function<const char*()> title) : m_title(title) {
FileDialog(std::function<const char*()> title, std::vector<std::string>& favorites)
: FileDialogBase(favorites), m_title(title) {
setToCurrentPath();
setDeleteTexture();
}
virtual ~FileDialog() = default;
void setToCurrentPath() { m_currentPath = std::filesystem::current_path(); }
void openDialog() {
restoreFavorites();
if constexpr (mode == FileDialogMode::Open) {
Open(m_title(), m_title(), "*.*", mode == FileDialogMode::MultiSelect,
reinterpret_cast<const char*>(m_currentPath.u8string().c_str()));
Expand All @@ -67,6 +75,7 @@ class FileDialog : public FileDialogBase {
m_results.reserve(results.size());
for (auto& result : results) m_results.push_back(result.u8string());
Close();
saveFavorites();
}
return done;
}
Expand Down
7 changes: 5 additions & 2 deletions src/gui/widgets/isobrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <stdint.h>

#include <functional>
#include <string>
#include <vector>

#include "gui/widgets/filedialog.h"
#include "support/coroutine.h"
Expand All @@ -35,7 +37,8 @@ namespace Widgets {

class IsoBrowser {
public:
IsoBrowser(bool& show) : m_show(show) {}
IsoBrowser(bool& show, std::vector<std ::string>& favorites)
: m_show(show), m_openIsoFileDialog(l_("Open Disk Image"), favorites) {}
void draw(CDRom* cdrom, const char* title);

bool& m_show;
Expand All @@ -47,7 +50,7 @@ class IsoBrowser {
float m_crcProgress = 0.0f;

Coroutine<> computeCRC(CDRIso*);
FileDialog<> m_openIsoFileDialog = {l_("Open Disk Image")};
FileDialog<> m_openIsoFileDialog;
};

} // namespace Widgets
Expand Down
9 changes: 6 additions & 3 deletions src/gui/widgets/memcard_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ namespace Widgets {

class MemcardManager {
public:
MemcardManager(bool& show) : m_show(show) {}
MemcardManager(bool& show, std::vector<std::string>& favorites)
: m_show(show),
m_importMemoryCardDialog(l_("Import Memory Card file"), favorites),
m_exportMemoryCardDialog(l_("Export Memory Card file"), favorites) {}
bool draw(GUI* gui, const char* title);
bool& m_show;
// The framecount from 0 to 59 inclusive. We need it to know which frame of multi-animation
Expand Down Expand Up @@ -73,8 +76,8 @@ class MemcardManager {

int m_undoIndex = 0;
std::unique_ptr<uint8_t[]> m_latest;
Widgets::FileDialog<> m_importMemoryCardDialog = {l_("Import Memory Card file")};
Widgets::FileDialog<FileDialogMode::Save> m_exportMemoryCardDialog = {l_("Export Memory Card file")};
Widgets::FileDialog<> m_importMemoryCardDialog;
Widgets::FileDialog<FileDialogMode::Save> m_exportMemoryCardDialog;
unsigned m_memoryCardImportExportIndex = 0;

void clearUndoBuffer() {
Expand Down
8 changes: 5 additions & 3 deletions src/gui/widgets/pio-cart.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

#pragma once

#include <stdbool.h>
#include <string>
#include <vector>

#include "gui/widgets/filedialog.h"

Expand All @@ -28,12 +29,13 @@ namespace PCSX {
namespace Widgets {
class PIOCart {
public:
PIOCart(bool& show) : m_show(show) {}
PIOCart(bool& show, std::vector<std::string>& favorites)
: m_show(show), m_selectEXP1Dialog(l_("Select EXP1"), favorites) {}
bool draw(const char* title);
bool& m_show;

private:
Widgets::FileDialog<> m_selectEXP1Dialog = {l_("Select EXP1")};
Widgets::FileDialog<> m_selectEXP1Dialog;
int m_flashSizeIndex;
bool m_switchOn = 1;
};
Expand Down
6 changes: 5 additions & 1 deletion src/gui/widgets/typed_debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ void PCSX::Widgets::TypedDebugger::import(std::string_view fileContents, ImportT
}
}

PCSX::Widgets::TypedDebugger::TypedDebugger(bool& show) : m_show(show), m_listener(g_system->m_eventBus) {
PCSX::Widgets::TypedDebugger::TypedDebugger(bool& show, std::vector<std::string>& favorites)
: m_show(show),
m_listener(g_system->m_eventBus),
m_importDataTypesFileDialog(l_("Import data types"), favorites),
m_importFunctionsFileDialog(l_("Import functions"), favorites) {
m_listener.listen<PCSX::Events::ExecutionFlow::Reset>([this](const auto& event) {
m_displayedWatchData.clear();
for (const auto* bp : m_watchBreakpoints) {
Expand Down
6 changes: 3 additions & 3 deletions src/gui/widgets/typed_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ class TypedDebugger {
public:
void draw(const char* title, GUI* gui);
bool& m_show;
TypedDebugger(bool& show);
TypedDebugger(bool& show, std::vector<std::string>& favorites);

private:
/**
* Data importation.
*/
std::vector<PCSX::u8string> m_dataTypesFile;
Widgets::FileDialog<> m_importDataTypesFileDialog = {l_("Import data types")};
Widgets::FileDialog<> m_importDataTypesFileDialog;
std::vector<PCSX::u8string> m_functionsFile;
Widgets::FileDialog<> m_importFunctionsFileDialog = {l_("Import functions")};
Widgets::FileDialog<> m_importFunctionsFileDialog;
enum class ImportType { DataTypes, Functions };
void import(std::string_view filename, ImportType importType);

Expand Down
3 changes: 2 additions & 1 deletion src/main/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ int pcsxMain(int argc, char **argv) {
// At this point, we're committed to run the emulator, so we first create it, and the UI next.
PCSX::Emulator *emulator = new PCSX::Emulator();
PCSX::g_emulator = emulator;
auto &favorites = emulator->settings.get<PCSX::Emulator::SettingOpenDialogFavorites>().value;

s_ui = args.get<bool>("no-ui") || args.get<bool>("cli") ? reinterpret_cast<PCSX::UI *>(new PCSX::TUI())
: reinterpret_cast<PCSX::UI *>(new PCSX::GUI());
: reinterpret_cast<PCSX::UI *>(new PCSX::GUI(favorites));
// Settings will be loaded after this initialization.
s_ui->init([&emulator, &args, &system]() {
// Start tweaking / sanitizing settings a bit, while continuing to parse the command line
Expand Down
Loading

0 comments on commit 33b7ec3

Please sign in to comment.