mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-24 19:52:37 +01:00
Qt: fix vfs dir remove button enabled state
This commit is contained in:
parent
332eb5fbd6
commit
7a105333dc
@ -11,7 +11,7 @@ inline std::string sstr(const QString& _in) { return _in.toStdString(); }
|
||||
vfs_dialog_tab::vfs_dialog_tab(vfs_settings_info settingsInfo, std::shared_ptr<gui_settings> guiSettings, std::shared_ptr<emu_settings> emuSettings, QWidget* parent)
|
||||
: QWidget(parent), m_info(std::move(settingsInfo)), m_gui_settings(std::move(guiSettings)), m_emu_settings(std::move(emuSettings))
|
||||
{
|
||||
m_dirList = new QListWidget(this);
|
||||
m_dir_dist = new QListWidget(this);
|
||||
|
||||
QStringList alldirs = m_gui_settings->GetValue(m_info.listLocation).toStringList();
|
||||
const QString current_dir = qstr(m_info.cfg_node->to_string());
|
||||
@ -20,77 +20,70 @@ vfs_dialog_tab::vfs_dialog_tab(vfs_settings_info settingsInfo, std::shared_ptr<g
|
||||
|
||||
for (const QString& dir : alldirs)
|
||||
{
|
||||
QListWidgetItem* item = new QListWidgetItem(dir, m_dirList);
|
||||
QListWidgetItem* item = new QListWidgetItem(dir, m_dir_dist);
|
||||
if (dir == current_dir)
|
||||
selected_item = item;
|
||||
}
|
||||
|
||||
// We must show the currently selected config.
|
||||
if (!selected_item)
|
||||
selected_item = new QListWidgetItem(current_dir, m_dirList);
|
||||
selected_item = new QListWidgetItem(current_dir, m_dir_dist);
|
||||
|
||||
selected_item->setSelected(true);
|
||||
|
||||
m_dirList->setMinimumWidth(m_dirList->sizeHintForColumn(0));
|
||||
m_dir_dist->setMinimumWidth(m_dir_dist->sizeHintForColumn(0));
|
||||
|
||||
QPushButton* addDir = new QPushButton(QStringLiteral("+"));
|
||||
addDir->setToolTip(tr("Add new directory"));
|
||||
addDir->setFixedWidth(addDir->sizeHint().height()); // Make button square
|
||||
connect(addDir, &QAbstractButton::clicked, this, &vfs_dialog_tab::AddNewDirectory);
|
||||
|
||||
QPushButton* removeDir = new QPushButton(QStringLiteral("-"));
|
||||
removeDir->setToolTip(tr("Remove directory"));
|
||||
removeDir->setFixedWidth(removeDir->sizeHint().height()); // Make button square
|
||||
removeDir->setEnabled(false);
|
||||
connect(removeDir, &QAbstractButton::clicked, this, &vfs_dialog_tab::RemoveDirectory);
|
||||
QPushButton* button_remove_dir = new QPushButton(QStringLiteral("-"));
|
||||
button_remove_dir->setToolTip(tr("Remove directory"));
|
||||
button_remove_dir->setFixedWidth(button_remove_dir->sizeHint().height()); // Make button square
|
||||
button_remove_dir->setEnabled(false);
|
||||
connect(button_remove_dir, &QAbstractButton::clicked, this, &vfs_dialog_tab::RemoveDirectory);
|
||||
|
||||
QHBoxLayout* selectedConfigLayout = new QHBoxLayout;
|
||||
m_selectedConfigLabel = new QLabel(current_dir.isEmpty() ? EmptyPath : current_dir);
|
||||
selectedConfigLayout->addWidget(new QLabel(tr("%0 directory:").arg(m_info.name)));
|
||||
selectedConfigLayout->addWidget(m_selectedConfigLabel);
|
||||
selectedConfigLayout->addStretch();
|
||||
selectedConfigLayout->addWidget(addDir);
|
||||
selectedConfigLayout->addWidget(removeDir);
|
||||
QHBoxLayout* selected_config_layout = new QHBoxLayout;
|
||||
m_selected_config_label = new QLabel(current_dir.isEmpty() ? EmptyPath : current_dir);
|
||||
selected_config_layout->addWidget(new QLabel(tr("%0 directory:").arg(m_info.name)));
|
||||
selected_config_layout->addWidget(m_selected_config_label);
|
||||
selected_config_layout->addStretch();
|
||||
selected_config_layout->addWidget(addDir);
|
||||
selected_config_layout->addWidget(button_remove_dir);
|
||||
|
||||
QVBoxLayout* vbox = new QVBoxLayout;
|
||||
vbox->addWidget(m_dirList);
|
||||
vbox->addLayout(selectedConfigLayout);
|
||||
vbox->addWidget(m_dir_dist);
|
||||
vbox->addLayout(selected_config_layout);
|
||||
|
||||
setLayout(vbox);
|
||||
|
||||
connect(m_dirList, &QListWidget::currentItemChanged, [this](QListWidgetItem* current, QListWidgetItem*)
|
||||
connect(m_dir_dist, &QListWidget::currentRowChanged, button_remove_dir, [this, button_remove_dir](int row)
|
||||
{
|
||||
if (!current)
|
||||
return;
|
||||
|
||||
m_selectedConfigLabel->setText(current->text().isEmpty() ? EmptyPath : current->text());
|
||||
});
|
||||
|
||||
connect(m_dirList, &QListWidget::currentRowChanged, [this, removeDir](int row)
|
||||
{
|
||||
SetCurrentRow(row);
|
||||
removeDir->setEnabled(row > 0);
|
||||
QListWidgetItem* item = m_dir_dist->item(row);
|
||||
m_selected_config_label->setText((item && !item->text().isEmpty()) ? item->text() : EmptyPath);
|
||||
button_remove_dir->setEnabled(item && row > 0);
|
||||
});
|
||||
}
|
||||
|
||||
void vfs_dialog_tab::SetSettings() const
|
||||
{
|
||||
QStringList allDirs;
|
||||
for (int i = 0; i < m_dirList->count(); ++i)
|
||||
for (int i = 0; i < m_dir_dist->count(); ++i)
|
||||
{
|
||||
allDirs += m_dirList->item(i)->text();
|
||||
allDirs += m_dir_dist->item(i)->text();
|
||||
}
|
||||
m_gui_settings->SetValue(m_info.listLocation, allDirs);
|
||||
|
||||
const std::string new_dir = m_selectedConfigLabel->text() == EmptyPath ? "" : sstr(m_selectedConfigLabel->text());
|
||||
const std::string new_dir = m_selected_config_label->text() == EmptyPath ? "" : sstr(m_selected_config_label->text());
|
||||
m_info.cfg_node->from_string(new_dir);
|
||||
m_emu_settings->SetSetting(m_info.settingLoc, new_dir);
|
||||
}
|
||||
|
||||
void vfs_dialog_tab::Reset() const
|
||||
{
|
||||
m_dirList->clear();
|
||||
m_dirList->setCurrentItem(new QListWidgetItem(qstr(m_info.cfg_node->def), m_dirList));
|
||||
m_dir_dist->clear();
|
||||
m_dir_dist->setCurrentItem(new QListWidgetItem(qstr(m_info.cfg_node->def), m_dir_dist));
|
||||
}
|
||||
|
||||
void vfs_dialog_tab::AddNewDirectory() const
|
||||
@ -103,11 +96,15 @@ void vfs_dialog_tab::AddNewDirectory() const
|
||||
if (!dir.endsWith("/"))
|
||||
dir += '/';
|
||||
|
||||
m_dirList->setCurrentItem(new QListWidgetItem(dir, m_dirList));
|
||||
m_dir_dist->setCurrentItem(new QListWidgetItem(dir, m_dir_dist));
|
||||
}
|
||||
|
||||
void vfs_dialog_tab::RemoveDirectory() const
|
||||
{
|
||||
QListWidgetItem* item = m_dirList->takeItem(m_currentRow);
|
||||
delete item;
|
||||
const int row = m_dir_dist->currentRow();
|
||||
if (row > 0)
|
||||
{
|
||||
QListWidgetItem* item = m_dir_dist->item(row);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
@ -39,16 +39,14 @@ public:
|
||||
private:
|
||||
void AddNewDirectory() const;
|
||||
void RemoveDirectory() const;
|
||||
void SetCurrentRow(int row) { m_currentRow = row; }
|
||||
|
||||
const QString EmptyPath = tr("Empty Path");
|
||||
|
||||
vfs_settings_info m_info;
|
||||
std::shared_ptr<gui_settings> m_gui_settings;
|
||||
std::shared_ptr<emu_settings> m_emu_settings;
|
||||
int m_currentRow = -1;
|
||||
|
||||
// UI variables needed in higher scope
|
||||
QListWidget* m_dirList;
|
||||
QLabel* m_selectedConfigLabel;
|
||||
QListWidget* m_dir_dist;
|
||||
QLabel* m_selected_config_label;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user