fix(ui): remove straight away when there is a single installation
The chooser answered an empty list when the provider held one copy, and the caller read that as "nothing was ticked" — so Supprimer on a package installed once showed "Aucune installation sélectionnée." and removed nothing, which is most packages. The row is now removed directly unless there is something to choose between, and the message about ticking nothing only appears where it can happen: after the chooser.
This commit is contained in:
2 files changed
+17
-12
No files matched your search
+14
-9
@@ -104,12 +104,21 @@ BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
connect(m_removeButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (m_selected.name.empty()) return;
|
||||
m_pendingSelect = QString::fromStdString(m_selected.name);
|
||||
|
||||
// One row stands for one installation, or for a provider that only ever
|
||||
// has one: there is nothing to choose, so the row is what gets removed.
|
||||
if (m_selected.instances.size() < 2) {
|
||||
start(core->remove(m_selected), tr("Suppression"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Several copies of the same application: the user says which ones go.
|
||||
// A cancelled chooser aborts, an empty choice tells why in the status bar.
|
||||
// A cancelled chooser aborts, an empty choice says so in the status bar.
|
||||
const auto targets = chooseInstancesToRemove();
|
||||
if (!targets.has_value()) return;
|
||||
if (targets->empty()) {
|
||||
emit message(tr("Aucune installation sélectionnée."));
|
||||
emit message(tr("Aucune installation sélectionnée : cochez les copies "
|
||||
"à supprimer, ou annulez."));
|
||||
return;
|
||||
}
|
||||
start(core->removeInstances(m_selected, *targets), tr("Suppression"));
|
||||
@@ -575,14 +584,10 @@ void BrowsePage::updateDetails(const PackageInfo& pkg) {
|
||||
// holds it more than once (flatpak: a user and a system-wide installation, or
|
||||
// two remotes or branches of the same id). One line per copy, each with the
|
||||
// provider's own target kept aside, so the core is handed exactly what it must
|
||||
// act on. Returns nothing when the user cancels.
|
||||
// act on. Returns nothing when the user cancels, and an empty list when they
|
||||
// ticked nothing — which is why the caller only asks when there are at least
|
||||
// two copies: with one, the row is the thing to remove.
|
||||
std::optional<std::vector<std::string>> BrowsePage::chooseInstancesToRemove() {
|
||||
if (m_selected.instances.size() < 2) {
|
||||
// A single installation, or a provider that only ever has one: the row
|
||||
// is the thing to remove, no question to ask.
|
||||
return std::vector<std::string>{};
|
||||
}
|
||||
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle(tr("Supprimer %1").arg(QString::fromStdString(m_selected.name)));
|
||||
|
||||
|
||||
+3
-3
@@ -51,9 +51,9 @@ private:
|
||||
void populateTable(const std::vector<PackageInfo>& packages);
|
||||
void appendRows(const std::vector<PackageInfo>& packages);
|
||||
void addRow(int row, const PackageInfo& pkg);
|
||||
// Which installations of the selected package to remove, when the provider
|
||||
// holds it more than once. Empty when there is only one to remove, nothing
|
||||
// (std::nullopt) when the user cancels the chooser.
|
||||
// Which installations of the selected package to remove, asked only when
|
||||
// the provider holds it more than once. Nothing (std::nullopt) when the
|
||||
// user cancels, an empty list when they tick nothing.
|
||||
std::optional<std::vector<std::string>> chooseInstancesToRemove();
|
||||
void updateDetails(const PackageInfo& pkg);
|
||||
void resetDetails();
|
||||
|
||||
Reference in new issue
Block a user