Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 55e4f3e0 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Get ride of some not needed methods in the EditorProxy class

parent b69259d4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!19Fake vim
......@@ -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();
}
......@@ -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;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter