undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoAppJSON.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include <string>
13#include <vector>
14#include <memory>
15#include <unordered_map>
16#include <functional>
17
18// Include ImGui for ImVec4 type
19#include <imgui.h>
20
21namespace undoApp {
22namespace JSON {
23
28{
29 std::string key;
30 std::string value;
31 bool isObject = false;
32 bool isArray = false;
33 std::vector<std::unique_ptr<JSONNode>> children;
34 bool expanded = false;
35 int depth = 0;
36};
37
46{
47 std::string path;
48 std::string rawText;
49 std::string prettyPrint;
50 bool pretty = false;
51};
52
60{
61public:
64
66 bool initialize();
67
69 void shutdown();
70
73
75 void loadJSONFile(const std::string& path);
76
78 void closeFile();
79
80 // ============================================================================
81 // Panel rendering methods
82 // ============================================================================
83
86
89
92 void setDocument(const JSONDocument& doc);
93
94 // ============================================================================
95 // JSON tree building and rendering
96 // ============================================================================
97
99 void buildJSONTree(const std::string& jsonString);
100
102 void renderJSONTree(JSONNode* node, const std::string& filter, int depth = 0);
103
105 static ImVec4 getValueColor(const std::string& value);
106
107private:
108 // ============================================================================
109 // Member variables
110 // ============================================================================
111
112 bool m_initialized = false;
113 std::vector<std::string> m_outputLines;
114
115 std::unique_ptr<JSONNode> m_jsonRoot;
116 std::string m_jsonSearchFilter;
117 bool m_jsonSearchActive = false;
118 std::string m_currentFilePath;
119 bool m_showPrettyPrint = false;
120 std::string m_rawJSONString;
121
122 // ============================================================================
123 // Popup states
124 // ============================================================================
125
126};
127
128} // namespace JSON
129} // namespace undoApp
std::string value
Definition Settings.cpp:30
Main application class for the JSON Viewer plugin.
Definition undoAppJSON.hpp:60
JSONDocument takeDocument()
Take the open file out whole, to be put back later.
bool initialize()
Initialize the JSON undoApp.
void loadJSONFile(const std::string &path)
Load a JSON file into the viewer.
void renderJSONPanel()
Render the JSON Viewer panel.
std::string m_rawJSONString
Raw JSON string for pretty print.
Definition undoAppJSON.hpp:120
void buildJSONTree(const std::string &jsonString)
Build the JSON tree from a string.
std::unique_ptr< JSONNode > m_jsonRoot
Root of the JSON tree.
Definition undoAppJSON.hpp:115
void renderJSONTree(JSONNode *node, const std::string &filter, int depth=0)
Recursively render the JSON tree with filtering.
bool m_initialized
Initialization flag.
Definition undoAppJSON.hpp:112
static JSONApp & getInstance()
Get the singleton instance of JSONApp.
bool m_jsonSearchActive
True if filtering is active.
Definition undoAppJSON.hpp:117
std::vector< std::string > m_outputLines
Lines to display in the Output panel.
Definition undoAppJSON.hpp:113
void closeFile()
Clear the JSON viewer state.
bool m_showPrettyPrint
True if pretty print is enabled.
Definition undoAppJSON.hpp:119
void setDocument(const JSONDocument &doc)
Show a file taken out by takeDocument()
std::string m_currentFilePath
Path of the loaded JSON file.
Definition undoAppJSON.hpp:118
static ImVec4 getValueColor(const std::string &value)
Helper to get color for value type.
void registerPanels()
Register UI panels with ImGuiManager.
std::string m_jsonSearchFilter
Filter string for searching.
Definition undoAppJSON.hpp:116
void shutdown()
Shutdown the JSON undoApp and release resources.
Definition undoAppCpp.hpp:26
One open JSON file, held while another file is in the viewer.
Definition undoAppJSON.hpp:46
bool pretty
Definition undoAppJSON.hpp:50
std::string rawText
The file as it was read.
Definition undoAppJSON.hpp:48
std::string path
Absolute path, where a later save goes.
Definition undoAppJSON.hpp:47
std::string prettyPrint
The formatted text, if pretty printing is on.
Definition undoAppJSON.hpp:49
Node structure for the JSON tree viewer.
Definition undoAppJSON.hpp:28
bool isArray
True if this node is a JSON array.
Definition undoAppJSON.hpp:32
bool isObject
True if this node is a JSON object.
Definition undoAppJSON.hpp:31
bool expanded
True if node is expanded in the tree.
Definition undoAppJSON.hpp:34
int depth
Node depth in the tree.
Definition undoAppJSON.hpp:35
std::string value
String representation of the value.
Definition undoAppJSON.hpp:30
std::string key
Object key (if part of an object)
Definition undoAppJSON.hpp:29
std::vector< std::unique_ptr< JSONNode > > children
Child nodes.
Definition undoAppJSON.hpp:33