From 55e4f3e05978ea12b8d6899051da49a6aeee2bd5 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Wed, 25 Aug 2021 14:13:41 +0200
Subject: [PATCH] UI: Get ride of some not needed methods in the EditorProxy
 class

---
 src/UI/ScriptViews/EditorProxy.cc | 75 +------------------------------
 src/UI/ScriptViews/EditorProxy.hh | 11 -----
 2 files changed, 1 insertion(+), 85 deletions(-)

diff --git a/src/UI/ScriptViews/EditorProxy.cc b/src/UI/ScriptViews/EditorProxy.cc
index f3294f3d..16845293 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 653b107c..97be1793 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;
-- 
GitLab