/// Indent if newline was added. void OnCharAdded(wxScintillaEvent &event) { // Change this if support for mac files with \r is needed if (event.GetKey() == '\n' || event.GetKey() == '\r') { int currentLine = GetCurrentLine(); if (currentLine <= 0) { return; } // width of one indent character int indentWidth = (GetUseTabs() ? GetTabWidth() : 1); if (indentWidth == 0) { return; } // indent as prev line level int indentSize = GetLineIndentation(currentLine - 1); SetLineIndentation(currentLine, indentSize); // position = (line start pos) + (tabs count) + (space count) GotoPos(PositionFromLine(currentLine) + (indentSize / indentWidth) + (indentSize % indentWidth)); // notify that the text was changed ChangeModified(true); } }
/* TextEditor::onCharAdded * Called when a character is added to the text *******************************************************************/ void TextEditor::onCharAdded(wxStyledTextEvent& e) { // Update line numbers margin width string numlines = S_FMT("0%d", GetNumberOfLines()); SetMarginWidth(0, TextWidth(wxSTC_STYLE_LINENUMBER, numlines)); // Auto indent int currentLine = GetCurrentLine(); if (txed_auto_indent && e.GetKey() == '\n') { // Get indentation amount int lineInd = 0; if (currentLine > 0) lineInd = GetLineIndentation(currentLine - 1); // Do auto-indent if needed if (lineInd != 0) { SetLineIndentation(currentLine, lineInd); // Skip to end of tabs while (1) { int chr = GetCharAt(GetCurrentPos()); if (chr == '\t' || chr == ' ') GotoPos(GetCurrentPos()+1); else break; } } } // The following require a language to work if (language) { // Call tip if (e.GetKey() == '(' && txed_calltips_parenthesis) { openCalltip(GetCurrentPos()); } // End call tip if (e.GetKey() == ')') { CallTipCancel(); } // Comma, possibly update calltip if (e.GetKey() == ',' && txed_calltips_parenthesis) { //openCalltip(GetCurrentPos()); //if (CallTipActive()) updateCalltip(); } } // Continue e.Skip(); }
void Edit::OnCharAdded (wxStyledTextEvent &event) { char chr = (char)event.GetKey(); int currentLine = GetCurrentLine(); // Change this if support for mac files with \r is needed if (chr == '\n') { int lineInd = 0; if (currentLine > 0) { lineInd = GetLineIndentation(currentLine - 1); } if (lineInd == 0) return; SetLineIndentation (currentLine, lineInd); GotoPos(PositionFromLine (currentLine) + lineInd); } }
void Edit::OnCharAdded(wxStyledTextEvent &event) { event.Skip(); const wxChar c = event.GetKey(); if (c == wxT('\n')) { const int line = GetCurrentLine(); const int indent = line < 1 ? 0 : GetLineIndentation(line - 1); if (indent != 0) { SetLineIndentation(line, indent); GotoPos(GetLineIndentPosition(line)); } } }
void IWnd_stc::OnCharAdded (wxStyledTextEvent &evt) { char chr = (char)evt.GetKey(); if (chr == '\n') { int currentLine = GetCurrentLine(); if (currentLine < 1) return; int lineInd = GetLineIndentation(currentLine - 1); if (lineInd == 0) return; SetLineIndentation (currentLine, lineInd); GotoPos(GetLineIndentPosition(currentLine)); } }
void PythonCodeCtrl::OnCharAdded(wxScintillaEvent& ke) { //User has pressed enter //if the cursor is at the end of a completed statement, submit the statement to the interpreter //otherwise, do auto-indentation if (ke.GetKey() == _T('\n')) { //int pos = GetCurrentPos(); int line = LineFromPosition(GetCurrentPos()); if(line>0) { wxString prevlinetext = GetLine(line-1).Trim(); int indentation = GetLineIndentation(line-1); if((indentation==0) //submit a return pressed on an unindented line || (indentation>0 && prevlinetext==wxEmptyString)) // or an indented block where the previous line was empty { long rs,re; GetSelection(&rs,&re); //if(rs==re && GetLastPosition()==rs) if(rs==re && GetLength()==rs) // only submit if the cursor is at the end of the control (and there is no selection) { m_pyctrl->DispatchCode(GetValue()); ke.Skip(); } } // Otherwise indent the code if necessary if (GetLine(line-1).Trim().EndsWith(_T(":"))) { if(GetStyleAt(GetLineEndPosition(line-1)-1) == wxSCI_P_OPERATOR) indentation+=GetIndent(); } if (indentation>0) { SetLineIndentation(line,indentation); SetCurrentPos(PositionFromLine(line)+indentation); SetAnchor(PositionFromLine(line)+indentation); } } } ke.Skip(); }
void Edit::OnAnnotationAdd(wxCommandEvent& WXUNUSED(event)) { const int line = GetCurrentLine(); wxString ann = AnnotationGetText(line); ann = wxGetTextFromUser ( wxString::Format("Enter annotation for the line %d", line), "Edit annotation", ann, this ); if ( ann.empty() ) return; AnnotationSetText(line, ann); AnnotationSetStyle(line, ANNOTATION_STYLE); // Scintilla doesn't update the scroll width for annotations, even with // scroll width tracking on, so do it manually. const int width = GetScrollWidth(); // NB: The following adjustments are only needed when using // wxSTC_ANNOTATION_BOXED annotations style, but we apply them always // in order to make things simpler and not have to redo the width // calculations when the annotations visibility changes. In a real // program you'd either just stick to a fixed annotations visibility or // update the width when it changes. // Take into account the fact that the annotation is shown indented, with // the same indent as the line it's attached to. int indent = GetLineIndentation(line); // This is just a hack to account for the width of the box, there doesn't // seem to be any way to get it directly from Scintilla. indent += 3; const int widthAnn = TextWidth(ANNOTATION_STYLE, ann + wxString(indent, ' ')); if (widthAnn > width) SetScrollWidth(widthAnn); }