Allow selecting between textual or flat binary when storing binary data
MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -31,6 +31,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
connect(m_ui->tabbar, &FancyTabBar::activeIndexChanged, m_ui->stackedWidget, &QStackedWidget::setCurrentIndex);
m_ui->tabbar->setActiveIndex(0);
+ m_binaryStoreAction = new QActionGroup(this);
+ m_binaryStoreAction->addAction(m_ui->actionSave_as_flat_binary);
+ m_binaryStoreAction->addAction(m_ui->actionSave_as_text);
+ m_binaryStoreAction->addAction(m_ui->actionDisable);
+ m_binaryStoreAction->setExclusive(true);
+ m_ui->actionDisable->setChecked(true);
+
// Setup tab pointers
m_ui->processortab->initRegWidget();
m_ui->processortab->initInstructionView();
@@ -176,9 +183,13 @@ void MainWindow::on_actionSave_Files_triggered() {
writeTextFile(file, Parser::getParser()->getDisassembledRepr());
}
- if (m_ui->actionSave_Binary->isChecked()) {
+ QAction* binaryStoreAction = m_binaryStoreAction->checkedAction();
+ if (binaryStoreAction == m_ui->actionSave_as_flat_binary) {
QFile file(removeFileExt(m_currentFile) + ".bin");
writeBinaryFile(file, m_ui->programfiletab->getBinaryData());
+ } else if (binaryStoreAction == m_ui->actionSave_as_text) {
+ QFile file(removeFileExt(m_currentFile) + "_bin.txt");
+ writeTextFile(file, Parser::getParser()->getBinaryRepr());
}
}

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -7,6 +7,8 @@ namespace Ui {
class MainWindow;
}
+QT_FORWARD_DECLARE_CLASS(QActionGroup)
+
class MainWindow : public QMainWindow {
Q_OBJECT
@@ -40,6 +42,7 @@ private:
Ui::MainWindow* m_ui;
void setupExamples();
QString m_currentFile = QString();
+ QActionGroup* m_binaryStoreAction;
};
#endif // MAINWINDOW_H

MODIFY
src/mainwindow.ui
src/mainwindow.ui
<string>Load Example...</string>
</property>
</widget>
+ <widget class="QMenu" name="menuSave_Binary">
+ <property name="title">
+ <string>Save Binary</string>
+ </property>
+ <addaction name="actionDisable"/>
+ <addaction name="actionSave_as_text"/>
+ <addaction name="actionSave_as_flat_binary"/>
+ </widget>
<addaction name="actionLoadBinaryFile"/>
<addaction name="actionLoadAssemblyFile"/>
<addaction name="separator"/>
<addaction name="actionSave_Files_As"/>
<addaction name="actionSave_Source"/>
<addaction name="actionSave_Disassembled"/>
- <addaction name="actionSave_Binary"/>
+ <addaction name="menuSave_Binary"/>
<addaction name="separator"/>
<addaction name="actionexit"/>
</widget>
<string>Save Disassembled</string>
</property>
</action>
- <action name="actionSave_Binary">
+ <action name="actionDisable">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
- <string>Save Binary</string>
+ <string>Disable</string>
+ </property>
+ </action>
+ <action name="actionSave_as_text">
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Save as text</string>
+ </property>
+ </action>
+ <action name="actionSave_as_flat_binary">
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Save as flat binary</string>
</property>
</action>
</widget>

Allow selecting between textual or flat binary when storing binary data