Пример #1
0
void SonicPiScintilla::toggleComment() {
  beginUndoAction();

  int linenum, cursor;
  getCursorPosition(&linenum, &cursor);

  //select the whole line
  setSelection(linenum, 0, linenum, cursor+1);

  QString selection = selectedText();

  // make sure we don't comment empty lines
  if (selection.length() > 0) {
      // if it's already commented, uncomment
      if (selection[0] == '#') {
          selection.remove(0, 1);
          replaceSelectedText(selection);
          if (cursor > 0) {
              setCursorPosition(linenum, cursor - 1);
          } else {
              setCursorPosition(linenum, cursor);
          }
      } else {
          selection.prepend('#');
          replaceSelectedText(selection);
          setCursorPosition(linenum, cursor + 1);
      }
  }
  deselect();
  endUndoAction();
}
Пример #2
0
void SonicPiScintilla::moveLineOrSelection(int numLines) {
  beginUndoAction();

  int linenum, cursor, origLinenum, origCursor;
  getCursorPosition(&linenum, &cursor);
  origLinenum = linenum;
  origCursor = cursor;

  bool hadSelectedText = hasSelectedText();


  if(!hadSelectedText) {
    setSelection(linenum, 0, linenum + 1, 0);
  }

  int lineFrom, indexFrom, lineTo, indexTo, lineOffset;
  getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo);
  lineOffset = lineTo - origLinenum;
  linenum = lineFrom;

  QString selection = selectedText();

  if(selection[selection.length()-1] != '\n') {
    selection = selection + "\n";
    lineTo += 1;
    lineOffset += 1;
    indexTo = 0;
    replaceSelectedText("");
    setCursorPosition(linenum, 0);
    SendScintilla(SCI_DELETEBACK);
  } else {
    replaceSelectedText("");
  }
  setCursorPosition(linenum, 0);

  moveLines(numLines);

  getCursorPosition(&linenum, &cursor);
  setCursorPosition(linenum, 0);
  insert(selection);

  setCursorPosition(linenum + lineOffset, origCursor);

  int diffLine = lineTo - lineFrom;
  int diffIndex = indexTo - indexFrom;

  setSelection(linenum + diffLine, diffIndex, linenum, 0);

  endUndoAction();
}
Пример #3
0
void SonicPiScintilla::transposeChars()
{
  int linenum, index;
  getCursorPosition(&linenum, &index);
  setSelection(linenum, 0, linenum + 1, 0);
  int lineLength = selectedText().size();

  //transpose chars
  if(index > 0){
    if(index < (lineLength - 1)){
      index = index + 1;
    }
    setSelection(linenum, index - 2, linenum, index);
    QString text = selectedText();
    QChar a, b;
    a = text.at(0);
    b = text.at(1);
    QString replacement  = "";
    replacement.append(b);
    replacement.append(a);
    replaceSelectedText(replacement);
  }

  setCursorPosition(linenum, index);
}
Пример #4
0
void SciDoc::uncommentLine(JuffScintilla* edit, int line, const QString& str1, const QString& comment) {
	int pos = str1.indexOf(comment);
	QString str2 = str1;
	str2.replace(pos, comment.length(), "");
	edit->setSelection(line, 0, line + 1, 0);
	replaceSelectedText(str2);
}
Пример #5
0
void ScriptFileInterpreter::toggleComment(bool addComment) {
  // Get selected text
  std::string whitespaces(" \t\f\r");
  int selFromLine, selFromInd, selToLine, selToInd;

  m_editor->getSelection(&selFromLine, &selFromInd, &selToLine, &selToInd);

  // Expand selection to first character on start line to the end char on second
  // line.
  if (selFromLine == -1) {
    m_editor->getCursorPosition(&selFromLine, &selFromInd);
    selToLine = selFromLine;
  }

  // For each line, select it, copy the line into a new string minus the comment
  QString replacementText = "";

  // If it's adding comment, check all lines to find the lowest index for a non
  // space character
  int minInd = -1;
  if (addComment) {
    for (int i = selFromLine; i <= selToLine; ++i) {
      std::string thisLine = m_editor->text(i).toUtf8().constData();
      int lineFirstChar =
          static_cast<int>(thisLine.find_first_not_of(whitespaces + "\n"));

      if (minInd == -1 || (lineFirstChar != -1 && lineFirstChar < minInd)) {
        minInd = lineFirstChar;
      }
    }
  }

  for (int i = selFromLine; i <= selToLine; ++i) {
    std::string thisLine = m_editor->text(i).toUtf8().constData();

    int lineFirstChar =
        static_cast<int>(thisLine.find_first_not_of(whitespaces + "\n"));

    if (lineFirstChar != -1) {
      if (addComment) {
        thisLine.insert(minInd, "#");
      } else {
        // Check that the first character is a #
        if (thisLine[lineFirstChar] ==
            '#') // Remove the comment, or ignore to add as is
        {
          thisLine = thisLine.erase(lineFirstChar, 1);
        }
      }
    }

    replacementText = replacementText + QString::fromStdString(thisLine);
  }

  m_editor->setSelection(selFromLine, 0, selToLine,
                         m_editor->lineLength(selToLine));
  replaceSelectedText(m_editor, replacementText);
  m_editor->setCursorPosition(selFromLine, selFromInd);
}
Пример #6
0
void SciDoc::setText(const QString& text) {
	if ( int_->curEdit_ == NULL ) return;

	int_->curEdit_->beginUndoAction();
	int_->curEdit_->selectAll();
	replaceSelectedText(text, false);
	int_->curEdit_->endUndoAction();
}
Пример #7
0
void SonicPiScintilla::replaceBuffer(QString content, int line, int index, int first_line) {
  beginUndoAction();
  insert(" ");
  SendScintilla(QsciCommand::Delete);
  selectAll();
  replaceSelectedText(content);
  setCursorPosition(line, index);
  setFirstVisibleLine(first_line);
  endUndoAction();
}
Пример #8
0
void QgsCodeEditor::insertText( const QString theText )
{
  // Insert the text or replace selected text
  if ( hasSelectedText() )
  {
    replaceSelectedText( theText );
  }
  else
  {
    int line, index;
    getCursorPosition( &line, &index );
    insertAt( theText, line, index );
    setCursorPosition( line, index + theText.length() );
  }
}
Пример #9
0
void MdiChild::replace(QString term, QString newTerm, int atLine, int atIndex, bool cs)
{
    Qt::CaseSensitivity caseSensitivity;
    if(cs)
        caseSensitivity = Qt::CaseSensitive;
    else
        caseSensitivity = Qt::CaseInsensitive;

    setSelection(atLine, atIndex, atLine, atIndex + term.length());
    if(selectedText().compare(term, caseSensitivity) == 0)
    {
        replaceSelectedText(newTerm);
    }
    else
        qDebug() << "Replacement failed : the text to be replaced was not found. ";
}
Пример #10
0
/// Convert spaces in selection to tabs
void ScriptFileInterpreter::spacesToTabs() {
  int selFromLine, selFromInd, selToLine, selToInd;

  m_editor->getSelection(&selFromLine, &selFromInd, &selToLine, &selToInd);
  if (selFromLine == -1)
    m_editor->selectAll();

  QString text = m_editor->selectedText();

  // Use the tab space count for each converted characters
  QString spaces = "";

  for (int i = 0; i < m_editor->tabWidth(); ++i)
    spaces = spaces + " ";

  text = text.replace(spaces, "\t", Qt::CaseInsensitive);
  replaceSelectedText(m_editor, text);
}
Пример #11
0
void SciDoc::stripTrailingSpaces() {
//	LOGGER;
	if ( int_->curEdit_ == NULL ) return;

	int line, col;
	getCursorPos(line, col);
	QString text = int_->curEdit_->text();
	QStringList lines = text.split(LineSeparatorRx);
	QRegExp rx("[ \t]+$");
	int i = 0;

	beginUndoAction();
	foreach (QString str, lines) {
		int pos = str.indexOf(rx);
		if ( pos >= 0 ) {
			int_->curEdit_->setSelection(i, 0, i, str.length());
			str.truncate(pos);
			replaceSelectedText(str);
		}
		++i;
	}
Пример #12
0
bool NumberInputWidget::textEdited(const std::string& text)
{
	std::string currentText = getText();
	std::string newText = replaceSelectedText(text);
	try
	{
		size_t i = 0;
		float value = std::stof(newText, &i);
		if (i == newText.size() && getPrecision(value) <= m_precision)
		{
			TextInputWidget::textEdited(text);
			float newStep = computeSmallestStep(getText());
			if (newStep < m_step)
			{
				m_step = newStep;
			}
		}
	}
	catch (...)
	{
	}
	return true;
}
Пример #13
0
void SonicPiScintilla::replaceLines(int lineStart, int lineFinish, QString newLines)
{
  setSelection(lineStart, 0, lineFinish + 1, 0);
  replaceSelectedText(newLines);
}
Пример #14
0
void SonicPiScintilla::replaceLine(int lineNumber, QString newLine)
{
  setSelection(lineNumber, 0, lineNumber + 1, 0);
  replaceSelectedText(newLine);
}
Пример #15
0
void SciDoc::toggleCommentBlock() {
//	LOGGER;

	JuffScintilla* edit = int_->curEdit_;
	if ( edit == NULL ) return;

	QString commBeg, commEnd;
	QString s = syntax();
	if ( s == "C++" || s == "Java" || s == "C#" || s == "PHP" || s == "CSS" || s == "JavaScript"
	     || s == "SQL") {
		commBeg = "/*";
		commEnd = "*/";
	}
	else if ( s == "HTML" || s == "XML" ) {
		commBeg = "<!--";
		commEnd = "-->";
	}
	else if ( s == "Python" ) {
		commBeg = "'''";
		commEnd = "'''";
	}
	else if ( s == "Qore" || s == "Qorus") {
		commBeg = "/*";
		commEnd = "*/";
	}
	//	TODO : need to add more syntaxes

	if ( commBeg.isEmpty() || commEnd.isEmpty() )
		return;

	if ( edit->hasSelectedText() ) {
		int line1, col1, line2, col2, curLine, curCol;
		edit->getSelection(&line1, &col1, &line2, &col2);
		edit->getCursorPosition(&curLine, &curCol);

		QString str1 = edit->selectedText();
		bool toComment = true;
		if ( str1.startsWith(commBeg) && str1.endsWith(commEnd) )
			toComment = false;

		QString str2;
		if ( toComment )
			str2 = commBeg + str1 + commEnd;
		else {
			str2 = str1;
			str2.chop(commEnd.length());
			str2.remove(0, commBeg.length());
		}
		replaceSelectedText(str2);
		if ( line1 == line2 ) {
			if ( curCol == col1 )
				edit->setCursorPosition(curLine, curCol);
			else
				edit->setCursorPosition(curLine, curCol + (commBeg.length() + commEnd.length()) * (toComment ? 1 : -1));
		}
		else {
			if ( curLine == line2 && curCol == col2)
				edit->setCursorPosition(curLine, curCol + commEnd.length() * (toComment ? 1 : -1) );
			else
				edit->setCursorPosition(curLine, curCol);
		}
	}
}
Пример #16
0
////////////////////////////////////////////////////////////////////////////////
// Helper functions
void SciDoc::commentLine(JuffScintilla* edit, int line, const QString& str1, const QString& comment) {
	QString str2 = comment + str1;
	edit->setSelection(line, 0, line + 1, 0);
	replaceSelectedText(str2);
}