Remove files from Settings::recentFileList(), if they fail to open. (#268)

- i.e. they no longer exist or have been moved
- update recent file menu in StartupView as Settings change
This commit is contained in:
Jaye Evins
2025-12-17 21:26:30 -05:00
committed by GitHub
parent aba0f11616
commit 90e236f847
5 changed files with 66 additions and 12 deletions
+4
View File
@@ -130,6 +130,8 @@ namespace glabels
}
else
{
model::Settings::removeFromRecentFileList( fileName );
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
@@ -168,6 +170,8 @@ namespace glabels
}
else
{
model::Settings::removeFromRecentFileList( fileName );
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
+39 -12
View File
@@ -47,18 +47,9 @@ namespace glabels
recentProjectButton->setEnabled( model::Settings::recentFileList().size() > 0 );
auto* recentMenu = new QMenu();
for ( auto& filename : model::Settings::recentFileList() )
{
QString basename = QFileInfo( filename ).completeBaseName();
auto* action = new QAction( basename, this );
action->setIcon( QIcon::fromTheme( "glabels" ) );
action->setData( filename );
connect( action, SIGNAL(triggered()), this, SLOT(onOpenRecentAction()) );
recentMenu->addAction( action );
}
recentMenu->setMinimumWidth( recentProjectButton->minimumWidth() );
recentProjectButton->setMenu( recentMenu );
loadRecentsMenu();
connect( model::Settings::instance(), SIGNAL(changed()), this, SLOT(onSettingsChanged()) );
}
@@ -92,4 +83,40 @@ namespace glabels
}
}
///
/// Settings changed Slot
///
void StartupView::onSettingsChanged()
{
// reload recents menu
loadRecentsMenu();
}
///
/// Create recents menu
///
void StartupView::loadRecentsMenu()
{
auto fileList = model::Settings::recentFileList();
auto* recentMenu = new QMenu();
for ( auto& filename : fileList )
{
QString basename = QFileInfo( filename ).completeBaseName();
auto* action = new QAction( basename, this );
action->setIcon( QIcon::fromTheme( "glabels" ) );
action->setData( filename );
connect( action, SIGNAL(triggered()), this, SLOT(onOpenRecentAction()) );
recentMenu->addAction( action );
}
recentMenu->setMinimumWidth( recentProjectButton->minimumWidth() );
recentProjectButton->setMenu( recentMenu );
recentProjectButton->setEnabled( fileList.size() != 0 );
}
} // namespace glabels
+8
View File
@@ -54,8 +54,16 @@ namespace glabels
void onNewProjectButtonClicked();
void onOpenProjectButtonClicked();
void onOpenRecentAction();
void onSettingsChanged();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadRecentsMenu();
/////////////////////////////////
// Private data
/////////////////////////////////
+14
View File
@@ -358,6 +358,20 @@ namespace glabels
}
void Settings::removeFromRecentFileList( const QString& filePath )
{
mInstance->beginGroup( "Recent" );
QStringList list = mInstance->value( "files" ).toStringList();
list.removeAll( filePath );
mInstance->setValue( "files", list );
mInstance->endGroup();
emit mInstance->changed();
}
QString Settings::recentPrinter()
{
mInstance->beginGroup( "Recent" );
+1
View File
@@ -101,6 +101,7 @@ namespace glabels
static int maxRecentFiles();
static QStringList recentFileList();
static void addToRecentFileList( const QString& filePath );
static void removeFromRecentFileList( const QString& filePath );
static QString recentPrinter();
static void setRecentPrinter( const QString& printer );