Commit 8f7eb161 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

use output view for external tools status things

parent ae4043d0
......@@ -171,11 +171,15 @@ void KateExternalToolsPlugin::runTool(const KateExternalTool &tool, KTextEditor:
// clear previous toolview data
auto pluginView = viewForMainWindow(mw);
pluginView->clearToolView();
pluginView->addToolStatus(i18n("Running external tool: %1", copy->name));
pluginView->addToolStatus(i18n("- Executable: %1", copy->executable));
pluginView->addToolStatus(i18n("- Arguments : %1", copy->arguments));
pluginView->addToolStatus(i18n("- Input : %1", copy->input));
pluginView->addToolStatus(QString());
// use generic output view for status
QVariantMap genericMessage;
genericMessage.insert(QStringLiteral("type"), QStringLiteral("Info"));
genericMessage.insert(QStringLiteral("category"), i18n("External Tools"));
genericMessage.insert(
QStringLiteral("plainText"),
i18n("Running external tool: %1\n- Executable: %2\n- Arguments: %3\n- Input: %4", copy->name, copy->executable, copy->arguments, copy->input));
Q_EMIT pluginView->message(genericMessage);
// expand macros
auto editor = KTextEditor::Editor::instance();
......@@ -254,24 +258,36 @@ void KateExternalToolsPlugin::handleToolFinished(KateToolRunner *runner, int exi
hasOutputInPane = !runner->outputData().isEmpty();
}
QString messageBody;
QString messageType = QStringLiteral("Info");
if (!runner->errorData().isEmpty()) {
pluginView->addToolStatus(i18n("Data written to stderr:"));
pluginView->addToolStatus(runner->errorData());
messageBody += i18n("Data written to stderr:\n");
messageBody += runner->errorData();
messageBody += QStringLiteral("\n");
messageType = QStringLiteral("Warning");
}
if (crashed || exitCode != 0) {
messageType = QStringLiteral("Error");
}
// empty line
pluginView->addToolStatus(QString());
// print crash & exit code
// print crash or exit code
if (crashed) {
pluginView->addToolStatus(i18n("Warning: External tool crashed."));
messageBody += i18n("Warning: External tool crashed.");
} else {
messageBody += i18n("Finished with exit code: %1", exitCode);
}
pluginView->addToolStatus(i18n("Finished with exit code: %1", exitCode));
if (crashed || exitCode != 0) {
pluginView->showToolView(ToolViewFocus::StatusTab);
} else if (hasOutputInPane) {
pluginView->showToolView(ToolViewFocus::OutputTab);
// use generic output view for status
QVariantMap genericMessage;
genericMessage.insert(QStringLiteral("type"), messageType);
genericMessage.insert(QStringLiteral("category"), i18n("External Tools"));
genericMessage.insert(QStringLiteral("plainText"), messageBody);
Q_EMIT pluginView->message(genericMessage);
// on successful execution => show output
// otherwise the global output pane settings will ensure we see the error output
if (!(crashed || exitCode != 0) && hasOutputInPane) {
pluginView->showToolView();
}
}
......
......@@ -151,7 +151,6 @@ KateExternalToolsPluginView::KateExternalToolsPluginView(KTextEditor::MainWindow
, m_plugin(plugin)
, m_mainWindow(mainWindow)
, m_outputDoc(new QTextDocument(this))
, m_statusDoc(new QTextDocument(this))
{
m_plugin->registerPluginView(this);
......@@ -212,12 +211,10 @@ void KateExternalToolsPluginView::createToolView()
// set the documents
m_ui->teOutput->setDocument(m_outputDoc);
m_ui->teStatus->setDocument(m_statusDoc);
// use fixed font for displaying status and output text
const auto fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
m_ui->teOutput->setFont(fixedFont);
m_ui->teStatus->setFont(fixedFont);
// close button to delete tool view
auto btnClose = new QToolButton();
......@@ -228,31 +225,16 @@ void KateExternalToolsPluginView::createToolView()
}
}
void KateExternalToolsPluginView::showToolView(ToolViewFocus tab)
void KateExternalToolsPluginView::showToolView()
{
createToolView();
if (tab == ToolViewFocus::OutputTab) {
m_ui->tabWidget->setCurrentWidget(m_ui->tabOutput);
} else {
m_ui->tabWidget->setCurrentWidget(m_ui->tabStatus);
}
m_ui->tabWidget->setCurrentWidget(m_ui->tabOutput);
mainWindow()->showToolView(m_toolView);
}
void KateExternalToolsPluginView::clearToolView()
{
m_outputDoc->clear();
m_statusDoc->clear();
}
void KateExternalToolsPluginView::addToolStatus(const QString &message)
{
QTextCursor cursor(m_statusDoc);
cursor.movePosition(QTextCursor::End);
cursor.insertText(message);
cursor.insertText(QStringLiteral("\n"));
}
void KateExternalToolsPluginView::setOutputData(const QString &data)
......
......@@ -32,8 +32,6 @@ namespace Ui
class ToolView;
}
enum class ToolViewFocus { OutputTab = 0, StatusTab };
/**
* Menu action that displays all KateExternalTool in a submenu.
* Enables/disables the tool actions whenever the view changes, depending on the mimetype.
......@@ -116,19 +114,13 @@ public Q_SLOTS:
/**
* Shows the tool view. The toolview will be created, if not yet existing.
*/
void showToolView(ToolViewFocus tab);
void showToolView();
/**
* Clears the toolview data. If no toolview is around, nothing happens.
*/
void clearToolView();
/**
* Shows the External Tools toolview and points the error message along with
* some more info about the tool.
*/
void addToolStatus(const QString &message);
/**
* Sets the output data to data;
*/
......@@ -144,6 +136,14 @@ public Q_SLOTS:
*/
void handleEsc(QEvent *event);
Q_SIGNALS:
/**
* Signal for outgoing message, the host application will handle them!
* Will only be handled inside the main windows of this plugin view.
* @param message outgoing message we send to the host application
*/
void message(const QVariantMap &message);
private:
KateExternalToolsPlugin *m_plugin;
KTextEditor::MainWindow *m_mainWindow;
......@@ -151,7 +151,6 @@ private:
QWidget *m_toolView = nullptr;
Ui::ToolView *m_ui = nullptr;
QTextDocument *m_outputDoc = nullptr;
QTextDocument *m_statusDoc = nullptr;
};
#endif // KTEXTEDITOR_EXTERNALTOOLS_H
......
......@@ -39,23 +39,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabStatus">
<attribute name="title">
<string>Status</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextEdit" name="teStatus">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>No errors detected</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<resources/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment