Add "New program" action
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.
ADD
resources/file.svg
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ viewBox="0 0 58 58" style="enable-background:new 0 0 58 58;" xml:space="preserve">
+<polygon style="fill:#EDEADA;" points="51.5,14 37.5,0 6.5,0 6.5,58 51.5,58 "/>
+<g>
+ <path style="fill:#CEC9AE;" d="M16.5,23h25c0.552,0,1-0.447,1-1s-0.448-1-1-1h-25c-0.552,0-1,0.447-1,1S15.948,23,16.5,23z"/>
+ <path style="fill:#CEC9AE;" d="M16.5,15h10c0.552,0,1-0.447,1-1s-0.448-1-1-1h-10c-0.552,0-1,0.447-1,1S15.948,15,16.5,15z"/>
+ <path style="fill:#CEC9AE;" d="M41.5,29h-25c-0.552,0-1,0.447-1,1s0.448,1,1,1h25c0.552,0,1-0.447,1-1S42.052,29,41.5,29z"/>
+ <path style="fill:#CEC9AE;" d="M41.5,37h-25c-0.552,0-1,0.447-1,1s0.448,1,1,1h25c0.552,0,1-0.447,1-1S42.052,37,41.5,37z"/>
+ <path style="fill:#CEC9AE;" d="M41.5,45h-25c-0.552,0-1,0.447-1,1s0.448,1,1,1h25c0.552,0,1-0.447,1-1S42.052,45,41.5,45z"/>
+</g>
+<polygon style="fill:#CEC9AE;" points="37.5,0 37.5,14 51.5,14 "/>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+</svg>

MODIFY
resources/images.qrc
resources/images.qrc
<file>spreadsheet.svg</file>
<file>documents.svg</file>
<file>logo.svg</file>
+ <file>file.svg</file>
</qresource>
</RCC>

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
#include <QMessageBox>
#include <QPushButton>
#include <QTextStream>
+
#include "parser.h"
#include "programfiletab.h"
@@ -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();
+}

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -34,6 +34,8 @@ private slots:
void on_actionSave_Files_As_triggered();
+ void on_actionNew_Program_triggered();
+
signals:
void update();
void updateMemoryTab();

MODIFY
src/mainwindow.ui
src/mainwindow.ui
<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"/>
<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>

MODIFY
src/programfiletab.cpp
src/programfiletab.cpp
@@ -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()) {

MODIFY
src/programfiletab.h
src/programfiletab.h
@@ -22,6 +22,7 @@ public:
void clearOutputArray();
QString getAssemblyText();
const QByteArray& getBinaryData();
+ void newProgram();
signals:
void loadBinaryFile();

Add "New program" action #32

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.