/* TextEditor::openCalltip * Opens a calltip for the function name before [pos]. Returns false * if the word before [pos] was not a function name, true otherwise *******************************************************************/ bool TextEditor::openCalltip(int pos, int arg) { // Don't bother if no language if (!language) return false; // Get start of word before bracket int start = WordStartPosition(pos - 1, false); // Get word before bracket string word = GetTextRange(WordStartPosition(start, true), WordEndPosition(start, true)); // Get matching language function (if any) TLFunction* func = language->getFunction(word); // Show calltip if it's a function if (func && func->nArgSets() > 0) { CallTipShow(pos, func->generateCallTipString()); ct_function = func; ct_argset = 0; ct_start = pos; // Highlight arg point2_t arg_ext = ct_function->getArgTextExtent(arg); CallTipSetHighlight(arg_ext.x, arg_ext.y); return true; } else { ct_function = NULL; return false; } }
/* TextEditor::showFindReplacePanel * Shows or hides the Find+Replace panel, depending on [show]. If * shown, fills the find text box with the current selection or the * current word at the caret *******************************************************************/ void TextEditor::showFindReplacePanel(bool show) { // Do nothing if no F+R panel has been set if (!panel_fr) return; // Hide if needed if (!show) { panel_fr->Hide(); panel_fr->GetParent()->Layout(); SetFocus(); return; } // Get currently selected text string find = GetSelectedText(); // Get the word at the current cursor position if there is no current selection if (find.IsEmpty()) { int ws = WordStartPosition(GetCurrentPos(), true); int we = WordEndPosition(GetCurrentPos(), true); find = GetTextRange(ws, we); } // Show the F+R panel panel_fr->Show(); panel_fr->GetParent()->Layout(); panel_fr->setFindText(find); }
/* TextEditor::onMouseDown * Called when a mouse button is clicked *******************************************************************/ void TextEditor::onMouseDown(wxMouseEvent& e) { e.Skip(); // No language, no checks if (!language) return; // Check for ctrl+left (web lookup) if (e.LeftDown() && e.GetModifiers() == wxMOD_CMD) { int pos = CharPositionFromPointClose(e.GetX(), e.GetY()); string word = GetTextRange(WordStartPosition(pos, true), WordEndPosition(pos, true)); if (!word.IsEmpty()) { // TODO: Reimplement for word lists //// Check for keyword //if (language->isKeyword(word)) //{ // string url = language->getKeywordLink(); // if (!url.IsEmpty()) // { // url.Replace("%s", word); // wxLaunchDefaultBrowser(url); // } //} //// Check for constant //else if (language->isConstant(word)) //{ // string url = language->getConstantLink(); // if (!url.IsEmpty()) // { // url.Replace("%s", word); // wxLaunchDefaultBrowser(url); // } //} // Check for function if (language->isFunction(word)) { string url = language->getFunctionLink(); if (!url.IsEmpty()) { url.Replace("%s", word); wxLaunchDefaultBrowser(url); } } hideCalltip(); } } if (e.RightDown() || e.LeftDown()) hideCalltip(); }
bool SearchableEditor::find(bool newSearch) { if (!fd) fd = new FindDialog(this, ::wxGetTopLevelParent(this)); if (newSearch || findTextM.empty()) { if (newSearch) { // find selected text wxString findText(GetSelectedText()); // failing that initialize with the word at the caret if (findText.empty()) { int pos = GetCurrentPos(); int start = WordStartPosition(pos, true); int end = WordEndPosition(pos, true); if (end > start) findText = GetTextRange(start, end); } fd->SetFindText(findText); } // do not re-center dialog if it is already visible if (!fd->IsShown()) fd->Show(); fd->SetFocus(); return false; // <- caller shouldn't care about this } int start = GetSelectionEnd(); if (findFlagsM.has(se::FROM_TOP)) { start = 0; findFlagsM.remove(se::ALERT); // remove flag after first find } int end = GetTextLength(); int p = FindText(start, end, findTextM, findFlagsM.asStc()); if (p == -1) { if (findFlagsM.has(se::WRAP)) p = FindText(0, end, findTextM, findFlagsM.asStc()); if (p == -1) { if (findFlagsM.has(se::ALERT)) wxMessageBox(_("No more matches"), _("Search complete"), wxICON_INFORMATION|wxOK); return false; } } centerCaret(true); GotoPos(p); GotoPos(p + findTextM.Length()); SetSelectionStart(p); SetSelectionEnd(p + findTextM.Length()); centerCaret(false); return true; }
/* 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::openCalltip * Opens a calltip for the function name before [pos]. Returns false * if the word before [pos] was not a function name, true otherwise *******************************************************************/ bool TextEditor::openCalltip(int pos, int arg, bool dwell) { // Don't bother if no language if (!language) return false; // Get start of word before bracket int start = WordStartPosition(pos - 1, false); int end = WordEndPosition(pos - 1, true); // Get word before bracket string word = GetTextRange(WordStartPosition(start, true), WordEndPosition(start, true)); // Get matching language function (if any) TLFunction* func = language->getFunction(word); // Show calltip if it's a function if (func && func->nArgSets() > 0) { call_tip->enableArgSwitch(!dwell && func->nArgSets() > 1); call_tip->openFunction(func, arg); showCalltip(dwell ? pos : end + 1); ct_function = func; ct_start = pos; ct_dwell = dwell; // Highlight arg call_tip->setCurrentArg(arg); return true; } else { ct_function = nullptr; return false; } }
/** * CHaracter added */ void FbEditor::onCharAdded(wxStyledTextEvent & event) { int p = GetCurrentPos(); auto w = GetTextRange(WordStartPosition(p, true), p); if (w.length() < 2) return; w.UpperCase(); wxString words = ""; int count = 0; for (auto id : m_srcCtx->getIdentifiers(LineFromPosition(p), p - LineFromPosition(p))) { wxString ID(id); ID.UpperCase(); if (ID.compare(0, w.length(), w) == 0) { if (ID.length() == w.length()) continue; words += id + " "; count++; } } if (count > 0) { AutoCompShow((int)w.Length(), words); } }
/* 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(); }