/* TextEditor::onCalltipClicked * Called when the current calltip is clicked on *******************************************************************/ void TextEditor::onCalltipClicked(wxStyledTextEvent& e) { // Can't do anything without function if (!ct_function) return; // Argset up if (e.GetPosition() == 1) { if (ct_argset > 0) { ct_argset--; updateCalltip(); } } // Argset down if (e.GetPosition() == 2) { if ((unsigned)ct_argset < ct_function->nArgSets() - 1) { ct_argset++; updateCalltip(); } } }
/* TextEditor::onCharAdded * Called when a character is added to the text *******************************************************************/ void TextEditor::onCharAdded(wxStyledTextEvent& e) { // Update line numbers margin width string numlines = S_FMT("0%d", txed_fold_debug ? 1234567 : GetNumberOfLines()); SetMarginWidth(0, TextWidth(wxSTC_STYLE_LINENUMBER, numlines)); // Auto indent int currentLine = GetCurrentLine(); if (txed_auto_indent && e.GetKey() == '\n') { // Get indentation amount int lineInd = 0; if (currentLine > 0) lineInd = GetLineIndentation(currentLine - 1); // Do auto-indent if needed if (lineInd != 0) { SetLineIndentation(currentLine, lineInd); // Skip to end of tabs while (1) { int chr = GetCharAt(GetCurrentPos()); if (chr == '\t' || chr == ' ') GotoPos(GetCurrentPos()+1); else break; } } } // The following require a language to work if (language) { // Call tip if (e.GetKey() == '(' && txed_calltips_parenthesis) openCalltip(GetCurrentPos(), 0); // End call tip if (e.GetKey() == ')' || e.GetKey() == WXK_BACK) updateCalltip(); // Comma, possibly update calltip if (e.GetKey() == ',' && txed_calltips_parenthesis) updateCalltip(); } // Continue e.Skip(); }
/* TextEditor::onUpdateUI * Called when anything is modified in the text editor (cursor * position, styling, text, etc) *******************************************************************/ void TextEditor::onUpdateUI(wxStyledTextEvent& e) { // Check for brace match if (txed_brace_match) checkBraceMatch(); // If a calltip is open, update it if (call_tip->IsShown()) updateCalltip(); // Do word matching if appropriate if (txed_match_cursor_word && language) { int word_start = WordStartPosition(GetCurrentPos(), true); int word_end = WordEndPosition(GetCurrentPos(), true); string current_word = GetTextRange(word_start, word_end); if (!current_word.IsEmpty() && HasFocus()) { if (current_word != prev_word_match) { prev_word_match = current_word; SetIndicatorCurrent(8); IndicatorClearRange(0, GetTextLength()); SetTargetStart(0); SetTargetEnd(GetTextLength()); SetSearchFlags(0); while (SearchInTarget(current_word) != -1) { IndicatorFillRange(GetTargetStart(), GetTargetEnd() - GetTargetStart()); SetTargetStart(GetTargetEnd()); SetTargetEnd(GetTextLength()); } } } else { SetIndicatorCurrent(8); IndicatorClearRange(0, GetTextLength()); prev_word_match = ""; } } // Hilight current line MarkerDeleteAll(1); MarkerDeleteAll(2); if (txed_hilight_current_line > 0 && HasFocus()) { int line = LineFromPosition(GetCurrentPos()); MarkerAdd(line, 1); if (txed_hilight_current_line > 1) MarkerAdd(line, 2); } e.Skip(); }
/* TextEditor::onUpdateUI * Called when anything is modified in the text editor (cursor * position, styling, text, etc) *******************************************************************/ void TextEditor::onUpdateUI(wxStyledTextEvent& e) { // Check for brace match if (txed_brace_match) checkBraceMatch(); // If a calltip is open, update it if (CallTipActive()) updateCalltip(); e.Skip(); }
/* TextEditor::onKeyDown * Called when a key is pressed *******************************************************************/ void TextEditor::onKeyDown(wxKeyEvent& e) { // Check if keypress matches any keybinds wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers())); // Go through matching binds bool handled = false; for (unsigned a = 0; a < binds.size(); a++) { string name = binds[a]; // Open/update calltip if (name == "ted_calltip") { updateCalltip(); handled = true; } // Autocomplete else if (name == "ted_autocomplete") { // Get word before cursor string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos()); // If a language is loaded, bring up autocompletion list if (language) { autocomp_list = language->getAutocompletionList(word); AutoCompShow(word.size(), autocomp_list); } handled = true; } // Find/replace else if (name == "ted_findreplace") { showFindReplaceDialog(); handled = true; } // Find next else if (name == "ted_findnext") { wxCommandEvent e; onFRDBtnFindNext(e); handled = true; } // Jump to else if (name == "ted_jumpto") { openJumpToDialog(); handled = true; } } #ifdef __WXMSW__ Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine())); #endif if (!handled) e.Skip(); }
/* TextEditor::onKeyDown * Called when a key is pressed *******************************************************************/ void TextEditor::onKeyDown(wxKeyEvent& e) { // Check if keypress matches any keybinds wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers())); // Go through matching binds bool handled = false; for (unsigned a = 0; a < binds.size(); a++) { string name = binds[a]; // Open/update calltip if (name == "ted_calltip") { updateCalltip(); handled = true; } // Autocomplete else if (name == "ted_autocomplete") { // Get word before cursor string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos()); // If a language is loaded, bring up autocompletion list if (language) { autocomp_list = language->getAutocompletionList(word); AutoCompShow(word.size(), autocomp_list); } handled = true; } // Find/replace else if (name == "ted_findreplace") { showFindReplaceDialog(); handled = true; } // Find next else if (name == "ted_findnext") { wxCommandEvent e; onFRDBtnFindNext(e); handled = true; } // Jump to else if (name == "ted_jumpto") { openJumpToDialog(); handled = true; } } #ifdef __WXMSW__ Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine())); #endif #ifdef __APPLE__ if (!handled) { const int keyCode = e.GetKeyCode(); const bool shiftDown = e.ShiftDown(); if (e.ControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { HomeExtend(); } else { Home(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { LineEndExtend(); } else { LineEnd(); } handled = true; } else if (WXK_UP == keyCode) { if (shiftDown) { DocumentStartExtend(); } else { DocumentStart(); } handled = true; } else if (WXK_DOWN == keyCode) { if (shiftDown) { DocumentEndExtend(); } else { DocumentEnd(); } handled = true; } } else if (e.RawControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { WordLeftExtend(); } else { WordLeft(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { WordRightExtend(); } else { WordRight(); } handled = true; } } } #endif // __APPLE__ if (!handled) e.Skip(); }
/* TextEditor::onKeyDown * Called when a key is pressed *******************************************************************/ void TextEditor::onKeyDown(wxKeyEvent& e) { // Check if keypress matches any keybinds wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers())); // Go through matching binds bool handled = false; for (unsigned a = 0; a < binds.size(); a++) { string name = binds[a]; // Open/update calltip if (name == "ted_calltip") { updateCalltip(); handled = true; } // Autocomplete else if (name == "ted_autocomplete") { // Get word before cursor string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos()); // If a language is loaded, bring up autocompletion list if (language) { autocomp_list = language->getAutocompletionList(word); AutoCompShow(word.size(), autocomp_list); } handled = true; } // Find/replace else if (name == "ted_findreplace") { showFindReplacePanel(); handled = true; } // Find next else if (name == "ted_findnext") { if (panel_fr && panel_fr->IsShown()) findNext(panel_fr->getFindText(), panel_fr->getFindFlags()); handled = true; } // Find previous else if (name == "ted_findprev") { if (panel_fr && panel_fr->IsShown()) findPrev(panel_fr->getFindText(), panel_fr->getFindFlags()); handled = true; } // Replace next else if (name == "ted_replacenext") { if (panel_fr && panel_fr->IsShown()) replaceCurrent(panel_fr->getFindText(), panel_fr->getReplaceText(), panel_fr->getFindFlags()); handled = true; } // Replace all else if (name == "ted_replaceall") { if (panel_fr && panel_fr->IsShown()) replaceAll(panel_fr->getFindText(), panel_fr->getReplaceText(), panel_fr->getFindFlags()); handled = true; } // Fold all else if (name == "ted_fold_foldall") { foldAll(true); handled = true; } // Unfold all else if (name == "ted_fold_unfoldall") { foldAll(false); handled = true; } // Jump to line else if (name == "ted_jumptoline") { jumpToLine(); handled = true; } } // Check for esc key if (!handled && e.GetKeyCode() == WXK_ESCAPE) { // Hide call tip if showing if (call_tip->IsShown()) call_tip->Show(false); // Hide F+R panel if showing else if (panel_fr && panel_fr->IsShown()) showFindReplacePanel(false); } // Check for up/down keys while calltip with multiple arg sets is open if (call_tip->IsShown() && ct_function && ct_function->nArgSets() > 1 && !ct_dwell) { if (e.GetKeyCode() == WXK_UP) { call_tip->prevArgSet(); handled = true; } else if (e.GetKeyCode() == WXK_DOWN) { call_tip->nextArgSet(); handled = true; } } #ifdef __WXMSW__ Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine())); #endif #ifdef __APPLE__ if (!handled) { const int keyCode = e.GetKeyCode(); const bool shiftDown = e.ShiftDown(); if (e.ControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { HomeExtend(); } else { Home(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { LineEndExtend(); } else { LineEnd(); } handled = true; } else if (WXK_UP == keyCode) { if (shiftDown) { DocumentStartExtend(); } else { DocumentStart(); } handled = true; } else if (WXK_DOWN == keyCode) { if (shiftDown) { DocumentEndExtend(); } else { DocumentEnd(); } handled = true; } } else if (e.RawControlDown()) { if (WXK_LEFT == keyCode) { if (shiftDown) { WordLeftExtend(); } else { WordLeft(); } handled = true; } else if (WXK_RIGHT == keyCode) { if (shiftDown) { WordRightExtend(); } else { WordRight(); } handled = true; } } } #endif // __APPLE__ if (!handled) e.Skip(); }