Skip to content

Commit

Permalink
Fixed issues with empty recent file menus
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Feb 16, 2025
1 parent 313ed77 commit 1567b62
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fixed the light direction being reset on changes to the render settings.
* Fixed loading Fallout 76 and Starfield cube maps with legacy DDS header.
* Fixed restoring the background color after silhouette mode.
* Fixed issues with empty recent file menus (e.g. recent archive files before opening an archive).
* Minor optimizations: faster cube map filtering, and use of SIMD data types in 'noavx' GCC and Clang builds.

#### NifSkope-2.0.dev9-20250130
Expand Down
53 changes: 28 additions & 25 deletions src/nifskope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,15 +611,25 @@ int updateRecentActions( QAction * acts[], const QStringList & files )
{
int numRecentFiles = std::min< qsizetype >( files.size(), NifSkope::NumRecentFiles );

for ( int i = 0; i < numRecentFiles; ++i ) {
QString text = QString( "&%1 %2" ).arg( i + 1 ).arg( strippedName( files[i] ) );
for ( int i = 0; i < NifSkope::NumRecentFiles; ++i ) {
QString fileName;
QString text;
if ( i >= numRecentFiles ) {
if ( i > 0 ) {
acts[i]->setVisible( false );
continue;
}
text = "<None>";
} else {
fileName = files[i];
text = QString( "&%1 %2" ).arg( i + 1 ).arg( strippedName( files[i] ) );
}
acts[i]->setText( text );
acts[i]->setData( files[i] );
acts[i]->setStatusTip( files[i] );
acts[i]->setData( fileName );
acts[i]->setStatusTip( fileName );
acts[i]->setVisible( true );
}
for ( int j = numRecentFiles; j < NifSkope::NumRecentFiles; ++j )
acts[j]->setVisible( false );
acts[0]->setEnabled( numRecentFiles > 0 );

return numRecentFiles;
}
Expand All @@ -639,10 +649,7 @@ void NifSkope::updateRecentFileActions()
QSettings settings;
QStringList files = settings.value( "File/Recent File List" ).toStringList();

int numRecentFiles = ::updateRecentActions( recentFileActs, files );

aRecentFilesSeparator->setVisible( numRecentFiles > 0 );
ui->mRecentFiles->setEnabled( numRecentFiles > 0 );
::updateRecentActions( recentFileActs, files );
}

void NifSkope::updateAllRecentFileActions()
Expand Down Expand Up @@ -737,12 +744,13 @@ void NifSkope::setCurrentArchive( bool isArchiveFolder )
archiveName += "/*.bsa,*.ba2";
currentArchiveNames += archiveName;

QSettings settings;
QStringList files = settings.value( "File/Recent Archive List" ).toStringList();
::updateRecentFiles( files, currentArchivePath );

settings.setValue( "File/Recent Archive List", files );
{
QSettings settings;
QStringList files = settings.value( "File/Recent Archive List" ).toStringList();
::updateRecentFiles( files, currentArchivePath );

settings.setValue( "File/Recent Archive List", files );
}
updateAllRecentFileActions();
}

Expand Down Expand Up @@ -770,24 +778,19 @@ void NifSkope::updateRecentArchiveActions()
QSettings settings;
QStringList files = settings.value( "File/Recent Archive List" ).toStringList();

int numRecentFiles = ::updateRecentActions( recentArchiveActs, files );

ui->mRecentArchives->setEnabled( numRecentFiles > 0 );
::updateRecentActions( recentArchiveActs, files );
}

void NifSkope::updateRecentArchiveFileActions()
{
QSettings settings;
QHash<QString, QVariant> hash = settings.value( "File/Recent Archive Files" ).toHash();

if ( !currentArchive || currentArchiveNames.empty() )
return;

QStringList files = hash.value( currentArchiveNames.back() ).toStringList();

int numRecentFiles = ::updateRecentActions( recentArchiveFileActs, files );
QStringList files;
if ( currentArchive && !currentArchiveNames.empty() )
files = hash.value( currentArchiveNames.back() ).toStringList();

mRecentArchiveFiles->setEnabled( numRecentFiles > 0 );
::updateRecentActions( recentArchiveFileActs, files );
}

QModelIndex NifSkope::currentNifIndex() const
Expand Down
2 changes: 1 addition & 1 deletion src/nifskope_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void NifSkope::initMenu()

updateRecentFileActions();
updateRecentArchiveActions();
//updateRecentArchiveFileActions();
updateRecentArchiveFileActions();

// Lighting Menu
auto mLight = lightingWidget();
Expand Down

0 comments on commit 1567b62

Please sign in to comment.