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; }
void StyledTextCtrl::OnMarginClick(wxStyledTextEvent& event) { int lineClick = LineFromPosition(event.GetPosition()); int levelClick = GetFoldLevel(lineClick); switch (event.GetMargin()) { case MARGIN_FOLD: if ((levelClick & wxSTC_FOLDLEVELHEADERFLAG) > 0) { ToggleFold(lineClick); } break; case MARGIN_LINE_BREAKS: if (MarkerGet(lineClick) == 0) { MarkerAdd(lineClick, 0); } else { MarkerDelete(lineClick, 0); } break; case MARGIN_LINE_EDITS: break; case MARGIN_LINE_NUMBERS: break; default: break; } }
bool wxSTEditorShell::SetMaxLines(int max_lines) { m_max_lines = max_lines; if (m_max_lines < 0) return false; int total_lines = GetLineCount(); total_lines = wxMax(0, total_lines-1); // delete lines when more than m_max_lines, you'll eventually crash otherwise if (total_lines > m_max_lines) { BeginWriteable(); int marker = MarkerGet(total_lines - m_max_lines); SetTargetStart(0); SetTargetEnd(PositionFromLine(total_lines - m_max_lines)); ReplaceTarget(wxEmptyString); // wipe marker that has moved up if there shouldn't be a marker if ((marker & (1<<markerPrompt)) == 0) MarkerDelete(0, markerPrompt); EndWriteable(); return true; } return false; }
/* This function will see if one or more 'areas' in the buffer can be made available (either for writing xor reading). Note: such a series of areas starts from the beginning. */ static int ScanMarkers(struct marker_list *pMarkerList, int *piSizeBWA, int *piSizeAWA, int *piNbrPendingXfers) { struct marker *pM; bool bMarkersAreNowAWA; int index; index = pMarkerList->iFirstMarker; __ASSERT_NO_MSG(-1 != index); bMarkersAreNowAWA = false; do { int index_next; __ASSERT_NO_MSG(index == pMarkerList->iFirstMarker); if (index == pMarkerList->iAWAMarker) { bMarkersAreNowAWA = true; /* from now on, everything is AWA */ } pM = &(pMarkerList->aMarkers[index]); if (pM->bXferBusy == true) { break; } if (!bMarkersAreNowAWA) { *piSizeBWA += pM->size; } else { *piSizeAWA += pM->size; } index_next = pM->Next; /* pMarkerList->iFirstMarker will be updated */ MarkerDelete(pMarkerList, index); /* adjust *piNbrPendingXfers */ if (piNbrPendingXfers) { __ASSERT_NO_MSG(0 <= *piNbrPendingXfers); (*piNbrPendingXfers)--; } index = index_next; } while (-1 != index); __ASSERT_NO_MSG(index == pMarkerList->iFirstMarker); if (bMarkersAreNowAWA) { pMarkerList->iAWAMarker = pMarkerList->iFirstMarker; } #ifdef STORE_NBR_MARKERS if (0 == pMarkerList->iNbrMarkers) { __ASSERT_NO_MSG(-1 == pMarkerList->iFirstMarker); __ASSERT_NO_MSG(-1 == pMarkerList->iLastMarker); __ASSERT_NO_MSG(-1 == pMarkerList->iAWAMarker); } #endif return pMarkerList->iFirstMarker; }
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; }
bool wxExEx::MarkerAdd(const wxUniChar& marker, int line) { MarkerDelete(marker); const int lin = (line == -1 ? m_STC->GetCurrentLine(): line); const int id = m_STC->MarkerAdd( lin, m_MarkerSymbol.GetNo()); if (id == -1) { wxLogError("Could not add marker: %c to line: %d", marker, lin); return false; } m_Markers[marker] = id; return true; }
void CodeEdit::OnModified(wxStyledTextEvent& event) { event.Skip(); int linesAdded = event.GetLinesAdded(); // If we're inserting new lines before a line, so we need to move the // markers down. STCntilla doesn't do this automatically for the current line. if (linesAdded > 0) { unsigned int position = event.GetPosition(); unsigned int line = LineFromPosition(position); unsigned int lineStartPosition = PositionFromLine(line); if (position == lineStartPosition) { int markers = MarkerGet(line); // Delete all of the markers from the line. for (int i = 0; i < 32; ++i) { MarkerDelete(line, i); } // Add the markers back on the new line. MarkerAddSet(line + linesAdded, markers); } } }
bool wxExEx::Substitute( const wxString& begin_address, const wxString& end_address, const wxString& patt, const wxString& repl) { if (m_STC->GetReadOnly()) { return false; } if (m_STC->HexMode()) { wxLogStatus(_("Not allowed in hex mode")); return false; } const int begin_line = ToLineNumber(begin_address); const int end_line = ToLineNumber(end_address); if (begin_line == 0 || end_line == 0 || end_line < begin_line) { return false; } if (!MarkerAdd('$', end_line - 1)) { return false; } const wxString pattern = (patt == "~" ? m_Replacement: patt); wxString replacement(repl); m_Replacement = replacement; m_STC->SetSearchFlags(m_SearchFlags); int nr_replacements = 0; m_STC->BeginUndoAction(); m_STC->SetTargetStart(m_STC->PositionFromLine(begin_line - 1)); m_STC->SetTargetEnd(m_STC->GetLineEndPosition(MarkerLine('$'))); while (m_STC->SearchInTarget(pattern) > 0) { const int target_start = m_STC->GetTargetStart(); if (target_start >= m_STC->GetTargetEnd()) { break; } if (replacement.Contains("&")) { wxString target = m_STC->GetTextRange( m_STC->GetTargetStart(), m_STC->GetTargetEnd()); if (replacement.StartsWith("\\L")) { target.MakeLower(); replacement.Replace("\\L", wxEmptyString); } else if (replacement.StartsWith("\\U")) { target.MakeUpper(); replacement.Replace("\\U", wxEmptyString); } replacement.Replace("&", target); } m_STC->MarkTargetChange(); const int length = m_STC->ReplaceTargetRE(replacement); // always RE! m_STC->SetTargetStart(target_start + length); m_STC->SetTargetEnd(m_STC->GetLineEndPosition(MarkerLine('$'))); nr_replacements++; } m_STC->EndUndoAction(); MarkerDelete('$'); m_Frame->ShowExMessage(wxString::Format(_("Replaced: %d occurrences of: %s"), nr_replacements, pattern.c_str())); return true; }