summaryrefslogtreecommitdiff
path: root/gui/glsledit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/glsledit.cpp')
-rw-r--r--gui/glsledit.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/gui/glsledit.cpp b/gui/glsledit.cpp
index 5c77882..f0e4613 100644
--- a/gui/glsledit.cpp
+++ b/gui/glsledit.cpp
@@ -961,4 +961,44 @@ void GLSLEdit::mark(const QString &str, Qt::CaseSensitivity sens)
d_ptr->highlighter->mark(str, sens);
}
+void GLSLEdit::indent()
+{
+ QTemporaryFile file(QLatin1String("shader.glsl"));
+ if (!file.open()) {
+ qDebug()<<"Couldn't create temporary file "<<file.fileName();
+ return;
+ }
+ file.write(toPlainText().toUtf8());
+ file.flush();
+
+ QString tempFileName =
+ QDir::toNativeSeparators(QFileInfo(file).canonicalFilePath());
+
+ QProcess astyle;
+ astyle.setStandardInputFile(tempFileName);
+ astyle.start("astyle");
+ if (!astyle.waitForStarted()) {
+ qDebug()<<"Couldn't start the 'astyle' process!";
+ return;
+ }
+
+ if (!astyle.waitForFinished()) {
+ qDebug()<<"Couldn't finish the 'astyle' process";
+ return;
+ }
+
+ QByteArray result = astyle.readAll();
+ setPlainText(QString::fromUtf8(result));
+}
+
+void GLSLEdit::contextMenuEvent(QContextMenuEvent *e)
+{
+ QMenu *menu = createStandardContextMenu();
+
+ menu->addAction(tr("Indent Code"), this, SLOT(indent()));
+
+ menu->exec(e->globalPos());
+ delete menu;
+}
+
#include "glsledit.moc"