Exemple #1
0
void CodeEdit::CommentSelection(const wxString& comment)
{


    if (GetSelectionStart() < GetSelectionEnd())
    {
  
        int startLine = LineFromPosition(GetSelectionStart());
        int endLine   = LineFromPosition(GetSelectionEnd());

        // Find the minimum indentation level for all of the selected lines.

        int minIndentation = INT_MAX;

        for (int i = startLine; i <= endLine; ++i)
        {
            
            wxString lineText = GetLine(i);
            int firstNonWhitespace = GetFirstNonWhitespace(lineText);

            if (firstNonWhitespace != -1)
            {
                minIndentation = wxMin(firstNonWhitespace, minIndentation);
            }

        }

        // Insert the comment string on each non-blank line.

        wxString result;

        for (int i = startLine; i <= endLine; ++i)
        {

            wxString lineText = GetLine(i);

            if (GetFirstNonWhitespace(lineText) != -1)
            {
                lineText.insert(minIndentation, comment);
            }

            result += lineText;

        }

        SetTargetStart(PositionFromLine(startLine));
        SetTargetEnd(PositionFromLine(endLine + 1));

        ReplaceTarget(result);

        // Select the replaced text.
        SetSelectionStart(GetTargetStart());
        SetSelectionEnd(GetTargetEnd() - 1);
    
    }

}
/**
 * Move the selection end to the buffer offset physically above
 * the current selection end.
 */
Boolean Selection::ExtendUp(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout)
{
    Int32 end = GetSelectionEnd(text);
    Int32 line;
    layout->GetLineForOffset(end, &line);

    if (line > 0) {
        Int32 move;
        Int32 direction1, direction2;
        layout->GetParagraphDirection(line, &direction1);
        layout->GetParagraphDirection(line - 1, &direction2);
        if (direction1 == direction2) {
            Float h;
            layout->GetPrimaryHorizontal(end, &h);
            layout->GetOffsetForHorizontal(line - 1, h, &move);
        }
        else {
            layout->GetLineStart(line - 1, &move);
        }

        ExtendSelection(text, move);
        return TRUE;
    }
    else if (end != 0) {
        ExtendSelection(text, 0);
        return TRUE;
    }

    return TRUE;
}
Exemple #3
0
/* TextEditor::findNext
 * Finds the next occurrence of the [find] after the caret position,
 * selects it and scrolls to it if needed. Returns false if the
 * [find] was invalid or no match was found, true otherwise
 *******************************************************************/
bool TextEditor::findNext(string find)
{
	// Check search string
	if (find.IsEmpty())
		return false;

	// Setup target range
	SetTargetEnd(GetTextLength());
	SetTargetStart(GetSelectionEnd());

	// Search within current target range
	if (SearchInTarget(find) < 0)
	{
		// None found, search again from start
		SetTargetStart(0);
		SetTargetEnd(GetTextLength());
		if (SearchInTarget(find) < 0)
		{
			// No matches found in entire text
			return false;
		}
	}

	// Select matched text
	SetSelection(GetTargetStart(), GetTargetEnd());

	// Scroll to selection
	EnsureCaretVisible();

	return true;
}
Exemple #4
0
/* TextEditor::replaceCurrent
 * Replaces the currently selected occurrence of [find] with
 * [replace], then selects and scrolls to the next occurrence of
 * [find] in the text. Returns false if [find] is invalid or the
 * current selection does not match it, true otherwise
 *******************************************************************/
bool TextEditor::replaceCurrent(string find, string replace)
{
	// Check search string
	if (find.IsEmpty())
		return false;

	// Check that we've done a find previously
	// (by searching for the find string within the current selection)
	if (GetSelectedText().Length() != find.Length())
		return false;
	SetTargetStart(GetSelectionStart());
	SetTargetEnd(GetSelectionEnd());
	if (SearchInTarget(find) < 0)
		return false;

	// Do the replace
	ReplaceTarget(replace);

	// Update selection
	SetSelection(GetTargetStart(), GetTargetEnd());

	// Do find next
	findNext(find);

	return true;
}
Exemple #5
0
void Edit::ReplaceText(const wxString &find_string)
{
  int found_start, found_end;
  const int select_start = GetSelectionStart();
  const int select_end = GetSelectionEnd();

  // replace & search
  if (select_start > -1 && select_end > select_start) {
    const wxString select_string = GetSelectedText();
    if (select_string == find_string) {
      ReplaceSelection(m_FindData.GetReplaceString());
      // search
      if (FindText(found_start, found_end, false)) {
        SetSelection(found_start, found_end);
      }
      else {
        wxMessageDialog dialog(this, wxT("Cannot find the text \"" + find_string + "\" from current position"), wxT("Find"));
        dialog.ShowModal();
      }
    }
  }
  // search
  else if (FindText(found_start, found_end, false)) {
    SetSelection(found_start, found_end);
  }
}
Int32 Selection::FindEdge(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout,
    /* [in] */ Int32 dir)
{
    Int32 pt = GetSelectionEnd(text);
    Int32 line;
    layout->GetLineForOffset(pt, &line);
    Int32 pdir;
    layout->GetParagraphDirection(line, &pdir);

    if (dir * pdir < 0) {
        Int32 start;
        layout->GetLineStart(line, &start);
        return start;
    }
    else {
        Int32 end;
        layout->GetLineEnd(line, &end);
        Int32 lineCount;
        layout->GetLineCount(&lineCount);
        if (line == lineCount - 1)
            return end;
        else
            return end - 1;
    }
}
Exemple #7
0
void fbtTextFile::cutEvent(wxCommandEvent& evt)
{
	if (GetReadOnly()  || GetSelectionEnd() - GetSelectionStart() <= 0)
		return;
	Cut();

}
/**
 * Move the selection end to the buffer offset physically below
 * the current selection end.
 */
Boolean Selection::ExtendDown(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout)
{
    Int32 end = GetSelectionEnd(text);
    Int32 line;
    layout->GetLineForOffset(end, &line);
    Int32 len;
    Int32 lineCount;
    layout->GetLineCount(&lineCount);
    if (line < lineCount - 1) {
        Int32 move;
        Int32 direction1, direction2;
        layout->GetParagraphDirection(line, &direction1);
        layout->GetParagraphDirection(line + 1, &direction2);
        if (direction1 == direction2) {
            Float h;
            layout->GetPrimaryHorizontal(end, &h);
            layout->GetOffsetForHorizontal(line + 1, h, &move);
        }
        else {
            layout->GetLineStart(line + 1, &move);
        }

        ExtendSelection(text, move);
        return TRUE;
    }
    else if (end != (text->GetLength(&len), len)) {
        ExtendSelection(text, len);
        return TRUE;
    }

    return TRUE;
}
Exemple #9
0
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;
}
NS_IMETHODIMP
HTMLTextAreaElement::GetSelectionEnd(int32_t *aSelectionEnd)
{
  NS_ENSURE_ARG_POINTER(aSelectionEnd);

  ErrorResult error;
  *aSelectionEnd = GetSelectionEnd(error);
  return error.ErrorCode();
}
Exemple #11
0
int SearchableEditor::replaceInSelection()
{
    findFlagsM.remove(se::FROM_TOP);    // turn flag off
    bool alert = findFlagsM.has(se::ALERT);
    if (alert)
        findFlagsM.remove(se::ALERT);    // turn flag off temporary
    bool wrap = findFlagsM.has(se::WRAP);
    if (wrap)
        findFlagsM.remove(se::WRAP);        // turn it off to prevent endless loop (if replace text contains search text)

    int cnt = 0;
    int selstart = GetSelectionStart();
    int selend = GetSelectionEnd();
    SetSelectionEnd(selstart);    // start replace from here
    while (find(false))
    {
        int start = GetSelectionStart();
        int end =   GetSelectionEnd();
        if (end <= selend)        // in range
        {
            selend += replaceTextM.Length() - (end-start);        // expand/contract range
            ReplaceSelection(replaceTextM);
            SetSelectionEnd(start + replaceTextM.Length());        // move to appropriate position for next find()
            cnt++;
        }
        else
            break;
    }

    if (alert)
    {
        wxMessageBox(wxString::Format(_("%d replacements were made."), cnt), _("Replace"), wxICON_INFORMATION|wxOK);
        findFlagsM.add(se::ALERT);        // turn it back on
    }
    if (wrap)                                // turn it back on
        findFlagsM.add(se::WRAP);
    SetSelectionStart(selstart);
    SetSelectionEnd(selend);
    return cnt;
}
Exemple #12
0
void CodeEdit::UncommentSelection(const wxString& commentString)
{

    if (GetSelectionStart() < GetSelectionEnd())
    {

        int startLine = LineFromPosition(GetSelectionStart());
        int endLine   = LineFromPosition(GetSelectionEnd());

        wxString result;
        
        for (int i = startLine; i <= endLine; ++i)
        {

            wxString lineText = GetLine(i);

            unsigned int c = GetFirstNonWhitespace(lineText);

            if (c != -1 && lineText.compare(c, commentString.Length(), commentString) == 0)
            {
                lineText.erase(c, commentString.Length());
            }

            result += lineText;

        }

        SetTargetStart(PositionFromLine(startLine));
        SetTargetEnd(PositionFromLine(endLine + 1));

        ReplaceTarget(result);

        // Select the replaced text.
        SetSelectionStart(GetTargetStart());
        SetSelectionEnd(GetTargetEnd() - 1);

    }

}
boost::python::tuple ScintillaWrapper::getUserCharSelection()
{
	int start = GetSelectionStart();
	int end   = GetSelectionEnd();

	if (start == end)
	{
		start = 0;
		end = GetLength();
	}

	return boost::python::make_tuple(start, end);

}
NS_IMETHODIMP
HTMLTextAreaElement::GetSelectionEnd(int32_t *aSelectionEnd)
{
  NS_ENSURE_ARG_POINTER(aSelectionEnd);

  ErrorResult error;
  Nullable<uint32_t> selEnd(GetSelectionEnd(error));
  if (error.Failed()) {
    return error.StealNSResult();
  }

  *aSelectionEnd = int32_t(selEnd.Value());
  return NS_OK;
}
Exemple #15
0
/////////////////////////////////////
// @mfunc Get selected string
// @rvalue CString | string with currentliy selected text
//
CString CScintillaWnd::GetSelectedText(void) {
    long lLen = (GetSelectionEnd() - GetSelectionStart()) + 1;
    if (lLen > 0) {
        TCHAR *p = new TCHAR[lLen+1];
        if (p != NULL) {
            *p = '\0';
            SendMessage(SCI_GETSELTEXT, 0, (ULONG_PTR)p);
            CString strReturn = p;
            delete [] p;
            return strReturn;
        }
    }
    return _T("");
}
/**
 * Move the selection end to the buffer offset physically to the right of
 * the current selection end.
 */
Boolean Selection::ExtendRight(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout)
{
    Int32 end = GetSelectionEnd(text);
    Int32 to;
    layout->GetOffsetToRightOf(end, &to);

    if (to != end) {
        ExtendSelection(text, to);
        return TRUE;
    }

    return TRUE;
}
/**
 * Set the selection anchor to <code>start</code> and the selection edge
 * to <code>stop</code>.
 */
void Selection::SetSelection(
    /* [in] */ ISpannable* text,
    /* [in] */ Int32 start,
    /* [in] */ Int32 stop)
{
    Int32 ostart = GetSelectionStart(text);
    Int32 oend = GetSelectionEnd(text);

    if (ostart != start || oend != stop) {
        text->SetSpan(
            SELECTION_START, start, start,
            ISpanned::SPAN_POINT_POINT | ISpanned::SPAN_INTERMEDIATE);
        text->SetSpan(
            SELECTION_END, stop, stop, ISpanned::SPAN_POINT_POINT);
    }
}
/**
 * Move the cursor to the buffer offset physically below the current
 * offset, or return FALSE if the cursor is already on the bottom line.
 */
Boolean Selection::MoveDown(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout)
{
    Int32 start = GetSelectionStart(text);
    Int32 end = GetSelectionEnd(text);

    if (start != end) {
        Int32 min = Elastos::Core::Math::Min(start, end);
        Int32 max = Elastos::Core::Math::Max(start, end);

        SetSelection(text, max);

        Int32 len;
        if (min == 0 && max == (text->GetLength(&len), len)) {
            return FALSE;
        }

        return TRUE;
    }
    else {
        Int32 line;
        layout->GetLineForOffset(end, &line);

        Int32 lineCount;
        layout->GetLineCount(&lineCount);
        if (line < lineCount - 1) {
            Int32 move;
            Int32 direction1, direction2;
            layout->GetParagraphDirection(line, &direction1);
            layout->GetParagraphDirection(line + 1, &direction2);
            if (direction1 ==direction2) {
                Float h;
                layout->GetPrimaryHorizontal(end, &h);
                layout->GetOffsetForHorizontal(line + 1, h, &move);
            }
            else {
                layout->GetLineStart(line + 1, &move);
            }

            SetSelection(text, move);
            return TRUE;
        }
    }

    return FALSE;
}
boost::python::tuple ScintillaWrapper::getUserLineSelection()
{
	int start = GetSelectionStart();
	int end   = GetSelectionEnd();
	if (start == end)
	{
		start = 0;
		end = GetLineCount() - 1;
	}
	else
	{
		start = LineFromPosition(start);
		end   = LineFromPosition(end);
	}

	return boost::python::make_tuple(start, end);
}
Exemple #20
0
    void StyledTextBox::RemoveSelectedText() {
        if (!HasSelectedText()) {
            return;
        }

        auto text = GetStdText();
        auto eraseStart = begin(text) + GetSelectionStart();
        auto eraseEnd = eraseStart + (GetSelectionEnd() - GetSelectionStart());

        text.erase(eraseStart, eraseEnd);

        SetCursorPosition(GetSelectionStart());

        SetText(text);

        ClearSelection();
    }
Exemple #21
0
bool wxSTEditorShell::CheckReadOnly(bool set)
{
    bool make_ro = !CaretOnPromptLine(STE_CARET_MOVE_NONE);

    if (!make_ro)
    {
        // also check selection and make ro so they can't cut text not on last line
        int prompt_line = GetPromptLine();
        make_ro |= ((LineFromPosition(GetSelectionStart()) < prompt_line) ||
                    (LineFromPosition(GetSelectionEnd())   < prompt_line));
    }

    if (set && (make_ro != GetReadOnly()))
        SetReadOnly(make_ro);

    return make_ro;
}
Exemple #22
0
void Edit::OnFindReplace(wxCommandEvent &event) {
  const wxString find_string = m_FindData.GetFindString();
  int found_start, found_end;

  if (event.GetId() == myID_FINDNEXT) {
    // search
    if (FindText(found_start, found_end, true)) {
      SetSelection(found_start, found_end);
    }
    else {
      wxMessageDialog dialog(this, wxT("Cannot find the text \"" + find_string + "\" from current position"), wxT("Find"));
      dialog.ShowModal();
    }
  }
  if (event.GetId() == myID_REPLACENEXT) {
    ReplaceText(find_string);
  }
  else {
    if (m_findReplace) {
      delete m_findReplace;
      m_findReplace = NULL;
    }

    const int select_start = GetSelectionStart();
    const int select_end = GetSelectionEnd();
    wxString find_text;
    if (select_start > -1 && select_end > select_start) {
      find_text = GetSelectedText();
    }

    if (event.GetId() == myID_DLG_FIND_TEXT) {
      if (find_text.size() > 0) {
        m_FindData.SetFindString(find_text);
      }
      m_findReplace = new wxFindReplaceDialog(this, &m_FindData, wxT("Find"));
    }
    else {
      if (find_text.size() > 0) {
        m_FindData.SetFindString(find_text);
      }
      m_findReplace = new wxFindReplaceDialog(this, &m_FindData, wxT("Find & Replace"), wxFR_REPLACEDIALOG);
    }
    m_findReplace->Show();
  }
}
/** {@hide} */
Boolean Selection::MoveToFollowing(
    /* [in] */ ISpannable* text,
    /* [in] */ ISelectionPositionIterator* iter,
    /* [in] */ Boolean extendSelection)
{
    assert(iter != NULL);

    Int32 offset;
    iter->Following(GetSelectionEnd(text), &offset);
//    if (offset != ISelectionPositionIterator::DONE) {
        if (extendSelection) {
            ExtendSelection(text, offset);
        } else {
            SetSelection(text, offset);
        }
//    }
    return TRUE;
}
Exemple #24
0
bool CodeEdit::GetHoverText(int position, wxString& result)
{

    int selectionStart = GetSelectionStart();
    int selectionEnd   = GetSelectionEnd();

    if (position >= selectionStart && position < selectionEnd)
    {
        // We're mousing over the selected text.
        result = GetSelectedText();
        return true;
    }

    // We don't use the : character as a joiner since we don't
    // want to evaulate with that.
    return GetTokenFromPosition(position, ".", result);
    
}
Exemple #25
0
bool SearchableEditor::replace(bool force)
{
    int start = GetSelectionStart();
    int end = GetSelectionEnd();
    if (start == end || FindText(start, end, findTextM, findFlagsM.asStc()) == -1)
    {
        if (!find(false))
            return false;
        if (!force)
            return false;
    }

    // we have selection here
    start = GetSelectionStart();
    ReplaceSelection(replaceTextM);
    SetSelectionEnd(start + replaceTextM.Length());        // position at end of replaced text
    find(false);
    return true;
}
/**
 * Move the cursor to the buffer offset physically to the right of
 * the current offset, or return FALSE if the cursor is already at
 * at the right edge of the line and there is not another line
 * to move it to.
 */
Boolean Selection::MoveRight(
    /* [in] */ ISpannable* text,
    /* [in] */ ILayout* layout)
{
    Int32 start = GetSelectionStart(text);
    Int32 end = GetSelectionEnd(text);

    if (start != end) {
        SetSelection(text, ChooseHorizontal(layout, 1, start, end));
        return TRUE;
    }
    else {
        Int32 to;
        layout->GetOffsetToRightOf(end, &to);
        if (to != end) {
            SetSelection(text, to);
            return TRUE;
        }
    }

    return FALSE;
}
Exemple #27
0
/* TextEditor::findPrev
 * Finds the previous occurrence of the [find] after the caret
 * position, selects it and scrolls to it if needed. Returns false
 * if the [find] was invalid or no match was found, true otherwise
 *******************************************************************/
bool TextEditor::findPrev(string find, int flags)
{
	// Check search string
	if (find.IsEmpty())
		return false;

	// Get current selection
	int sel_start = GetSelectionStart();
	int sel_end = GetSelectionEnd();

	// Search back from the start of the current selection
	SetSelection(sel_start, sel_start);
	SearchAnchor();
	int found = SearchPrev(flags, find);
	if (found < 0)
	{
		// Not found, loop back to end
		SetSelection(GetTextLength() - 1, GetTextLength() - 1);
		SearchAnchor();
		found = SearchPrev(flags, find);
		if (found < 0)
		{
			// No match found in entire text, reset selection
			SetSelection(sel_start, sel_end);
			return false;
		}
	}

	// Set caret to the end of the matching text
	// (it defaults to the start for some dumb reason)
	// and scroll to the selection
	SetSelection(found, found + find.length());
	EnsureCaretVisible();

	return true;
}
void DisassemblyTextCtrl::OnGPM(wxMouseEvent& event)
{
    if(platform::gtk == false) // only if GPM is not already implemented by the OS
    {
        int pos = PositionFromPoint(wxPoint(event.GetX(), event.GetY()));

        if(pos == wxSCI_INVALID_POSITION)
            return;

        int start = GetSelectionStart();
        int end = GetSelectionEnd();

        const wxString s = GetSelectedText();

        if(pos < GetCurrentPos())
        {
            start += s.length();
            end += s.length();
        }

        InsertText(pos, s);
        SetSelectionVoid(start, end);
    }
} // end of OnGPM
Exemple #29
0
void Edit::OnEditCopy (wxCommandEvent &WXUNUSED(event)) {
    if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
    Copy ();
}
Exemple #30
0
void Edit::OnEditCut (wxCommandEvent &WXUNUSED(event)) {
    if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
    Cut ();
}