From 8db093e99a1e0ee39cc32227a5ddc731ea2a14a3 Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Mon, 17 Feb 2025 04:28:34 -0700 Subject: [PATCH] Minor source editor improvements. - hotkeys: use Ctrl+G, Ctrl+F, Ctrl+H - when opening dialogs, focus will correctly follow - fix a bug with Go To Dialog being drawn at incorrect location - remove unused code --- neo/libs/ImGuiColorTextEdit/TextEditor.cpp | 17 + neo/libs/ImGuiColorTextEdit/TextEditor.h | 10 + neo/tools/imgui/scripteditor/ScriptEditor.cpp | 2 +- neo/tools/imgui/util/ImGui_IdWidgets.cpp | 31 +- neo/tools/imgui/util/ImGui_IdWidgets.h | 2 + neo/tools/imgui/util/SyntaxRichEditCtrl.cpp | 413 ++---------------- neo/tools/imgui/util/SyntaxRichEditCtrl.h | 67 ++- 7 files changed, 123 insertions(+), 419 deletions(-) diff --git a/neo/libs/ImGuiColorTextEdit/TextEditor.cpp b/neo/libs/ImGuiColorTextEdit/TextEditor.cpp index d4e45aeb..77dd6121 100644 --- a/neo/libs/ImGuiColorTextEdit/TextEditor.cpp +++ b/neo/libs/ImGuiColorTextEdit/TextEditor.cpp @@ -48,6 +48,8 @@ TextEditor::TextEditor() , mShowWhitespaces(true) , mStartTime(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()) , mLastClick(-1.0f) + , mKeyPressData(NULL) + , mKeyPressHandler(NULL) { SetPalette(GetDarkPalette()); SetLanguageDefinition(LanguageDefinition::HLSL()); @@ -60,6 +62,15 @@ TextEditor::~TextEditor() { } +void TextEditor::Focus() { + mSetFocus = true; +} + +void TextEditor::SetKeyPress(void* data, textEditKeyPress_t keyPress) { + mKeyPressData = data; + mKeyPressHandler = keyPress; +} + void TextEditor::SetLanguageDefinition(const LanguageDefinition & aLanguageDef) { mLanguageDefinition = aLanguageDef; @@ -769,6 +780,8 @@ void TextEditor::HandleKeyboardInputs() EnterCharacter('\n', false); else if (!IsReadOnly() && !ctrl && !alt && ImGui::IsKeyPressed(ImGuiKey_Tab)) EnterCharacter('\t', shift); + else if (mKeyPressHandler && !mKeyPressHandler(mKeyPressData, ctrl, shift, alt)) + return; if (!IsReadOnly() && !io.InputQueueCharacters.empty()) { @@ -1124,6 +1137,10 @@ void TextEditor::Render() ImGui::SetWindowFocus(); mScrollToCursor = false; } + if (mSetFocus) { + ImGui::SetWindowFocus(); + mSetFocus = false; + } } void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder) diff --git a/neo/libs/ImGuiColorTextEdit/TextEditor.h b/neo/libs/ImGuiColorTextEdit/TextEditor.h index 3bb7d7e0..e12ab57f 100644 --- a/neo/libs/ImGuiColorTextEdit/TextEditor.h +++ b/neo/libs/ImGuiColorTextEdit/TextEditor.h @@ -13,6 +13,8 @@ class TextEditor { public: + typedef bool (*textEditKeyPress_t)(void* data, bool ctrl, bool shift, bool alt); + enum class PaletteIndex { Default, @@ -185,6 +187,10 @@ public: TextEditor(); ~TextEditor(); + void Focus(); + + void SetKeyPress(void *data, textEditKeyPress_t keyPress); + void SetLanguageDefinition(const LanguageDefinition& aLanguageDef); const LanguageDefinition& GetLanguageDefinition() const { return mLanguageDefinition; } @@ -402,4 +408,8 @@ private: bool mMarkedUnsaved; int mUndoIndexFirstEdit; int mUndoIndexLastSave; + + void* mKeyPressData; + textEditKeyPress_t mKeyPressHandler; + bool mSetFocus; }; diff --git a/neo/tools/imgui/scripteditor/ScriptEditor.cpp b/neo/tools/imgui/scripteditor/ScriptEditor.cpp index b6679a91..a6ec1840 100644 --- a/neo/tools/imgui/scripteditor/ScriptEditor.cpp +++ b/neo/tools/imgui/scripteditor/ScriptEditor.cpp @@ -339,7 +339,7 @@ void ScriptEditor::OpenFile( const char *fileName ) { UpdateStatusBar(); - //scriptEdit.SetFocus(); + scriptEdit.SetFocus(); } // ScriptEditor message handlers diff --git a/neo/tools/imgui/util/ImGui_IdWidgets.cpp b/neo/tools/imgui/util/ImGui_IdWidgets.cpp index 57690d00..f4ff659c 100644 --- a/neo/tools/imgui/util/ImGui_IdWidgets.cpp +++ b/neo/tools/imgui/util/ImGui_IdWidgets.cpp @@ -418,6 +418,7 @@ GoToLineDialog::GoToLineDialog() , lastLine(0) , waiting(false) , valid(false) + , focus(false) , caption() { } @@ -428,12 +429,16 @@ void GoToLineDialog::Start( int _firstLine, int _lastLine, int _line ) { numberEdit = _line; valid = ( idMath::ClampInt( firstLine, lastLine, numberEdit ) == numberEdit ); waiting = true; + focus = true; caption = va( "Line number (%d - %d)", firstLine, lastLine ); - ImGui::OpenPopup( "Go To Line" ); } bool GoToLineDialog::Draw( const ImVec2 &pos, const ImVec2 &size ) { bool accepted = false; + + if ( !waiting ) { + return accepted; + } ImGuiStyle& style = ImGui::GetStyle(); float fieldWidth = 250.0f; @@ -452,34 +457,37 @@ bool GoToLineDialog::Draw( const ImVec2 &pos, const ImVec2 &size ) { fieldWidth + style.ItemSpacing.x + captionWidth; + ImVec2 oldCursorPos = ImGui::GetCursorPos(); + // TODO: this seems off, the dialog should be centered - ImGui::SetNextWindowPos(ImVec2( + ImGui::SetCursorPos(ImVec2( pos.x + (size.x - windowWidth)*0.5f, pos.y + (size.y - windowHeight)*0.5f)); - ImGui::SetNextWindowSize( ImVec2( windowWidth, windowHeight ) ); - if ( ImGui::BeginPopup( "Go To Line" ) ) { + if ( ImGui::BeginChild( "Go To Line", ImVec2( windowWidth, windowHeight ), ImGuiChildFlags_Borders ) ) { ImGui::SetNextItemWidth( fieldWidth ); if ( ImGui::InputInt( caption.c_str(), &numberEdit, 0, 0 ) ) { valid = ( idMath::ClampInt( firstLine, lastLine, numberEdit ) == numberEdit ); } + if ( focus ) { + ImGui::SetKeyboardFocusHere( -1 ); + focus = false; + } ImGui::BeginDisabled( !valid ); if ( ImGui::Button( "OK" ) ) { waiting = false; accepted = true; - ImGui::CloseCurrentPopup(); } ImGui::EndDisabled(); ImGui::SameLine(); if ( ImGui::Button( "Cancel" ) ) { waiting = false; accepted = false; - ImGui::CloseCurrentPopup(); } - - ImGui::EndPopup(); } + ImGui::EndChild(); + ImGui::SetCursorPos( oldCursorPos ); return accepted; } @@ -492,6 +500,7 @@ FindReplaceDialog::FindReplaceDialog() , replacement(false) , valid(false) , visible(false) + , focus(false) { } @@ -503,6 +512,7 @@ void FindReplaceDialog::Start( idStr &selection, bool _replacement ) { replacement = _replacement; valid = ( find.Length() > 0 ); visible = true; + focus = true; } FindReplaceDialog::command_t FindReplaceDialog::Draw( const ImVec2 &pos, const ImVec2 &size ) { @@ -545,6 +555,10 @@ FindReplaceDialog::command_t FindReplaceDialog::Draw( const ImVec2 &pos, const I if ( ImGui::InputTextStr( "###Find", &find ) ) { valid = ( find.Length() > 0 ); } + if ( focus ) { + ImGui::SetKeyboardFocusHere( -1 ); + focus = false; + } ImGui::SetItemTooltip( "Search term" ); ImGui::SameLine(); @@ -571,6 +585,7 @@ FindReplaceDialog::command_t FindReplaceDialog::Draw( const ImVec2 &pos, const I if ( ImGui::Button( "x", ImVec2( optionWidth, 0.0f ) ) ) { visible = false; + command = DONE; } ImGui::SetNextItemWidth( fieldWidth ); diff --git a/neo/tools/imgui/util/ImGui_IdWidgets.h b/neo/tools/imgui/util/ImGui_IdWidgets.h index 3b80b3f1..ed298c15 100644 --- a/neo/tools/imgui/util/ImGui_IdWidgets.h +++ b/neo/tools/imgui/util/ImGui_IdWidgets.h @@ -149,6 +149,7 @@ private: int lastLine; bool waiting; bool valid; + bool focus; idStr caption; }; @@ -174,6 +175,7 @@ private: bool replacement; bool valid; bool visible; + bool focus; }; } //namespace ImGuiTools diff --git a/neo/tools/imgui/util/SyntaxRichEditCtrl.cpp b/neo/tools/imgui/util/SyntaxRichEditCtrl.cpp index b9c1d2c5..c69c220f 100644 --- a/neo/tools/imgui/util/SyntaxRichEditCtrl.cpp +++ b/neo/tools/imgui/util/SyntaxRichEditCtrl.cpp @@ -53,6 +53,10 @@ const COLORREF MULTILINE_COMMENT_BACK_COLOR = SRE_COLOR_WHITE - 1; //#define IDC_LISTBOX_AUTOCOMPLETE 700 //#define IDC_EDITBOX_FUNCPARMS 701 +bool SyntaxRichEditCtrlKeyPress( void* data, bool ctrl, bool shift, bool alt ) { + return reinterpret_cast(data)->OnChar(ctrl, shift, alt); +} + static keyWord_t defaultKeyWords[] = { { NULL, vec3_origin, "" } }; @@ -86,8 +90,6 @@ SyntaxRichEditCtrl::SyntaxRichEditCtrl( void ) : scriptEdit( NULL ) , scriptEditPos( 0.0f, 0.0f ) , scriptEditSize( 400.0f, 400.0f ) - , okButtonEnabled( false ) - , cancelButtonEnabled( true ) , errorText() , findDlg() , gotoDlg() @@ -172,6 +174,7 @@ SyntaxRichEditCtrl::Init */ void SyntaxRichEditCtrl::Init( void ) { scriptEdit = new TextEditor(); + scriptEdit->SetKeyPress( this, SyntaxRichEditCtrlKeyPress ); /* // get the Rich Edit ITextDocument to use the wonky TOM interface @@ -184,6 +187,8 @@ void SyntaxRichEditCtrl::Init( void ) { InitSyntaxHighlighting(); + SetFocus(); + //SetEventMask( GetEventMask() | ENM_CHANGE | ENM_KEYEVENTS | ENM_MOUSEEVENTS | ENM_PROTECTED ); // ENM_SCROLLEVENTS //EnableToolTips( TRUE ); @@ -209,22 +214,6 @@ void SyntaxRichEditCtrl::Draw() scriptEditSize = ImVec2( 800, 600 ); scriptEdit->Render( "Text", scriptEditSize, false ); - if ( !scriptEdit->IsSaved() ) { - okButtonEnabled = true; - } - /* - ImGui::BeginDisabled( !okButtonEnabled ); - if (ImGui::Button("OK")) { - OnBnClickedOk(); - } - ImGui::EndDisabled(); - ImGui::SameLine(); - ImGui::BeginDisabled( !cancelButtonEnabled ); - if ( ImGui::Button( "Cancel" ) ) { - showTool = false; - } - ImGui::EndDisabled(); - ImGui::SameLine();*/ if ( ImGui::Button( "Go to" ) ) { OnEditGoToLine(); @@ -246,6 +235,7 @@ void SyntaxRichEditCtrl::Draw() TextEditor::Coordinates coords( gotoDlg.GetLine() - 1 - firstLine, 0 ); scriptEdit->SetCursorPosition( coords ); + SetFocus(); } FindReplaceDialog::command_t findReplaceResult = findDlg.Draw( scriptEditPos, scriptEditSize ); OnFindDialogMessage( findReplaceResult ); @@ -526,93 +516,6 @@ void SyntaxRichEditCtrl::EnableKeyWordAutoCompletion( bool enable ) { keyWordAutoCompletion = enable; } -/* -================ -SyntaxRichEditCtrl::GetVisibleRange -================ -*//* -CHARRANGE SyntaxRichEditCtrl::GetVisibleRange( void ) const { - RECT rectArea; - int firstLine, lastLine; - CHARRANGE range; - - firstLine = GetFirstVisibleLine(); - GetClientRect( &rectArea ); - lastLine = firstLine + ( rectArea.bottom / ( defaultCharFormat.yHeight / 20 ) ); - - if ( lastLine >= GetLineCount() ) { - lastLine = GetLineCount() - 1; - } - range.cpMin = LineIndex( firstLine ); - if ( range.cpMin < 0 ) { - range.cpMin = 0; - } - range.cpMax = LineIndex( lastLine ); - if ( range.cpMax == -1 ) { - range.cpMax = range.cpMin + LineLength( range.cpMin ); - } else { - range.cpMax += LineLength( range.cpMax ); - } - if ( range.cpMax >= GetTextLength() ) { - range.cpMax = GetTextLength() - 1; - } - return range; -}*/ - -/* -================ -SyntaxRichEditCtrl::SetDefaultFont -================ -*/ -void SyntaxRichEditCtrl::SetDefaultFont( int startCharIndex, int endCharIndex ) { - /*tom::ITextRange* range; - - updateSyntaxHighlighting = false; - - m_TextDoc->Range( startCharIndex, endCharIndex, &range ); - - m_TextDoc->Undo( tom::tomSuspend, NULL ); - range->put_Font( m_DefaultFont ); - m_TextDoc->Undo( tom::tomResume, NULL ); - - range->Release(); - - updateSyntaxHighlighting = true;*/ -} - -/* -================ -SyntaxRichEditCtrl::SetColor -================ -*/ -void SyntaxRichEditCtrl::SetColor( int startCharIndex, int endCharIndex, const idVec3 &foreColor, const idVec3 &backColor, bool bold ) { - /*tom::ITextRange* range; - tom::ITextFont *font; - long prop; - - updateSyntaxHighlighting = false; - - m_TextDoc->Range( startCharIndex, endCharIndex, &range ); - range->get_Font( &font ); - - m_TextDoc->Undo( tom::tomSuspend, &prop ); - font->put_ForeColor( foreColor ); - m_TextDoc->Undo( tom::tomResume, &prop ); - - m_TextDoc->Undo( tom::tomSuspend, &prop ); - font->put_BackColor( backColor ); - m_TextDoc->Undo( tom::tomResume, &prop ); - - m_TextDoc->Undo( tom::tomSuspend, &prop ); - font->put_Bold( bold ? tom::tomTrue : tom::tomFalse ); - m_TextDoc->Undo( tom::tomResume, &prop ); - - font->Release(); - range->Release(); - - updateSyntaxHighlighting = true;*/ -} - /* ================ SyntaxRichEditCtrl::GetBackColor @@ -635,246 +538,6 @@ idVec3 SyntaxRichEditCtrl::GetBackColor( int charIndex ) const { return vec3_origin; } -/* -================ -SyntaxRichEditCtrl::HighlightSyntax - - Update the syntax highlighting for the given character range. -================ -*/ -void SyntaxRichEditCtrl::HighlightSyntax( int startCharIndex, int endCharIndex ) { - /*int c, t, line, charIndex, textLength, syntaxStart, keyWordLength, keyWordIndex; - const char *keyWord; - CHARRANGE visRange; - CString text; - - // get text length - GetTextRange( 0, GetTextLength(), text ); - textLength = text.GetLength(); - - // make sure the indexes are within bounds - if ( startCharIndex < 0 ) { - startCharIndex = 0; - } - if ( endCharIndex < 0 ) { - endCharIndex = textLength - 1; - } else if ( endCharIndex >= textLength ) { - endCharIndex = textLength - 1; - } - - // move the start index to the beginning of the line - for ( ; startCharIndex > 0; startCharIndex-- ) { - if ( idStr::CharIsNewLine( text[startCharIndex-1] ) ) { - break; - } - } - - // move the end index to the end of the line - for ( ; endCharIndex < textLength - 1; endCharIndex++ ) { - if ( idStr::CharIsNewLine( text[endCharIndex+1] ) ) { - break; - } - } - - // get the visible char range - visRange = GetVisibleRange(); - - // never update beyond the visible range - if ( startCharIndex < visRange.cpMin ) { - SetColor( startCharIndex, visRange.cpMin - 1, SRE_COLOR_BLACK, INVALID_BACK_COLOR, false ); - startCharIndex = visRange.cpMin; - } - if ( visRange.cpMax < endCharIndex ) { - SetColor( visRange.cpMax, endCharIndex, SRE_COLOR_BLACK, INVALID_BACK_COLOR, false ); - endCharIndex = visRange.cpMax; - if ( endCharIndex >= textLength ) { - endCharIndex = textLength - 1; - } - } - - // test if the start index is inside a multi-line comment - if ( startCharIndex > 0 ) { - // multi-line comments have a slightly different background color - if ( GetBackColor( startCharIndex-1 ) == MULTILINE_COMMENT_BACK_COLOR ) { - for( ; startCharIndex > 0; startCharIndex-- ) { - if ( text[startCharIndex] == '/' && text[startCharIndex+1] == '*' ) { - break; - } - } - } - } - - // test if the end index is inside a multi-line comment - if ( endCharIndex < textLength - 1 ) { - // multi-line comments have a slightly different background color - if ( GetBackColor( endCharIndex+1 ) == MULTILINE_COMMENT_BACK_COLOR ) { - for( endCharIndex++; endCharIndex < textLength - 1; endCharIndex++ ) { - if ( text[endCharIndex-1] == '*' && text[endCharIndex] == '/' ) { - break; - } - } - } - } - - line = 0; - stringColorLine = -1; - stringColorIndex = 0; - - // set the default color - SetDefaultFont( startCharIndex, endCharIndex + 1 ); - - // syntax based colors - for( charIndex = startCharIndex; charIndex <= endCharIndex; charIndex++ ) { - - t = charType[text[charIndex]]; - switch( t ) { - case CT_WHITESPACE: { - if ( idStr::CharIsNewLine( text[charIndex] ) ) { - line++; - } - break; - } - case CT_COMMENT: { - c = text[charIndex+1]; - if ( c == '/' ) { - // single line comment - syntaxStart = charIndex; - for ( charIndex += 2; charIndex < textLength; charIndex++ ) { - if ( idStr::CharIsNewLine( text[charIndex] ) ) { - break; - } - } - SetColor( syntaxStart, charIndex + 1, singleLineCommentColor, DEFAULT_BACK_COLOR, false ); - } else if ( c == '*' ) { - // multi-line comment - syntaxStart = charIndex; - for ( charIndex += 2; charIndex < textLength; charIndex++ ) { - if ( text[charIndex] == '*' && text[charIndex+1] == '/' ) { - break; - } - } - charIndex++; - SetColor( syntaxStart, charIndex + 1, multiLineCommentColor, MULTILINE_COMMENT_BACK_COLOR, false ); - } - break; - } - case CT_STRING: { - if ( line != stringColorLine ) { - stringColorLine = line; - stringColorIndex = 0; - } - syntaxStart = charIndex; - for ( charIndex++; charIndex < textLength; charIndex++ ) { - c = text[charIndex]; - if ( charType[c] == CT_STRING && text[charIndex-1] != '\\' ) { - break; - } - if ( idStr::CharIsNewLine( c ) ) { - line++; - break; - } - } - SetColor( syntaxStart, charIndex + 1, stringColor[stringColorIndex], DEFAULT_BACK_COLOR, false ); - stringColorIndex ^= 1; - break; - } - case CT_LITERAL: { - syntaxStart = charIndex; - for ( charIndex++; charIndex < textLength; charIndex++ ) { - c = text[charIndex]; - if ( charType[c] == CT_LITERAL && text[charIndex-1] != '\\' ) { - break; - } - if ( idStr::CharIsNewLine( c ) ) { - line++; - break; - } - } - SetColor( syntaxStart, charIndex + 1, literalColor, DEFAULT_BACK_COLOR, false ); - break; - } - case CT_NUMBER: { - break; - } - case CT_NAME: { - syntaxStart = charIndex; - keyWord = ((const char *)text) + charIndex; - for ( charIndex++; charIndex < textLength; charIndex++ ) { - c = text[charIndex]; - t = charType[c]; - if ( t != CT_NAME && t != CT_NUMBER ) { - // allow path names - if ( !allowPathNames || ( c != '/' && c != '\\' && c != '.' ) ) { - break; - } - } - } - keyWordLength = charIndex - syntaxStart; - keyWordIndex = FindKeyWord( keyWord, keyWordLength ); - if ( keyWordIndex != -1 ) { - SetColor( syntaxStart, syntaxStart + keyWordLength, keyWordColors[keyWordIndex], DEFAULT_BACK_COLOR, false ); - } - break; - } - case CT_PUNCTUATION: { - break; - } - } - } - - // show braced section - BracedSectionShow();*/ -} - -/* -================ -SyntaxRichEditCtrl::UpdateVisibleRange - - Updates the visible character range if it is not yet properly highlighted. -================ -*/ -void SyntaxRichEditCtrl::UpdateVisibleRange( void ) { - /*CHARRANGE visRange; - tom::ITextRange *range; - tom::ITextFont *font; - long backColor; - bool update = false; - - if ( !updateSyntaxHighlighting ) { - return; - } - - visRange = GetVisibleRange(); - - m_TextDoc->Range( visRange.cpMin, visRange.cpMax, &range ); - range->get_End( &visRange.cpMax ); - - range->get_Font( &font ); - - range->SetRange( visRange.cpMin, visRange.cpMin ); - while( 1 ) { - range->get_Start( &visRange.cpMin ); - if ( visRange.cpMin >= visRange.cpMax ) { - break; - } - font->get_BackColor( &backColor ); - if ( backColor == INVALID_BACK_COLOR ) { - update = true; - break; - } - if ( range->Move( tom::tomCharFormat, 1, NULL ) != S_OK ) { - break; - } - } - - font->Release(); - range->Release(); - - if ( update ) { - HighlightSyntax( visRange.cpMin, visRange.cpMax - 1 ); - }*/ -} - /* ================ SyntaxRichEditCtrl::GetCursorPos @@ -896,23 +559,6 @@ void SyntaxRichEditCtrl::GetText( idStr &text ) const { text = scriptEdit->GetText().c_str(); } -/* -================ -SyntaxRichEditCtrl::GetText -================ -*//* -void SyntaxRichEditCtrl::GetText( idStr &text, int startCharIndex, int endCharIndex ) const { - tom::ITextRange* range; - BSTR bstr; - USES_CONVERSION; - - m_TextDoc->Range( startCharIndex, endCharIndex, &range ); - range->get_Text( &bstr ); - text = W2A( bstr ); - range->Release(); - text.StripTrailingOnce( "\r" ); // remove last carriage return which is always added to a tom::ITextRange -}*/ - /* ================ SyntaxRichEditCtrl::SetText @@ -931,6 +577,15 @@ bool SyntaxRichEditCtrl::IsEdited() const { return scriptEdit->CanUndo(); } +/* +================ +SyntaxRichEditCtrl::SetFocus +================ +*/ +void SyntaxRichEditCtrl::SetFocus() { + scriptEdit->Focus(); +} + /* ================ SyntaxRichEditCtrl::AutoCompleteInsertText @@ -1342,7 +997,12 @@ SyntaxRichEditCtrl::OnEditFindNext ================ */ void SyntaxRichEditCtrl::OnEditFindNext() { - scriptEdit->FindNext( findStr.c_str(), matchCase, matchWholeWords, searchForward ); + if ( scriptEdit->FindNext( findStr.c_str(), matchCase, matchWholeWords, searchForward ) ) { + SetFocus(); + } else { + //AfxMessageBox( "The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 ); + } + } /* @@ -1397,8 +1057,10 @@ void SyntaxRichEditCtrl::OnFindDialogMessage( FindReplaceDialog::command_t comma }*/ break; } - case FindReplaceDialog::command_t::NONE: case FindReplaceDialog::command_t::DONE: + SetFocus(); + break; + case FindReplaceDialog::command_t::NONE: default: break; } @@ -1564,9 +1226,9 @@ void CSyntaxRichEditCtrl::OnKeyDown( UINT nKey, UINT nRepCnt, UINT nFlags ) { ================ SyntaxRichEditCtrl::OnChar ================ -*//* -void SyntaxRichEditCtrl::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags ) { - +*/ +bool SyntaxRichEditCtrl::OnChar( bool ctrl, bool shift, bool alt ) { + /* if ( nChar == VK_TAB ) { return; // tab is handle in OnKeyDown } @@ -1675,8 +1337,23 @@ void SyntaxRichEditCtrl::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags ) { } } return; + }*/ + bool result = true; + + if ( ctrl && ImGui::IsKeyPressed( ImGuiKey_G ) ) { + OnEditGoToLine(); + } else if ( ctrl && ImGui::IsKeyPressed( ImGuiKey_F ) ) { + idStr selText = scriptEdit->GetSelectedText().c_str(); + + findDlg.Start( selText, false ); + } else if ( ctrl && ImGui::IsKeyPressed( ImGuiKey_H ) ) { + idStr selText = scriptEdit->GetSelectedText().c_str(); + + findDlg.Start( selText, true ); } -}*/ + + return result; +} /* ================ diff --git a/neo/tools/imgui/util/SyntaxRichEditCtrl.h b/neo/tools/imgui/util/SyntaxRichEditCtrl.h index fc0084aa..2416dd49 100644 --- a/neo/tools/imgui/util/SyntaxRichEditCtrl.h +++ b/neo/tools/imgui/util/SyntaxRichEditCtrl.h @@ -54,31 +54,26 @@ class TextEditor; namespace ImGuiTools { -static const char* FONT_NAME = "Courier"; -static const int FONT_HEIGHT = 10; -static const int FONT_WIDTH = 8; static const int TAB_SIZE = 4; -/* -static const COLORREF SRE_COLOR_BLACK = RGB(0, 0, 0); -static const COLORREF SRE_COLOR_WHITE = RGB(255, 255, 255); -static const COLORREF SRE_COLOR_RED = RGB(255, 0, 0); -static const COLORREF SRE_COLOR_GREEN = RGB(0, 255, 0); -static const COLORREF SRE_COLOR_BLUE = RGB(0, 0, 255); -static const COLORREF SRE_COLOR_YELLOW = RGB(255, 255, 0); -static const COLORREF SRE_COLOR_MAGENTA = RGB(255, 0, 255); -static const COLORREF SRE_COLOR_CYAN = RGB(0, 255, 255); -static const COLORREF SRE_COLOR_ORANGE = RGB(255, 128, 0); -static const COLORREF SRE_COLOR_PURPLE = RGB(150, 0, 150); -static const COLORREF SRE_COLOR_PINK = RGB(186, 102, 123); -static const COLORREF SRE_COLOR_GREY = RGB(85, 85, 85); -static const COLORREF SRE_COLOR_BROWN = RGB(100, 90, 20); -static const COLORREF SRE_COLOR_LIGHT_GREY = RGB(170, 170, 170); -static const COLORREF SRE_COLOR_LIGHT_BROWN = RGB(170, 150, 20); -static const COLORREF SRE_COLOR_DARK_GREEN = RGB(0, 128, 0); -static const COLORREF SRE_COLOR_DARK_CYAN = RGB(0, 150, 150); -static const COLORREF SRE_COLOR_DARK_YELLOW = RGB(220, 200, 20); -*/ +static const idVec3 SRE_COLOR_BLACK = idVec3(0.0f, 0.0f, 0.0f); +static const idVec3 SRE_COLOR_WHITE = idVec3(1.0f, 1.0f, 1.0f); +static const idVec3 SRE_COLOR_RED = idVec3(1.0f, 0.0f, 0.0f); +static const idVec3 SRE_COLOR_GREEN = idVec3(0.0f, 1.0f, 0.0f); +static const idVec3 SRE_COLOR_BLUE = idVec3(0.0f, 0.0f, 1.0f); +static const idVec3 SRE_COLOR_YELLOW = idVec3(1.0f, 1.0f, 0.0f); +static const idVec3 SRE_COLOR_MAGENTA = idVec3(1.0f, 0.0f, 1.0f); +static const idVec3 SRE_COLOR_CYAN = idVec3(0.0f, 1.0f, 1.0f); +static const idVec3 SRE_COLOR_ORANGE = idVec3(1.0f, 0.5f, 0.0f); +static const idVec3 SRE_COLOR_PURPLE = idVec3(0.59f, 0.0f, 0.59f); +static const idVec3 SRE_COLOR_PINK = idVec3(0.73f, 0.4f, 0.48f); +static const idVec3 SRE_COLOR_GREY = idVec3(0.33f, 0.33f, 0.33f); +static const idVec3 SRE_COLOR_BROWN = idVec3(0.4f, 0.35f, 0.07f); +static const idVec3 SRE_COLOR_LIGHT_GREY = idVec3(0.66f, 0.66f, 0.66f); +static const idVec3 SRE_COLOR_LIGHT_BROWN = idVec3(0.66f, 0.59f, 0.08f); +static const idVec3 SRE_COLOR_DARK_GREEN = idVec3(0.0f, 0.5f, 0.0f); +static const idVec3 SRE_COLOR_DARK_CYAN = idVec3(0.0f, 0.59f, 0.59f); +static const idVec3 SRE_COLOR_DARK_YELLOW = idVec3(0.86f, 0.78f, 0.07f); typedef struct { const char * keyWord; @@ -86,9 +81,8 @@ typedef struct { const char * description; } keyWord_t; -typedef bool (*objectMemberCallback_t)(const char* objectName, idStrList& listBox); -typedef bool (*toolTipCallback_t)(const char* name, idStr& string); - +typedef bool ( *objectMemberCallback_t )( const char* objectName, idStrList &listBox ); +typedef bool ( *toolTipCallback_t )( const char* name, idStr &string ); class SyntaxRichEditCtrl { public: @@ -115,19 +109,20 @@ public: idVec3 GetBackColor( int charIndex ) const; void GetCursorPos( int &line, int &column, int &character ) const; - //CHARRANGE GetVisibleRange(void) const; void GetText( idStr &text ) const; - //void GetText( idStr &text, int startCharIndex, int endCharIndex ) const; void SetText( const char *text ); bool IsEdited() const; -private: + void SetFocus(); + +public: //virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const; bool OnToolTipNotify(); //afx_msg UINT OnGetDlgCode(); - //afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); + bool OnChar( bool ctrl, bool shift, bool alt ); +private: //afx_msg void OnKeyDown(UINT nKey, UINT nRepCnt, UINT nFlags); //afx_msg void OnLButtonDown(UINT nFlags, CPoint point); //afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); @@ -148,8 +143,6 @@ private: TextEditor * scriptEdit; ImVec2 scriptEditPos; ImVec2 scriptEditSize; - bool okButtonEnabled; - bool cancelButtonEnabled; idStr errorText; FindReplaceDialog findDlg; GoToLineDialog gotoDlg; @@ -195,11 +188,6 @@ private: toolTipCallback_t GetFunctionParms; toolTipCallback_t GetToolTip; - // run-time variables - //tom::ITextDocument* m_TextDoc; - //tom::ITextFont* m_DefaultFont; - - //CHARRANGE updateRange; bool updateSyntaxHighlighting; int stringColorIndex; int stringColorLine; @@ -222,15 +210,10 @@ private: private: void InitSyntaxHighlighting( void ); void SetCharType( int first, int last, int type ); - void SetDefaultFont( int startCharIndex, int endCharIndex ); - void SetColor( int startCharIndex, int endCharIndex, const idVec3 &foreColor, const idVec3 &backColor, bool bold ); void FreeKeyWordsFromFile( void ); int FindKeyWord( const char *keyWord, int length ) const; - void HighlightSyntax( int startCharIndex, int endCharIndex ); - void UpdateVisibleRange( void ); - bool GetNameBeforeCurrentSelection( idStr &name, int &charIndex ) const; bool GetNameForMousePosition( idStr &name ) const;