diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index 1e10ac512..060ee336d 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -67,6 +67,7 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent ) connect( m_core, &PartitionCoreModule::isDirtyChanged, m_ui->revertButton, &QWidget::setEnabled ); + connect( m_ui->partitionTreeView, &QAbstractItemView::activated, this, &PartitionPage::onPartitionViewActivated ); connect( m_ui->revertButton, &QAbstractButton::clicked, this, &PartitionPage::onRevertClicked ); connect( m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked ); connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked ); @@ -185,6 +186,29 @@ PartitionPage::onRevertClicked() updateFromCurrentDevice(); } +void +PartitionPage::onPartitionViewActivated() +{ + QModelIndex index = m_ui->partitionTreeView->currentIndex(); + if ( !index.isValid() ) + return; + + const PartitionModel* model = static_cast< const PartitionModel* >( index.model() ); + Q_ASSERT( model ); + Partition* partition = model->partitionForIndex( index ); + Q_ASSERT( partition ); + + // Use the buttons to trigger the actions so that they do nothing if they + // are disabled. Alternatively, the code could use QAction to centralize, + // but I don't expect there will be other occurences of triggering the same + // action from multiple UI elements in this page, so it does not feel worth + // the price. + if ( PMUtils::isPartitionFreeSpace( partition ) ) + m_ui->createButton->click(); + else + m_ui->editButton->click(); +} + void PartitionPage::updatePartitionToCreate( Device* device, Partition* partition ) { diff --git a/src/modules/partition/PartitionPage.h b/src/modules/partition/PartitionPage.h index 155ac7af4..aacb7d220 100644 --- a/src/modules/partition/PartitionPage.h +++ b/src/modules/partition/PartitionPage.h @@ -49,6 +49,7 @@ private: void onCreateClicked(); void onEditClicked(); void onDeleteClicked(); + void onPartitionViewActivated(); void updatePartitionToCreate( Device*, Partition* ); void editExistingPartition( Device*, Partition* ); diff --git a/src/modules/partition/PartitionPage.ui b/src/modules/partition/PartitionPage.ui index 5e7d5ffed..005e518ea 100644 --- a/src/modules/partition/PartitionPage.ui +++ b/src/modules/partition/PartitionPage.ui @@ -63,6 +63,9 @@ + + QAbstractItemView::NoEditTriggers + false