forked from qt-creator/qt-creator
Core: Allow users to open output window contents in scratch buffer
Task-number: QTCREATORBUG-31144 Change-Id: I474e60392281c5e3bd769d64719c3c6a31c57d2f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "corejsextensions.h"
|
||||
|
||||
#include "messagemanager.h"
|
||||
|
||||
#include <utils/appinfo.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/mimeutils.h>
|
||||
@@ -126,20 +128,12 @@ QString UtilsJsExtension::mktemp(const QString &pattern) const
|
||||
QString tmp = pattern;
|
||||
if (tmp.isEmpty())
|
||||
tmp = QStringLiteral("qt_temp.XXXXXX");
|
||||
QFileInfo fi(tmp);
|
||||
if (!fi.isAbsolute()) {
|
||||
QString tempPattern = QDir::tempPath();
|
||||
if (!tempPattern.endsWith(QLatin1Char('/')))
|
||||
tempPattern += QLatin1Char('/');
|
||||
tmp = tempPattern + tmp;
|
||||
const auto res = FileUtils::scratchBufferFilePath(tmp);
|
||||
if (!res) {
|
||||
MessageManager::writeDisrupting(res.error());
|
||||
return {};
|
||||
}
|
||||
|
||||
QTemporaryFile file(tmp);
|
||||
file.setAutoRemove(false);
|
||||
const bool isOpen = file.open();
|
||||
QTC_ASSERT(isOpen, return {});
|
||||
file.close();
|
||||
return file.fileName();
|
||||
return res->toFSPathString();
|
||||
}
|
||||
|
||||
QString UtilsJsExtension::asciify(const QString &input) const
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
#include "editormanager/editormanager.h"
|
||||
#include "find/basetextfind.h"
|
||||
#include "icore.h"
|
||||
#include "messagemanager.h"
|
||||
|
||||
#include <aggregation/aggregate.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/outputformatter.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -294,6 +296,27 @@ void OutputWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||
QFileDialog::saveFileContent(toPlainText().toUtf8(), d->outputFileNameHint);
|
||||
});
|
||||
saveAction->setEnabled(!document()->isEmpty());
|
||||
QAction *openAction = menu->addAction(Tr::tr("Copy Contents to Scratch Buffer"));
|
||||
connect(openAction, &QAction::triggered, this, [this] {
|
||||
QString scratchBufferPrefix = FilePath::fromString(d->outputFileNameHint).baseName();
|
||||
if (scratchBufferPrefix.isEmpty())
|
||||
scratchBufferPrefix = "scratch";
|
||||
const auto tempPath = FileUtils::scratchBufferFilePath(
|
||||
QString::fromUtf8("%1-XXXXXX.txt").arg(scratchBufferPrefix));
|
||||
if (!tempPath) {
|
||||
MessageManager::writeDisrupting(tempPath.error());
|
||||
return;
|
||||
}
|
||||
IEditor * const editor = EditorManager::openEditor(*tempPath);
|
||||
if (!editor) {
|
||||
MessageManager::writeDisrupting(
|
||||
Tr::tr("Failed to open editor for \"%1\".").arg(tempPath->toUserOutput()));
|
||||
return;
|
||||
}
|
||||
editor->document()->setTemporary(true);
|
||||
editor->document()->setContents(toPlainText().toUtf8());
|
||||
});
|
||||
openAction->setEnabled(!document()->isEmpty());
|
||||
|
||||
menu->addSeparator();
|
||||
QAction *clearAction = menu->addAction(Tr::tr("Clear"));
|
||||
|
||||
Reference in New Issue
Block a user