From 7a055a2f0ad7bd99eb5629f8ce6dfa5ae7a27080 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 6 Feb 2024 15:21:13 +0100 Subject: [PATCH] OutputWindow: Add "Save Contents" to context menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And give individual output windows the option to set a default file name. Change-Id: If3090063055c1b37f4f2d63b971fe0476f11806e Reviewed-by: Orgad Shaneh Reviewed-by: André Hartmann Reviewed-by: Reviewed-by: Tasuku Suzuki --- src/plugins/coreplugin/outputwindow.cpp | 14 ++++++++++++++ src/plugins/coreplugin/outputwindow.h | 2 ++ src/plugins/projectexplorer/appoutputpane.cpp | 2 ++ .../projectexplorer/compileoutputwindow.cpp | 2 ++ 4 files changed, 20 insertions(+) diff --git a/src/plugins/coreplugin/outputwindow.cpp b/src/plugins/coreplugin/outputwindow.cpp index ca0de974560..dbbcdde585a 100644 --- a/src/plugins/coreplugin/outputwindow.cpp +++ b/src/plugins/coreplugin/outputwindow.cpp @@ -73,6 +73,8 @@ public: QTimer scrollTimer; QElapsedTimer lastMessage; QHash> taskPositions; + //: default file name suggested for saving text from output views + QString outputFileNameHint{Tr::tr("output.txt")}; }; } // namespace Internal @@ -289,6 +291,13 @@ void OutputWindow::contextMenuEvent(QContextMenuEvent *event) adaptContextMenu(menu, event->pos()); + menu->addSeparator(); + QAction *saveAction = menu->addAction(Tr::tr("Save Contents...")); + connect(saveAction, &QAction::triggered, this, [this] { + QFileDialog::saveFileContent(toPlainText().toUtf8(), d->outputFileNameHint); + }); + saveAction->setEnabled(!document()->isEmpty()); + menu->addSeparator(); QAction *clearAction = menu->addAction(Tr::tr("Clear")); connect(clearAction, &QAction::triggered, this, [this] { clear(); }); @@ -368,6 +377,11 @@ void OutputWindow::updateFilterProperties( filterNewContent(); } +void OutputWindow::setOutputFileNameHint(const QString &fileName) +{ + d->outputFileNameHint = fileName; +} + void OutputWindow::filterNewContent() { QTextBlock lastBlock = document()->findBlockByNumber(d->lastFilteredBlockNumber); diff --git a/src/plugins/coreplugin/outputwindow.h b/src/plugins/coreplugin/outputwindow.h index cfcea8aae05..cd44e5678e9 100644 --- a/src/plugins/coreplugin/outputwindow.h +++ b/src/plugins/coreplugin/outputwindow.h @@ -67,6 +67,8 @@ public: bool regexp, bool isInverted); + void setOutputFileNameHint(const QString &fileName); + signals: void wheelZoom(); diff --git a/src/plugins/projectexplorer/appoutputpane.cpp b/src/plugins/projectexplorer/appoutputpane.cpp index 898acaba2a9..94e2694acc2 100644 --- a/src/plugins/projectexplorer/appoutputpane.cpp +++ b/src/plugins/projectexplorer/appoutputpane.cpp @@ -429,6 +429,8 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc) ow->setWindowIcon(Icons::WINDOW.icon()); ow->setWordWrapEnabled(m_settings.wrapOutput); ow->setMaxCharCount(m_settings.maxCharCount); + //: file name suggested for saving application output, %1 = run configuration display name + ow->setOutputFileNameHint(Tr::tr("application-output-%1.txt").arg(rc->displayName())); auto updateFontSettings = [ow] { ow->setBaseFont(TextEditor::TextEditorSettings::fontSettings().font()); diff --git a/src/plugins/projectexplorer/compileoutputwindow.cpp b/src/plugins/projectexplorer/compileoutputwindow.cpp index 8d2b12983bd..c5255d127f5 100644 --- a/src/plugins/projectexplorer/compileoutputwindow.cpp +++ b/src/plugins/projectexplorer/compileoutputwindow.cpp @@ -61,6 +61,8 @@ CompileOutputWindow::CompileOutputWindow(QAction *cancelBuildAction) : m_outputWindow->setReadOnly(true); m_outputWindow->setUndoRedoEnabled(false); m_outputWindow->setMaxCharCount(Core::Constants::DEFAULT_MAX_CHAR_COUNT); + //: file name suggested for saving compile output + m_outputWindow->setOutputFileNameHint(Tr::tr("compile-output.txt")); Utils::ProxyAction *cancelBuildProxyButton = Utils::ProxyAction::proxyActionWithIcon(cancelBuildAction,