Skip to content

Commit

Permalink
[desktop] Remember directory from last laoded rom.
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Dec 8, 2023
1 parent 31650b8 commit ed62779
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
11 changes: 10 additions & 1 deletion platforms/desktop-shared/FileBrowser/ImGuiFileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ namespace imgui_addons
ImGui::CloseCurrentPopup();
}

bool ImGuiFileBrowser::showFileDialog(const std::string& label, const DialogMode mode, const ImVec2& sz_xy, const std::string& valid_types, bool* is_open)
bool ImGuiFileBrowser::showFileDialog(const std::string& label, const DialogMode mode, const ImVec2& sz_xy,
const std::string& valid_types, bool* is_open, const std::string& start_path)
{
is_open_ = is_open;
dialog_mode = mode;
Expand Down Expand Up @@ -140,6 +141,13 @@ namespace imgui_addons
setValidExtTypes(valid_types);
}

if (!start_path.empty())
{
current_path = start_path;
if (current_path.back() != '/')
current_path += '/';
}

/* If current path is empty (can happen on Windows if user closes dialog while inside MyComputer.
* Since this is a virtual folder, path would be empty) load the drives on Windows else initialize the current path on Unix.
*/
Expand Down Expand Up @@ -192,6 +200,7 @@ namespace imgui_addons
if(check)
{
selected_path = current_path + selected_fn;
selected_path_without_file_name = current_path;

//Add a trailing "/" to emphasize its a directory not a file. If you want just the dir name it's accessible through "selected_fn"
if(dialog_mode == DialogMode::SELECT)
Expand Down
4 changes: 3 additions & 1 deletion platforms/desktop-shared/FileBrowser/ImGuiFileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ namespace imgui_addons
* the size, a DialogMode enum value defining in which mode the dialog should operate and optionally the extensions that are valid for opening.
* Note that the select directory mode doesn't need any extensions.
*/
bool showFileDialog(const std::string& label, const DialogMode mode, const ImVec2& sz_xy = ImVec2(0,0), const std::string& valid_types = "*.*", bool* is_open = 0);
bool showFileDialog(const std::string& label, const DialogMode mode, const ImVec2& sz_xy = ImVec2(0,0),
const std::string& valid_types = "*.*", bool* is_open = 0, const std::string& start_path = "");

/* Store the opened/saved file name or dir name (incase of selectDirectoryDialog) and the absolute path to the selection
* Should only be accessed when above functions return true else may contain garbage.
*/
std::string selected_fn;
std::string selected_path;
std::string selected_path_without_file_name;
std::string ext; // Store the saved file extension


Expand Down
2 changes: 2 additions & 0 deletions platforms/desktop-shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void config_read(void)
config_emulator.savefiles_path = read_string("Emulator", "SaveFilesPath");
config_emulator.savestates_dir_option = read_int("Emulator", "SaveStatesDirOption", 0);
config_emulator.savestates_path = read_string("Emulator", "SaveStatesPath");
config_emulator.last_open_path = read_string("Emulator", "LastOpenPath");

if (config_emulator.savefiles_path.empty())
{
Expand Down Expand Up @@ -289,6 +290,7 @@ void config_write(void)
write_string("Emulator", "SaveFilesPath", config_emulator.savefiles_path);
write_int("Emulator", "SaveStatesDirOption", config_emulator.savestates_dir_option);
write_string("Emulator", "SaveStatesPath", config_emulator.savestates_path);
write_string("Emulator", "LastOpenPath", config_emulator.last_open_path);

for (int i = 0; i < config_max_recent_roms; i++)
{
Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct config_Emulator
std::string savefiles_path;
int savestates_dir_option = 0;
std::string savestates_path;
std::string last_open_path;
};

struct config_Video
Expand Down
4 changes: 3 additions & 1 deletion platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,10 @@ static void main_window(void)

static void file_dialog_open_rom(void)
{
if(file_dialog.showFileDialog("Open ROM...", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 400), "*.*,.sms,.gg,.sg,.mv,.rom,.bin,.zip", &dialog_in_use))
if(file_dialog.showFileDialog("Open ROM...", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 400), "*.*,.col,.cv,.rom,.bin,.zip", &dialog_in_use, config_emulator.last_open_path))
{
config_emulator.last_open_path.assign(file_dialog.selected_path_without_file_name);

gui_load_rom(file_dialog.selected_path.c_str());
}
}
Expand Down

0 comments on commit ed62779

Please sign in to comment.