diff --git a/UEFITool/QHexView/src/qhexview.cpp b/UEFITool/QHexView/src/qhexview.cpp index 4055317..78ad475 100644 --- a/UEFITool/QHexView/src/qhexview.cpp +++ b/UEFITool/QHexView/src/qhexview.cpp @@ -466,7 +466,7 @@ void QHexView::checkState() { int doclines = static_cast(this->lines()), vislines = this->visibleLines(true); - qint64 vscrollmax = doclines - vislines + 1; // UEFITool: ensure the very last line is visible on macOS + qint64 vscrollmax = doclines - vislines; if(doclines >= vislines) vscrollmax++; diff --git a/UEFITool/uefitool.cpp b/UEFITool/uefitool.cpp index aa6ac32..b580e87 100644 --- a/UEFITool/uefitool.cpp +++ b/UEFITool/uefitool.cpp @@ -92,6 +92,9 @@ markingEnabled(true) // Read stored settings readSettings(); + + // Update recent files list in menu + updateRecentFilesMenu(); } UEFITool::~UEFITool() @@ -211,6 +214,38 @@ void UEFITool::updateUiForNewColorScheme(Qt::ColorScheme scheme) } #endif +void UEFITool::updateRecentFilesMenu(const QString& fileName) +{ + // Update list + if (!fileName.isEmpty()) { + recentFiles.removeAll(fileName); + recentFiles.prepend(fileName); + while (recentFiles.size() > 21) { + recentFiles.removeLast(); + } + } + + // Delete old actions + for (QAction* action : recentFileActions) { + ui->menuFile->removeAction(action); + delete action; + } + recentFileActions.clear(); + + if (!recentFiles.isEmpty()) { + // Insert new actions before "Quit" + for (const QString& path : recentFiles) { + QAction* action = new QAction(QDir::toNativeSeparators(path), this); + connect(action, SIGNAL(triggered()), this, SLOT(openRecentImageFile())); + action->setData(path); + ui->menuFile->insertAction(ui->actionQuit, action); + recentFileActions.append(action); + } + // Finally, insert a separator after the list and before "Quit" + recentFileActions.append(ui->menuFile->insertSeparator(ui->actionQuit)); + } +} + void UEFITool::populateUi(const QItemSelection &selected) { if (selected.isEmpty()) { @@ -518,7 +553,7 @@ void UEFITool::extract(const UINT8 mode) return; } - name = QDir::toNativeSeparators(currentDir + QDir::separator() + name); + name = QDir::toNativeSeparators(extractDir + QDir::separator() + name); //ui->statusBar->showMessage(name); @@ -568,6 +603,8 @@ void UEFITool::extract(const UINT8 mode) outputFile.resize(0); outputFile.write(extracted); outputFile.close(); + + extractDir = QFileInfo(path).absolutePath(); } void UEFITool::rebuild() @@ -621,18 +658,30 @@ void UEFITool::saveImageFile() void UEFITool::openImageFile() { - QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"), currentDir, tr("BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)")); + QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"), openImageDir, tr("BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)")); openImageFile(path); } void UEFITool::openImageFileInNewWindow() { - QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file in new window"), currentDir, tr("BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)")); + QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file in new window"), openImageDir, tr("BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)")); if (path.trimmed().isEmpty()) return; QProcess::startDetached(currentProgramPath, QStringList(path)); } +void UEFITool::openRecentImageFile() +{ + QAction* action = qobject_cast(sender()); + if (action) { + QString fileName = action->data().toString(); + if (!fileName.isEmpty()) { + openImageFile(fileName); + } + } +} + + void UEFITool::openImageFile(QString path) { if (path.trimmed().isEmpty()) @@ -701,9 +750,15 @@ void UEFITool::openImageFile(QString path) // Set current directory currentDir = fileInfo.absolutePath(); - + openImageDir = currentDir; + // Set current path currentPath = path; + + // Update menu + updateRecentFilesMenu(currentPath); + + ui->structureTreeView->expandToDepth(1); } void UEFITool::enableMessagesCopyActions(QListWidgetItem* item) @@ -945,6 +1000,10 @@ void UEFITool::readSettings() ui->structureTreeView->setColumnWidth(3, settings.value("tree/columnWidth3", ui->structureTreeView->columnWidth(3)).toInt()); markingEnabled = settings.value("tree/markingEnabled", true).toBool(); ui->actionToggleBootGuardMarking->setChecked(markingEnabled); + openImageDir = settings.value("paths/openImageDir", ".").toString(); + openGuidDatabaseDir = settings.value("paths/openGuidDatabaseDir", ".").toString(); + extractDir = settings.value("paths/extractDir", ".").toString(); + recentFiles = settings.value("paths/recentFiles").toStringList(); // Set monospace font QString fontName; @@ -980,6 +1039,10 @@ void UEFITool::writeSettings() settings.setValue("tree/markingEnabled", markingEnabled); settings.setValue("mainWindow/fontName", currentFont.family()); settings.setValue("mainWindow/fontSize", currentFont.pointSize()); + settings.setValue("paths/openImageDir", openImageDir); + settings.setValue("paths/openGuidDatabaseDir", openGuidDatabaseDir); + settings.setValue("paths/extractDir", extractDir); + settings.setValue("paths/recentFiles", recentFiles); } void UEFITool::showFitTable() @@ -1044,11 +1107,12 @@ void UEFITool::currentTabChanged(int index) void UEFITool::loadGuidDatabase() { - QString path = QFileDialog::getOpenFileName(this, tr("Select GUID database file to load"), currentDir, tr("Comma-separated values files (*.csv);;All files (*)")); + QString path = QFileDialog::getOpenFileName(this, tr("Select GUID database file to load"), openGuidDatabaseDir, tr("Comma-separated values files (*.csv);;All files (*)")); if (!path.isEmpty()) { initGuidDatabase(path); if (!currentPath.isEmpty() && QMessageBox::Yes == QMessageBox::information(this, tr("New GUID database loaded"), tr("Apply new GUID database on the opened file?\nUnsaved changes and tree position will be lost."), QMessageBox::Yes, QMessageBox::No)) openImageFile(currentPath); + openGuidDatabaseDir = QFileInfo(path).absolutePath(); } } diff --git a/UEFITool/uefitool.h b/UEFITool/uefitool.h index 08ef908..991a728 100644 --- a/UEFITool/uefitool.h +++ b/UEFITool/uefitool.h @@ -77,6 +77,7 @@ private slots: void openImageFile(); void openImageFileInNewWindow(); + void openRecentImageFile(); void saveImageFile(); void search(); @@ -144,9 +145,14 @@ private: GoToBaseDialog* goToBaseDialog; GoToAddressDialog* goToAddressDialog; QClipboard* clipboard; + QStringList recentFiles; + QList recentFileActions; QString currentDir; QString currentPath; QString currentProgramPath; + QString openImageDir; + QString openGuidDatabaseDir; + QString extractDir; QFont currentFont; const QString version; bool markingEnabled; @@ -155,6 +161,7 @@ private: void dragEnterEvent(QDragEnterEvent* event); void dropEvent(QDropEvent* event); void contextMenuEvent(QContextMenuEvent* event); + void updateRecentFilesMenu(const QString& fileName = QString()); void readSettings(); void showParserMessages(); void showFinderMessages(); diff --git a/UEFITool/uefitool.ui b/UEFITool/uefitool.ui index 51b6248..32cbf20 100644 --- a/UEFITool/uefitool.ui +++ b/UEFITool/uefitool.ui @@ -48,11 +48,11 @@ - Qt::Vertical + Qt::Orientation::Vertical - Qt::Horizontal + Qt::Orientation::Horizontal @@ -196,7 +196,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -311,7 +311,7 @@ 0 0 851 - 31 + 33 @@ -329,6 +329,7 @@ + @@ -699,7 +700,7 @@ F1 - QAction::AboutRole + QAction::MenuRole::AboutRole @@ -710,7 +711,7 @@ Shift+F1 - QAction::AboutQtRole + QAction::MenuRole::AboutQtRole @@ -721,7 +722,7 @@ Alt+X - QAction::QuitRole + QAction::MenuRole::QuitRole