コード例 #1
0
ファイル: TextEditor.cpp プロジェクト: macressler/SLADE
/* 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;
	}
}
コード例 #2
0
ファイル: TextEditor.cpp プロジェクト: Gaerzi/SLADE
/* 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);
}
コード例 #3
0
ファイル: TextEditor.cpp プロジェクト: Gaerzi/SLADE
/* 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();
}
コード例 #4
0
ファイル: FindDialog.cpp プロジェクト: DragonZX/flamerobin
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;
}
コード例 #5
0
ファイル: TextEditor.cpp プロジェクト: Gaerzi/SLADE
/* 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();
}
コード例 #6
0
ファイル: TextEditor.cpp プロジェクト: Gaerzi/SLADE
/* 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;
	}
}