Track opened files, expand the first level of the item tree on file open

This commit is contained in:
Nikolaj Schlej 2025-04-28 17:05:34 +07:00
parent a072527138
commit ebf4f83ac9
4 changed files with 85 additions and 13 deletions

View file

@ -466,7 +466,7 @@ void QHexView::checkState() {
int doclines = static_cast<int>(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++;

View file

@ -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<QAction*>(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();
}
}

View file

@ -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<QAction*> 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();

View file

@ -48,11 +48,11 @@
<item>
<widget class="QSplitter" name="messagesSplitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<widget class="QSplitter" name="infoSplitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<widget class="QGroupBox" name="structureGroupBox">
<property name="title">
@ -196,7 +196,7 @@
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<widget class="QTableWidget" name="fitTableWidget"/>
</widget>
@ -311,7 +311,7 @@
<x>0</x>
<y>0</y>
<width>851</width>
<height>31</height>
<height>33</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -329,6 +329,7 @@
<addaction name="actionUnloadGuidDatabase"/>
<addaction name="actionExportDiscoveredGuids"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuHelp">
@ -699,7 +700,7 @@
<string>F1</string>
</property>
<property name="menuRole">
<enum>QAction::AboutRole</enum>
<enum>QAction::MenuRole::AboutRole</enum>
</property>
</action>
<action name="actionAboutQt">
@ -710,7 +711,7 @@
<string>Shift+F1</string>
</property>
<property name="menuRole">
<enum>QAction::AboutQtRole</enum>
<enum>QAction::MenuRole::AboutQtRole</enum>
</property>
</action>
<action name="actionQuit">
@ -721,7 +722,7 @@
<string>Alt+X</string>
</property>
<property name="menuRole">
<enum>QAction::QuitRole</enum>
<enum>QAction::MenuRole::QuitRole</enum>
</property>
</action>
<action name="actionSearch">