mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
Adhere to coding guidelines https://github.com/vcmi/vcmi/blob/develop/docs/developers/Coding_Guidelines.md
This commit is contained in:
parent
75ad171285
commit
c66cf03a8c
@ -452,29 +452,32 @@ void MainWindow::on_actionOpenRecent_triggered()
|
|||||||
QSettings s(Ui::teamName, Ui::appName);
|
QSettings s(Ui::teamName, Ui::appName);
|
||||||
QStringList recentFiles = s.value(recentlyOpenedFilesSetting).toStringList();
|
QStringList recentFiles = s.value(recentlyOpenedFilesSetting).toStringList();
|
||||||
|
|
||||||
class RecentFileDialog : public QDialog {
|
class RecentFileDialog : public QDialog
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RecentFileDialog(const QStringList& recentFiles, QWidget *parent)
|
RecentFileDialog(const QStringList& recentFiles, QWidget *parent)
|
||||||
: QDialog(parent), layout(new QVBoxLayout(this)), listWidget(new QListWidget(this)) {
|
: QDialog(parent), layout(new QVBoxLayout(this)), listWidget(new QListWidget(this))
|
||||||
|
{
|
||||||
|
|
||||||
setWindowTitle(tr("Recently Opened Files"));
|
setWindowTitle(tr("Recently Opened Files"));
|
||||||
setMinimumWidth(600);
|
setMinimumWidth(600);
|
||||||
|
|
||||||
auto onSelect = [this](QListWidgetItem *item) {
|
connect(listWidget, &QListWidget::itemActivated, this, [this](QListWidgetItem *item)
|
||||||
|
{
|
||||||
accept();
|
accept();
|
||||||
};
|
});
|
||||||
|
|
||||||
connect(listWidget, &QListWidget::itemActivated, this, onSelect);
|
for (const QString &file : recentFiles)
|
||||||
|
{
|
||||||
for (const QString &file : recentFiles) {
|
|
||||||
QListWidgetItem *item = new QListWidgetItem(file);
|
QListWidgetItem *item = new QListWidgetItem(file);
|
||||||
listWidget->addItem(item);
|
listWidget->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select most recent items by default.
|
// Select most recent items by default.
|
||||||
// This enables a "CTRL+R => Enter"-workflow instead of "CTRL+R => 'mouse click on first item'"
|
// This enables a "CTRL+R => Enter"-workflow instead of "CTRL+R => 'mouse click on first item'"
|
||||||
if(listWidget->count() > 0) {
|
if(listWidget->count() > 0)
|
||||||
|
{
|
||||||
listWidget->item(0)->setSelected(true);
|
listWidget->item(0)->setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,21 +485,20 @@ void MainWindow::on_actionOpenRecent_triggered()
|
|||||||
layout->addWidget(listWidget);
|
layout->addWidget(listWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getSelectedFilePath() const {
|
QString getSelectedFilePath() const
|
||||||
|
{
|
||||||
return listWidget->currentItem()->text();
|
return listWidget->currentItem()->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QVBoxLayout * layout;
|
QVBoxLayout * layout;
|
||||||
QListWidget * listWidget;
|
QListWidget * listWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
RecentFileDialog d(recentFiles, this);
|
RecentFileDialog d(recentFiles, this);
|
||||||
if(d.exec() == QDialog::Accepted) {
|
if(d.exec() == QDialog::Accepted && getAnswerAboutUnsavedChanges())
|
||||||
if(getAnswerAboutUnsavedChanges()) {
|
{
|
||||||
openMap(d.getSelectedFilePath());
|
openMap(d.getSelectedFilePath());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user