diff --git a/lib/imgui_code_editor/imgui_code_editor.cpp b/lib/imgui_code_editor/imgui_code_editor.cpp index 2f190ad..5533d28 100644 --- a/lib/imgui_code_editor/imgui_code_editor.cpp +++ b/lib/imgui_code_editor/imgui_code_editor.cpp @@ -1,5 +1,6 @@ #include "imgui_code_editor.h" #include "../imgui/imgui_internal.h" +#include #include #include #include @@ -113,6 +114,34 @@ static int ImTextAppendUtf8ToStdStr(std::string &buf, CodeEditor::Char chr) { return ret; } +static size_t ImTextToLowerCase(std::string &str) { + size_t i = 0; + while (i < str.length()) { + int n = ImTextExpectUtf8Char(str.c_str() + i); + if (n == 0) + break; + else if (n == 1) + str[i] = (char)::tolower(str[i]); + i += n; + } + + return i; +} + +static size_t ImTextToUpperCase(std::string &str) { + size_t i = 0; + while (i < str.length()) { + int n = ImTextExpectUtf8Char(str.c_str() + i); + if (n == 0) + break; + else if (n == 1) + str[i] = (char)::toupper(str[i]); + i += n; + } + + return i; +} + CodeEditor::LanguageDefinition CodeEditor::LanguageDefinition::Text(void) { static bool inited = false; static LanguageDefinition langDef; @@ -590,7 +619,9 @@ bool CodeEditor::UndoRecord::Similar(const UndoRecord* o) const { void CodeEditor::UndoRecord::Undo(CodeEditor* aEditor) { if (!Content.empty()) { switch (Type) { - case UndoType::Add: { + case UndoType::Add: // Fall through. + case UndoType::ToLowerCase: // Fall through. + case UndoType::ToUpperCase: { aEditor->State = After; aEditor->DeleteRange(Start, End); @@ -759,7 +790,9 @@ void CodeEditor::UndoRecord::Undo(CodeEditor* aEditor) { void CodeEditor::UndoRecord::Redo(CodeEditor* aEditor) { if (!Content.empty()) { switch (Type) { - case UndoType::Add: { + case UndoType::Add: // Fall through. + case UndoType::ToLowerCase: // Fall through. + case UndoType::ToUpperCase: { aEditor->State = Before; aEditor->DeleteSelection(); @@ -915,6 +948,13 @@ void CodeEditor::UndoRecord::Redo(CodeEditor* aEditor) { aEditor->OnModified(); } +CodeEditor::Error::Error() { +} + +CodeEditor::Error::Error(const std::string &msg, bool isWarning_, bool withLineNumber_) : + message(msg), isWarning(isWarning_), withLineNumber(withLineNumber_) { +} + CodeEditor::Glyph::Glyph(Char aChar, ImU32 aColorIndex) : Character(aChar), ColorIndex(aColorIndex), MultiLineComment(false) { if (aChar <= 255) { Codepoint = (ImWchar)aChar; @@ -960,8 +1000,10 @@ CodeEditor::CodeEditor() : UndoIndex(0), SavedIndex(0), Font(nullptr), + IndentWithTab(false), TabSize(4), TextStart(7), + HeadSize(0), Overwrite(false), ReadOnly(false), ShowLineNumbers(true), @@ -973,8 +1015,10 @@ CodeEditor::CodeEditor() : ColorRangeMin(0), ColorRangeMax(0), CheckMultilineComments(0), + ErrorTipEnabled(true), TooltipEnabled(true), ShowWhiteSpaces(true), + SafeColumnIndicatorOffset(0), EditorFocused(false), ProgramPointer(-1) { @@ -1154,8 +1198,6 @@ void CodeEditor::Render(const char* aTitle, const ImVec2 &aSize, bool aBorder) { MoveHome(shift); else if (!ctrl && !alt && IsKeyPressed(GetKeyIndex(ImGuiKey_End))) MoveEnd(shift); - else if (!IsReadOnly() && !ctrl && !shift && !alt && IsKeyPressed(GetKeyIndex(ImGuiKey_Backspace))) - BackSpace(); if (!IsReadOnly()) { if (IsKeyPressed(GetKeyIndex(ImGuiKey_Enter)) || OnKeyPressed(ImGuiKey_Enter)) { @@ -1187,6 +1229,14 @@ void CodeEditor::Render(const char* aTitle, const ImVec2 &aSize, bool aBorder) { BackSpace(); // Unindent single line. } } + } else if (!ctrl && !shift && !alt && IsKeyPressed(GetKeyIndex(ImGuiKey_Backspace))) { + BackSpace(); + } else if (ctrl && !alt && IsKeyPressed(SDL_SCANCODE_U)) { + if (shift) { + ToUpperCase(); + } else { + ToLowerCase(); + } } } @@ -1205,7 +1255,7 @@ void CodeEditor::Render(const char* aTitle, const ImVec2 &aSize, bool aBorder) { if (IndentWithTab) { EnterCharacter(c); } else { - for (int n = 0; n < TabSize; ++n) + for (int i = 0; i < TabSize; ++i) EnterCharacter(' '); } } else { @@ -1235,8 +1285,17 @@ void CodeEditor::Render(const char* aTitle, const ImVec2 &aSize, bool aBorder) { int lineNo = (int)floor(scrollY / CharAdv.y); const int lineMax = std::max(0, std::min((int)CodeLines.size() - 1, lineNo + (int)ceil((scrollY + contentSize.y) / CharAdv.y))); if (!CodeLines.empty()) { + if (GetSafeColumnIndicatorOffset() > 0) { + const ImVec2 istart( + cursorScreenPos.x + CharAdv.x * TextStart + CharAdv.x * GetSafeColumnIndicatorOffset(), + cursorScreenPos.y + CharAdv.y * lineNo + ); + const ImVec2 iend(istart.x, istart.y + std::max(CharAdv.y * (lineMax + 1), contentSize.y)); + drawList->AddLine(istart, iend, Plt[(int)PaletteIndex::CurrentLineEdge]); + } + while (lineNo <= lineMax) { - ImVec2 lineStartScreenPos = ImVec2(cursorScreenPos.x, cursorScreenPos.y + lineNo * CharAdv.y); + ImVec2 lineStartScreenPos = ImVec2(cursorScreenPos.x, cursorScreenPos.y + CharAdv.y * lineNo); ImVec2 textScreenPos = ImVec2(lineStartScreenPos.x + CharAdv.x * TextStart, lineStartScreenPos.y); Line &line = CodeLines[lineNo]; @@ -1258,8 +1317,8 @@ void CodeEditor::Render(const char* aTitle, const ImVec2 &aSize, bool aBorder) { ++ssend; if (sstart != -1 && ssend != -1 && sstart < ssend) { - const ImVec2 vstart(lineStartScreenPos.x + (CharAdv.x) * (sstart + TextStart), lineStartScreenPos.y); - const ImVec2 vend(lineStartScreenPos.x + (CharAdv.x) * (ssend + TextStart), lineStartScreenPos.y + CharAdv.y); + const ImVec2 vstart(lineStartScreenPos.x + CharAdv.x * (sstart + TextStart), lineStartScreenPos.y); + const ImVec2 vend(lineStartScreenPos.x + CharAdv.x * (ssend + TextStart), lineStartScreenPos.y + CharAdv.y); drawList->AddRectFilled(vstart, vend, Plt[(int)PaletteIndex::Selection]); } @@ -1313,20 +1372,35 @@ void CodeEditor::Render(const char* aTitle, const ImVec2 &aSize, bool aBorder) { ErrorMarkers::iterator errorIt = Errs.find(lineNo); if (errorIt != Errs.end()) { + const int ln = errorIt->first; + const Error &err = errorIt->second; const ImVec2 end(lineStartScreenPos.x + contentSize.x + 2.0f * scrollX, lineStartScreenPos.y + CharAdv.y); - drawList->AddRectFilled(start, end, Plt[(int)PaletteIndex::ErrorMarker]); + if (err.isWarning) + drawList->AddRectFilled(start, end, Plt[(int)PaletteIndex::WarningMarker]); + else + drawList->AddRectFilled(start, end, Plt[(int)PaletteIndex::ErrorMarker]); - if (IsTooltipEnabled()) { + if (IsErrorTipEnabled()) { if (IsMouseHoveringRect(lineStartScreenPos, end)) { + PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8, 8)); BeginTooltip(); - PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.2f, 0.2f, 1.0f)); - Text("Error at line %d:", errorIt->first); - PopStyleColor(); - Separator(); - PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 0.2f, 1.0f)); - Text("%s", errorIt->second.c_str()); - PopStyleColor(); + if (err.withLineNumber) { + if (err.isWarning) { + Text("Warning at line %d:", ln); + } else { + Text("Error at line %d:", ln); + } + Separator(); + Text("%s", err.message.c_str()); + } else { + if (err.isWarning) { + Text("Warning: %s", err.message.c_str()); + } else { + Text("Error: %s", err.message.c_str()); + } + } EndTooltip(); + PopStyleVar(); } } } @@ -1788,6 +1862,14 @@ bool CodeEditor::IsShortcutsEnabled(ShortcutType aType) const { return !!(ShortcutsEnabled & aType); } +void CodeEditor::SetErrorTipEnabled(bool aValue) { + ErrorTipEnabled = aValue; +} + +bool CodeEditor::IsErrorTipEnabled(void) const { + return ErrorTipEnabled; +} + void CodeEditor::SetTooltipEnabled(bool aValue) { TooltipEnabled = aValue; } @@ -1804,6 +1886,14 @@ bool CodeEditor::IsShowWhiteSpaces(void) const { return ShowWhiteSpaces; } +void CodeEditor::SetSafeColumnIndicatorOffset(int aValue) { + SafeColumnIndicatorOffset = aValue; +} + +int CodeEditor::GetSafeColumnIndicatorOffset(void) const { + return SafeColumnIndicatorOffset; +} + bool CodeEditor::IsEditorFocused(void) const { return EditorFocused; } @@ -2392,6 +2482,66 @@ void CodeEditor::Unindent(bool aByKey) { } } +void CodeEditor::ToLowerCase(void) { + if (!HasSelection()) + return; + + UndoRecord u; + u.Type = UndoType::ToLowerCase; + u.Before = State; + + std::string txt = GetSelectionText(); + u.Overwritten = txt; + DeleteSelection(); + + ImTextToLowerCase(txt); + u.Content = txt; + u.Start = GetActualCursorCoordinates(); + + InsertText(txt.c_str()); + + u.End = GetActualCursorCoordinates(); + u.After = State; + AddUndo(u); + State = u.Before; + + OnModified(); + + OnChanged(u.Start, u.End, 0); + + InteractiveStart = InteractiveEnd = State.CursorPosition; +} + +void CodeEditor::ToUpperCase(void) { + if (!HasSelection()) + return; + + UndoRecord u; + u.Type = UndoType::ToUpperCase; + u.Before = State; + + std::string txt = GetSelectionText(); + u.Overwritten = txt; + DeleteSelection(); + + ImTextToUpperCase(txt); + u.Content = txt; + u.Start = GetActualCursorCoordinates(); + + InsertText(txt.c_str()); + + u.End = GetActualCursorCoordinates(); + u.After = State; + AddUndo(u); + State = u.Before; + + OnModified(); + + OnChanged(u.Start, u.End, 0); + + InteractiveStart = InteractiveEnd = State.CursorPosition; +} + void CodeEditor::Comment(void) { if (IsReadOnly()) return; @@ -2656,7 +2806,8 @@ const CodeEditor::Palette &CodeEditor::GetDarkPalette(void) { 0xff2c2c2c, // Background. 0xffe0e0e0, // Cursor. 0x80a06020, // Selection. - 0x804d00ff, // ErrorMarker. + 0x804d00ff, // Error marker. + 0x8005f0fa, // Warning marker. 0xe00020f0, // Breakpoint. 0xe000f0f0, // Program pointer. 0xffaf912b, // Line number. @@ -2690,7 +2841,8 @@ const CodeEditor::Palette &CodeEditor::GetLightPalette(void) { 0xffffffff, // Background. 0xff000000, // Cursor. 0xffffd6ad, // Selection. - 0xa00010ff, // ErrorMarker. + 0xa00010ff, // Error marker. + 0x8005f0fa, // Warning marker. 0xe00020f0, // Breakpoint. 0xe000f0f0, // Program pointer. 0xffaf912b, // Line number. @@ -2724,7 +2876,8 @@ const CodeEditor::Palette &CodeEditor::GetRetroBluePalette(void) { 0xff753929, // Background. 0xff0080ff, // Cursor. 0x80ffff00, // Selection. - 0xa00000ff, // ErrorMarker. + 0xa00000ff, // Error marker. + 0x8005f0fa, // Warning marker. 0xe00020f0, // Breakpoint. 0xe000f0f0, // Program pointer. 0xff808000, // Line number. diff --git a/lib/imgui_code_editor/imgui_code_editor.h b/lib/imgui_code_editor/imgui_code_editor.h index e33fc75..c018d0f 100644 --- a/lib/imgui_code_editor/imgui_code_editor.h +++ b/lib/imgui_code_editor/imgui_code_editor.h @@ -59,6 +59,7 @@ class CodeEditor { Cursor, Selection, ErrorMarker, + WarningMarker, Breakpoint, ProgramPointer, LineNumber, @@ -132,7 +133,15 @@ class CodeEditor { typedef std::unordered_map Identifiers; typedef std::unordered_set Keywords; - typedef std::map ErrorMarkers; + struct Error { + std::string message; + bool isWarning = false; + bool withLineNumber = false; + + Error(); + Error(const std::string &msg, bool isWarning_, bool withLineNumber_); + }; + typedef std::map ErrorMarkers; typedef std::unordered_map Breakpoints; typedef std::array Palette; @@ -274,12 +283,18 @@ class CodeEditor { void DisableShortcut(ShortcutType aType); bool IsShortcutsEnabled(ShortcutType aType) const; + void SetErrorTipEnabled(bool aValue); + bool IsErrorTipEnabled(void) const; + void SetTooltipEnabled(bool aValue); bool IsTooltipEnabled(void) const; void SetShowWhiteSpaces(bool aValue); bool IsShowWhiteSpaces(void) const; + void SetSafeColumnIndicatorOffset(int aValue); + int GetSafeColumnIndicatorOffset(void) const; + bool IsEditorFocused(void) const; void MoveUp(int aAmount = 1, bool aSelect = false); @@ -312,6 +327,8 @@ class CodeEditor { void Delete(void); void Indent(bool aByKey = true); void Unindent(bool aByKey = true); + void ToLowerCase(void); + void ToUpperCase(void); void Comment(void); void Uncomment(void); void MoveLineUp(void); @@ -341,6 +358,8 @@ class CodeEditor { Remove, Indent, Unindent, + ToLowerCase, + ToUpperCase, Comment, Uncomment, MoveLineUp, @@ -418,10 +437,10 @@ class CodeEditor { const ImFont* Font; ImVector InputBuffer; ImVec2 CharAdv; - bool IndentWithTab = false; + bool IndentWithTab; int TabSize; int TextStart; - float HeadSize = 0; + float HeadSize; bool Overwrite; bool ReadOnly; bool ShowLineNumbers; @@ -434,8 +453,10 @@ class CodeEditor { std::string LastSymbol; PaletteIndex LastSymbolPalette; int CheckMultilineComments; + bool ErrorTipEnabled; bool TooltipEnabled; bool ShowWhiteSpaces; + int SafeColumnIndicatorOffset; ImVec2 CursorScreenPos; bool EditorFocused; diff --git a/src/theme_sketchbook.cpp b/src/theme_sketchbook.cpp index cfe8e05..d009232 100644 --- a/src/theme_sketchbook.cpp +++ b/src/theme_sketchbook.cpp @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */ diff --git a/src/theme_sketchbook.h b/src/theme_sketchbook.h index 0c7059e..d866b68 100644 --- a/src/theme_sketchbook.h +++ b/src/theme_sketchbook.h @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */ diff --git a/src/widgets_sketchbook.cpp b/src/widgets_sketchbook.cpp index a43b7e7..25a9f6b 100644 --- a/src/widgets_sketchbook.cpp +++ b/src/widgets_sketchbook.cpp @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */ @@ -105,6 +105,49 @@ void PreferencesPopupBox::update(void) { { TextUnformatted(_theme->windowPreferences_Editor_TextEditor()); + PushID("#Col"); + { + AlignTextToFramePadding(); + TextUnformatted(_theme->windowPreferences_Editor_ColumnIndicator()); + + SameLine(); + + const char* items[] = { + _theme->windowPreferences_Editor_None().c_str(), + _theme->windowPreferences_Editor_40().c_str(), + _theme->windowPreferences_Editor_80().c_str(), + _theme->windowPreferences_Editor_100().c_str(), + _theme->windowPreferences_Editor_120().c_str() + }; + int pref = (int)_settingsShadow.editorColumnIndicator; + SetNextItemWidth(GetContentRegionAvail().x); + if (Combo("", &pref, items, BITTY_COUNTOF(items))) + _settingsShadow.editorColumnIndicator = (Workspace::Settings::ColumnIndicator)pref; + } + PopID(); + + PushID("#Ind"); + { + AlignTextToFramePadding(); + TextUnformatted(_theme->windowPreferences_Editor_IndentWith()); + + SameLine(); + + const char* items[] = { + _theme->windowPreferences_Editor_2Spaces().c_str(), + _theme->windowPreferences_Editor_4Spaces().c_str(), + _theme->windowPreferences_Editor_8Spaces().c_str(), + _theme->windowPreferences_Editor_Tab2SpacesWide().c_str(), + _theme->windowPreferences_Editor_Tab4SpacesWide().c_str(), + _theme->windowPreferences_Editor_Tab8SpacesWide().c_str() + }; + int pref = (int)_settingsShadow.editorIndentRule; + SetNextItemWidth(GetContentRegionAvail().x); + if (Combo("", &pref, items, BITTY_COUNTOF(items))) + _settingsShadow.editorIndentRule = (Workspace::Settings::IndentRules)pref; + } + PopID(); + Checkbox(_theme->windowPreferences_Editor_ShowWhiteSpaces(), &_settingsShadow.editorShowWhiteSpaces); TextUnformatted(_theme->windowPreferences_Editor_Console()); @@ -363,7 +406,7 @@ void AboutPopupBox::update(void) { SameLine(); Url("Tony Wang", "https://paladin-t.github.io/"); SameLine(); - TextUnformatted(", 2020 - 2023"); + TextUnformatted(", 2020 - 2024"); NewLine(); } Separator(); diff --git a/src/widgets_sketchbook.h b/src/widgets_sketchbook.h index 9c11ca6..96ec596 100644 --- a/src/widgets_sketchbook.h +++ b/src/widgets_sketchbook.h @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */ diff --git a/src/workspace.cpp b/src/workspace.cpp index 8066b20..6d24db7 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */ @@ -983,6 +983,16 @@ bool Workspace::load(class Window* wnd, class Renderer* rnd, const class Project Jpath::get(doc, settings()->projectLoadLastProjectAtStartup, "project", "load_last_project_at_startup"); Jpath::get(doc, settings()->projectAutoBackup, "project", "auto_backup"); + unsigned indentRule = 0; + if (Jpath::get(doc, indentRule, "editor", "indent_rule")) + settings()->editorIndentRule = (Settings::IndentRules)indentRule; + else + settings()->editorIndentRule = Settings::TAB_4; + unsigned columnIndicator = 0; + if (Jpath::get(doc, columnIndicator, "editor", "column_indicator")) + settings()->editorColumnIndicator = (Settings::ColumnIndicator)columnIndicator; + else + settings()->editorColumnIndicator = Settings::COL_80; Jpath::get(doc, settings()->editorShowWhiteSpaces, "editor", "show_white_spaces"); Jpath::get(doc, settings()->editorCaseSensitive, "editor", "case_sensitive"); Jpath::get(doc, settings()->editorMatchWholeWord, "editor", "match_whole_word"); @@ -1090,6 +1100,8 @@ bool Workspace::save(class Window* wnd, class Renderer*, const class Project*, c Jpath::set(doc, doc, settings()->projectLoadLastProjectAtStartup, "project", "load_last_project_at_startup"); Jpath::set(doc, doc, settings()->projectAutoBackup, "project", "auto_backup"); + Jpath::set(doc, doc, (unsigned)settings()->editorIndentRule, "editor", "indent_rule"); + Jpath::set(doc, doc, (unsigned)settings()->editorColumnIndicator, "editor", "column_indicator"); Jpath::set(doc, doc, settings()->editorShowWhiteSpaces, "editor", "show_white_spaces"); Jpath::set(doc, doc, settings()->editorCaseSensitive, "editor", "case_sensitive"); Jpath::set(doc, doc, settings()->editorMatchWholeWord, "editor", "match_whole_word"); @@ -3190,6 +3202,10 @@ int Workspace::withEditingAsset(const class Project* project, EditorHandler hand void Workspace::fillAssetEditorSettings(Editable* editor) const { editor->post(Editable::SET_THEME_STYLE, (Variant::Int)theme()->styleIndex()); + editor->post(Editable::SET_INDENT_RULE, (Variant::Int)settings()->editorIndentRule); + + editor->post(Editable::SET_COLUMN_INDICATOR, (Variant::Int)settings()->editorColumnIndicator); + editor->post(Editable::SET_SHOW_SPACES, settings()->editorShowWhiteSpaces); } diff --git a/src/workspace.h b/src/workspace.h index c366dc1..35c25a7 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */ @@ -160,6 +160,22 @@ class CodeEditor; class Workspace : public Executable::Observer, public Dispatchable, public NonCopyable { public: struct Settings { + enum IndentRules : unsigned { + SPACE_2, + SPACE_4, + SPACE_8, + TAB_2, + TAB_4, + TAB_8 + }; + enum ColumnIndicator : unsigned { + COL_NONE, + COL_40, + COL_80, + COL_100, + COL_120 + }; + int applicationWindowDisplayIndex = 0; bool applicationWindowFullscreen = false; bool applicationWindowMaximized = false; @@ -177,6 +193,8 @@ class Workspace : public Executable::Observer, public Dispatchable, public NonCo bool assetsVisible = true; + IndentRules editorIndentRule = TAB_4; + ColumnIndicator editorColumnIndicator = COL_80; bool editorShowWhiteSpaces = true; bool editorCaseSensitive = false; bool editorMatchWholeWord = false; diff --git a/src/workspace_sketchbook.cpp b/src/workspace_sketchbook.cpp index 25dd383..a8c421e 100644 --- a/src/workspace_sketchbook.cpp +++ b/src/workspace_sketchbook.cpp @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */ @@ -66,6 +66,8 @@ WorkspaceSketchbook::SketchbookSettings &WorkspaceSketchbook::SketchbookSettings bannerVisible = other.bannerVisible; assetsVisible = other.assetsVisible; + editorIndentRule = other.editorIndentRule; + editorColumnIndicator = other.editorColumnIndicator; editorShowWhiteSpaces = other.editorShowWhiteSpaces; editorCaseSensitive = other.editorCaseSensitive; editorMatchWholeWord = other.editorMatchWholeWord; @@ -126,7 +128,9 @@ bool WorkspaceSketchbook::SketchbookSettings::operator != (const SketchbookSetti if (assetsVisible != other.assetsVisible) return true; - if (editorShowWhiteSpaces != other.editorShowWhiteSpaces || + if (editorIndentRule != other.editorIndentRule || + editorColumnIndicator != other.editorColumnIndicator || + editorShowWhiteSpaces != other.editorShowWhiteSpaces || editorCaseSensitive != other.editorCaseSensitive || editorMatchWholeWord != other.editorMatchWholeWord || editorGlobalSearch != other.editorGlobalSearch @@ -1395,6 +1399,24 @@ void WorkspaceSketchbook::showPreferences(class Window* wnd, class Renderer*, co _settings.projectAutoBackup = sets.projectAutoBackup; } + if (sets.editorIndentRule != _settings.editorIndentRule) { + prj->foreach( + [&] (Asset* &asset, Asset::List::Index) -> void { + Editable* editor = asset->editor(); + if (editor) + editor->post(Editable::SET_INDENT_RULE, (Variant::Int)sets.editorIndentRule); + } + ); + } + if (sets.editorColumnIndicator != _settings.editorColumnIndicator) { + prj->foreach( + [&] (Asset* &asset, Asset::List::Index) -> void { + Editable* editor = asset->editor(); + if (editor) + editor->post(Editable::SET_COLUMN_INDICATOR, (Variant::Int)sets.editorColumnIndicator); + } + ); + } if (sets.editorShowWhiteSpaces != _settings.editorShowWhiteSpaces) { prj->foreach( [&] (Asset* &asset, Asset::List::Index) -> void { diff --git a/src/workspace_sketchbook.h b/src/workspace_sketchbook.h index 3cf14be..9bd9c44 100644 --- a/src/workspace_sketchbook.h +++ b/src/workspace_sketchbook.h @@ -3,7 +3,7 @@ ** ** An itty bitty game engine. ** -** Copyright (C) 2020 - 2023 Tony Wang, all rights reserved +** Copyright (C) 2020 - 2024 Tony Wang, all rights reserved ** ** For the latest info, see https://github.com/paladin-t/bitty/ */