Make TextEditor compatible with Core Notes, drop Core Notes

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-01-24 20:45:02 +00:00
parent d37fc6dda9
commit 362cf9b2b9
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
7 changed files with 47 additions and 16 deletions

View file

@ -145,11 +145,10 @@ void ImGuiTextEditor::drawImGui()
const TextEditor::Coordinates cpos = editor.GetCursorPosition();
ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s",
ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s",
cpos.mLine + 1, cpos.mColumn + 1,
editor.GetTotalLines(),
editor.IsOverwrite() ? "Ovr" : "Ins",
editor.CanUndo() ? "*" : " ",
editor.GetLanguageDefinition().mName.c_str(),
pData->file.c_str());
@ -158,3 +157,26 @@ void ImGuiTextEditor::drawImGui()
ImGui::End();
}
/*
void ImGuiTextEditor::onSelectKey(const SelectKeyEvent& e)
{
ImGuiWidget::onSelectKey(e);
if (e.action == GLFW_PRESS && (e.mods & GLFW_MOD_CONTROL) != 0)
{
switch (e.key)
{
case GLFW_KEY_X:
pData->editor.Cut();
break;
case GLFW_KEY_C:
pData->editor.Copy();
break;
case GLFW_KEY_V:
pData->editor.Paste();
break;
}
}
}
*/

View file

@ -59,4 +59,7 @@ struct ImGuiTextEditor : ImGuiWidget
protected:
/** @internal */
void drawImGui() override;
/*
void onSelectKey(const SelectKeyEvent& e) override;
*/
};

View file

@ -50,13 +50,29 @@ struct TextEditorModule : Module {
json_t* rootJ = json_object();
json_object_set_new(rootJ, "filepath", json_string(file.c_str()));
json_object_set_new(rootJ, "lang", json_string(lang.c_str()));
json_object_set_new(rootJ, "text", json_string(text.c_str()));
json_object_set_new(rootJ, "etext", json_string(text.c_str()));
json_object_set_new(rootJ, "width", json_integer(width));
return rootJ;
}
void dataFromJson(json_t* const rootJ) override
{
// Rack Core Notes compatiblity
if (json_t* const textJ = json_object_get(rootJ, "text"))
{
text = json_string_value(textJ);
file = "";
lang = "None";
width = 16;
#ifndef HEADLESS
if (ImGuiTextEditor* const widget = widgetPtr)
{
widget->setLanguageDefinition(lang);
widget->setText(text);
}
#endif
}
if (json_t* const widthJ = json_object_get(rootJ, "width"))
width = json_integer_value(widthJ);
@ -90,7 +106,7 @@ struct TextEditorModule : Module {
}
}
if (json_t* const textJ = json_object_get(rootJ, "text"))
if (json_t* const textJ = json_object_get(rootJ, "etext"))
{
text = json_string_value(textJ);
#ifndef HEADLESS