7#include "imgui/imgui.h"
8#include "imgui/misc/cpp/imgui_stdlib.h"
15 name = project_path.substr(project_path.find_last_of(
"/") + 1);
17 std::ifstream in(project_path);
20 return absl::InternalError(
"Could not open project file.");
24 std::getline(in,
name);
31 while (std::getline(in, line)) {
39 return absl::OkStatus();
47 return absl::InternalError(
"Could not open project file.");
50 out <<
name << std::endl;
61 return absl::OkStatus();
65 std::ifstream file(filename);
66 if (!file.is_open()) {
68 std::ofstream create_file(filename);
69 if (!create_file.is_open()) {
74 if (!file.is_open()) {
81 while (std::getline(file, line)) {
82 std::istringstream iss(line);
83 std::string type, key, value;
84 if (std::getline(iss, type,
',') && std::getline(iss, key,
',') &&
85 std::getline(iss, value)) {
98 if (!file.is_open()) {
101 for (
const auto& type_pair :
labels_) {
102 for (
const auto& label_pair : type_pair.second) {
103 file << type_pair.first <<
"," << label_pair.first <<
","
104 << label_pair.second << std::endl;
113 ImGui::Text(
"No labels loaded.");
117 if (ImGui::Begin(
"Resource Labels", p_open)) {
118 for (
const auto& type_pair :
labels_) {
119 if (ImGui::TreeNode(type_pair.first.c_str())) {
120 for (
const auto& label_pair : type_pair.second) {
121 std::string label_id = type_pair.first +
"_" + label_pair.first;
122 ImGui::Text(
"%s: %s", label_pair.first.c_str(),
123 label_pair.second.c_str());
129 if (ImGui::Button(
"Update Labels")) {
131 ImGui::Text(
"Labels updated successfully!");
133 ImGui::Text(
"Failed to update labels.");
141 const std::string& key,
142 const std::string& newValue) {
147 bool selected,
const std::string& type,
const std::string& key,
148 const std::string& defaultValue) {
150 ImGui::Selectable(label.c_str(), selected,
151 ImGuiSelectableFlags_AllowDoubleClick);
152 std::string label_id = type +
"_" + key;
153 if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
154 ImGui::OpenPopup(label_id.c_str());
157 if (ImGui::BeginPopupContextItem(label_id.c_str())) {
158 std::string* new_label = &
labels_[type][key];
159 if (ImGui::InputText(
"##Label", new_label,
160 ImGuiInputTextFlags_EnterReturnsTrue)) {
161 labels_[type][key] = *new_label;
164 ImGui::CloseCurrentPopup();
171 const std::string& key) {
176 const std::string& type,
const std::string& key,
177 const std::string& defaultValue) {
179 labels_[type] = std::unordered_map<std::string, std::string>();
182 labels_[type][key] = defaultValue;
#define RETURN_IF_ERROR(expression)
Main namespace for the application.
constexpr char kEndOfProjectFile[]
absl::Status Open(const std::string &project_path)
absl::Status CheckForEmptyFields()
std::string keybindings_file
std::string rom_filename_
std::string labels_filename_
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
bool LoadLabels(const std::string &filename)
std::string GetLabel(const std::string &type, const std::string &key)
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
void DisplayLabels(bool *p_open)
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)