71
71
"functionality using <b>astyle</b> library.</p>"));
72
72
connect(m_formatTextAction, SIGNAL(triggered()), this, SLOT(beautifySource()));
74
m_formatLine = actionCollection()->addAction("edit_reformat_line");
75
m_formatLine->setText(i18n("Reformat Line"));
76
m_formatLine->setToolTip(i18n("Reformat current line using AStyle"));
77
m_formatLine->setWhatsThis(i18n("<b>Reformat line</b>"
78
"<p>Source reformatting of line under cursor using <b>astyle</b> library.</p>"));
79
connect(m_formatLine, SIGNAL(triggered()), this, SLOT(beautifyLine()));
74
81
m_formatFilesAction = actionCollection()->addAction("tools_astyle");
75
82
m_formatFilesAction->setText(i18n("Format files"));
76
83
m_formatFilesAction->setToolTip(i18n("Format file(s) using the current theme"));
288
void SourceFormatterController::beautifyLine()
290
KDevelop::IDocumentController *docController = KDevelop::ICore::self()->documentController();
291
KDevelop::IDocument *doc = docController->activeDocument();
292
if (!doc || !doc->isTextDocument())
294
KTextEditor::Document *tDoc = doc->textDocument();
295
if (!tDoc->activeView())
297
// load the appropriate formatter
298
KMimeType::Ptr mime = KMimeType::findByUrl(doc->url());
299
ISourceFormatter *formatter = formatterForMimeType(mime);
301
kDebug() << "no formatter available for" << mime;
305
const KTextEditor::Cursor cursor = tDoc->activeView()->cursorPosition();
306
const QString line = tDoc->line(cursor.line());
307
const QString prev = tDoc->text(KTextEditor::Range(0, 0, cursor.line(), 0));
308
const QString post = tDoc->text(KTextEditor::Range(KTextEditor::Cursor(cursor.line() + 1, 0), tDoc->documentEnd()));
310
const QString formatted = formatter->formatSource(line, mime, prev, post);
311
tDoc->replaceText(KTextEditor::Range(cursor.line(), 0, cursor.line(), line.length()), formatted);
312
// advance cursor one line
313
tDoc->activeView()->setCursorPosition(KTextEditor::Cursor(cursor.line() + 1, 0));
281
316
void SourceFormatterController::formatDocument(KDevelop::IDocument *doc, ISourceFormatter *formatter, const KMimeType::Ptr &mime)
283
318
KTextEditor::Document *textDoc = doc->textDocument();