| 680 | } |
| 681 | |
| 682 | void SourceFormatterController::beautifyLine() |
| 683 | { |
| 684 | Q_D(const SourceFormatterController); |
| 685 | |
| 686 | KDevelop::IDocumentController *docController = KDevelop::ICore::self()->documentController(); |
| 687 | KDevelop::IDocument *doc = docController->activeDocument(); |
| 688 | if (!doc) |
| 689 | return; |
| 690 | KTextEditor::Document *tDoc = doc->textDocument(); |
| 691 | if (!tDoc) |
| 692 | return; |
| 693 | KTextEditor::View* view = doc->activeTextView(); |
| 694 | if (!view) |
| 695 | return; |
| 696 | // load the appropriate formatter |
| 697 | FileFormatter ff(*doc); |
| 698 | if (!ff.readFormatterAndStyle(d->sourceFormatters)) { |
| 699 | qCDebug(SHELL) << "no formatter available for" << doc->url(); |
| 700 | return; |
| 701 | } |
| 702 | |
| 703 | const KTextEditor::Cursor cursor = view->cursorPosition(); |
| 704 | const QString line = tDoc->line(cursor.line()); |
| 705 | const QString prev = tDoc->text(KTextEditor::Range(0, 0, cursor.line(), 0)); |
| 706 | const QString post = QLatin1Char('\n') + tDoc->text(KTextEditor::Range(KTextEditor::Cursor(cursor.line() + 1, 0), tDoc->documentEnd())); |
| 707 | |
| 708 | const QString formatted = ff.format(line, prev, post); |
| 709 | |
| 710 | // We don't use KTextEditor::Document directly, because CodeRepresentation transparently works |
| 711 | // around a possible tab-replacement incompatibility between kate and kdevelop |
| 712 | DynamicCodeRepresentation::Ptr code(dynamic_cast<DynamicCodeRepresentation*>( KDevelop::createCodeRepresentation( IndexedString( doc->url() ) ).data() ) ); |
| 713 | Q_ASSERT( code ); |
| 714 | code->replace( KTextEditor::Range(cursor.line(), 0, cursor.line(), line.length()), line, formatted ); |
| 715 | |
| 716 | // advance cursor one line |
| 717 | view->setCursorPosition(KTextEditor::Cursor(cursor.line() + 1, 0)); |
| 718 | } |
| 719 | |
| 720 | void SourceFormatterController::FileFormatter::formatDocument(IDocument& doc) const |
| 721 | { |
nothing calls this directly
no test coverage detected