cutter/src/dialogs/MapFileDialog.cpp

48 lines
1.2 KiB
C++
Raw Normal View History

2020-04-07 13:20:52 +00:00
#include "MapFileDialog.h"
#include "ui_MapFileDialog.h"
2018-06-20 09:24:28 +00:00
#include "common/Configuration.h"
2018-06-20 09:24:28 +00:00
#include <QFileDialog>
2020-04-07 13:20:52 +00:00
MapFileDialog::MapFileDialog(QWidget *parent):
2018-06-20 09:24:28 +00:00
QDialog(parent),
2020-04-07 13:20:52 +00:00
ui(new Ui::MapFileDialog)
2018-06-20 09:24:28 +00:00
{
ui->setupUi(this);
}
2020-04-07 13:20:52 +00:00
MapFileDialog::~MapFileDialog() {}
2018-06-20 09:24:28 +00:00
2020-04-07 13:20:52 +00:00
void MapFileDialog::on_selectFileButton_clicked()
2018-06-20 09:24:28 +00:00
{
QString currentDir = Config()->getRecentFolder();
QString fileName = QFileDialog::getOpenFileName(this, tr("Select file"), currentDir);
2018-06-20 09:24:28 +00:00
if (!fileName.isEmpty()) {
ui->filenameLineEdit->setText(fileName);
Config()->setRecentFolder(QFileInfo(fileName).absolutePath());
2018-06-20 09:24:28 +00:00
}
}
2020-04-07 13:20:52 +00:00
void MapFileDialog::on_buttonBox_accepted()
2018-06-20 09:24:28 +00:00
{
const QString &filePath = QDir::toNativeSeparators(ui->filenameLineEdit->text());
2018-06-20 09:24:28 +00:00
RVA mapAddress = RVA_INVALID;
QString mapAddressStr = ui->mapAddressLineEdit->text();
if (!mapAddressStr.isEmpty()) {
2018-06-20 09:24:28 +00:00
mapAddress = Core()->math(mapAddressStr);
}
2020-04-07 13:20:52 +00:00
if (!Core()->mapFile(filePath, mapAddress)) {
QMessageBox::critical(this, tr("Map new file file"), tr("Failed to map a new file"));
return;
}
close();
2018-06-20 09:24:28 +00:00
}
2020-04-07 13:20:52 +00:00
void MapFileDialog::on_buttonBox_rejected()
2018-06-20 09:24:28 +00:00
{
close();
}