mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested. Separate "roots" can be configured which save to separate files. In particular, this is used to save wpigui and ImGui window position to a -window.json file. ImGui's ini (for window position) is mapped to JSON. You can optionally specify a directory to load from on the command line. If one isn't provided, it uses the global system directory. Any changes made are automatically saved here. Workspace | Open: select directory, the current layout is replaced with that workspace, and future auto-saves also switch to that location. The main window size/location is not changed, only the contents. Workspace | Save As: select directory, the current layout is saved there, and future auto-saves also switch to that location. Workspace | Reset: window locations are preserved, but all other settings are reset to default (including e.g. removing plot windows). This will also end up clearing the current save file. as with load, the main window size/location is not changed. Workspace | Save As Global: "save as" to the global system location Notably, the main window size/location is only loaded at startup, but is auto-saved as part of the current workspace.
This commit is contained in:
@@ -12,13 +12,9 @@ using namespace glass;
|
||||
|
||||
wpi::sig::Signal<const char*, DataSource*> DataSource::sourceCreated;
|
||||
|
||||
DataSource::DataSource(std::string_view id) : m_id{id} {
|
||||
auto it = gContext->sources.try_emplace(m_id, this);
|
||||
auto& srcName = it.first->getValue();
|
||||
m_name = srcName.name.get();
|
||||
if (!srcName.source) {
|
||||
srcName.source = this;
|
||||
}
|
||||
DataSource::DataSource(std::string_view id)
|
||||
: m_id{id}, m_name{gContext->sourceNameStorage.GetString(m_id)} {
|
||||
gContext->sources.try_emplace(m_id, this);
|
||||
sourceCreated(m_id.c_str(), this);
|
||||
}
|
||||
|
||||
@@ -32,43 +28,7 @@ DataSource::~DataSource() {
|
||||
if (!gContext) {
|
||||
return;
|
||||
}
|
||||
auto it = gContext->sources.find(m_id);
|
||||
if (it == gContext->sources.end()) {
|
||||
return;
|
||||
}
|
||||
auto& srcName = it->getValue();
|
||||
if (srcName.source == this) {
|
||||
srcName.source = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void DataSource::SetName(std::string_view name) {
|
||||
m_name->SetName(name);
|
||||
}
|
||||
|
||||
const char* DataSource::GetName() const {
|
||||
return m_name->GetName();
|
||||
}
|
||||
|
||||
void DataSource::PushEditNameId(int index) {
|
||||
m_name->PushEditNameId(index);
|
||||
}
|
||||
|
||||
void DataSource::PushEditNameId(const char* name) {
|
||||
m_name->PushEditNameId(name);
|
||||
}
|
||||
|
||||
bool DataSource::PopupEditName(int index) {
|
||||
return m_name->PopupEditName(index);
|
||||
}
|
||||
|
||||
bool DataSource::PopupEditName(const char* name) {
|
||||
return m_name->PopupEditName(name);
|
||||
}
|
||||
|
||||
bool DataSource::InputTextName(const char* label_id,
|
||||
ImGuiInputTextFlags flags) {
|
||||
return m_name->InputTextName(label_id, flags);
|
||||
gContext->sources.erase(m_id);
|
||||
}
|
||||
|
||||
void DataSource::LabelText(const char* label, const char* fmt, ...) const {
|
||||
@@ -82,7 +42,7 @@ void DataSource::LabelText(const char* label, const char* fmt, ...) const {
|
||||
void DataSource::LabelTextV(const char* label, const char* fmt,
|
||||
va_list args) const {
|
||||
ImGui::PushID(label);
|
||||
ImGui::LabelTextV("##input", fmt, args);
|
||||
ImGui::LabelTextV("##input", fmt, args); // NOLINT
|
||||
ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
ImGui::Selectable(label);
|
||||
ImGui::PopID();
|
||||
@@ -141,7 +101,7 @@ void DataSource::EmitDrag(ImGuiDragDropFlags flags) const {
|
||||
if (ImGui::BeginDragDropSource(flags)) {
|
||||
auto self = this;
|
||||
ImGui::SetDragDropPayload("DataSource", &self, sizeof(self)); // NOLINT
|
||||
const char* name = GetName();
|
||||
const char* name = GetName().c_str();
|
||||
ImGui::TextUnformatted(name[0] == '\0' ? m_id.c_str() : name);
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
@@ -152,5 +112,5 @@ DataSource* DataSource::Find(std::string_view id) {
|
||||
if (it == gContext->sources.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->getValue().source;
|
||||
return it->getValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user