TextEditor: implement/expose syntax highlight options
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
31adcb5622
commit
730cee0029
3 changed files with 37 additions and 34 deletions
|
|
@ -73,6 +73,28 @@ std::string ImGuiTextEditor::getFile() const
|
||||||
return pData->file;
|
return pData->file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGuiTextEditor::setLanguageDefinition(const std::string& lang)
|
||||||
|
{
|
||||||
|
if (lang == "AngelScript")
|
||||||
|
return pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition::AngelScript());
|
||||||
|
if (lang == "C")
|
||||||
|
return pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition::C());
|
||||||
|
if (lang == "C++")
|
||||||
|
return pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus());
|
||||||
|
if (lang == "GLSL")
|
||||||
|
return pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition::GLSL());
|
||||||
|
if (lang == "HLSL")
|
||||||
|
return pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition::HLSL());
|
||||||
|
if (lang == "Lua")
|
||||||
|
return pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition::Lua());
|
||||||
|
if (lang == "SQL")
|
||||||
|
return pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition::SQL());
|
||||||
|
|
||||||
|
pData->editor.SetLanguageDefinition(TextEditor::LanguageDefinition());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void ImGuiTextEditor::setText(const std::string& text)
|
void ImGuiTextEditor::setText(const std::string& text)
|
||||||
{
|
{
|
||||||
pData->file.clear();
|
pData->file.clear();
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ struct ImGuiTextEditor : ImGuiWidget
|
||||||
void setFileWithKnownText(const std::string& file, const std::string& text);
|
void setFileWithKnownText(const std::string& file, const std::string& text);
|
||||||
std::string getFile() const;
|
std::string getFile() const;
|
||||||
|
|
||||||
|
void setLanguageDefinition(const std::string& lang);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Methods from internal TextEdit.
|
Methods from internal TextEdit.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -36,30 +36,6 @@
|
||||||
"int such_highlight_much_wow() { return 1337; }\n"
|
"int such_highlight_much_wow() { return 1337; }\n"
|
||||||
#define DEFAULT_WIDTH 30
|
#define DEFAULT_WIDTH 30
|
||||||
|
|
||||||
#if 0 // ndef HEADLESS
|
|
||||||
// utils
|
|
||||||
static const TextEditor::LanguageDefinition& getLangFromString(const std::string& lang)
|
|
||||||
{
|
|
||||||
if (lang == "AngelScript")
|
|
||||||
return TextEditor::LanguageDefinition::AngelScript();
|
|
||||||
if (lang == "C")
|
|
||||||
return TextEditor::LanguageDefinition::C();
|
|
||||||
if (lang == "C++")
|
|
||||||
return TextEditor::LanguageDefinition::CPlusPlus();
|
|
||||||
if (lang == "GLSL")
|
|
||||||
return TextEditor::LanguageDefinition::GLSL();
|
|
||||||
if (lang == "HLSL")
|
|
||||||
return TextEditor::LanguageDefinition::HLSL();
|
|
||||||
if (lang == "Lua")
|
|
||||||
return TextEditor::LanguageDefinition::Lua();
|
|
||||||
if (lang == "SQL")
|
|
||||||
return TextEditor::LanguageDefinition::SQL();
|
|
||||||
|
|
||||||
static const TextEditor::LanguageDefinition none;
|
|
||||||
return none;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct TextEditorModule : Module {
|
struct TextEditorModule : Module {
|
||||||
std::string file;
|
std::string file;
|
||||||
std::string lang = DEFAULT_LANG;
|
std::string lang = DEFAULT_LANG;
|
||||||
|
|
@ -88,8 +64,8 @@ struct TextEditorModule : Module {
|
||||||
{
|
{
|
||||||
lang = json_string_value(langJ);
|
lang = json_string_value(langJ);
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
// if (ImGuiTextEditor* const widget = widgetPtr)
|
if (ImGuiTextEditor* const widget = widgetPtr)
|
||||||
// widget->SetLanguageDefinition(getLangFromString(lang));
|
widget->setLanguageDefinition(lang);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,17 +124,20 @@ struct TextEditorLangSelectItem : MenuItem {
|
||||||
|
|
||||||
TextEditorLangSelectItem(TextEditorModule* const textEditorModule,
|
TextEditorLangSelectItem(TextEditorModule* const textEditorModule,
|
||||||
ImGuiTextEditor* const textEditorWidget,
|
ImGuiTextEditor* const textEditorWidget,
|
||||||
const char* const textToUse)
|
const char* const lang)
|
||||||
: module(textEditorModule),
|
: module(textEditorModule),
|
||||||
widget(textEditorWidget)
|
widget(textEditorWidget)
|
||||||
{
|
{
|
||||||
text = textToUse;
|
text = lang;
|
||||||
|
|
||||||
|
if (module->lang == lang)
|
||||||
|
rightText = CHECKMARK_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAction(const event::Action &e) override
|
void onAction(const event::Action &e) override
|
||||||
{
|
{
|
||||||
module->lang = text;
|
module->lang = text;
|
||||||
// widget->SetLanguageDefinition(getLangFromString(text));
|
widget->setLanguageDefinition(text);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -185,12 +164,12 @@ struct TextEditorLangSelectMenuItem : MenuItem {
|
||||||
widget(textEditorWidget)
|
widget(textEditorWidget)
|
||||||
{
|
{
|
||||||
text = "Syntax Highlight";
|
text = "Syntax Highlight";
|
||||||
|
rightText = RIGHT_ARROW;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAction(const event::Action &e) override
|
Menu* createChildMenu() override
|
||||||
{
|
{
|
||||||
// TODO
|
return new TextEditorLangSelectMenu(module, widget);
|
||||||
// new TextEditorLangSelectMenu(module, widget);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -328,6 +307,7 @@ struct TextEditorModuleWidget : ModuleWidget {
|
||||||
textEditorModule = module;
|
textEditorModule = module;
|
||||||
textEditorWidget = new ImGuiTextEditor();
|
textEditorWidget = new ImGuiTextEditor();
|
||||||
textEditorWidget->setFileWithKnownText(module->file, module->text);
|
textEditorWidget->setFileWithKnownText(module->file, module->text);
|
||||||
|
textEditorWidget->setLanguageDefinition(module->lang);
|
||||||
textEditorWidget->box.pos = Vec(RACK_GRID_WIDTH, 0);
|
textEditorWidget->box.pos = Vec(RACK_GRID_WIDTH, 0);
|
||||||
textEditorWidget->box.size = Vec((module->width - 2) * RACK_GRID_WIDTH, box.size.y);
|
textEditorWidget->box.size = Vec((module->width - 2) * RACK_GRID_WIDTH, box.size.y);
|
||||||
addChild(textEditorWidget);
|
addChild(textEditorWidget);
|
||||||
|
|
@ -342,8 +322,7 @@ struct TextEditorModuleWidget : ModuleWidget {
|
||||||
{
|
{
|
||||||
menu->addChild(new MenuSeparator);
|
menu->addChild(new MenuSeparator);
|
||||||
menu->addChild(new TextEditorLoadFileItem(textEditorModule, textEditorWidget));
|
menu->addChild(new TextEditorLoadFileItem(textEditorModule, textEditorWidget));
|
||||||
// TODO
|
menu->addChild(new TextEditorLangSelectMenuItem(textEditorModule, textEditorWidget));
|
||||||
// menu->addChild(new TextEditorLangSelectMenuItem(textEditorModule, textEditorWidget));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void step() override
|
void step() override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue