Exemplo n.º 1
0
/* TextEditor::onFRDKeyDown
 * Called when a key is pressed on the Find+Replace frame
 *******************************************************************/
void TextEditor::onFRDKeyDown(wxKeyEvent& e)
{
	// Esc (close)
	if (e.GetKeyCode() == WXK_ESCAPE)
		dlg_fr->Close();

	// Enter
	else if (e.GetKeyCode() == WXK_RETURN)
	{
		// Find Next
		if (dlg_fr->getTextFind()->HasFocus())
		{
			// Check find string
			string find = dlg_fr->getFindString();
			if (find.IsEmpty())
				return;

			// Set search options
			int flags = 0;
			if (dlg_fr->matchCase()) flags |= wxSTC_FIND_MATCHCASE;
			if (dlg_fr->matchWord()) flags |= wxSTC_FIND_WHOLEWORD;
			SetSearchFlags(flags);

			// Do find
			if (!findNext(find))
				wxLogMessage("No text matching \"%s\" found.", find);
		}

		// Replace
		else if (dlg_fr->getTextReplace()->HasFocus())
		{
			// Set search options
			int flags = 0;
			if (dlg_fr->matchCase()) flags |= wxSTC_FIND_MATCHCASE;
			if (dlg_fr->matchWord()) flags |= wxSTC_FIND_WHOLEWORD;
			SetSearchFlags(flags);

			// Do replace
			replaceCurrent(dlg_fr->getFindString(), dlg_fr->getReplaceString());
		}

		else
			e.Skip();
	}

	// Other
	else
		e.Skip();
}
Exemplo n.º 2
0
int TextEditorStc::Find(int flags, const char *text)
{
	findFlags = flags;
	findText = text;
	SetSearchFlags(flags);
	int wrap = 0;
	int start = edwnd->GetCurrentPos();
// wx doesn't provide find with the TextFind struct, which is
// needed to determine the amount of text matched. So, we
// send the message directly.
//	int found = edwnd->FindText(start, edwnd->GetLength() - 1, findText, sciFlags);
	Sci_TextToFind ttf;
	ttf.chrg.cpMin = start;
	ttf.chrg.cpMax = edwnd->GetLength() + 1;
	ttf.lpstrText = (char *)text;
	int found = edwnd->SendMsg(2150, sciFlags, (wxIntPtr) &ttf);
	if (found == -1 && start > 0)
	{
		//found = edwnd->FindText(0, start, findText, sciFlags);
		ttf.chrg.cpMin = 0;
		found = edwnd->SendMsg(2150, sciFlags, (wxIntPtr) &ttf);
		wrap = 1;
	}
	if (found >= 0)
	{
		edwnd->SetSelection(ttf.chrgText.cpMin, ttf.chrgText.cpMax);
		edwnd->SetAnchor(ttf.chrgText.cpMin);
		edwnd->SetCurrentPos(ttf.chrgText.cpMax);
		edwnd->EnsureCaretVisible();
		return wrap;
	}
	return -1;
}
Exemplo n.º 3
0
/* 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();
}
Exemplo n.º 4
0
/* TextEditor::onFRDBtnReplace
 * Called when the 'Replace' button on the Find+Replace frame is
 * clicked
 *******************************************************************/
void TextEditor::onFRDBtnReplace(wxCommandEvent& e)
{
	// Set search options
	int flags = 0;
	if (dlg_fr->matchCase()) flags |= wxSTC_FIND_MATCHCASE;
	if (dlg_fr->matchWord()) flags |= wxSTC_FIND_WHOLEWORD;
	SetSearchFlags(flags);

	// Do replace
	replaceCurrent(dlg_fr->getFindString(), dlg_fr->getReplaceString());
}
Exemplo n.º 5
0
/* TextEditor::onFRDBtnReplaceAll
 * Called when the 'Replace All' button on the Find+Replace frame is
 * clicked
 *******************************************************************/
void TextEditor::onFRDBtnReplaceAll(wxCommandEvent& e)
{
	// Set search options
	int flags = 0;
	if (dlg_fr->matchCase()) flags |= wxSTC_FIND_MATCHCASE;
	if (dlg_fr->matchWord()) flags |= wxSTC_FIND_WHOLEWORD;
	SetSearchFlags(flags);

	// Do replace all
	int replaced = replaceAll(dlg_fr->getFindString(), dlg_fr->getReplaceString());
	wxMessageBox(S_FMT("Replaced %d occurrences", replaced), "Replace All");
}
Exemplo n.º 6
0
/* TextEditor::onFRDBtnFindNext
 * Called when the 'Find Next' button on the Find+Replace frame is
 * clicked
 *******************************************************************/
void TextEditor::onFRDBtnFindNext(wxCommandEvent& e)
{
	// Check find string
	string find = dlg_fr->getFindString();
	if (find.IsEmpty())
		return;

	// Set search options
	int flags = 0;
	if (dlg_fr->matchCase()) flags |= wxSTC_FIND_MATCHCASE;
	if (dlg_fr->matchWord()) flags |= wxSTC_FIND_WHOLEWORD;
	SetSearchFlags(flags);

	// Do find
	if (!findNext(find))
		wxLogMessage("No text matching \"%s\" found.", find);
}
Exemplo n.º 7
0
int TextEditorStc::MatchSel(int flags, const char *text)
{
	SetSearchFlags(flags);
	int start = edwnd->GetSelectionStart();
	int end = edwnd->GetSelectionEnd();
	if (start == end)
		return 0;
//	int found = edwnd->FindText(start, end, wxString(text), sciFlags);
	Sci_TextToFind ttf;
	ttf.chrg.cpMin = start;
	ttf.chrg.cpMax = end;
	ttf.lpstrText = (char *)text;
	int found = edwnd->SendMsg(2150, sciFlags, (wxIntPtr) &ttf);
	if (found >= 0)
	{
		return start == ttf.chrg.cpMin && end == ttf.chrg.cpMax;
	}
	return 0;
}
Exemplo n.º 8
0
int TextEditorStc::ReplaceAll(int flags, const char *ftext, const char *rtext, SelectInfo& info)
{
	findFlags = flags;
	findText = ftext;
	int count = 0;
	SetSearchFlags(flags);
	edwnd->BeginUndoAction();
	SelectInfo si;
	si.startPos = info.startPos;
	si.endPos = info.endPos;
	if (si.startPos == si.endPos)
	{
		si.endPos = edwnd->GetLength();
		si.endLn = edwnd->LineFromPosition(si.endPos)+1;
		si.endCh = 0;
	}
	else
	{
		si.endLn = info.endLn;
		si.endCh = info.endCh;
	}

	wxString rt(rtext);
	wxString ft(ftext);

	do
	{
		edwnd->SetTargetStart(si.startPos);
		edwnd->SetTargetEnd(si.endPos);
		if (edwnd->SearchInTarget(ft) == -1)
			break;
		count++;
		if (flags & wxSTC_FIND_REGEXP)
			edwnd->ReplaceTargetRE(rt);
		else
			edwnd->ReplaceTarget(rt);
		si.startPos = edwnd->GetTargetEnd();
		si.endPos = edwnd->PositionFromLine(si.endLn) + si.endCh;
	} while (si.startPos <= si.endPos);
	edwnd->EndUndoAction();
	return count;
}