Skip to content

Commit

Permalink
Merge branch 'vedderb:master' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
darwinbeing authored Aug 23, 2024
2 parents 842c8cd + 7f49dbb commit dbd5354
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 46 deletions.
17 changes: 17 additions & 0 deletions QCodeEditor/src/internal/QCodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,23 @@ void QCodeEditor::keyPressEvent(QKeyEvent* e) {
return;
}

// Duplicate line
if (e->key() == Qt::Key_D &&
(e->modifiers() & Qt::ControlModifier) &&
(e->modifiers() & Qt::ShiftModifier)) {
auto tc = textCursor();
auto linepos = tc.positionInBlock();
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
tc.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);
auto line = tc.selectedText();
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
tc.insertText(line);
tc.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor);
tc.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, linepos);
setTextCursor(tc);
return;
}

bool doSave = false;

if (e->modifiers() == Qt::ControlModifier) {
Expand Down
32 changes: 17 additions & 15 deletions pages/pagelisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,16 @@ void PageLisp::updateRecentList()
void PageLisp::makeEditorConnections(ScriptEditor *editor)
{
connect(editor->codeEditor(), &QCodeEditor::textChanged, [editor, this]() {
setEditorDirty(editor);
setEditorDirty(editor);
});
connect(editor->codeEditor(), &QCodeEditor::clearConsoleTriggered, [this]() {
ui->debugEdit->clear();
});
connect(editor, &ScriptEditor::fileOpened, [this](QString fileName) {
connect(editor, &ScriptEditor::fileOpened, [editor, this](QString fileName) {
mRecentFiles.removeAll(fileName);
mRecentFiles.prepend(fileName);
updateRecentList();
setEditorClean(editor);
});
connect(editor, &ScriptEditor::fileSaved, [editor, this](QString fileName) {
if (mVesc) {
Expand Down Expand Up @@ -702,19 +703,20 @@ void PageLisp::on_helpButton_clicked()
"in the lisp-scripting chat at<br>"
"<a href=\"https://discord.gg/JgvV5NwYts\">https://discord.gg/JgvV5NwYts</a><br><br>"
"<b>Keyboard Commands</b><br>"
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected lines<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Upload (and run if set) application<br>"
"Ctrl + 'w' : Stream application<br>"
"Ctrl + 'q' : Stop application<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>"
"Ctrl + 'r' : Run selected block in REPL<br>";
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected lines<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Upload (and run if set) application<br>"
"Ctrl + 'w' : Stream application<br>"
"Ctrl + 'q' : Stop application<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>"
"Ctrl + 'r' : Run selected block in REPL<br>"
"Ctrl + Shift + 'd' : Duplicate current line<br>";

HelpDialog::showHelpMonospace(this, "VESC Tool Script Editor", html);
}
Expand Down
32 changes: 17 additions & 15 deletions pages/pagescripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,11 @@ void PageScripting::makeEditorConnections(ScriptEditor *editor)
connect(editor->codeEditor(), &QCodeEditor::clearConsoleTriggered, [this]() {
ui->debugEdit->clear();
});
connect(editor, &ScriptEditor::fileOpened, [this](QString fileName) {
connect(editor, &ScriptEditor::fileOpened, [editor, this](QString fileName) {
mRecentFiles.removeAll(fileName);
mRecentFiles.prepend(fileName);
updateRecentList();
setEditorClean(editor);
});
connect(editor, &ScriptEditor::fileSaved, [editor, this](QString fileName) {
if (mVesc) {
Expand Down Expand Up @@ -711,20 +712,21 @@ bool PageScripting::eraseQml(int size, bool reload)
void PageScripting::on_helpButton_clicked()
{
QString html = "<b>Keyboard Commands</b><br>"
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected line or block<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Run or restart embedded<br>"
"Ctrl + 'w' : Run or restart window<br>"
"Ctrl + 'q' : Stop code<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>";

HelpDialog::showHelpMonospace(this, "VESC Tool Script Editor", html.replace(" ","&nbsp;"));
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected line or block<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Run or restart embedded<br>"
"Ctrl + 'w' : Run or restart window<br>"
"Ctrl + 'q' : Stop code<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>"
"Ctrl + Shift + 'd' : Duplicate current line<br>";

HelpDialog::showHelpMonospace(this, "VESC Tool Script Editor", html);
}

void PageScripting::on_exportCArrayHwButton_clicked()
Expand Down
2 changes: 2 additions & 0 deletions res/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#### Released TBD
* Auto-save UI-state on regular intervals.
* Movable lisp-tabs and better tab behavior in general.
* Detect file system changes in script editor.
* Duplicate line shortcut in script editor.

### 6.05
#### Released 2024-08-19
Expand Down
66 changes: 51 additions & 15 deletions widgets/scripteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ ScriptEditor::ScriptEditor(QWidget *parent) :
ui->saveButton->setIcon(Utility::getIcon("icons/Save-96.png"));
ui->saveAsButton->setIcon(Utility::getIcon("icons/Save as-96.png"));
ui->refreshButton->setIcon(Utility::getIcon("icons/Refresh-96.png"));
ui->fileChangedReloadButton->setIcon(Utility::getIcon("icons/Refresh-96.png"));
ui->fileChangeIgnoreButton->setIcon(Utility::getIcon("icons/Cancel-96.png"));
ui->fileChangedWidget->setStyleSheet("background-color:rgba(200, 52, 52, 100);");
ui->searchWidget->setVisible(false);
ui->fileChangedWidget->setVisible(false);
ui->codeEdit->setTabReplaceSize(4);

connect(ui->codeEdit, &QCodeEditor::saveTriggered, [this]() {
on_saveButton_clicked();
});

connect(ui->codeEdit, &QCodeEditor::searchTriggered, [this]() {
ui->searchWidget->setVisible(true);
auto selected = ui->codeEdit->textCursor().selectedText();
Expand All @@ -57,6 +62,19 @@ ScriptEditor::ScriptEditor(QWidget *parent) :
ui->searchEdit->setFocus();
ui->searchEdit->selectAll();
});

connect(&mFsWatcher, &QFileSystemWatcher::fileChanged, [this](const QString &path) {
(void)path;

if (hasUnsavedContent()) {
ui->fileChangedWidget->setVisible(true);
ui->codeEdit->setEnabled(false);
}

if (!mFsWatcher.files().contains(path)) {
mFsWatcher.addPath(path);
}
});
}

ScriptEditor::~ScriptEditor()
Expand All @@ -77,6 +95,13 @@ QString ScriptEditor::fileNow()
void ScriptEditor::setFileNow(QString fileName)
{
ui->fileNowLabel->setText(fileName);

mFsWatcher.removePaths(mFsWatcher.files());
QFileInfo f(fileName);
if (f.exists()) {
mFsWatcher.addPath(fileName);
}

emit fileNameChanged(fileName);
}

Expand Down Expand Up @@ -105,7 +130,7 @@ QString ScriptEditor::contentAsText()
QString res = ui->codeEdit->toPlainText();

if (!QSettings().value("scripting/uploadContentEditor", true).toBool()) {
QString fileName = ui->fileNowLabel->text();
QString fileName = fileNow();

QFileInfo fi(fileName);
if (!fi.exists()) {
Expand All @@ -129,7 +154,7 @@ bool ScriptEditor::hasUnsavedContent()
{
bool res = false;

QString fileName = ui->fileNowLabel->text();
QString fileName = fileNow();
QFileInfo fi(fileName);
if (!fi.exists()) {
// Use a threshold of 5 characters
Expand Down Expand Up @@ -160,7 +185,7 @@ void ScriptEditor::keyPressEvent(QKeyEvent *event)

void ScriptEditor::on_openFileButton_clicked()
{
QString path = ui->fileNowLabel->text();
QString path = fileNow();
if (path.isEmpty()) {
path = QSettings().value("scripting/lastPath", "").toString();
}
Expand All @@ -180,8 +205,7 @@ void ScriptEditor::on_openFileButton_clicked()
QSettings().setValue("scripting/lastPath", QFileInfo(file).canonicalPath());

ui->codeEdit->setPlainText(file.readAll());
ui->fileNowLabel->setText(fileName);
emit fileNameChanged(fileName);
setFileNow(fileName);

emit fileOpened(fileName);

Expand All @@ -191,7 +215,7 @@ void ScriptEditor::on_openFileButton_clicked()

void ScriptEditor::on_saveButton_clicked()
{
QString fileName = ui->fileNowLabel->text();
QString fileName = fileNow();

QFileInfo fi(fileName);
if (!fi.exists()) {
Expand All @@ -206,22 +230,24 @@ void ScriptEditor::on_saveButton_clicked()
return;
}

mFsWatcher.removePaths(mFsWatcher.files());
file.write(ui->codeEdit->toPlainText().toUtf8());
file.close();
mFsWatcher.addPath(fileName);

emit fileSaved(fileName);
}

void ScriptEditor::on_saveAsButton_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save %1").arg(mIsModeLisp ? "Lisp" : "Qml"), ui->fileNowLabel->text(),
tr("Save %1").arg(mIsModeLisp ? "Lisp" : "Qml"), fileNow(),
mIsModeLisp ? tr("Lisp files (*.lisp)") : tr("QML files (*.qml)"));

QString ending = mIsModeLisp ? ".lisp" : ".qml";

if (!fileName.isEmpty()) {
if (!fileName.toLower().endsWith(ending)) {
if (!fileName.endsWith(ending, Qt::CaseInsensitive)) {
fileName.append(ending);
}

Expand All @@ -232,12 +258,11 @@ void ScriptEditor::on_saveAsButton_clicked()
return;
}

mFsWatcher.removePaths(mFsWatcher.files());
file.write(ui->codeEdit->toPlainText().toUtf8());
file.close();

ui->fileNowLabel->setText(fileName);
emit fileNameChanged(fileName);

setFileNow(fileName);
emit fileSaved(fileName);
}
}
Expand Down Expand Up @@ -290,7 +315,7 @@ void ScriptEditor::on_searchCaseSensitiveBox_toggled(bool checked)

void ScriptEditor::on_refreshButton_clicked()
{
QString fileName = ui->fileNowLabel->text();
QString fileName = fileNow();

QFileInfo fi(fileName);
if (!fi.exists()) {
Expand All @@ -306,10 +331,8 @@ void ScriptEditor::on_refreshButton_clicked()
}

ui->codeEdit->setPlainText(QString::fromUtf8(file.readAll()));
ui->fileNowLabel->setText(fileName);
emit fileOpened(fileName);

file.close();
emit fileOpened(fileName);
}

void ScriptEditor::on_searchEdit_returnPressed()
Expand All @@ -320,3 +343,16 @@ void ScriptEditor::on_searchEdit_returnPressed()
ui->codeEdit->searchNextResult();
}
}

void ScriptEditor::on_fileChangeIgnoreButton_clicked()
{
ui->fileChangedWidget->setVisible(false);
ui->codeEdit->setEnabled(true);
ui->codeEdit->setFocus();
}

void ScriptEditor::on_fileChangedReloadButton_clicked()
{
on_refreshButton_clicked();
on_fileChangeIgnoreButton_clicked();
}
4 changes: 4 additions & 0 deletions widgets/scripteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <QWidget>
#include <QCodeEditor>
#include <QFileSystemWatcher>

namespace Ui {
class ScriptEditor;
Expand Down Expand Up @@ -66,10 +67,13 @@ private slots:
void on_searchCaseSensitiveBox_toggled(bool checked);
void on_refreshButton_clicked();
void on_searchEdit_returnPressed();
void on_fileChangeIgnoreButton_clicked();
void on_fileChangedReloadButton_clicked();

private:
Ui::ScriptEditor *ui;
bool mIsModeLisp;
QFileSystemWatcher mFsWatcher;

};

Expand Down
Loading

0 comments on commit dbd5354

Please sign in to comment.