Skip to content

Commit

Permalink
Add "New program" action #32
Browse files Browse the repository at this point in the history
This action allows for the user to create a new program. This will check whether
the current program should be saved, and if so, present the user with save
options.
  • Loading branch information
mortbopet committed Mar 31, 2019
1 parent 5ac2fb7 commit 4764aa1
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 0 deletions.
44 changes: 44 additions & 0 deletions resources/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<file>spreadsheet.svg</file>
<file>documents.svg</file>
<file>logo.svg</file>
<file>file.svg</file>
</qresource>
</RCC>
43 changes: 43 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QMessageBox>
#include <QPushButton>
#include <QTextStream>

#include "parser.h"

#include "programfiletab.h"
Expand Down Expand Up @@ -203,3 +204,45 @@ void MainWindow::on_actionSave_Files_As_triggered() {
on_actionSave_Files_triggered();
}
}

void MainWindow::on_actionNew_Program_triggered() {
QMessageBox mbox;
mbox.setWindowTitle("New Program...");
mbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (!m_ui->programfiletab->getAssemblyText().isEmpty() && m_currentFile.isEmpty()) {
// User wrote a program but did not save it to a file yet
mbox.setText("Save program before creating new file?");
auto ret = mbox.exec();
switch (ret) {
case QMessageBox::Yes: {
on_actionSave_Files_As_triggered();
break;
}
case QMessageBox::No: {
break;
}
case QMessageBox::Cancel: {
return;
}
}
} else if (!m_currentFile.isEmpty()) {
// User previously stored a program but may have updated in the meantime - prompt to ask whether the program
// should be stored to the current file name
mbox.setText(QString("Save program \"%1\" before creating new file?").arg(m_currentFile));
auto ret = mbox.exec();
switch (ret) {
case QMessageBox::Yes: {
on_actionSave_Files_triggered();
break;
}
case QMessageBox::No: {
break;
}
case QMessageBox::Cancel: {
return;
}
}
}
m_currentFile.clear();
m_ui->programfiletab->newProgram();
}
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private slots:

void on_actionSave_Files_As_triggered();

void on_actionNew_Program_triggered();

signals:
void update();
void updateMemoryTab();
Expand Down
10 changes: 10 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<addaction name="actionSave_as_text"/>
<addaction name="actionSave_as_flat_binary"/>
</widget>
<addaction name="actionNew_Program"/>
<addaction name="actionLoadBinaryFile"/>
<addaction name="actionLoadAssemblyFile"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -274,6 +275,15 @@
<string>Save as flat binary</string>
</property>
</action>
<action name="actionNew_Program">
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/file.svg</normaloff>:/icons/file.svg</iconset>
</property>
<property name="text">
<string>New Program...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
6 changes: 6 additions & 0 deletions src/programfiletab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ void ProgramfileTab::setTimerEnabled(bool state) {
m_ui->assemblyedit->setTimerEnabled(state);
}

void ProgramfileTab::newProgram() {
m_ui->assemblyfile->toggle();
m_ui->assemblyedit->reset();
m_ui->assemblyedit->clear();
}

void ProgramfileTab::on_pushButton_clicked() {
// load file based on current file type selection
if (m_ui->binaryfile->isChecked()) {
Expand Down
1 change: 1 addition & 0 deletions src/programfiletab.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ProgramfileTab : public QWidget {
void clearOutputArray();
QString getAssemblyText();
const QByteArray& getBinaryData();
void newProgram();

signals:
void loadBinaryFile();
Expand Down

0 comments on commit 4764aa1

Please sign in to comment.