Beispiel #1
0
/* 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;
	}
}
void MaterialScriptEditor::OnCharAdded(wxScintillaEvent &event)
{
    ScintillaEditor::OnCharAdded(event);

    char ch = event.GetKey();
    if(getCallTipManager().isTrigger(ch))
    {
        int lineNum = GetCurrentLine();
        if(lineNum != -1)
        {
            wxString line = GetLine(lineNum);
            int pos = GetCurrentPos() - 1;

            wxString word("");
            wxChar ch;
            while(pos)
            {
                ch = GetCharAt(--pos);
                if(ch != ' ' && ch != '\n' && ch != '\r' && ch != '\t' && ch != '{' && ch != '}') word.Prepend(ch);
                else break;
            }

            wxString* tips = getCallTipManager().find(word);
            if(tips != NULL)
            {
                CallTipShow(pos, *tips);
            }
        }
    }
}
Beispiel #3
0
void Edit::OnKeyDown (wxKeyEvent &event)
{
    if (CallTipActive())
        CallTipCancel();
    if (event.GetKeyCode() == WXK_SPACE && event.ControlDown() && event.ShiftDown())
    {
        int pos = GetCurrentPos();
        CallTipSetBackground(*wxYELLOW);
        CallTipShow(pos,
                    "This is a CallTip with multiple lines.\n"
                    "It is meant to be a context sensitive popup helper for the user.");
        return;
    }
    event.Skip();
}
Beispiel #4
0
/* TextEditor::updateCalltip
 * Updates the current calltip, or attempts to open one if none is
 * currently showing
 *******************************************************************/
void TextEditor::updateCalltip()
{
	// Don't bother if no language
	if (!language)
		return;

	if (!CallTipActive())
	{
		// No calltip currently showing, check if we're in a function
		int pos = GetCurrentPos() - 1;
		while (pos >= 0)
		{
			// Get character
			int chr = GetCharAt(pos);

			// If we find a closing bracket, skip to matching brace
			if (chr == ')')
			{
				while (pos >= 0 && chr != '(')
				{
					pos--;
					chr = GetCharAt(pos);
				}
				pos--;
				continue;
			}

			// If we find an opening bracket, try to open a calltip
			if (chr == '(')
			{
				if (!openCalltip(pos))
					return;
				else
					break;
			}

			// Go to previous character
			pos--;
		}
	}

	if (ct_function)
	{
		// Calltip currently showing, determine what arg we're at
		int pos = ct_start+1;
		int arg = 0;
		while (pos < GetCurrentPos() && pos < GetTextLength())
		{
			// Get character
			int chr = GetCharAt(pos);

			// If it's an opening brace, skip until closing (ie skip a function as an arg)
			if (chr == '(')
			{
				while (chr != ')')
				{
					// Exit if we get to the current position or the end of the text
					if (pos == GetCurrentPos() || pos == GetTextLength()-1)
						break;

					// Get next character
					pos++;
					chr = GetCharAt(pos);
				}

				pos++;
				continue;
			}

			// If it's a comma, increment arg
			if (chr == ',')
				arg++;

			// If it's a closing brace, we're outside the function, so cancel the calltip
			if (chr == ')')
			{
				CallTipCancel();
				ct_function = NULL;
				return;
			}

			// Go to next character
			pos++;
		}

		// Update calltip string with the selected arg set and the current arg highlighted
		CallTipShow(ct_start, ct_function->generateCallTipString(ct_argset));
		point2_t arg_ext = ct_function->getArgTextExtent(arg, ct_argset);
		CallTipSetHighlight(arg_ext.x, arg_ext.y);
	}
}