diff --git a/src/drivers/Qt/HexEditor.cpp b/src/drivers/Qt/HexEditor.cpp index 3172fc8f..cc1a59f4 100644 --- a/src/drivers/Qt/HexEditor.cpp +++ b/src/drivers/Qt/HexEditor.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "../../types.h" @@ -308,6 +309,14 @@ HexEditorDialog_t::HexEditorDialog_t(QWidget *parent) saveROM->setStatusTip(tr("Save ROM File")); connect(saveROM, SIGNAL(triggered()), this, SLOT(saveRomFile(void)) ); + fileMenu->addAction(saveROM); + + // File -> Save ROM As + saveROM = new QAction(tr("Save ROM As"), this); + //saveROM->setShortcuts(QKeySequence::Open); + saveROM->setStatusTip(tr("Save ROM File As")); + connect(saveROM, SIGNAL(triggered()), this, SLOT(saveRomFileAs(void)) ); + fileMenu->addAction(saveROM); // View @@ -524,7 +533,52 @@ void HexEditorDialog_t::gotoAddress( int newAddr ) //---------------------------------------------------------------------------- void HexEditorDialog_t::saveRomFile(void) { - printf("ROM File: '%s'\n", getRomFile() ); + //FlushUndoBuffer(); + iNesSave(); + //UpdateColorTable(); +} +//---------------------------------------------------------------------------- +void HexEditorDialog_t::saveRomFileAs(void) +{ + int ret, useNativeFileDialogVal; + QString filename; + QFileDialog dialog(this, tr("Save ROM To File") ); + + dialog.setFileMode(QFileDialog::AnyFile); + + dialog.setNameFilter(tr("NES Files (*.nes *.NES) ;; All files (*)")); + + dialog.setViewMode(QFileDialog::List); + dialog.setFilter( QDir::AllEntries | QDir::Hidden ); + dialog.setLabelText( QFileDialog::Accept, tr("Save") ); + dialog.setDefaultSuffix( tr(".nes") ); + + // Check config option to use native file dialog or not + g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); + + dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + + dialog.show(); + ret = dialog.exec(); + + if ( ret ) + { + QStringList fileList; + fileList = dialog.selectedFiles(); + + if ( fileList.size() > 0 ) + { + filename = fileList[0]; + } + } + + if ( filename.isNull() ) + { + return; + } + qDebug() << "selected file path : " << filename.toUtf8(); + + iNesSaveAs( filename.toStdString().c_str() ); } //---------------------------------------------------------------------------- void HexEditorDialog_t::setViewRAM(void) diff --git a/src/drivers/Qt/HexEditor.h b/src/drivers/Qt/HexEditor.h index 059a5d86..b21a5f82 100644 --- a/src/drivers/Qt/HexEditor.h +++ b/src/drivers/Qt/HexEditor.h @@ -158,6 +158,7 @@ class HexEditorDialog_t : public QDialog void vbarChanged(int value); void hbarChanged(int value); void saveRomFile(void); + void saveRomFileAs(void); void setViewRAM(void); void setViewPPU(void); void setViewOAM(void); diff --git a/src/ines.cpp b/src/ines.cpp index 1b75ae07..00abebeb 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -956,7 +956,7 @@ init_ok: } // bbit edited: the whole function below was added -int iNesSave() { +int iNesSave(void) { char name[2048]; strcpy(name, LoadedRomFName); @@ -967,7 +967,7 @@ int iNesSave() { return iNesSaveAs(name); } -int iNesSaveAs(char* name) +int iNesSaveAs(const char* name) { //adelikat: TODO: iNesSave() and this have pretty much the same code, outsource the common code to a single function //caitsith2: done. iNesSave() now gets filename and calls iNesSaveAs with that filename. diff --git a/src/ines.h b/src/ines.h index 6ad2657b..6f9d65e8 100644 --- a/src/ines.h +++ b/src/ines.h @@ -43,8 +43,8 @@ extern uint8 *VROM; extern uint32 VROM_size; extern uint32 ROM_size; extern uint8 *ExtraNTARAM; -extern int iNesSave(); //bbit Edited: line added -extern int iNesSaveAs(char* name); +extern int iNesSave(void); //bbit Edited: line added +extern int iNesSaveAs(const char* name); extern char LoadedRomFName[2048]; //bbit Edited: line added extern const TMasterRomInfo* MasterRomInfo; extern TMasterRomInfoParams MasterRomInfoParams;