2 Description: stdout viewer
4 Author: Marco Costalba (C) 2006-2007
6 Copyright: See COPYING file that comes with this distribution
11 #include <QMessageBox>
12 #include "myprocess.h"
14 #include "consoleimpl.h"
16 ConsoleImpl::ConsoleImpl(const QString
& nm
, Git
* g
) : git(g
), actionName(nm
) {
18 setAttribute(Qt::WA_DeleteOnClose
);
20 textEditOutput
->setFont(QGit::TYPE_WRITER_FONT
);
21 QFont f
= textLabelCmd
->font();
23 textLabelCmd
->setFont(f
);
24 setWindowTitle("\'" + actionName
+ "\' output window - QGit");
25 QGit::restoreGeometrySetting(QGit::CON_GEOM_KEY
, this);
28 void ConsoleImpl::typeWriterFontChanged() {
30 QTextEdit
* te
= textEditOutput
;
31 te
->setFont(QGit::TYPE_WRITER_FONT
);
32 te
->setPlainText(te
->toPlainText());
33 te
->moveCursor(QTextCursor::End
);
36 void ConsoleImpl::pushButtonOk_clicked() {
41 void ConsoleImpl::pushButtonTerminate_clicked() {
43 git
->cancelProcess(proc
);
47 void ConsoleImpl::closeEvent(QCloseEvent
* ce
) {
49 if (proc
&& proc
->state() == QProcess::Running
)
50 if (QMessageBox::question(this, "Action output window - QGit",
51 "Action is still running.\nAre you sure you want to close "
52 "the window and leave the action running in background?",
53 "&Yes", "&No", QString(), 1, 1) == 1) {
57 if (QApplication::overrideCursor())
58 QApplication::restoreOverrideCursor();
60 QGit::saveGeometrySetting(QGit::CON_GEOM_KEY
, this);
61 QMainWindow::closeEvent(ce
);
64 bool ConsoleImpl::start(const QString
& cmd
, const QString
& cmdArgs
) {
66 statusBar()->showMessage("Executing \'" + actionName
+ "\' action...");
68 // in case of a multi-sequence, line arguments are bounded to first command only
69 QString txt
= cmd
.section('\n', 0, 0).trimmed();
70 QString args
= cmdArgs
.trimmed();
71 QString
tail(cmd
.section('\n', 1).trimmed());
74 txt
.append(' ' + args
);
76 if (!tail
.isEmpty()) // any one-line command followed by a newline would fail
77 txt
.append('\n' + tail
);
79 textLabelCmd
->setText(txt
);
81 proc
= git
->runAsync(txt
, this);
83 proc
= git
->runAsScript(txt
.append('\n'), this); // wrap in a script
88 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
90 return !proc
.isNull();
93 void ConsoleImpl::procReadyRead(const QByteArray
& data
) {
96 if (QGit::stripPartialParaghraps(data
, &newParagraph
, &inpBuf
))
97 // QTextEdit::append() adds a new paragraph,
98 // i.e. inserts a LF if not already present.
99 textEditOutput
->append(newParagraph
);
102 void ConsoleImpl::procFinished() {
104 textEditOutput
->append(inpBuf
);
106 QApplication::restoreOverrideCursor();
107 statusBar()->showMessage("End of \'" + actionName
+ "\' execution.");
108 pushButtonTerminate
->setEnabled(false);
109 emit
customAction_exited(actionName
);