mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
feat: allow moving accounts in list
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
20055aa2fa
commit
40af45bb1c
5 changed files with 61 additions and 0 deletions
|
|
@ -168,6 +168,24 @@ void AccountList::removeAccount(QModelIndex index)
|
|||
}
|
||||
}
|
||||
|
||||
void AccountList::moveAccount(QModelIndex index, int delta) {
|
||||
int row = index.row();
|
||||
int newRow = row + delta;
|
||||
if (index.isValid() && row < m_accounts.size() && newRow >= 0 && newRow < m_accounts.size()) {
|
||||
auto account = m_accounts.at(row);
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
m_accounts.removeAt(row);
|
||||
endRemoveRows();
|
||||
|
||||
beginInsertRows(QModelIndex(), newRow, newRow);
|
||||
m_accounts.insert(newRow, account);
|
||||
endInsertRows();
|
||||
|
||||
onListChanged();
|
||||
}
|
||||
}
|
||||
|
||||
MinecraftAccountPtr AccountList::defaultAccount() const
|
||||
{
|
||||
return m_defaultAccount;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ class AccountList : public QAbstractListModel {
|
|||
|
||||
void addAccount(MinecraftAccountPtr account);
|
||||
void removeAccount(QModelIndex index);
|
||||
void moveAccount(QModelIndex index, int delta);
|
||||
int findAccountByProfileId(const QString& profileId) const;
|
||||
MinecraftAccountPtr getAccountByProfileName(const QString& profileName) const;
|
||||
QStringList profileNames() const;
|
||||
|
|
|
|||
|
|
@ -210,11 +210,17 @@ void AccountListPage::updateButtonStates()
|
|||
bool hasSelection = !selection.empty();
|
||||
bool accountIsReady = false;
|
||||
bool accountIsOnline = false;
|
||||
bool accountCanMoveUp = false;
|
||||
bool accountCanMoveDown = false;
|
||||
if (hasSelection) {
|
||||
QModelIndex selected = selection.first();
|
||||
MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();
|
||||
accountIsReady = !account->isActive();
|
||||
accountIsOnline = account->accountType() != AccountType::Offline;
|
||||
|
||||
accountCanMoveUp = selected.row() > 0;
|
||||
int indexOfLast = m_accounts->count() - 1;
|
||||
accountCanMoveDown = selected.row() < indexOfLast;
|
||||
}
|
||||
ui->actionRemove->setEnabled(accountIsReady);
|
||||
ui->actionSetDefault->setEnabled(accountIsReady);
|
||||
|
|
@ -228,6 +234,8 @@ void AccountListPage::updateButtonStates()
|
|||
ui->actionNoDefault->setEnabled(true);
|
||||
ui->actionNoDefault->setChecked(false);
|
||||
}
|
||||
ui->actionMoveUp->setEnabled(accountCanMoveUp);
|
||||
ui->actionMoveDown->setEnabled(accountCanMoveDown);
|
||||
ui->listView->resizeColumnToContents(3);
|
||||
}
|
||||
|
||||
|
|
@ -241,3 +249,23 @@ void AccountListPage::on_actionManageSkins_triggered()
|
|||
dialog.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void AccountListPage::on_actionMoveUp_triggered()
|
||||
{
|
||||
QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
|
||||
if (selection.size() > 0) {
|
||||
QModelIndex selected = selection.first();
|
||||
m_accounts->moveAccount(selected, -1);
|
||||
ui->listView->selectionModel()->select(ui->listView->indexAbove(selected), QItemSelectionModel::SelectCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
void AccountListPage::on_actionMoveDown_triggered()
|
||||
{
|
||||
QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
|
||||
if (selection.size() > 0) {
|
||||
QModelIndex selected = selection.first();
|
||||
m_accounts->moveAccount(selected, 1);
|
||||
ui->listView->selectionModel()->select(ui->listView->indexBelow(selected), QItemSelectionModel::SelectCurrent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ class AccountListPage : public QMainWindow, public BasePage {
|
|||
void on_actionSetDefault_triggered();
|
||||
void on_actionNoDefault_triggered();
|
||||
void on_actionManageSkins_triggered();
|
||||
void on_actionMoveUp_triggered();
|
||||
void on_actionMoveDown_triggered();
|
||||
|
||||
void listChanged();
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@
|
|||
<addaction name="actionRemove"/>
|
||||
<addaction name="actionSetDefault"/>
|
||||
<addaction name="actionNoDefault"/>
|
||||
<addaction name="actionMoveUp"/>
|
||||
<addaction name="actionMoveDown"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionManageSkins"/>
|
||||
</widget>
|
||||
|
|
@ -105,6 +107,16 @@
|
|||
<string>Remo&ve</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionMoveUp">
|
||||
<property name="text">
|
||||
<string>Move &Up</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionMoveDown">
|
||||
<property name="text">
|
||||
<string>Move &Down</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue