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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
pData->file.clear();
|
||||
|
|
|
@ -42,6 +42,8 @@ struct ImGuiTextEditor : ImGuiWidget
|
|||
void setFileWithKnownText(const std::string& file, const std::string& text);
|
||||
std::string getFile() const;
|
||||
|
||||
void setLanguageDefinition(const std::string& lang);
|
||||
|
||||
/**
|
||||
Methods from internal TextEdit.
|
||||
*/
|
||||
|
|
|
@ -36,30 +36,6 @@
|
|||
"int such_highlight_much_wow() { return 1337; }\n"
|
||||
#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 {
|
||||
std::string file;
|
||||
std::string lang = DEFAULT_LANG;
|
||||
|
@ -88,8 +64,8 @@ struct TextEditorModule : Module {
|
|||
{
|
||||
lang = json_string_value(langJ);
|
||||
#ifndef HEADLESS
|
||||
// if (ImGuiTextEditor* const widget = widgetPtr)
|
||||
// widget->SetLanguageDefinition(getLangFromString(lang));
|
||||
if (ImGuiTextEditor* const widget = widgetPtr)
|
||||
widget->setLanguageDefinition(lang);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -148,17 +124,20 @@ struct TextEditorLangSelectItem : MenuItem {
|
|||
|
||||
TextEditorLangSelectItem(TextEditorModule* const textEditorModule,
|
||||
ImGuiTextEditor* const textEditorWidget,
|
||||
const char* const textToUse)
|
||||
const char* const lang)
|
||||
: module(textEditorModule),
|
||||
widget(textEditorWidget)
|
||||
{
|
||||
text = textToUse;
|
||||
text = lang;
|
||||
|
||||
if (module->lang == lang)
|
||||
rightText = CHECKMARK_STRING;
|
||||
}
|
||||
|
||||
void onAction(const event::Action &e) override
|
||||
{
|
||||
module->lang = text;
|
||||
// widget->SetLanguageDefinition(getLangFromString(text));
|
||||
widget->setLanguageDefinition(text);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -185,12 +164,12 @@ struct TextEditorLangSelectMenuItem : MenuItem {
|
|||
widget(textEditorWidget)
|
||||
{
|
||||
text = "Syntax Highlight";
|
||||
rightText = RIGHT_ARROW;
|
||||
}
|
||||
|
||||
void onAction(const event::Action &e) override
|
||||
Menu* createChildMenu() override
|
||||
{
|
||||
// TODO
|
||||
// new TextEditorLangSelectMenu(module, widget);
|
||||
return new TextEditorLangSelectMenu(module, widget);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -328,6 +307,7 @@ struct TextEditorModuleWidget : ModuleWidget {
|
|||
textEditorModule = module;
|
||||
textEditorWidget = new ImGuiTextEditor();
|
||||
textEditorWidget->setFileWithKnownText(module->file, module->text);
|
||||
textEditorWidget->setLanguageDefinition(module->lang);
|
||||
textEditorWidget->box.pos = Vec(RACK_GRID_WIDTH, 0);
|
||||
textEditorWidget->box.size = Vec((module->width - 2) * RACK_GRID_WIDTH, box.size.y);
|
||||
addChild(textEditorWidget);
|
||||
|
@ -342,8 +322,7 @@ struct TextEditorModuleWidget : ModuleWidget {
|
|||
{
|
||||
menu->addChild(new MenuSeparator);
|
||||
menu->addChild(new TextEditorLoadFileItem(textEditorModule, textEditorWidget));
|
||||
// TODO
|
||||
// menu->addChild(new TextEditorLangSelectMenuItem(textEditorModule, textEditorWidget));
|
||||
menu->addChild(new TextEditorLangSelectMenuItem(textEditorModule, textEditorWidget));
|
||||
}
|
||||
|
||||
void step() override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue