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 else
{ {
model::Settings::removeFromRecentFileList( fileName );
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") ); msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok ); msgBox.setStandardButtons( QMessageBox::Ok );
@@ -168,6 +170,8 @@ namespace glabels
} }
else else
{ {
model::Settings::removeFromRecentFileList( fileName );
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") ); msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok ); msgBox.setStandardButtons( QMessageBox::Ok );
+39 -12
View File
@@ -47,18 +47,9 @@ namespace glabels
recentProjectButton->setEnabled( model::Settings::recentFileList().size() > 0 ); recentProjectButton->setEnabled( model::Settings::recentFileList().size() > 0 );
auto* recentMenu = new QMenu(); loadRecentsMenu();
for ( auto& filename : model::Settings::recentFileList() )
{ connect( model::Settings::instance(), SIGNAL(changed()), this, SLOT(onSettingsChanged()) );
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 );
} }
@@ -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 } // namespace glabels
+8
View File
@@ -54,6 +54,14 @@ namespace glabels
void onNewProjectButtonClicked(); void onNewProjectButtonClicked();
void onOpenProjectButtonClicked(); void onOpenProjectButtonClicked();
void onOpenRecentAction(); void onOpenRecentAction();
void onSettingsChanged();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadRecentsMenu();
///////////////////////////////// /////////////////////////////////
+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() QString Settings::recentPrinter()
{ {
mInstance->beginGroup( "Recent" ); mInstance->beginGroup( "Recent" );
+1
View File
@@ -101,6 +101,7 @@ namespace glabels
static int maxRecentFiles(); static int maxRecentFiles();
static QStringList recentFileList(); static QStringList recentFileList();
static void addToRecentFileList( const QString& filePath ); static void addToRecentFileList( const QString& filePath );
static void removeFromRecentFileList( const QString& filePath );
static QString recentPrinter(); static QString recentPrinter();
static void setRecentPrinter( const QString& printer ); static void setRecentPrinter( const QString& printer );