1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
Description: stdout viewer
Author: Marco Costalba (C) 2006-2007
Copyright: See COPYING file that comes with this distribution
*/
#include <QSettings>
#include <QStatusBar>
#include <QMessageBox>
#include "myprocess.h"
#include "git.h"
#include "consoleimpl.h"
ConsoleImpl::ConsoleImpl(const QString& nm, Git* g) : git(g), actionName(nm) {
setAttribute(Qt::WA_DeleteOnClose);
setupUi(this);
textEditOutput->setFont(QGit::TYPE_WRITER_FONT);
QFont f = textLabelCmd->font();
f.setBold(true);
textLabelCmd->setFont(f);
setWindowTitle("\'" + actionName + "\' output window - QGit");
QGit::restoreGeometrySetting(QGit::CON_GEOM_KEY, this);
}
void ConsoleImpl::typeWriterFontChanged() {
QTextEdit* te = textEditOutput;
te->setFont(QGit::TYPE_WRITER_FONT);
te->setPlainText(te->toPlainText());
te->moveCursor(QTextCursor::End);
}
void ConsoleImpl::pushButtonOk_clicked() {
close();
}
void ConsoleImpl::pushButtonTerminate_clicked() {
git->cancelProcess(proc);
procFinished();
}
void ConsoleImpl::closeEvent(QCloseEvent* ce) {
if (proc && proc->state() == QProcess::Running)
if (QMessageBox::question(this, "Action output window - QGit",
"Action is still running.\nAre you sure you want to close "
"the window and leave the action running in background?",
"&Yes", "&No", QString(), 1, 1) == 1) {
ce->ignore();
return;
}
if (QApplication::overrideCursor())
QApplication::restoreOverrideCursor();
QGit::saveGeometrySetting(QGit::CON_GEOM_KEY, this);
QMainWindow::closeEvent(ce);
}
bool ConsoleImpl::start(const QString& cmd, const QString& cmdArgs) {
statusBar()->showMessage("Executing \'" + actionName + "\' action...");
// in case of a multi-sequence, line arguments are bounded to first command only
QString txt = cmd.section('\n', 0, 0).trimmed();
QString args = cmdArgs.trimmed();
QString tail(cmd.section('\n', 1).trimmed());
if (!args.isEmpty())
txt.append(' ' + args);
if (!tail.isEmpty()) // any one-line command followed by a newline would fail
txt.append('\n' + tail);
textLabelCmd->setText(txt);
if (tail.isEmpty())
proc = git->runAsync(txt, this);
else
proc = git->runAsScript(txt.append('\n'), this); // wrap in a script
if (proc.isNull())
deleteLater();
else
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
return !proc.isNull();
}
void ConsoleImpl::procReadyRead(const QByteArray& data) {
QString newParagraph;
if (QGit::stripPartialParaghraps(data, &newParagraph, &inpBuf))
// QTextEdit::append() adds a new paragraph,
// i.e. inserts a LF if not already present.
textEditOutput->append(newParagraph);
}
void ConsoleImpl::procFinished() {
textEditOutput->append(inpBuf);
inpBuf = "";
QApplication::restoreOverrideCursor();
statusBar()->showMessage("End of \'" + actionName + "\' execution.");
pushButtonTerminate->setEnabled(false);
emit customAction_exited(actionName);
}
|