QString KateCTagsView::currentWord( ) { KTextEditor::View *kv = mainWindow()->activeView(); if (!kv) { kDebug() << "no KTextEditor::View" << endl; return QString(); } if (kv->selection()) { return kv->selectionText(); } if (!kv->cursorPosition().isValid()) { kDebug() << "cursor not valid!" << endl; return QString(); } int line = kv->cursorPosition().line(); int col = kv->cursorPosition().column(); bool includeColon = m_ctagsUi.cmdEdit->text().contains("--extra=+q"); QString linestr = kv->document()->line(line); int startPos = qMax(qMin(col, linestr.length()-1), 0); int endPos = startPos; while (startPos >= 0 && (linestr[startPos].isLetterOrNumber() || (linestr[startPos] == ':' && includeColon) || linestr[startPos] == '_' || linestr[startPos] == '~')) { startPos--; } while (endPos < (int)linestr.length() && (linestr[endPos].isLetterOrNumber() || (linestr[endPos] == ':' && includeColon) || linestr[endPos] == '_')) { endPos++; } if (startPos == endPos) { kDebug() << "no word found!" << endl; return QString(); } //kDebug() << linestr.mid(startPos+1, endPos-startPos-1); return linestr.mid(startPos+1, endPos-startPos-1); }
static void slipInFilter(KProcess & proc, KTextEditor::View & view, QString command) { QString inputText; if (view.selection()) { inputText = view.selectionText(); } proc.clearProgram (); proc.setShellCommand(command); proc.start(); QByteArray encoded = inputText.toLocal8Bit(); proc.write(encoded); proc.closeWriteChannel(); // TODO: Put up a modal dialog to defend the text from further // keystrokes while the command is out. With a cancel button... }