8#include "imgui/imgui.h"
9#include "imgui/misc/cpp/imgui_stdlib.h"
16 name = project_path.substr(project_path.find_last_of(
"/") + 1);
18 std::ifstream in(project_path);
21 return absl::InternalError(
"Could not open project file.");
25 std::getline(in,
name);
32 while (std::getline(in, line)) {
40 return absl::OkStatus();
48 return absl::InternalError(
"Could not open project file.");
51 out <<
name << std::endl;
62 return absl::OkStatus();
66 std::ifstream file(filename);
67 if (!file.is_open()) {
69 std::ofstream create_file(filename);
70 if (!create_file.is_open()) {
75 if (!file.is_open()) {
82 while (std::getline(file, line)) {
83 std::istringstream iss(line);
84 std::string type, key, value;
85 if (std::getline(iss, type,
',') && std::getline(iss, key,
',') &&
86 std::getline(iss, value)) {
99 if (!file.is_open()) {
102 for (
const auto& type_pair :
labels_) {
103 for (
const auto& label_pair : type_pair.second) {
104 file << type_pair.first <<
"," << label_pair.first <<
","
105 << label_pair.second << std::endl;
114 ImGui::Text(
"No labels loaded.");
118 if (ImGui::Begin(
"Resource Labels", p_open)) {
119 for (
const auto& type_pair :
labels_) {
120 if (ImGui::TreeNode(type_pair.first.c_str())) {
121 for (
const auto& label_pair : type_pair.second) {
122 std::string label_id = type_pair.first +
"_" + label_pair.first;
123 ImGui::Text(
"%s: %s", label_pair.first.c_str(),
124 label_pair.second.c_str());
130 if (ImGui::Button(
"Update Labels")) {
132 ImGui::Text(
"Labels updated successfully!");
134 ImGui::Text(
"Failed to update labels.");
142 const std::string& key,
143 const std::string& newValue) {
148 bool selected,
const std::string& type,
const std::string& key,
149 const std::string& defaultValue) {
151 ImGui::Selectable(label.c_str(), selected,
152 ImGuiSelectableFlags_AllowDoubleClick);
153 std::string label_id = type +
"_" + key;
154 if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
155 ImGui::OpenPopup(label_id.c_str());
158 if (ImGui::BeginPopupContextItem(label_id.c_str())) {
159 std::string* new_label = &
labels_[type][key];
160 if (ImGui::InputText(
"##Label", new_label,
161 ImGuiInputTextFlags_EnterReturnsTrue)) {
162 labels_[type][key] = *new_label;
165 ImGui::CloseCurrentPopup();
172 const std::string& key) {
177 const std::string& type,
const std::string& key,
178 const std::string& defaultValue) {
180 labels_[type] = std::unordered_map<std::string, std::string>();
183 labels_[type][key] = defaultValue;
#define RETURN_IF_ERROR(expression)
constexpr char kEndOfProjectFile[]
absl::Status Open(const std::string &project_path)
std::string labels_filename_
std::string keybindings_file
absl::Status CheckForEmptyFields()
std::string rom_filename_
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
void DisplayLabels(bool *p_open)
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
std::string GetLabel(const std::string &type, const std::string &key)
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
bool LoadLabels(const std::string &filename)