2020-12-26 14:31:24 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include "glass/Context.h"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cinttypes>
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
#include <filesystem>
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
#include <fmt/format.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <imgui_internal.h>
|
|
|
|
|
#include <imgui_stdlib.h>
|
2023-09-21 23:20:09 -07:00
|
|
|
#include <wpi/MemoryBuffer.h>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <wpi/StringExtras.h>
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
#include <wpi/fs.h>
|
|
|
|
|
#include <wpi/json.h>
|
|
|
|
|
#include <wpi/raw_ostream.h>
|
2020-12-17 07:27:29 -08:00
|
|
|
#include <wpi/timestamp.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <wpigui.h>
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
#include <wpigui_internal.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include "glass/ContextInternal.h"
|
|
|
|
|
|
|
|
|
|
using namespace glass;
|
|
|
|
|
|
|
|
|
|
Context* glass::gContext;
|
|
|
|
|
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
static void WorkspaceResetImpl() {
|
|
|
|
|
// call reset functions
|
|
|
|
|
for (auto&& reset : gContext->workspaceReset) {
|
|
|
|
|
if (reset) {
|
|
|
|
|
reset();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
// clear storage
|
|
|
|
|
for (auto&& root : gContext->storageRoots) {
|
|
|
|
|
root.second->Clear();
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
|
|
|
|
|
// ImGui reset
|
|
|
|
|
ImGui::ClearIniSettings();
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
static void WorkspaceInit() {
|
|
|
|
|
for (auto&& init : gContext->workspaceInit) {
|
|
|
|
|
if (init) {
|
|
|
|
|
init();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
for (auto&& root : gContext->storageRoots) {
|
|
|
|
|
root.getValue()->Apply();
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
static bool JsonToWindow(const wpi::json& jfile, const char* filename) {
|
|
|
|
|
if (!jfile.is_object()) {
|
|
|
|
|
ImGui::LogText("%s top level is not object", filename);
|
|
|
|
|
return false;
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
|
|
|
|
|
// loop over JSON and generate ini format
|
|
|
|
|
std::string iniStr;
|
|
|
|
|
wpi::raw_string_ostream ini{iniStr};
|
|
|
|
|
|
|
|
|
|
for (auto&& jsection : jfile.items()) {
|
2022-06-01 21:28:30 -07:00
|
|
|
if (jsection.key() == "Docking") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
if (!jsection.value().is_object()) {
|
|
|
|
|
ImGui::LogText("%s section %s is not object", filename,
|
|
|
|
|
jsection.key().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for (auto&& jsubsection : jsection.value().items()) {
|
|
|
|
|
if (!jsubsection.value().is_object()) {
|
|
|
|
|
ImGui::LogText("%s section %s subsection %s is not object", filename,
|
|
|
|
|
jsection.key().c_str(), jsubsection.key().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
ini << '[' << jsection.key() << "][" << jsubsection.key() << "]\n";
|
|
|
|
|
for (auto&& jkv : jsubsection.value().items()) {
|
|
|
|
|
try {
|
|
|
|
|
auto& value = jkv.value().get_ref<const std::string&>();
|
|
|
|
|
ini << jkv.key() << '=' << value << "\n";
|
|
|
|
|
} catch (wpi::json::exception&) {
|
|
|
|
|
ImGui::LogText("%s section %s subsection %s value %s is not string",
|
|
|
|
|
filename, jsection.key().c_str(),
|
|
|
|
|
jsubsection.key().c_str(), jkv.key().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ini << '\n';
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-01 21:28:30 -07:00
|
|
|
|
|
|
|
|
// emit Docking section last
|
|
|
|
|
auto docking = jfile.find("Docking");
|
|
|
|
|
if (docking != jfile.end()) {
|
|
|
|
|
for (auto&& jsubsection : docking->items()) {
|
|
|
|
|
if (!jsubsection.value().is_array()) {
|
|
|
|
|
ImGui::LogText("%s section %s subsection %s is not array", filename,
|
|
|
|
|
"Docking", jsubsection.key().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
ini << "[Docking][" << jsubsection.key() << "]\n";
|
|
|
|
|
for (auto&& jv : jsubsection.value()) {
|
|
|
|
|
try {
|
|
|
|
|
auto& value = jv.get_ref<const std::string&>();
|
|
|
|
|
ini << value << "\n";
|
|
|
|
|
} catch (wpi::json::exception&) {
|
|
|
|
|
ImGui::LogText("%s section %s subsection %s value is not string",
|
|
|
|
|
filename, "Docking", jsubsection.key().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ini << '\n';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
ini.flush();
|
|
|
|
|
|
|
|
|
|
ImGui::LoadIniSettingsFromMemory(iniStr.data(), iniStr.size());
|
|
|
|
|
return true;
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
static bool LoadWindowStorageImpl(const std::string& filename) {
|
|
|
|
|
std::error_code ec;
|
2023-09-21 23:20:09 -07:00
|
|
|
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
|
|
|
|
|
wpi::MemoryBuffer::GetFile(filename, ec);
|
|
|
|
|
if (fileBuffer == nullptr || ec) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
|
|
|
|
ec.message().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
2023-09-21 23:20:09 -07:00
|
|
|
return JsonToWindow(
|
2023-10-15 05:53:56 +01:00
|
|
|
wpi::json::parse(fileBuffer->begin(), fileBuffer->end()),
|
2023-09-21 23:20:09 -07:00
|
|
|
filename.c_str());
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
} catch (wpi::json::parse_error& e) {
|
|
|
|
|
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08: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.
2021-11-25 00:51:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool LoadStorageRootImpl(Context* ctx, const std::string& filename,
|
|
|
|
|
std::string_view rootName) {
|
|
|
|
|
std::error_code ec;
|
2023-09-21 23:20:09 -07:00
|
|
|
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
|
|
|
|
|
wpi::MemoryBuffer::GetFile(filename, ec);
|
|
|
|
|
if (fileBuffer == nullptr || ec) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
|
|
|
|
ec.message().c_str());
|
|
|
|
|
return false;
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
auto& storage = ctx->storageRoots[rootName];
|
|
|
|
|
bool createdStorage = false;
|
|
|
|
|
if (!storage) {
|
|
|
|
|
storage = std::make_unique<Storage>();
|
|
|
|
|
createdStorage = true;
|
|
|
|
|
}
|
|
|
|
|
try {
|
2023-09-21 23:20:09 -07:00
|
|
|
storage->FromJson(
|
2023-10-15 05:53:56 +01:00
|
|
|
wpi::json::parse(fileBuffer->begin(), fileBuffer->end()),
|
2023-09-21 23:20:09 -07:00
|
|
|
filename.c_str());
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
} catch (wpi::json::parse_error& e) {
|
|
|
|
|
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
|
|
|
|
if (createdStorage) {
|
|
|
|
|
ctx->storageRoots.erase(rootName);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool LoadStorageImpl(Context* ctx, std::string_view dir,
|
|
|
|
|
std::string_view name) {
|
|
|
|
|
WorkspaceResetImpl();
|
|
|
|
|
|
|
|
|
|
bool rv = true;
|
|
|
|
|
for (auto&& root : ctx->storageRoots) {
|
|
|
|
|
std::string filename;
|
|
|
|
|
auto rootName = root.getKey();
|
|
|
|
|
if (rootName.empty()) {
|
|
|
|
|
filename = (fs::path{dir} / fmt::format("{}.json", name)).string();
|
|
|
|
|
} else {
|
|
|
|
|
filename =
|
|
|
|
|
(fs::path{dir} / fmt::format("{}-{}.json", name, rootName)).string();
|
|
|
|
|
}
|
|
|
|
|
if (!LoadStorageRootImpl(ctx, filename, rootName)) {
|
|
|
|
|
rv = false;
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
|
|
|
|
|
WorkspaceInit();
|
|
|
|
|
return rv;
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
static wpi::json WindowToJson() {
|
|
|
|
|
size_t iniLen;
|
|
|
|
|
const char* iniData = ImGui::SaveIniSettingsToMemory(&iniLen);
|
|
|
|
|
std::string_view ini{iniData, iniLen};
|
|
|
|
|
|
|
|
|
|
// parse the ini data and build JSON
|
|
|
|
|
// JSON format:
|
|
|
|
|
// {
|
|
|
|
|
// "Section": {
|
|
|
|
|
// "Subsection": {
|
|
|
|
|
// "Key": "Value" // all values are saved as strings
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
wpi::json out = wpi::json::object();
|
|
|
|
|
wpi::json* curSection = nullptr;
|
|
|
|
|
while (!ini.empty()) {
|
|
|
|
|
std::string_view line;
|
|
|
|
|
std::tie(line, ini) = wpi::split(ini, '\n');
|
|
|
|
|
line = wpi::trim(line);
|
|
|
|
|
if (line.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (line[0] == '[') {
|
|
|
|
|
// new section
|
|
|
|
|
auto [section, subsection] = wpi::split(line, ']');
|
|
|
|
|
section = wpi::drop_front(section); // drop '['; ']' was dropped by split
|
|
|
|
|
subsection = wpi::drop_back(wpi::drop_front(subsection)); // drop []
|
|
|
|
|
auto& jsection = out[section];
|
|
|
|
|
if (jsection.is_null()) {
|
|
|
|
|
jsection = wpi::json::object();
|
|
|
|
|
}
|
|
|
|
|
curSection = &jsection[subsection];
|
|
|
|
|
if (curSection->is_null()) {
|
2022-06-01 21:28:30 -07:00
|
|
|
if (section == "Docking") {
|
|
|
|
|
*curSection = wpi::json::array();
|
|
|
|
|
} else {
|
|
|
|
|
*curSection = wpi::json::object();
|
|
|
|
|
}
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// value
|
|
|
|
|
if (!curSection) {
|
|
|
|
|
continue; // shouldn't happen, but just in case
|
|
|
|
|
}
|
|
|
|
|
auto [name, value] = wpi::split(line, '=');
|
2022-06-01 21:28:30 -07:00
|
|
|
if (curSection->is_object()) {
|
|
|
|
|
(*curSection)[name] = value;
|
|
|
|
|
} else if (curSection->is_array()) {
|
|
|
|
|
curSection->emplace_back(line);
|
|
|
|
|
}
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
bool SaveWindowStorageImpl(const std::string& filename) {
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
wpi::raw_fd_ostream os{filename, ec};
|
|
|
|
|
if (ec) {
|
|
|
|
|
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
|
|
|
|
ec.message().c_str());
|
|
|
|
|
return false;
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
WindowToJson().dump(os, 2);
|
|
|
|
|
os << '\n';
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool SaveStorageRootImpl(Context* ctx, const std::string& filename,
|
|
|
|
|
const Storage& storage) {
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
wpi::raw_fd_ostream os{filename, ec};
|
|
|
|
|
if (ec) {
|
|
|
|
|
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
|
|
|
|
ec.message().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
storage.ToJson().dump(os, 2);
|
|
|
|
|
os << '\n';
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool SaveStorageImpl(Context* ctx, std::string_view dir,
|
|
|
|
|
std::string_view name, bool exiting) {
|
|
|
|
|
fs::path dirPath{dir};
|
|
|
|
|
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
fs::create_directories(dirPath, ec);
|
|
|
|
|
if (ec) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handle erasing save files on exit if requested
|
|
|
|
|
if (exiting && wpi::gui::gContext->resetOnExit) {
|
|
|
|
|
fs::remove(dirPath / fmt::format("{}-window.json", name), ec);
|
|
|
|
|
for (auto&& root : ctx->storageRoots) {
|
|
|
|
|
auto rootName = root.getKey();
|
|
|
|
|
if (rootName.empty()) {
|
|
|
|
|
fs::remove(dirPath / fmt::format("{}.json", name), ec);
|
|
|
|
|
} else {
|
|
|
|
|
fs::remove(dirPath / fmt::format("{}-{}.json", name, rootName), ec);
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
|
|
|
|
|
bool rv = SaveWindowStorageImpl(
|
|
|
|
|
(dirPath / fmt::format("{}-window.json", name)).string());
|
|
|
|
|
|
|
|
|
|
for (auto&& root : ctx->storageRoots) {
|
|
|
|
|
auto rootName = root.getKey();
|
|
|
|
|
std::string filename;
|
|
|
|
|
if (rootName.empty()) {
|
|
|
|
|
filename = (dirPath / fmt::format("{}.json", name)).string();
|
|
|
|
|
} else {
|
|
|
|
|
filename = (dirPath / fmt::format("{}-{}.json", name, rootName)).string();
|
|
|
|
|
}
|
|
|
|
|
if (!SaveStorageRootImpl(ctx, filename, *root.getValue())) {
|
|
|
|
|
rv = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rv;
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
Context::Context()
|
|
|
|
|
: sourceNameStorage{storageRoots.insert({"", std::make_unique<Storage>()})
|
|
|
|
|
.first->getValue()
|
|
|
|
|
->GetChild("sourceNames")} {
|
|
|
|
|
storageStack.emplace_back(storageRoots[""].get());
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
// override ImGui ini saving
|
|
|
|
|
wpi::gui::ConfigureCustomSaveSettings(
|
|
|
|
|
[this] { LoadStorageImpl(this, storageLoadDir, storageName); },
|
|
|
|
|
[this] {
|
|
|
|
|
LoadWindowStorageImpl((fs::path{storageLoadDir} /
|
|
|
|
|
fmt::format("{}-window.json", storageName))
|
|
|
|
|
.string());
|
|
|
|
|
},
|
|
|
|
|
[this](bool exiting) {
|
|
|
|
|
SaveStorageImpl(this, storageAutoSaveDir, storageName, exiting);
|
|
|
|
|
});
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
Context::~Context() {
|
|
|
|
|
wpi::gui::ConfigureCustomSaveSettings(nullptr, nullptr, nullptr);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
Context* glass::CreateContext() {
|
|
|
|
|
Context* ctx = new Context;
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!gContext) {
|
|
|
|
|
SetCurrentContext(ctx);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::DestroyContext(Context* ctx) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!ctx) {
|
|
|
|
|
ctx = gContext;
|
|
|
|
|
}
|
|
|
|
|
if (gContext == ctx) {
|
|
|
|
|
SetCurrentContext(nullptr);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
delete ctx;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
Context* glass::GetCurrentContext() {
|
|
|
|
|
return gContext;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void glass::SetCurrentContext(Context* ctx) {
|
|
|
|
|
gContext = ctx;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void glass::ResetTime() {
|
|
|
|
|
gContext->zeroTime = wpi::Now();
|
|
|
|
|
}
|
2020-12-17 07:27:29 -08:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
uint64_t glass::GetZeroTime() {
|
|
|
|
|
return gContext->zeroTime;
|
|
|
|
|
}
|
2020-12-17 07:27:29 -08: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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::WorkspaceReset() {
|
|
|
|
|
WorkspaceResetImpl();
|
|
|
|
|
WorkspaceInit();
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::AddWorkspaceInit(std::function<void()> init) {
|
|
|
|
|
if (init) {
|
|
|
|
|
gContext->workspaceInit.emplace_back(std::move(init));
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::AddWorkspaceReset(std::function<void()> reset) {
|
|
|
|
|
if (reset) {
|
|
|
|
|
gContext->workspaceReset.emplace_back(std::move(reset));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::SetStorageName(std::string_view name) {
|
|
|
|
|
gContext->storageName = name;
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::SetStorageDir(std::string_view dir) {
|
|
|
|
|
if (dir.empty()) {
|
|
|
|
|
gContext->storageLoadDir = ".";
|
|
|
|
|
gContext->storageAutoSaveDir = ".";
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
gContext->storageLoadDir = dir;
|
|
|
|
|
gContext->storageAutoSaveDir = dir;
|
|
|
|
|
gContext->isPlatformSaveDir = (dir == wpi::gui::GetPlatformSaveFileDir());
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
std::string glass::GetStorageDir() {
|
|
|
|
|
return gContext->storageAutoSaveDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::LoadStorage(std::string_view dir) {
|
|
|
|
|
SaveStorage();
|
|
|
|
|
SetStorageDir(dir);
|
|
|
|
|
LoadWindowStorageImpl((fs::path{gContext->storageLoadDir} /
|
|
|
|
|
fmt::format("{}-window.json", gContext->storageName))
|
|
|
|
|
.string());
|
|
|
|
|
return LoadStorageImpl(gContext, dir, gContext->storageName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::SaveStorage() {
|
|
|
|
|
return SaveStorageImpl(gContext, gContext->storageAutoSaveDir,
|
|
|
|
|
gContext->storageName, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::SaveStorage(std::string_view dir) {
|
|
|
|
|
return SaveStorageImpl(gContext, dir, gContext->storageName, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Storage& glass::GetCurStorageRoot() {
|
|
|
|
|
return *gContext->storageStack.front();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Storage& glass::GetStorageRoot(std::string_view rootName) {
|
|
|
|
|
auto& storage = gContext->storageRoots[rootName];
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!storage) {
|
|
|
|
|
storage = std::make_unique<Storage>();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
return *storage;
|
|
|
|
|
}
|
|
|
|
|
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::ResetStorageStack(std::string_view rootName) {
|
|
|
|
|
if (gContext->storageStack.size() != 1) {
|
|
|
|
|
ImGui::LogText("resetting non-empty storage stack");
|
2020-12-28 12:58:06 -08: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.
2021-11-25 00:51:00 -08:00
|
|
|
gContext->storageStack.clear();
|
|
|
|
|
gContext->storageStack.emplace_back(&GetStorageRoot(rootName));
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
Storage& glass::GetStorage() {
|
|
|
|
|
return *gContext->storageStack.back();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::PushStorageStack(std::string_view label_id) {
|
|
|
|
|
gContext->storageStack.emplace_back(
|
|
|
|
|
&gContext->storageStack.back()->GetChild(label_id));
|
2020-09-12 10:55:46 -07: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.
2021-11-25 00:51:00 -08:00
|
|
|
void glass::PushStorageStack(Storage& storage) {
|
|
|
|
|
gContext->storageStack.emplace_back(&storage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::PopStorageStack() {
|
|
|
|
|
if (gContext->storageStack.size() <= 1) {
|
|
|
|
|
ImGui::LogText("attempted to pop empty storage stack, mismatch push/pop?");
|
|
|
|
|
return; // ignore
|
|
|
|
|
}
|
|
|
|
|
gContext->storageStack.pop_back();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PushStorageStack(name);
|
2020-09-12 10:55:46 -07:00
|
|
|
return ImGui::Begin(name, p_open, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::End() {
|
|
|
|
|
ImGui::End();
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PopStorageStack();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::BeginChild(const char* str_id, const ImVec2& size, bool border,
|
|
|
|
|
ImGuiWindowFlags flags) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PushStorageStack(str_id);
|
2020-09-12 10:55:46 -07:00
|
|
|
return ImGui::BeginChild(str_id, size, border, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::EndChild() {
|
|
|
|
|
ImGui::EndChild();
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PopStorageStack();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
bool& open = GetStorage().GetChild(label).GetBool(
|
|
|
|
|
"open", (flags & ImGuiTreeNodeFlags_DefaultOpen) != 0);
|
|
|
|
|
ImGui::SetNextItemOpen(open);
|
|
|
|
|
open = ImGui::CollapsingHeader(label, flags);
|
|
|
|
|
return open;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::TreeNodeEx(const char* label, ImGuiTreeNodeFlags flags) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PushStorageStack(label);
|
|
|
|
|
bool& open = GetStorage().GetBool(
|
|
|
|
|
"open", (flags & ImGuiTreeNodeFlags_DefaultOpen) != 0);
|
|
|
|
|
ImGui::SetNextItemOpen(open);
|
|
|
|
|
open = ImGui::TreeNodeEx(label, flags);
|
|
|
|
|
if (!open) {
|
|
|
|
|
PopStorageStack();
|
2020-12-28 12:58:06 -08: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.
2021-11-25 00:51:00 -08:00
|
|
|
return open;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::TreePop() {
|
|
|
|
|
ImGui::TreePop();
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PopStorageStack();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::PushID(const char* str_id) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PushStorageStack(str_id);
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::PushID(str_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::PushID(const char* str_id_begin, const char* str_id_end) {
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PushStorageStack(std::string_view(str_id_begin, str_id_end - str_id_begin));
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::PushID(str_id_begin, str_id_end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::PushID(int int_id) {
|
|
|
|
|
char buf[16];
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(buf, sizeof(buf), "{}", int_id);
|
|
|
|
|
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PushStorageStack(buf);
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::PushID(int_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::PopID() {
|
|
|
|
|
ImGui::PopID();
|
[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.
2021-11-25 00:51:00 -08:00
|
|
|
PopStorageStack();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glass::PopupEditName(const char* label, std::string* name) {
|
|
|
|
|
bool rv = false;
|
|
|
|
|
if (ImGui::BeginPopupContextItem(label)) {
|
2023-01-01 21:05:09 -07:00
|
|
|
rv = ItemEditName(name);
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
2023-01-01 21:05:09 -07:00
|
|
|
|
|
|
|
|
bool glass::ItemEditName(std::string* name) {
|
|
|
|
|
bool rv = false;
|
|
|
|
|
|
|
|
|
|
ImGui::Text("Edit name:");
|
|
|
|
|
if (ImGui::InputText("##editname", name)) {
|
|
|
|
|
rv = true;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::Button("Close") || ImGui::IsKeyPressedMap(ImGuiKey_Enter) ||
|
|
|
|
|
ImGui::IsKeyPressedMap(ImGuiKey_KeyPadEnter)) {
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|