Compare commits
No commits in common. "5e91fd4a1ae57558d678b7aa06ff45251eab3923" and "a08cf6a682be32a3adbceb6d93e0c62f22ca4b28" have entirely different histories.
5e91fd4a1a
...
a08cf6a682
2 changed files with 2 additions and 121 deletions
113
mainwindow.cpp
113
mainwindow.cpp
|
|
@ -1,9 +1,6 @@
|
||||||
#include <eismultiplexer.h>
|
#include <eismultiplexer.h>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QFile>
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "triggerwidget.h"
|
#include "triggerwidget.h"
|
||||||
|
|
@ -11,9 +8,7 @@
|
||||||
MainWindow::MainWindow(QWidget *parent):
|
MainWindow::MainWindow(QWidget *parent):
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
codeEditor(this),
|
codeEditor(this)
|
||||||
currentFilePath(""),
|
|
||||||
isFileModified(false)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
enumerateDevices();
|
enumerateDevices();
|
||||||
|
|
@ -28,22 +23,7 @@ MainWindow::MainWindow(QWidget *parent):
|
||||||
|
|
||||||
ui->codeLayout->addWidget(&codeEditor);
|
ui->codeLayout->addWidget(&codeEditor);
|
||||||
|
|
||||||
// Set up keyboard shortcuts
|
|
||||||
ui->actionOpen->setShortcut(QKeySequence::Open);
|
|
||||||
ui->actionSave->setShortcut(QKeySequence::Save);
|
|
||||||
ui->actionSave_As->setShortcut(QKeySequence::SaveAs);
|
|
||||||
ui->actionQuit->setShortcut(QKeySequence::Quit);
|
|
||||||
|
|
||||||
connect(ui->actionQuit, &QAction::triggered, this, [this]() {close();});
|
connect(ui->actionQuit, &QAction::triggered, this, [this]() {close();});
|
||||||
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::onActionOpenTriggered);
|
|
||||||
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::onActionSaveTriggered);
|
|
||||||
connect(ui->actionSave_As, &QAction::triggered, this, &MainWindow::onActionSaveAsTriggered);
|
|
||||||
|
|
||||||
// Connect text changed signal to track modifications
|
|
||||||
connect(&codeEditor, &QTextEdit::textChanged, this, [this]() {
|
|
||||||
isFileModified = true;
|
|
||||||
updateTitle();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
@ -51,97 +31,6 @@ MainWindow::~MainWindow()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateTitle()
|
|
||||||
{
|
|
||||||
QString windowTitle = "EisMultiplexer-Qt";
|
|
||||||
if (!currentFilePath.isEmpty()) {
|
|
||||||
windowTitle = QString("%1 - %2").arg(currentFilePath);
|
|
||||||
}
|
|
||||||
if (isFileModified) {
|
|
||||||
windowTitle += "[*]";
|
|
||||||
}
|
|
||||||
setWindowTitle(windowTitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onActionOpenTriggered()
|
|
||||||
{
|
|
||||||
QString filePath = QFileDialog::getOpenFileName(this, tr("Open Python Script"),
|
|
||||||
"",
|
|
||||||
tr("Python Files (*.py);;All Files (*)"));
|
|
||||||
|
|
||||||
if (filePath.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile file(filePath);
|
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Could not open file: %1").arg(filePath));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTextStream in(&file);
|
|
||||||
QString content = in.readAll();
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
codeEditor.setPlainText(content);
|
|
||||||
currentFilePath = filePath;
|
|
||||||
isFileModified = false;
|
|
||||||
updateTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onActionSaveTriggered()
|
|
||||||
{
|
|
||||||
if (currentFilePath.isEmpty()) {
|
|
||||||
onActionSaveAsTriggered();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile file(currentFilePath);
|
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Could not save file: %1").arg(currentFilePath));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTextStream out(&file);
|
|
||||||
out << codeEditor.toPlainText();
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
isFileModified = false;
|
|
||||||
updateTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onActionSaveAsTriggered()
|
|
||||||
{
|
|
||||||
QString filePath = QFileDialog::getSaveFileName(this, tr("Save Python Script"),
|
|
||||||
"",
|
|
||||||
tr("Python Files (*.py);;All Files (*)"));
|
|
||||||
|
|
||||||
if (filePath.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the file has a .py extension if it's a Python file
|
|
||||||
if (filePath.endsWith(".py", Qt::CaseInsensitive)) {
|
|
||||||
// File already has .py extension
|
|
||||||
} else {
|
|
||||||
filePath += ".py";
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile file(filePath);
|
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Could not save file: %1").arg(filePath));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTextStream out(&file);
|
|
||||||
out << codeEditor.toPlainText();
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
currentFilePath = filePath;
|
|
||||||
isFileModified = false;
|
|
||||||
updateTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::enumerateDevices()
|
void MainWindow::enumerateDevices()
|
||||||
{
|
{
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,9 @@ public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onActionOpenTriggered();
|
|
||||||
void onActionSaveTriggered();
|
|
||||||
void onActionSaveAsTriggered();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void enumerateDevices();
|
void enumerateDevices();
|
||||||
void generateExample();
|
void generateExample();
|
||||||
void updateTitle();
|
|
||||||
QString currentFilePath;
|
|
||||||
bool isFileModified;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue