diff --git a/mainwindow.cpp b/mainwindow.cpp index 8cd4086..379cd2b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,9 +1,6 @@ #include #include #include -#include -#include -#include #include "mainwindow.h" #include "ui_mainwindow.h" #include "triggerwidget.h" @@ -11,9 +8,7 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow), - codeEditor(this), - currentFilePath(""), - isFileModified(false) + codeEditor(this) { ui->setupUi(this); enumerateDevices(); @@ -28,22 +23,7 @@ MainWindow::MainWindow(QWidget *parent): 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->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() @@ -51,97 +31,6 @@ MainWindow::~MainWindow() 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() { size_t count = 0; diff --git a/mainwindow.h b/mainwindow.h index 508f1c2..7373d2b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -34,17 +34,9 @@ public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); -private slots: - void onActionOpenTriggered(); - void onActionSaveTriggered(); - void onActionSaveAsTriggered(); - private: void enumerateDevices(); - void generateExample(); - void updateTitle(); - QString currentFilePath; - bool isFileModified; + void generateExample(); }; #endif // MAINWINDOW_H