Exemple #1
0
/* 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", 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());
		}

		// End call tip
		if (e.GetKey() == ')')
		{
			CallTipCancel();
		}

		// Comma, possibly update calltip
		if (e.GetKey() == ',' && txed_calltips_parenthesis)
		{
			//openCalltip(GetCurrentPos());
			//if (CallTipActive())
			updateCalltip();
		}
	}

	// Continue
	e.Skip();
}
Exemple #2
0
/* TextEditor::onMouseDwellStart
 * Called when the mouse pointer has 'dwelt' in one position for a
 * certain amount of time
 *******************************************************************/
void TextEditor::onMouseDwellStart(wxStyledTextEvent& e)
{
	if (wxTheApp->IsActive() && HasFocus() && !call_tip->IsShown() && txed_calltips_mouse && e.GetPosition() >= 0)
	{
		openCalltip(e.GetPosition(), -1, true);
		ct_dwell = true;
	}
}
Exemple #3
0
/* TextEditor::onMouseDwellStart
 * Called when the mouse pointer has 'dwelt' in one position for a
 * certain amount of time
 *******************************************************************/
void TextEditor::onMouseDwellStart(wxStyledTextEvent& e)
{
	if (!CallTipActive() && txed_calltips_mouse)
		openCalltip(e.GetPosition(), -1);
}
Exemple #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);
	}
}
Exemple #5
0
/* TextEditor::onMouseDwellStart
 * Called when the mouse pointer has 'dwelt' in one position for a
 * certain amount of time
 *******************************************************************/
void TextEditor::onMouseDwellStart(wxStyledTextEvent& e)
{
	if (wxTheApp->IsActive() && HasFocus() && !CallTipActive() && txed_calltips_mouse && e.GetPosition() >= 0)
		openCalltip(e.GetPosition(), -1);
}
Exemple #6
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 (!call_tip->IsShown())
	{
		// 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, 0))
					return;
				else
					break;
			}

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

	if (ct_function)
	{
		// Hide calltip if we've gone before the start of the function
		if (GetCurrentPos() < ct_start)
		{
			hideCalltip();
			ct_function = nullptr;
			return;
		}

		// 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 == ')')
			{
				hideCalltip();
				ct_function = nullptr;
				return;
			}

			// Go to next character
			pos++;
		}

		// Update calltip string with the selected arg set and the current arg highlighted
		call_tip->setCurrentArg(arg);
	}
}