[partition] Centralize setting-of-mountpoint

- map empty to the 0'th index
 - add new entries as needed

This avoids having selected index 0, but a different text.
main
Adriaan de Groot 7 years ago
parent a49c39bb53
commit 4402198b37

@ -328,7 +328,7 @@ CreatePartitionDialog::initFromPartitionToCreate( Partition* partition )
m_ui->fsComboBox->setCurrentText( FileSystem::nameForType( fsType ) );
// Mount point
m_ui->mountPointComboBox->setCurrentText( PartitionInfo::mountPoint( partition ) );
setSelectedMountPoint( m_ui->mountPointComboBox, PartitionInfo::mountPoint( partition ) );
updateMountPointUi();
}

@ -65,3 +65,24 @@ selectedMountPoint(QComboBox& combo)
return QString();
return combo.currentText();
}
void
setSelectedMountPoint(QComboBox& combo, const QString& selected)
{
cDebug() << "Setting mount point" << selected;
if ( selected.isEmpty() )
combo.setCurrentIndex( 0 ); // (no mount point)
else
{
for ( int i = 0; i < combo.count(); ++i )
if ( selected == combo.itemText( i ) )
{
cDebug() << " .. found at index" << i;
combo.setCurrentIndex( i );
return;
}
cDebug() << " .. new item";
combo.addItem( selected );
combo.setCurrentIndex( combo.count() - 1);
}
}

@ -53,5 +53,7 @@ void standardMountPoints( QComboBox&, const QString& selected );
QString selectedMountPoint( QComboBox& combo );
static inline QString selectedMountPoint(QComboBox* combo) { return selectedMountPoint(*combo); }
void setSelectedMountPoint( QComboBox& combo, const QString& selected );
static inline void setSelectedMountPoint(QComboBox* combo, const QString& selected) { setSelectedMountPoint( *combo, selected); }
#endif

Loading…
Cancel
Save