예제 #1
0
파일: ex.cpp 프로젝트: Emmavw/wxExtension
bool wxExEx::Move(
  const wxString& begin_address, 
  const wxString& end_address, 
  const wxString& destination)
{
  if (m_STC->GetReadOnly())
  {
    return false;
  }

  const int dest_line = ToLineNumber(destination);

  if (dest_line == 0)
  {
    return false;
  }

  if (!SetSelection(begin_address, end_address))
  {
    return false;
  }

  if (begin_address.StartsWith("'"))
  {
    if (begin_address.size() > 1)
    {
      MarkerDelete(begin_address.GetChar(1));
    }
  }

  if (end_address.StartsWith("'"))
  {
    if (end_address.size() > 1)
    {
      MarkerDelete(end_address.GetChar(1));
    }
  }

  m_STC->BeginUndoAction();

  m_STC->Cut();
  m_STC->GotoLine(dest_line - 1);
  m_STC->Paste();

  m_STC->EndUndoAction();
  
  const int lines = wxExGetNumberOfLines(m_STC->GetSelectedText());
  if (lines >= 2)
  {
    m_Frame->ShowExMessage(wxString::Format(_("%d lines moved"), lines));
  }

  return true;
}
예제 #2
0
파일: ex.cpp 프로젝트: Emmavw/wxExtension
bool wxExEx::Delete(
  const wxString& begin_address, 
  const wxString& end_address)
{
  if (m_STC->GetReadOnly() || m_STC->HexMode())
  {
    return false;
  }
  
  if (!SetSelection(begin_address, end_address))
  {
    return false;
  }

  const int lines = wxExGetNumberOfLines(m_STC->GetSelectedText());
  
  m_STC->Cut();

  if (begin_address.StartsWith("'"))
  {
    if (begin_address.size() > 1)
    {
      MarkerDelete(begin_address.GetChar(1));
    }
  }

  if (end_address.StartsWith("'"))
  {
    if (end_address.size() > 1)
    {
      MarkerDelete(end_address.GetChar(1));
    }
  }

  if (lines >= 2)
  {
    m_Frame->ShowExMessage(wxString::Format(_("%d fewer lines"), lines));
  }

  return true;
}
예제 #3
0
const wxString wxExLink::FindPath(const wxString& text) const
{
  if (
    text.empty() ||
    // wxPathList cannot handle links over several lines.
    wxExGetNumberOfLines(text) > 1)
  {
    return wxEmptyString;
  }

  // Better first try to find "...", then <...>, as in next example.
  // <A HREF="http://www.scintilla.org">scintilla</A> component.

  // So, first get text between " signs.
  size_t pos_char1 = text.find("\"");
  size_t pos_char2 = text.rfind("\"");

  // If that did not succeed, then get text between < and >.
  if (pos_char1 == wxString::npos || 
      pos_char2 == wxString::npos || 
      pos_char2 <= pos_char1)
  {
    pos_char1 = text.find("<");
    pos_char2 = text.rfind(">");
  }

  // If that did not succeed, then get text between : and : (in .po files).
  if (m_STC->GetLexer().GetScintillaLexer() == "po" && 
      (pos_char1 == wxString::npos || 
       pos_char2 == wxString::npos || 
       pos_char2 <= pos_char1))
  {
    pos_char1 = text.find(": ");
    pos_char2 = text.rfind(":");
  }

  // If that did not succeed, then get text between ' and '.
  if (pos_char1 == wxString::npos ||
      pos_char2 == wxString::npos || 
      pos_char2 <= pos_char1)
  {
    pos_char1 = text.find("'");
    pos_char2 = text.rfind("'");
  }
  
  wxString out;

  // If we did not find anything.
  if (pos_char1 == wxString::npos || 
      pos_char2 == wxString::npos || 
      pos_char2 <= pos_char1)
  {
    wxRegEx regex("(.*):[0-9]+");
    
    if (regex.Matches(text))
    {
      size_t start, len;

      if (regex.GetMatch(&start, &len, 1))
      {
        out = text.substr(start, len);
      }
      else
      {
        out = text;
      }
    }
    else
    {
      out = text;
    }
  }
  else
  {
    // Okay, get everything inbetween.
    out = text.substr(pos_char1 + 1, pos_char2 - pos_char1 - 1);
  }

  // And make sure we skip white space.
  out.Trim(true);
  out.Trim(false);
  
  return out;
}
예제 #4
0
파일: frame.cpp 프로젝트: hfvw/wxExtension
// Do not make it const, too many const_casts needed,
// I thought that might cause crash in rect selection, but it didn't.
bool wxExFrame::UpdateStatusBar(wxExSTC* stc, const wxString& pane)
{
    if (stc == NULL)
    {
        return false;
    }

    wxString text;

    if (pane == "PaneInfo")
    {
        if (stc->GetCurrentPos() == 0)
        {
            text = wxString::Format("%d", stc->GetLineCount());
        }
        else
        {
            int start;
            int end;
            stc->GetSelection(&start, &end);

            const int len  = end - start;
            const int line = stc->GetCurrentLine() + 1;
            const int pos = stc->GetCurrentPos() + 1 - stc->PositionFromLine(line - 1);

            if (len == 0)
            {
                text = wxString::Format("%d,%d", line, pos);
            }
            else
            {
                if (stc->SelectionIsRectangle())
                {
                    text = wxString::Format("%d,%d,%d", line, pos, stc->GetSelectedText().length());
                }
                else
                {
                    // There might be NULL's inside selection.
                    // So use the GetSelectedTextRaw variant.
                    const int number_of_lines =
                        wxExGetNumberOfLines(stc->GetSelectedTextRaw());

                    if (number_of_lines <= 1)
                        text = wxString::Format("%d,%d,%d", line, pos, len);
                    else
                        text = wxString::Format("%d,%d,%d", line, number_of_lines, len);
                }
            }
        }
    }
    else if (pane == "PaneLexer")
    {
        text = stc->GetLexer().GetDisplayLexer();
    }
    else if (pane == "PaneFileType")
    {
        switch (stc->GetEOLMode())
        {
        case wxSTC_EOL_CRLF:
            text = "DOS";
            break;
        case wxSTC_EOL_CR:
            text = "MAC";
            break;
        case wxSTC_EOL_LF:
            text = "UNIX";
            break;
        default:
            text = "UNKNOWN";
        }
    }
    else
    {
        return false;
    }

    return StatusText(text, pane);
}
예제 #5
0
파일: link.cpp 프로젝트: hfvw/wxExtension
const wxString wxExLink::FindPath(const wxString& text) const
{
    if (
        text.empty() ||
        // wxPathList cannot handle links over several lines.
        // add trimmed argument, to skip eol
        wxExGetNumberOfLines(text, true) > 1)
    {
        return wxEmptyString;
    }

    // Path in .po files.
    if (
        m_STC != NULL &&
        m_STC->GetLexer().GetScintillaLexer() == "po" && text.StartsWith("#: "))
    {
        return text.Mid(3);
    }

    // Better first try to find "...", then <...>, as in next example.
    // <A HREF="http://www.scintilla.org">scintilla</A> component.

    // So, first get text between " signs.
    size_t pos_char1 = text.find("\"");
    size_t pos_char2 = text.rfind("\"");

    // If that did not succeed, then get text between < and >.
    if (pos_char1 == wxString::npos ||
            pos_char2 == wxString::npos ||
            pos_char2 <= pos_char1)
    {
        pos_char1 = text.find("<");
        pos_char2 = text.rfind(">");
    }

    // If that did not succeed, then get text between ' and '.
    if (pos_char1 == wxString::npos ||
            pos_char2 == wxString::npos ||
            pos_char2 <= pos_char1)
    {
        pos_char1 = text.find("'");
        pos_char2 = text.rfind("'");
    }

    wxString out;

    // If we did not find anything.
    if (pos_char1 == wxString::npos ||
            pos_char2 == wxString::npos ||
            pos_char2 <= pos_char1)
    {
        out = text;
    }
    else
    {
        // Okay, get everything inbetween.
        out = text.substr(pos_char1 + 1, pos_char2 - pos_char1 - 1);
    }

    // And make sure we skip white space.
    out.Trim(true);
    out.Trim(false);

    return out;
}