aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/basefilefind.cpp2
-rw-r--r--src/plugins/texteditor/formattexteditor.cpp36
-rw-r--r--src/plugins/texteditor/formattexteditor.h24
3 files changed, 24 insertions, 38 deletions
diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp
index 399e275fe4f..ce6d2f4999f 100644
--- a/src/plugins/texteditor/basefilefind.cpp
+++ b/src/plugins/texteditor/basefilefind.cpp
@@ -21,7 +21,7 @@
#include <utils/algorithm.h>
#include <utils/fadingindicator.h>
#include <utils/futuresynchronizer.h>
-#include <utils/process.h>
+#include <utils/qtcprocess.h>
#include <utils/qtcassert.h>
#include <QComboBox>
diff --git a/src/plugins/texteditor/formattexteditor.cpp b/src/plugins/texteditor/formattexteditor.cpp
index 14f3d4e4e78..879387b991a 100644
--- a/src/plugins/texteditor/formattexteditor.cpp
+++ b/src/plugins/texteditor/formattexteditor.cpp
@@ -12,7 +12,7 @@
#include <utils/async.h>
#include <utils/differ.h>
-#include <utils/process.h>
+#include <utils/qtcprocess.h>
#include <utils/qtcassert.h>
#include <utils/temporarydirectory.h>
#include <utils/textutils.h>
@@ -27,6 +27,18 @@ using namespace std::chrono_literals;
namespace TextEditor {
+class FormatTask
+{
+public:
+ Utils::FilePath filePath;
+ QString sourceData;
+ TextEditor::Command command;
+ int startPos = -1;
+ int endPos = 0;
+ QString formattedData = {};
+ QString error = {};
+};
+
void formatCurrentFile(const Command &command, int startPos, int endPos)
{
if (TextEditorWidget *editor = TextEditorWidget::currentTextEditorWidget())
@@ -256,7 +268,7 @@ static void showError(const QString &error)
* Checks the state of @a task and if the formatting was successful calls updateEditorText() with
* the respective members of @a task.
*/
-static void checkAndApplyTask(const FormatTask &task)
+static void checkAndApplyTask(const QPointer<QPlainTextEdit> &textEditor, const FormatTask &task)
{
if (!task.error.isEmpty()) {
showError(task.error);
@@ -264,15 +276,12 @@ static void checkAndApplyTask(const FormatTask &task)
}
if (task.formattedData.isEmpty()) {
- showError(Tr::tr("Could not format file %1.").arg(
- task.filePath.displayName()));
+ showError(Tr::tr("Could not format file %1.").arg(task.filePath.displayName()));
return;
}
- QPlainTextEdit *textEditor = task.editor;
if (!textEditor) {
- showError(Tr::tr("File %1 was closed.").arg(
- task.filePath.displayName()));
+ showError(Tr::tr("File %1 was closed.").arg(task.filePath.displayName()));
return;
}
@@ -298,8 +307,8 @@ void formatEditor(TextEditorWidget *editor, const Command &command, int startPos
const QString sd = sourceData(editor, startPos, endPos);
if (sd.isEmpty())
return;
- checkAndApplyTask(format(FormatTask(editor, editor->textDocument()->filePath(), sd,
- command, startPos, endPos)));
+ checkAndApplyTask(editor,
+ format({editor->textDocument()->filePath(), sd, command, startPos, endPos}));
}
/**
@@ -316,15 +325,16 @@ void formatEditorAsync(TextEditorWidget *editor, const Command &command, int sta
auto watcher = new QFutureWatcher<FormatTask>;
const TextDocument *doc = editor->textDocument();
QObject::connect(doc, &TextDocument::contentsChanged, watcher, &QFutureWatcher<FormatTask>::cancel);
- QObject::connect(watcher, &QFutureWatcherBase::finished, [watcher] {
+ QObject::connect(watcher, &QFutureWatcherBase::finished,
+ [watcher, editor = QPointer<QPlainTextEdit>(editor)] {
if (watcher->isCanceled())
showError(Tr::tr("File was modified."));
else
- checkAndApplyTask(watcher->result());
+ checkAndApplyTask(editor, watcher->result());
watcher->deleteLater();
});
- watcher->setFuture(Utils::asyncRun(&format, FormatTask(editor, doc->filePath(), sd,
- command, startPos, endPos)));
+ watcher->setFuture(
+ Utils::asyncRun(&format, FormatTask{doc->filePath(), sd, command, startPos, endPos}));
}
} // namespace TextEditor
diff --git a/src/plugins/texteditor/formattexteditor.h b/src/plugins/texteditor/formattexteditor.h
index e1c58cdf94f..929763ecba8 100644
--- a/src/plugins/texteditor/formattexteditor.h
+++ b/src/plugins/texteditor/formattexteditor.h
@@ -10,35 +10,11 @@
#include <utils/filepath.h>
#include <QPlainTextEdit>
-#include <QPointer>
namespace TextEditor {
class TextEditorWidget;
-class TEXTEDITOR_EXPORT FormatTask
-{
-public:
- FormatTask(QPlainTextEdit *_editor, const Utils::FilePath &_filePath, const QString &_sourceData,
- const Command &_command, int _startPos = -1, int _endPos = 0) :
- editor(_editor),
- filePath(_filePath),
- sourceData(_sourceData),
- command(_command),
- startPos(_startPos),
- endPos(_endPos)
- {}
-
- QPointer<QPlainTextEdit> editor;
- Utils::FilePath filePath;
- QString sourceData;
- TextEditor::Command command;
- int startPos = -1;
- int endPos = 0;
- QString formattedData;
- QString error;
-};
-
TEXTEDITOR_EXPORT void formatCurrentFile(const TextEditor::Command &command, int startPos = -1, int endPos = 0);
TEXTEDITOR_EXPORT void formatEditor(TextEditorWidget *editor, const TextEditor::Command &command,
int startPos = -1, int endPos = 0);