refactor(ui): name the sidebar page ids instead of hardcoding them
A maintenance page is about to be inserted between two existing entries, and the numeric ids were duplicated across the sidebar, the dashboard shortcuts, the menu bar and the keyboard shortcuts. Naming them keeps those entry points in sync. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
4ef37dcda6
commit
b8f8dc569f
2 files changed
+70
-41
No files matched your search
@@ -127,6 +127,29 @@ private slots:
|
||||
private:
|
||||
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
|
||||
|
||||
// Sidebar entries, in display order. Named so the sidebar, the dashboard
|
||||
// shortcuts, the menu bar and the keyboard shortcuts cannot drift apart
|
||||
// when a page is inserted.
|
||||
enum NavPage {
|
||||
NavDashboard = 0,
|
||||
NavSearch,
|
||||
NavInstalled,
|
||||
NavUpdates,
|
||||
NavHistory,
|
||||
NavLogs,
|
||||
NavPlugins,
|
||||
};
|
||||
|
||||
// Indices in the stacked widget. Search / Installed / Updates share the
|
||||
// browse page, so these deliberately differ from the nav ids.
|
||||
enum StackedPage {
|
||||
PageDashboard = 0,
|
||||
PageBrowse,
|
||||
PageHistory,
|
||||
PageLogs,
|
||||
PagePlugins,
|
||||
};
|
||||
|
||||
// When the sudo password is requested: once per session (at launch) or
|
||||
// before every privileged operation.
|
||||
enum class CredentialMode { AtLaunch, EachTime };
|
||||
|
||||
+47
-41
@@ -535,17 +535,17 @@ void MainWindow::setupSidebar() {
|
||||
return btn;
|
||||
};
|
||||
|
||||
addNavButton(0, "home", "Tableau de bord", "Vue d'ensemble du système");
|
||||
addNavButton(1, "search", "Recherche", "Rechercher des paquets");
|
||||
addNavButton(2, "package", "Installés", "Voir les paquets installés");
|
||||
addNavButton(3, "arrow-up", "Mises à jour", "Voir les mises à jour disponibles");
|
||||
addNavButton(NavDashboard, "home", "Tableau de bord", "Vue d'ensemble du système");
|
||||
addNavButton(NavSearch, "search", "Recherche", "Rechercher des paquets");
|
||||
addNavButton(NavInstalled, "package", "Installés", "Voir les paquets installés");
|
||||
addNavButton(NavUpdates, "arrow-up", "Mises à jour", "Voir les mises à jour disponibles");
|
||||
layout->addSpacing(8);
|
||||
addNavButton(4, "history", "Historique", "Historique des actions");
|
||||
addNavButton(5, "logs", "Logs", "Logs pacman");
|
||||
addNavButton(6, "plugin", "Plugins", "Gestionnaires de paquets et extensions");
|
||||
addNavButton(NavHistory, "history", "Historique", "Historique des actions");
|
||||
addNavButton(NavLogs, "logs", "Logs", "Logs pacman");
|
||||
addNavButton(NavPlugins, "plugin", "Plugins", "Gestionnaires de paquets et extensions");
|
||||
|
||||
connect(m_navGroup, &QButtonGroup::idClicked, this, &MainWindow::onNavChanged);
|
||||
m_navGroup->button(0)->setChecked(true);
|
||||
m_navGroup->button(NavDashboard)->setChecked(true);
|
||||
|
||||
layout->addStretch();
|
||||
|
||||
@@ -615,7 +615,7 @@ void MainWindow::setupDashboardPage() {
|
||||
btnSearch->setProperty("variant", "primary");
|
||||
btnSearch->setIcon(loadIcon("search"));
|
||||
connect(btnSearch, &QPushButton::clicked, this, [this]() {
|
||||
m_navGroup->button(1)->click();
|
||||
m_navGroup->button(NavSearch)->click();
|
||||
m_searchBar->setFocus();
|
||||
});
|
||||
actionsRow->addWidget(btnSearch);
|
||||
@@ -623,7 +623,7 @@ void MainWindow::setupDashboardPage() {
|
||||
QPushButton* btnInstalled = new QPushButton("Paquets installés");
|
||||
btnInstalled->setIcon(loadIcon("package"));
|
||||
connect(btnInstalled, &QPushButton::clicked, this, [this]() {
|
||||
m_navGroup->button(2)->click();
|
||||
m_navGroup->button(NavInstalled)->click();
|
||||
});
|
||||
actionsRow->addWidget(btnInstalled);
|
||||
|
||||
@@ -642,7 +642,7 @@ void MainWindow::setupDashboardPage() {
|
||||
QPushButton* btnLogs = new QPushButton("Logs pacman");
|
||||
btnLogs->setIcon(loadIcon("logs"));
|
||||
connect(btnLogs, &QPushButton::clicked, this, [this]() {
|
||||
m_navGroup->button(5)->click();
|
||||
m_navGroup->button(NavLogs)->click();
|
||||
});
|
||||
actionsRow->addWidget(btnLogs);
|
||||
|
||||
@@ -1084,16 +1084,22 @@ void MainWindow::setupMenuBar() {
|
||||
fileMenu->addAction("Quitter", this, &QWidget::close);
|
||||
|
||||
QMenu* toolsMenu = menuBar->addMenu("Outils");
|
||||
toolsMenu->addAction("Tableau de bord", this, [this]() { m_navGroup->button(0)->click(); });
|
||||
toolsMenu->addAction("Tableau de bord", this,
|
||||
[this]() { m_navGroup->button(NavDashboard)->click(); });
|
||||
toolsMenu->addAction("Rechercher", this, [this]() {
|
||||
m_navGroup->button(1)->click();
|
||||
m_navGroup->button(NavSearch)->click();
|
||||
m_searchBar->setFocus();
|
||||
});
|
||||
toolsMenu->addAction("Paquets installés", this, [this]() { m_navGroup->button(2)->click(); });
|
||||
toolsMenu->addAction("Mises à jour", this, [this]() { m_navGroup->button(3)->click(); });
|
||||
toolsMenu->addAction("Historique", this, [this]() { m_navGroup->button(4)->click(); });
|
||||
toolsMenu->addAction("Logs pacman", this, [this]() { m_navGroup->button(5)->click(); });
|
||||
toolsMenu->addAction("Plugins", this, [this]() { m_navGroup->button(6)->click(); });
|
||||
toolsMenu->addAction("Paquets installés", this,
|
||||
[this]() { m_navGroup->button(NavInstalled)->click(); });
|
||||
toolsMenu->addAction("Mises à jour", this,
|
||||
[this]() { m_navGroup->button(NavUpdates)->click(); });
|
||||
toolsMenu->addAction("Historique", this,
|
||||
[this]() { m_navGroup->button(NavHistory)->click(); });
|
||||
toolsMenu->addAction("Logs pacman", this,
|
||||
[this]() { m_navGroup->button(NavLogs)->click(); });
|
||||
toolsMenu->addAction("Plugins", this,
|
||||
[this]() { m_navGroup->button(NavPlugins)->click(); });
|
||||
toolsMenu->addSeparator();
|
||||
toolsMenu->addAction("Prévisualiser les mises à jour", this, &MainWindow::onPreviewUpdates);
|
||||
toolsMenu->addAction("Rafraîchir les sources", this, &MainWindow::onRefresh);
|
||||
@@ -1290,31 +1296,31 @@ QFrame* MainWindow::makeStatCard(const QString& iconName, const QString& title,
|
||||
|
||||
void MainWindow::updatePageTitle() {
|
||||
switch (m_navGroup->checkedId()) {
|
||||
case 0:
|
||||
case NavDashboard:
|
||||
m_headerTitle->setText("Tableau de bord");
|
||||
m_headerSubtitle->setText("Vue d'ensemble de votre système");
|
||||
break;
|
||||
case 1:
|
||||
case NavSearch:
|
||||
m_headerTitle->setText("Recherche");
|
||||
m_headerSubtitle->setText("Trouvez et installez des paquets");
|
||||
break;
|
||||
case 2:
|
||||
case NavInstalled:
|
||||
m_headerTitle->setText("Paquets installés");
|
||||
m_headerSubtitle->setText("Parcourez les paquets de votre système");
|
||||
break;
|
||||
case 3:
|
||||
case NavUpdates:
|
||||
m_headerTitle->setText("Mises à jour disponibles");
|
||||
m_headerSubtitle->setText("Maintenez votre système à jour");
|
||||
break;
|
||||
case 4:
|
||||
case NavHistory:
|
||||
m_headerTitle->setText("Historique");
|
||||
m_headerSubtitle->setText("Journal de toutes vos actions");
|
||||
break;
|
||||
case 5:
|
||||
case NavLogs:
|
||||
m_headerTitle->setText("Logs pacman");
|
||||
m_headerSubtitle->setText("Journal brut du gestionnaire de paquets");
|
||||
break;
|
||||
case 6:
|
||||
case NavPlugins:
|
||||
m_headerTitle->setText("Plugins");
|
||||
m_headerSubtitle->setText("Gestionnaires de paquets et extensions");
|
||||
break;
|
||||
@@ -1328,32 +1334,32 @@ void MainWindow::onNavChanged(int id) {
|
||||
updatePageTitle();
|
||||
|
||||
switch (id) {
|
||||
case 0:
|
||||
m_pages->setCurrentIndex(0);
|
||||
case NavDashboard:
|
||||
m_pages->setCurrentIndex(PageDashboard);
|
||||
refreshDashboard();
|
||||
break;
|
||||
case 1:
|
||||
case NavSearch:
|
||||
setBrowseMode(ModeSearch);
|
||||
m_searchBar->setFocus();
|
||||
break;
|
||||
case 2:
|
||||
case NavInstalled:
|
||||
setBrowseMode(ModeInstalled);
|
||||
loadInstalled();
|
||||
break;
|
||||
case 3:
|
||||
case NavUpdates:
|
||||
setBrowseMode(ModeUpdates);
|
||||
loadUpdates();
|
||||
break;
|
||||
case 4:
|
||||
m_pages->setCurrentIndex(2);
|
||||
case NavHistory:
|
||||
m_pages->setCurrentIndex(PageHistory);
|
||||
refreshHistoryTable();
|
||||
break;
|
||||
case 5:
|
||||
m_pages->setCurrentIndex(3);
|
||||
case NavLogs:
|
||||
m_pages->setCurrentIndex(PageLogs);
|
||||
loadLogs();
|
||||
break;
|
||||
case 6:
|
||||
m_pages->setCurrentIndex(4);
|
||||
case NavPlugins:
|
||||
m_pages->setCurrentIndex(PagePlugins);
|
||||
refreshPluginsTable();
|
||||
break;
|
||||
default:
|
||||
@@ -1363,7 +1369,7 @@ void MainWindow::onNavChanged(int id) {
|
||||
|
||||
void MainWindow::setBrowseMode(BrowseMode mode) {
|
||||
m_browseMode = mode;
|
||||
m_pages->setCurrentIndex(1);
|
||||
m_pages->setCurrentIndex(PageBrowse);
|
||||
|
||||
m_searchRowWidget->setVisible(mode == ModeSearch);
|
||||
m_filterRowWidget->setVisible(mode == ModeInstalled);
|
||||
@@ -1491,7 +1497,7 @@ void MainWindow::onRecentActivityClicked(QListWidgetItem* item) {
|
||||
if (name.isEmpty()) return;
|
||||
|
||||
m_pendingSelect = name.toStdString();
|
||||
m_navGroup->button(2)->click(); // Installed page -> loadInstalled() runs
|
||||
m_navGroup->button(NavInstalled)->click(); // Installed page -> loadInstalled() runs
|
||||
statusBar()->showMessage(
|
||||
QString("Ouverture des détails de %1...").arg(name));
|
||||
}
|
||||
@@ -2446,14 +2452,14 @@ void MainWindow::setupShortcuts() {
|
||||
};
|
||||
|
||||
bind(QKeySequence::Find, [this]() {
|
||||
m_navGroup->button(1)->click();
|
||||
m_navGroup->button(NavSearch)->click();
|
||||
m_searchBar->setFocus();
|
||||
m_searchBar->selectAll();
|
||||
});
|
||||
bind(QKeySequence::Refresh, [this]() { onRefresh(); });
|
||||
bind(QKeySequence(Qt::Key_F5), [this]() { onRefresh(); });
|
||||
bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() {
|
||||
m_navGroup->button(3)->click();
|
||||
m_navGroup->button(NavUpdates)->click();
|
||||
});
|
||||
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() { onExportPackageList(); });
|
||||
bind(QKeySequence::Quit, [this]() { close(); });
|
||||
@@ -2462,7 +2468,7 @@ void MainWindow::setupShortcuts() {
|
||||
// Shows the pending updates without applying anything: jumps to the updates
|
||||
// page, which lists every outdated package across the active providers.
|
||||
void MainWindow::onPreviewUpdates() {
|
||||
m_navGroup->button(3)->click();
|
||||
m_navGroup->button(NavUpdates)->click();
|
||||
statusBar()->showMessage("Prévisualisation des mises à jour disponibles");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user