Skip to content

Commit

Permalink
Merge pull request #119 from audetto/filebrowser
Browse files Browse the repository at this point in the history
sa2: add simple file browser.

#118
  • Loading branch information
audetto committed Dec 10, 2023
2 parents c4ff239 + 601c3bd commit 124c089
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "source/frontends/sdl/imgui/imgui_club"]
path = source/frontends/sdl/imgui/imgui_club
url = ../../ocornut/imgui_club
[submodule "source/frontends/sdl/imgui/imgui-filebrowser"]
path = source/frontends/sdl/imgui/imgui-filebrowser
url = ../../AirGuanZ/imgui-filebrowser
1 change: 1 addition & 0 deletions source/frontends/sdl/imgui/imgui-filebrowser
Submodule imgui-filebrowser added at 7cc76a
45 changes: 43 additions & 2 deletions source/frontends/sdl/imgui/sdlsettings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "StdAfx.h"
#include "frontends/sdl/imgui/sdlsettings.h"
#include "frontends/sdl/imgui/settingshelper.h"
#include "frontends/sdl/processfile.h"
#include "frontends/sdl/sdirectsound.h"
#include "frontends/sdl/sdlframe.h"
#include "linux/registryclass.h"
Expand Down Expand Up @@ -248,7 +249,7 @@ namespace sa2
size_t dragAndDropDrive;
frame->getDragDropSlotAndDrive(dragAndDropSlot, dragAndDropDrive);

if (ImGui::BeginTable("Disk2", 12, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit))
if (ImGui::BeginTable("Disk2", 13, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit))
{
ImGui::TableSetupColumn("Slot", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Drive", ImGuiTableColumnFlags_WidthFixed);
Expand All @@ -260,6 +261,7 @@ namespace sa2
ImGui::TableSetupColumn("Eject", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Swap", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("D&D", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Open", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Filename", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableHeadersRow();

Expand Down Expand Up @@ -319,8 +321,16 @@ namespace sa2
frame->setDragDropSlotAndDrive(slot, drive);
}

ImGui::TableNextColumn();
if (ImGui::SmallButton("Open"))
{
const std::string & diskName = card2->DiskGetFullPathName(drive);
openFileDialog(diskName, slot, drive);
}

ImGui::TableNextColumn();
ImGui::TextUnformatted(card2->GetFullDiskFilename(drive).c_str());

ImGui::PopID();
}
}
Expand All @@ -342,33 +352,52 @@ namespace sa2
ImGui::TableNextColumn();
ImGui::TableNextColumn();
ImGui::TableNextColumn();
ImGui::TableNextColumn();

ImGui::TableNextColumn();
ImGui::TextUnformatted(getDiskStatusName(disk1Status_).c_str());

ImGui::TableNextColumn();
if (ImGui::SmallButton("Eject"))
{
pHarddiskCard->Unplug(drive);
}

ImGui::TableNextColumn();
if (ImGui::SmallButton("Swap"))
{
pHarddiskCard->ImageSwap();
}

ImGui::TableNextColumn();
if (ImGui::RadioButton("##Sel", (dragAndDropSlot == slot) && (dragAndDropDrive == drive)))
{
frame->setDragDropSlotAndDrive(slot, drive);
}

ImGui::TableNextColumn();
if (ImGui::SmallButton("Open"))
{
const std::string & diskName = pHarddiskCard->HarddiskGetFullPathName(drive);
openFileDialog(diskName, slot, drive);
}

ImGui::TableNextColumn();
ImGui::TextUnformatted(pHarddiskCard->GetFullName(drive).c_str());

ImGui::PopID();
}
}
ImGui::PopID();
}
ImGui::EndTable();

myFileDialog.Display();
if (myFileDialog.HasSelected())
{
sa2::processFile(frame, myFileDialog.GetSelected().string().c_str(), myOpenSlot, myOpenDrive);
myFileDialog.ClearSelected();
}

}
ImGui::EndTabItem();
}
Expand Down Expand Up @@ -762,4 +791,16 @@ namespace sa2
myDebugger.resetDebuggerCycles();
}

void ImGuiSettings::openFileDialog(const std::string & diskName, const size_t slot, const size_t drive)
{
if (!diskName.empty())
{
const std::filesystem::path path(diskName);
myFileDialog.SetPwd(path.parent_path());
}
myFileDialog.Open();
myOpenSlot = slot;
myOpenDrive = drive;
}

}
6 changes: 6 additions & 0 deletions source/frontends/sdl/imgui/sdlsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "frontends/sdl/imgui/glselector.h"
#include "frontends/sdl/imgui/sdldebugger.h"
#include "frontends/sdl/imgui/imgui-filebrowser/imfilebrowser.h"
#include "frontends/sdl/sdirectsound.h"

namespace sa2
Expand All @@ -27,7 +28,11 @@ namespace sa2
int mySpeakerVolume;
int myMockingboardVolume;

size_t myOpenSlot = 0;
size_t myOpenDrive = 0;

ImGuiDebugger myDebugger;
ImGui::FileBrowser myFileDialog;

std::vector<MemoryEditor> myMemoryEditors;

Expand All @@ -36,6 +41,7 @@ namespace sa2
void showSettings(SDLFrame* frame);
void showMemory();
void showAboutWindow();
void openFileDialog(const std::string & diskName, const size_t slot, const size_t drive);
};

}
2 changes: 1 addition & 1 deletion source/frontends/sdl/processfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace
bool doesExtensionMatch(const char * filename, const std::vector<const char *> & valid)
{
return std::any_of(valid.begin(), valid.end(), [filename] (const char * ext) {
return strlen(filename) > strlen(ext) && !strcmp(filename + strlen(filename) - strlen(ext), ext);
return strlen(filename) > strlen(ext) && !strcasecmp(filename + strlen(filename) - strlen(ext), ext);
});
}

Expand Down

0 comments on commit 124c089

Please sign in to comment.