Skip to content

Commit 4ed6741

Browse files
committed
GH-988 add ability to toggle mods with keyboard
1 parent d31184f commit 4ed6741

4 files changed

Lines changed: 32 additions & 7 deletions

File tree

api/logic/minecraft/mod/ModFolderModel.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,29 @@ bool ModFolderModel::enableMods(const QModelIndexList& indexes, bool enable)
312312
if(indexes.isEmpty())
313313
return true;
314314

315-
for (auto i: indexes)
315+
for (auto index: indexes)
316316
{
317-
Mod &m = mods[i.row()];
317+
Mod &m = mods[index.row()];
318318
m.enable(enable);
319-
emit dataChanged(i, i);
319+
emit dataChanged(index, index);
320320
}
321321
return true;
322322
}
323323

324+
void ModFolderModel::toggleEnabled(const QModelIndex& index)
325+
{
326+
if(interaction_disabled) {
327+
return;
328+
}
329+
if(!index.isValid()) {
330+
return;
331+
}
332+
333+
Mod &m = mods[index.row()];
334+
m.enable(!m.enabled());
335+
emit dataChanged(index, index);
336+
}
337+
324338
bool ModFolderModel::deleteMods(const QModelIndexList& indexes)
325339
{
326340
if(interaction_disabled) {

api/logic/minecraft/mod/ModFolderModel.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,24 @@ class MULTIMC_LOGIC_EXPORT ModFolderModel : public QAbstractListModel
8282
}
8383

8484
/// Reloads the mod list and returns true if the list changed.
85-
virtual bool update();
85+
bool update();
8686

8787
/**
8888
* Adds the given mod to the list at the given index - if the list supports custom ordering
8989
*/
9090
bool installMod(const QString& filename);
9191

9292
/// Deletes all the selected mods
93-
virtual bool deleteMods(const QModelIndexList &indexes);
93+
bool deleteMods(const QModelIndexList &indexes);
9494

9595
/// Enable or disable listed mods
96-
virtual bool enableMods(const QModelIndexList &indexes, bool enable = true);
96+
bool enableMods(const QModelIndexList &indexes, bool enable = true);
97+
void toggleEnabled(const QModelIndex &index);
9798

9899
void startWatching();
99100
void stopWatching();
100101

101-
virtual bool isValid();
102+
bool isValid();
102103

103104
QDir dir()
104105
{

application/pages/instance/ModFolderPage.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,22 @@ ModFolderPage::ModFolderPage(
139139
ui->modTreeView->sortByColumn(1, Qt::AscendingOrder);
140140
ui->modTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
141141
connect(ui->modTreeView, &ModListView::customContextMenuRequested, this, &ModFolderPage::ShowContextMenu);
142+
connect(ui->modTreeView, &ModListView::activated, this, &ModFolderPage::modItemActivated);
142143

143144
auto smodel = ui->modTreeView->selectionModel();
144145
connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent);
145146
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged );
146147
connect(m_inst, &BaseInstance::runningStatusChanged, this, &ModFolderPage::on_RunningState_changed);
147148
}
148149

150+
void ModFolderPage::modItemActivated(const QModelIndex& index)
151+
{
152+
auto modsModelIndex = m_filterModel->mapToSource(index);
153+
if(modsModelIndex.isValid()) {
154+
m_mods->toggleEnabled(modsModelIndex);
155+
}
156+
}
157+
149158
QMenu * ModFolderPage::createPopupMenu()
150159
{
151160
QMenu* filteredMenu = QMainWindow::createPopupMenu();

application/pages/instance/ModFolderPage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public
9494

9595
private
9696
slots:
97+
void modItemActivated(const QModelIndex &index);
9798
void on_filterTextChanged(const QString & newContents);
9899
void on_RunningState_changed(bool running);
99100
void on_actionAdd_triggered();

0 commit comments

Comments
 (0)