Skip to content

Commit

Permalink
Added persistent history of commands to Console window
Browse files Browse the repository at this point in the history
The last 10 commands are remembered now.
  • Loading branch information
bjorn committed Jun 28, 2019
1 parent 74b6c94 commit e52e396
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/tiled/consoledock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

#include "logginginterface.h"
#include "pluginmanager.h"
#include "preferences.h"
#include "scriptmanager.h"

#include <QLineEdit>
#include <QPlainTextEdit>
#include <QSettings>
#include <QShortcut>
#include <QVBoxLayout>

Expand Down Expand Up @@ -73,6 +75,10 @@ ConsoleDock::ConsoleDock(QWidget *parent)
this, &ConsoleDock::onObjectAdded);

setWidget(widget);

QSettings *settings = Preferences::instance()->settings();
mHistory = settings->value(QStringLiteral("Console/History")).toStringList();
mHistoryPosition = mHistory.size();
}

ConsoleDock::~ConsoleDock()
Expand Down Expand Up @@ -119,6 +125,11 @@ void ConsoleDock::executeScript()

mHistory.append(script);
mHistoryPosition = mHistory.size();

// Remember the last few script lines
QSettings *settings = Preferences::instance()->settings();
settings->setValue(QStringLiteral("Console/History"),
QStringList(mHistory.mid(mHistory.size() - 10)));
}

void ConsoleDock::moveHistory(int direction)
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/consoledock.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private slots:

QPlainTextEdit *mPlainTextEdit;
QLineEdit *mLineEdit;
QVector<QString> mHistory;
QStringList mHistory;
int mHistoryPosition = 0;
};

Expand Down

0 comments on commit e52e396

Please sign in to comment.