GH-988 add ability to toggle mods with keyboard

This commit is contained in:
Petr Mrázek 2019-08-04 21:13:50 +02:00
parent d31184f9a4
commit 4ed67413ac
4 changed files with 32 additions and 7 deletions

View File

@ -312,15 +312,29 @@ bool ModFolderModel::enableMods(const QModelIndexList& indexes, bool enable)
if(indexes.isEmpty()) if(indexes.isEmpty())
return true; return true;
for (auto i: indexes) for (auto index: indexes)
{ {
Mod &m = mods[i.row()]; Mod &m = mods[index.row()];
m.enable(enable); m.enable(enable);
emit dataChanged(i, i); emit dataChanged(index, index);
} }
return true; return true;
} }
void ModFolderModel::toggleEnabled(const QModelIndex& index)
{
if(interaction_disabled) {
return;
}
if(!index.isValid()) {
return;
}
Mod &m = mods[index.row()];
m.enable(!m.enabled());
emit dataChanged(index, index);
}
bool ModFolderModel::deleteMods(const QModelIndexList& indexes) bool ModFolderModel::deleteMods(const QModelIndexList& indexes)
{ {
if(interaction_disabled) { if(interaction_disabled) {

View File

@ -82,7 +82,7 @@ public:
} }
/// Reloads the mod list and returns true if the list changed. /// Reloads the mod list and returns true if the list changed.
virtual bool update(); bool update();
/** /**
* Adds the given mod to the list at the given index - if the list supports custom ordering * Adds the given mod to the list at the given index - if the list supports custom ordering
@ -90,15 +90,16 @@ public:
bool installMod(const QString& filename); bool installMod(const QString& filename);
/// Deletes all the selected mods /// Deletes all the selected mods
virtual bool deleteMods(const QModelIndexList &indexes); bool deleteMods(const QModelIndexList &indexes);
/// Enable or disable listed mods /// Enable or disable listed mods
virtual bool enableMods(const QModelIndexList &indexes, bool enable = true); bool enableMods(const QModelIndexList &indexes, bool enable = true);
void toggleEnabled(const QModelIndex &index);
void startWatching(); void startWatching();
void stopWatching(); void stopWatching();
virtual bool isValid(); bool isValid();
QDir dir() QDir dir()
{ {

View File

@ -139,6 +139,7 @@ ModFolderPage::ModFolderPage(
ui->modTreeView->sortByColumn(1, Qt::AscendingOrder); ui->modTreeView->sortByColumn(1, Qt::AscendingOrder);
ui->modTreeView->setContextMenuPolicy(Qt::CustomContextMenu); ui->modTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->modTreeView, &ModListView::customContextMenuRequested, this, &ModFolderPage::ShowContextMenu); connect(ui->modTreeView, &ModListView::customContextMenuRequested, this, &ModFolderPage::ShowContextMenu);
connect(ui->modTreeView, &ModListView::activated, this, &ModFolderPage::modItemActivated);
auto smodel = ui->modTreeView->selectionModel(); auto smodel = ui->modTreeView->selectionModel();
connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent); connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent);
@ -146,6 +147,14 @@ ModFolderPage::ModFolderPage(
connect(m_inst, &BaseInstance::runningStatusChanged, this, &ModFolderPage::on_RunningState_changed); connect(m_inst, &BaseInstance::runningStatusChanged, this, &ModFolderPage::on_RunningState_changed);
} }
void ModFolderPage::modItemActivated(const QModelIndex& index)
{
auto modsModelIndex = m_filterModel->mapToSource(index);
if(modsModelIndex.isValid()) {
m_mods->toggleEnabled(modsModelIndex);
}
}
QMenu * ModFolderPage::createPopupMenu() QMenu * ModFolderPage::createPopupMenu()
{ {
QMenu* filteredMenu = QMainWindow::createPopupMenu(); QMenu* filteredMenu = QMainWindow::createPopupMenu();

View File

@ -94,6 +94,7 @@ slots:
private private
slots: slots:
void modItemActivated(const QModelIndex &index);
void on_filterTextChanged(const QString & newContents); void on_filterTextChanged(const QString & newContents);
void on_RunningState_changed(bool running); void on_RunningState_changed(bool running);
void on_actionAdd_triggered(); void on_actionAdd_triggered();