diff --git a/src/UI/ScriptViews/EditorProxy.cc b/src/UI/ScriptViews/EditorProxy.cc index f3294f3d04c79d7e9e077ae1000a62bb1a4ec069..16845293ca0bb5e1e2a9f40be4d2f82a4e6f699c 100644 --- a/src/UI/ScriptViews/EditorProxy.cc +++ b/src/UI/ScriptViews/EditorProxy.cc @@ -58,12 +58,6 @@ EditorProxy::EditorProxy(QPlainTextEdit *widg) noexcept EditorProxy::~EditorProxy() { qDebug() << "~EditorProxy"; } -void -EditorProxy::openFile(const QString &filename) noexcept -{ - emit handleInput(QString(QStringLiteral(":r %1<CR>")).arg(filename)); -} - void EditorProxy::changeStatusData(const QString &info) noexcept { @@ -147,7 +141,7 @@ EditorProxy::handleExCommand(bool *handled, const ExCommand &cmd) noexcept else if (wantQuit(cmd)) { // :q! if (cmd.hasBang) - invalidate(); + emit requestQuit(); // :q else @@ -330,70 +324,3 @@ EditorProxy::wantRun(const ExCommand &cmd) noexcept { return cmd.matches("run", "run") || cmd.matches("make", "make"); } - -bool -EditorProxy::save(const QString &fileName) noexcept -{ - if (!hasChanges(fileName)) - return true; - - QTemporaryFile tmpFile; - if (!tmpFile.open()) { - qCritical() << tr("Cannot create temporary file: %1").arg(tmpFile.errorString()); - return false; - } - - QTextStream ts(&tmpFile); - ts << content(); - ts.flush(); - - QFile::remove(fileName); - if (!QFile::copy(tmpFile.fileName(), fileName)) { - qCritical() << tr("Cannot write to file \"%1\"").arg(fileName); - return false; - } - - return true; -} - -void -EditorProxy::cancel(const QString &fileName) noexcept -{ - if (hasChanges(fileName)) - qCritical() << tr("File \"%1\" was changed").arg(fileName); - - else - invalidate(); -} - -void -EditorProxy::invalidate() noexcept -{ - emit requestQuit(); -} - -bool -EditorProxy::hasChanges(const QString &fileName) noexcept -{ - if (fileName.isEmpty() && content().isEmpty()) - return false; - - QFile f(fileName); - if (!f.open(QIODevice::ReadOnly)) - return true; - - QTextStream ts(&f); - return content() != ts.readAll(); -} - -QTextDocument * -EditorProxy::document() const noexcept -{ - return widget->document(); -} - -QString -EditorProxy::content() const noexcept -{ - return document()->toPlainText(); -} diff --git a/src/UI/ScriptViews/EditorProxy.hh b/src/UI/ScriptViews/EditorProxy.hh index 653b107c8a3f082166c8bb9fe2cffdf0733821c8..97be179342081b7b48e87c3dc9c8ef5adff18baa 100644 --- a/src/UI/ScriptViews/EditorProxy.hh +++ b/src/UI/ScriptViews/EditorProxy.hh @@ -31,11 +31,6 @@ class EditorProxy final : public QObject { public: ~EditorProxy() override; - void openFile(const QString &fileName) noexcept; - - bool save(const QString &fileName) noexcept; - void cancel(const QString &fileName) noexcept; - signals: void handleInput(const QString &keys); void requestSave(); @@ -66,12 +61,6 @@ private: bool wantQuit(const FakeVim::Internal::ExCommand &cmd) noexcept; bool wantRun(const FakeVim::Internal::ExCommand &cmd) noexcept; - void invalidate() noexcept; - bool hasChanges(const QString &fileName) noexcept; - - QTextDocument *document() const noexcept; - QString content() const noexcept; - QPlainTextEdit *widget; QString statusMessage; QString statusData;