NOISSUE do not lose selection on mod enable/disable toggle
This commit is contained in:
parent
dfb30d9139
commit
c291946d2a
@ -174,6 +174,11 @@ bool copy::operator()(const QString &offset)
|
|||||||
bool deletePath(QString path)
|
bool deletePath(QString path)
|
||||||
{
|
{
|
||||||
bool OK = true;
|
bool OK = true;
|
||||||
|
QFileInfo finfo(path);
|
||||||
|
if(finfo.isFile()) {
|
||||||
|
return QFile::remove(path);
|
||||||
|
}
|
||||||
|
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
|
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "Mod.h"
|
#include "Mod.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <FileSystem.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -100,34 +101,15 @@ bool Mod::enable(bool value)
|
|||||||
if (!foo.rename(path))
|
if (!foo.rename(path))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_file = QFileInfo(path);
|
repath(QFileInfo(path));
|
||||||
m_enabled = value;
|
m_enabled = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mod::destroy()
|
bool Mod::destroy()
|
||||||
{
|
{
|
||||||
if (m_type == MOD_FOLDER)
|
m_type = MOD_UNKNOWN;
|
||||||
{
|
return FS::deletePath(m_file.filePath());
|
||||||
QDir d(m_file.filePath());
|
|
||||||
if (d.removeRecursively())
|
|
||||||
{
|
|
||||||
m_type = MOD_UNKNOWN;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (m_type == MOD_SINGLEFILE || m_type == MOD_ZIPFILE || m_type == MOD_LITEMOD)
|
|
||||||
{
|
|
||||||
QFile f(m_file.filePath());
|
|
||||||
if (f.remove())
|
|
||||||
{
|
|
||||||
m_type = MOD_UNKNOWN;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ bool ModFolderModel::installMod(const QString &filename)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModFolderModel::enableMods(const QModelIndexList& indexes, bool enable)
|
bool ModFolderModel::setModStatus(const QModelIndexList& indexes, ModStatusAction enable)
|
||||||
{
|
{
|
||||||
if(interaction_disabled) {
|
if(interaction_disabled) {
|
||||||
return false;
|
return false;
|
||||||
@ -314,27 +314,14 @@ bool ModFolderModel::enableMods(const QModelIndexList& indexes, bool enable)
|
|||||||
|
|
||||||
for (auto index: indexes)
|
for (auto index: indexes)
|
||||||
{
|
{
|
||||||
Mod &m = mods[index.row()];
|
if(index.column() != 0) {
|
||||||
m.enable(enable);
|
continue;
|
||||||
emit dataChanged(index, index);
|
}
|
||||||
|
setModStatus(index.row(), enable);
|
||||||
}
|
}
|
||||||
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) {
|
||||||
@ -418,16 +405,52 @@ bool ModFolderModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||||||
|
|
||||||
if (role == Qt::CheckStateRole)
|
if (role == Qt::CheckStateRole)
|
||||||
{
|
{
|
||||||
auto &mod = mods[index.row()];
|
return setModStatus(index.row(), Toggle);
|
||||||
if (mod.enable(!mod.enabled()))
|
|
||||||
{
|
|
||||||
emit dataChanged(index, index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ModFolderModel::setModStatus(int row, ModFolderModel::ModStatusAction action)
|
||||||
|
{
|
||||||
|
if(row < 0 || row >= mods.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &mod = mods[row];
|
||||||
|
bool desiredStatus;
|
||||||
|
switch(action) {
|
||||||
|
case Enable:
|
||||||
|
desiredStatus = true;
|
||||||
|
break;
|
||||||
|
case Disable:
|
||||||
|
desiredStatus = false;
|
||||||
|
break;
|
||||||
|
case Toggle:
|
||||||
|
default:
|
||||||
|
desiredStatus = !mod.enabled();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(desiredStatus == mod.enabled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// preserve the row, but change its ID
|
||||||
|
auto oldId = mod.mmc_id();
|
||||||
|
if(!mod.enable(!mod.enabled())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto newId = mod.mmc_id();
|
||||||
|
if(modsIndex.contains(newId)) {
|
||||||
|
// NOTE: this could handle a corner case, where we are overwriting a file, because the same 'mod' exists both enabled and disabled
|
||||||
|
// But is it necessary?
|
||||||
|
}
|
||||||
|
modsIndex.remove(oldId);
|
||||||
|
modsIndex[newId] = row;
|
||||||
|
emit dataChanged(index(row, 0), index(row, columnCount(QModelIndex()) - 1));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
switch (role)
|
switch (role)
|
||||||
|
@ -48,6 +48,11 @@ public:
|
|||||||
DateColumn,
|
DateColumn,
|
||||||
NUM_COLUMNS
|
NUM_COLUMNS
|
||||||
};
|
};
|
||||||
|
enum ModStatusAction {
|
||||||
|
Disable,
|
||||||
|
Enable,
|
||||||
|
Toggle
|
||||||
|
};
|
||||||
ModFolderModel(const QString &dir);
|
ModFolderModel(const QString &dir);
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
@ -93,8 +98,7 @@ public:
|
|||||||
bool deleteMods(const QModelIndexList &indexes);
|
bool deleteMods(const QModelIndexList &indexes);
|
||||||
|
|
||||||
/// Enable or disable listed mods
|
/// Enable or disable listed mods
|
||||||
bool enableMods(const QModelIndexList &indexes, bool enable = true);
|
bool setModStatus(const QModelIndexList &indexes, ModStatusAction action);
|
||||||
void toggleEnabled(const QModelIndex &index);
|
|
||||||
|
|
||||||
void startWatching();
|
void startWatching();
|
||||||
void stopWatching();
|
void stopWatching();
|
||||||
@ -125,6 +129,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void resolveMod(Mod& m);
|
void resolveMod(Mod& m);
|
||||||
|
bool setModStatus(int index, ModStatusAction action);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QFileSystemWatcher *m_watcher;
|
QFileSystemWatcher *m_watcher;
|
||||||
|
@ -147,12 +147,13 @@ 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)
|
void ModFolderPage::modItemActivated(const QModelIndex&)
|
||||||
{
|
{
|
||||||
auto modsModelIndex = m_filterModel->mapToSource(index);
|
if(!m_controlsEnabled) {
|
||||||
if(modsModelIndex.isValid()) {
|
return;
|
||||||
m_mods->toggleEnabled(modsModelIndex);
|
|
||||||
}
|
}
|
||||||
|
auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
|
||||||
|
m_mods->setModStatus(selection.indexes(), ModFolderModel::Toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu * ModFolderPage::createPopupMenu()
|
QMenu * ModFolderPage::createPopupMenu()
|
||||||
@ -297,7 +298,7 @@ void ModFolderPage::on_actionEnable_triggered()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
|
auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
|
||||||
m_mods->enableMods(selection.indexes(), true);
|
m_mods->setModStatus(selection.indexes(), ModFolderModel::Enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModFolderPage::on_actionDisable_triggered()
|
void ModFolderPage::on_actionDisable_triggered()
|
||||||
@ -306,7 +307,7 @@ void ModFolderPage::on_actionDisable_triggered()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
|
auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
|
||||||
m_mods->enableMods(selection.indexes(), false);
|
m_mods->setModStatus(selection.indexes(), ModFolderModel::Disable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModFolderPage::on_actionRemove_triggered()
|
void ModFolderPage::on_actionRemove_triggered()
|
||||||
|
@ -87,6 +87,7 @@
|
|||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
<addaction name="actionAdd"/>
|
<addaction name="actionAdd"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionRemove"/>
|
<addaction name="actionRemove"/>
|
||||||
<addaction name="actionEnable"/>
|
<addaction name="actionEnable"/>
|
||||||
<addaction name="actionDisable"/>
|
<addaction name="actionDisable"/>
|
||||||
@ -95,27 +96,39 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<action name="actionAdd">
|
<action name="actionAdd">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add</string>
|
<string>&Add</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Add mods</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionRemove">
|
<action name="actionRemove">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Remove</string>
|
<string>&Remove</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Remove selected mods</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEnable">
|
<action name="actionEnable">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enable</string>
|
<string>&Enable</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Enable selected mods</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionDisable">
|
<action name="actionDisable">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Disable</string>
|
<string>&Disable</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Disable selected mods</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionView_configs">
|
<action name="actionView_configs">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>View configs</string>
|
<string>View &Configs</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Open the 'config' folder in the system file manager.</string>
|
<string>Open the 'config' folder in the system file manager.</string>
|
||||||
@ -123,7 +136,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionView_Folder">
|
<action name="actionView_Folder">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>View Folder</string>
|
<string>View &Folder</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
@ -145,6 +158,10 @@
|
|||||||
<header>widgets/WideBar.h</header>
|
<header>widgets/WideBar.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>modTreeView</tabstop>
|
||||||
|
<tabstop>filterEdit</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -16,6 +16,12 @@ There are some accessibility fixes thrown in too.
|
|||||||
|
|
||||||
It now also shows disabled mods, and has prefix and suffix that shows if the mod is enabled, and if it is a folder.
|
It now also shows disabled mods, and has prefix and suffix that shows if the mod is enabled, and if it is a folder.
|
||||||
|
|
||||||
|
- You can now enable and disable mods with the keyboard.
|
||||||
|
|
||||||
|
Toggle with enter.
|
||||||
|
|
||||||
|
- Enabling and disabling mods no longer makes the list forget what was selected.
|
||||||
|
|
||||||
- GH-358: Switched all the dialog pages from using buttons in layouts to toolbars.
|
- GH-358: Switched all the dialog pages from using buttons in layouts to toolbars.
|
||||||
|
|
||||||
Toolbar buttons are smaller, and the toolbars can overflow buttons into an overflow space. This allows requiring a lot less space for the windows.
|
Toolbar buttons are smaller, and the toolbars can overflow buttons into an overflow space. This allows requiring a lot less space for the windows.
|
||||||
|
Loading…
Reference in New Issue
Block a user