MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / dataFromJson

Method dataFromJson

plugins/Cardinal/src/TextEditor.cpp:84–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82 {}
83
84 void dataFromJson(json_t* const rootJ) override
85 {
86 file.clear();
87
88 // Rack Core Notes compatibility
89 if (json_t* const textJ = json_object_get(rootJ, "text"))
90 {
91 text = json_string_value(textJ);
92 lang = "None";
93 width = 16;
94#ifndef HEADLESS
95 if (ImGuiTextEditor* const widget = widgetPtr)
96 {
97 widget->setLanguageDefinition(lang);
98 widget->setText(text);
99 }
100#endif
101 return;
102 }
103
104 if (json_t* const widthJ = json_object_get(rootJ, "width"))
105 width = json_integer_value(widthJ);
106
107 if (json_t* const langJ = json_object_get(rootJ, "lang"))
108 {
109 lang = json_string_value(langJ);
110#ifndef HEADLESS
111 if (ImGuiTextEditor* const widget = widgetPtr)
112 widget->setLanguageDefinition(lang);
113#endif
114 }
115
116 if (json_t* const filepathJ = json_object_get(rootJ, "filepath"))
117 {
118 const char* const filepath = json_string_value(filepathJ);
119
120 if (filepath[0] != '\0')
121 {
122 std::ifstream f(filepath);
123
124 if (f.good())
125 {
126 file = filepath;
127 text = std::string((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
128#ifndef HEADLESS
129 if (ImGuiTextEditor* const widget = widgetPtr)
130 widget->setFileWithKnownText(file, text);
131#endif
132 return;
133 }
134 }
135 }
136
137 if (json_t* const textJ = json_object_get(rootJ, "etext"))
138 {
139 text = json_string_value(textJ);
140#ifndef HEADLESS
141 if (ImGuiTextEditor* const widget = widgetPtr)

Callers

nothing calls this directly

Calls 6

json_object_getFunction · 0.85
json_integer_valueFunction · 0.85
setLanguageDefinitionMethod · 0.80
setTextMethod · 0.80
setFileWithKnownTextMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected