Esempio n. 1
0
void StyledTextCtrl::OnAutoComplete(wxStyledTextEvent& event)
{

    if (!AutoCompActive())
    {
        AutoCompShow(1, *autoCompWords);
    }
    //AutoCompStops(functionKeywords);
}
Esempio n. 2
0
void ctlSQLBox::OnAutoComplete(wxCommandEvent &rev)
{
	if (GetReadOnly())
		return;
	if (m_database == NULL)
		return;
	if (m_autocompDisabled)
		return;

	wxString what = GetCurLine().Left(GetCurrentPos() - PositionFromLine(GetCurrentLine()));;
	int spaceidx = what.Find(' ', true);

	char *tab_ret;
	if (spaceidx == -1)
		tab_ret = tab_complete(what.mb_str(wxConvUTF8), 0, what.Len() + 1, m_database);
	else
		tab_ret = tab_complete(what.mb_str(wxConvUTF8), spaceidx + 1, what.Len() + 1, m_database);

	if (tab_ret == NULL || tab_ret[0] == '\0')
		return; /* No autocomplete available for this string */

	wxString wxRet = wxString(tab_ret, wxConvUTF8);
	free(tab_ret);

	// Switch to the generic list control. Native doesn't play well with
	// autocomplete on Mac.
#ifdef __WXMAC__
	wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), true);
#endif

	if (spaceidx == -1)
		AutoCompShow(what.Len(), wxRet);
	else
		AutoCompShow(what.Len() - spaceidx - 1, wxRet);

	// Now switch back
#ifdef __WXMAC__
	wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), false);
#endif
}
Esempio n. 3
0
/**
 * 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);
    }
}
Esempio n. 4
0
/* 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();
}
Esempio n. 5
0
/* 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();
}
Esempio n. 6
0
/* 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();
}
Esempio n. 7
0
void CodeEdit::StartAutoCompletion(const wxString& token)
{

    wxASSERT(m_autoCompleteManager != NULL);

    wxString items;

    // Get the actual prefix of the thing we're trying to match for autocompletion.
    // If the token refers to a member, the prefix is the member name.

    wxString prefix;
    wxString newToken;
    bool member = false;
    bool function = false;

    if (GetLexer() == wxSTC_LEX_LUA)
    {

        int end1 = token.Find('.', true);

        if (end1 == wxNOT_FOUND)
        {
            end1 = 0;
        }
        else
        {
            // Skip the '.' character.
            ++end1;
            member = true;
        }

        int end2 = token.Find(':', true);

        if (end2 == wxNOT_FOUND)
        {
            end2 = 0;
        }
        else
        {
            // Skip the ':' character.
            ++end2;
            member = true;
        }

        int end = std::max(end1, end2);
        newToken = token.Right(token.Length() - end);
        prefix = token.Left(end - 1);

        if (end != 0 && token[end - 1] == ':')
          function = true;
    }
    else
    {
        // No autocompletion when using the default lexer.
        return;
    }

    if (!member && newToken.Length() < m_minAutoCompleteLength)
    {
        // Don't pop up the auto completion if the user hasn't typed in very
        // much yet.
        return;
    }

    wxVector<wxString> prefixes;

    m_autoCompleteManager->ParsePrefix(prefix, file, GetCurrentLine(), prefixes);
    m_autoCompleteManager->GetMatchingItems(newToken, prefixes, member, function, items);

    if (!AutoCompActive() || m_autoCompleteItems != items)
    {

        // Remember the items in the list so that we don't redisplay the list
        // with the same set of items (reduces flickering).
        m_autoCompleteItems = items;

        if (!items.IsEmpty())
        {
            // Show the autocomplete selection list.
          AutoCompShow(newToken.Length(), items);
        }
        else
        {
            // We have no matching items, so hide the autocompletion selection.
            AutoCompCancel();
        }

    }

}