-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathmodinfodialog.cpp
More file actions
822 lines (668 loc) · 21.4 KB
/
modinfodialog.cpp
File metadata and controls
822 lines (668 loc) · 21.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.
This file is part of Mod Organizer.
Mod Organizer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Mod Organizer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "modinfodialog.h"
#include "modinfodialogcategories.h"
#include "modinfodialogconflicts.h"
#include "modinfodialogesps.h"
#include "modinfodialogfiletree.h"
#include "modinfodialogimages.h"
#include "modinfodialognexus.h"
#include "modinfodialogtextfiles.h"
#include "modlistview.h"
#include "organizercore.h"
#include "plugincontainer.h"
#include "shared/directoryentry.h"
#include "shared/filesorigin.h"
#include "ui_modinfodialog.h"
#include <filesystem>
using namespace MOBase;
using namespace MOShared;
namespace fs = std::filesystem;
const int max_scan_for_context_menu = 50;
bool canPreviewFile(const PluginContainer& pluginContainer, bool isArchive,
const QString& filename)
{
const auto ext = QFileInfo(filename).suffix().toLower();
return pluginContainer.previewGenerator().previewSupported(ext, isArchive);
}
bool isExecutableFilename(const QString& filename)
{
static const std::set<QString> exeExtensions = {"exe", "cmd", "bat"};
const auto ext = QFileInfo(filename).suffix().toLower();
return exeExtensions.contains(ext);
}
bool canRunFile(bool isArchive, const QString& filename)
{
// can run executables that are not archives
return !isArchive && isExecutableFilename(filename);
}
bool canOpenFile(bool isArchive, const QString& filename)
{
// can open non-executables that are not archives
return !isArchive && !isExecutableFilename(filename);
}
bool canExploreFile(bool isArchive, const QString&)
{
// can explore anything as long as it's not in an archive
return !isArchive;
}
bool canHideFile(bool isArchive, const QString& filename)
{
if (isArchive) {
// can't hide files from archives
return false;
}
if (filename.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
// already hidden
return false;
}
return true;
}
bool canUnhideFile(bool isArchive, const QString& filename)
{
if (isArchive) {
// can't unhide files from archives
return false;
}
if (!filename.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
// already visible
return false;
}
return true;
}
FileRenamer::RenameResults hideFile(FileRenamer& renamer, const QString& oldName)
{
const QString newName = oldName + ModInfo::s_HiddenExt;
return renamer.rename(oldName, newName);
}
FileRenamer::RenameResults unhideFile(FileRenamer& renamer, const QString& oldName)
{
QString newName = oldName.left(oldName.length() - ModInfo::s_HiddenExt.length());
return renamer.rename(oldName, newName);
}
FileRenamer::RenameResults restoreHiddenFilesRecursive(FileRenamer& renamer,
const QString& targetDir)
{
FileRenamer::RenameResults results = FileRenamer::RESULT_OK;
QDir currentDir = targetDir;
for (QString hiddenFile :
currentDir.entryList((QStringList() << "*" + ModInfo::s_HiddenExt),
QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) {
QString oldName = currentDir.absoluteFilePath(hiddenFile);
QString newName = oldName.left(oldName.length() - ModInfo::s_HiddenExt.length());
auto partialResult = renamer.rename(oldName, newName);
if (partialResult == FileRenamer::RESULT_CANCEL) {
return FileRenamer::RESULT_CANCEL;
}
if (partialResult == FileRenamer::RESULT_SKIP) {
results = FileRenamer::RESULT_SKIP;
}
}
for (QString dirName : currentDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)) {
const QString dirPath = currentDir.absoluteFilePath(dirName);
// recurse on childrend directories
auto partialResult = restoreHiddenFilesRecursive(renamer, dirPath);
if (partialResult == FileRenamer::RESULT_CANCEL) {
return FileRenamer::RESULT_CANCEL;
}
if (partialResult == FileRenamer::RESULT_SKIP) {
results = FileRenamer::RESULT_SKIP;
}
}
return results;
}
ModInfoDialog::TabInfo::TabInfo(std::unique_ptr<ModInfoDialogTab> tab)
: tab(std::move(tab)), realPos(-1), widget(nullptr)
{}
bool ModInfoDialog::TabInfo::isVisible() const
{
return (realPos != -1);
}
ModInfoDialog::ModInfoDialog(OrganizerCore& core, PluginContainer& plugin,
ModInfo::Ptr mod, ModListView* modListView,
QWidget* parent)
: TutorableDialog("ModInfoDialog", parent), ui(new Ui::ModInfoDialog), m_core(core),
m_plugin(plugin), m_modListView(modListView), m_initialTab(ModInfoTabIDs::None),
m_arrangingTabs(false)
{
ui->setupUi(this);
{
auto* sc = new QShortcut(QKeySequence::Delete, this);
connect(sc, &QShortcut::activated, [&] {
onDeleteShortcut();
});
}
{
auto* sc = new QShortcut(QKeySequence::MoveToNextPage, this);
connect(sc, &QShortcut::activated, [&] {
onNextMod();
});
}
{
auto* sc = new QShortcut(QKeySequence::MoveToPreviousPage, this);
connect(sc, &QShortcut::activated, [&] {
onPreviousMod();
});
}
setMod(mod);
createTabs();
connect(ui->tabWidget, &QTabWidget::currentChanged, [&] {
onTabSelectionChanged();
});
connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, [&] {
onTabMoved();
});
connect(ui->close, &QPushButton::clicked, [&] {
onCloseButton();
});
connect(ui->previousMod, &QPushButton::clicked, [&] {
onPreviousMod();
});
connect(ui->nextMod, &QPushButton::clicked, [&] {
onNextMod();
});
}
ModInfoDialog::~ModInfoDialog() = default;
template <class T>
std::unique_ptr<ModInfoDialogTab> createTab(ModInfoDialog& d, ModInfoTabIDs id)
{
return std::make_unique<T>(ModInfoDialogTabContext(
d.m_core, d.m_plugin, &d, d.ui.get(), id, d.m_mod, d.getOrigin()));
}
void ModInfoDialog::createTabs()
{
m_tabs.clear();
m_tabs.push_back(createTab<TextFilesTab>(*this, ModInfoTabIDs::TextFiles));
m_tabs.push_back(createTab<IniFilesTab>(*this, ModInfoTabIDs::IniFiles));
m_tabs.push_back(createTab<ImagesTab>(*this, ModInfoTabIDs::Images));
m_tabs.push_back(createTab<ESPsTab>(*this, ModInfoTabIDs::Esps));
m_tabs.push_back(createTab<ConflictsTab>(*this, ModInfoTabIDs::Conflicts));
m_tabs.push_back(createTab<CategoriesTab>(*this, ModInfoTabIDs::Categories));
m_tabs.push_back(createTab<NexusTab>(*this, ModInfoTabIDs::Nexus));
m_tabs.push_back(createTab<NotesTab>(*this, ModInfoTabIDs::Notes));
m_tabs.push_back(createTab<FileTreeTab>(*this, ModInfoTabIDs::Filetree));
// check for tabs in the ui not having a corresponding tab in the list
int count = ui->tabWidget->count();
if (count < 0 || count > static_cast<int>(m_tabs.size())) {
log::error("mod info dialog has more tabs than expected");
count = static_cast<int>(m_tabs.size());
}
// for each tab in the widget; connects the widgets with the tab objects
//
for (int i = 0; i < count; ++i) {
auto& tabInfo = m_tabs[static_cast<std::size_t>(i)];
// remembering tab information so tabs can be removed and re-added
tabInfo.widget = ui->tabWidget->widget(i);
tabInfo.caption = ui->tabWidget->tabText(i);
tabInfo.icon = ui->tabWidget->tabIcon(i);
connect(tabInfo.tab.get(), &ModInfoDialogTab::originModified, [this](int originID) {
onOriginModified(originID);
});
connect(tabInfo.tab.get(), &ModInfoDialogTab::modOpen, [&](const QString& name) {
setMod(name);
update();
});
connect(tabInfo.tab.get(), &ModInfoDialogTab::hasDataChanged, [&] {
setTabsColors();
});
connect(tabInfo.tab.get(), &ModInfoDialogTab::wantsFocus,
[&, id = tabInfo.tab->tabID()] {
switchToTab(id);
});
}
}
int ModInfoDialog::exec()
{
GeometrySaver gs(Settings::instance(), this);
restoreState();
// whether to select the first tab; if the main window requested a specific
// tab, it is selected when encountered in update()
const auto noCustomTabRequested = (m_initialTab == ModInfoTabIDs::None);
const auto requestedTab = m_initialTab;
update(true);
if (noCustomTabRequested) {
m_core.settings().widgets().restoreIndex(ui->tabWidget);
}
const int r = TutorableDialog::exec();
saveState();
return r;
}
void ModInfoDialog::setMod(ModInfo::Ptr mod)
{
Q_ASSERT(mod);
m_mod = mod;
// resetting the first activation flag so selecting tabs will trigger it
// again
for (auto& tabInfo : m_tabs) {
tabInfo.tab->resetFirstActivation();
}
}
void ModInfoDialog::setMod(const QString& name)
{
unsigned int index = ModInfo::getIndex(name);
if (index == UINT_MAX) {
log::error("failed to resolve mod name {}", name);
return;
}
auto mod = ModInfo::getByIndex(index);
if (!mod) {
log::error("mod by index {} is null", index);
return;
}
setMod(mod);
}
void ModInfoDialog::selectTab(ModInfoTabIDs id)
{
if (!isVisible()) {
// can't select a tab if the dialog hasn't been properly updated yet
m_initialTab = id;
return;
}
switchToTab(id);
}
ModInfoDialog::TabInfo* ModInfoDialog::currentTab()
{
const auto index = ui->tabWidget->currentIndex();
if (index < 0) {
return nullptr;
}
// looking for the actual tab at that position
for (auto& tabInfo : m_tabs) {
if (tabInfo.realPos == index) {
return &tabInfo;
}
}
return nullptr;
}
void ModInfoDialog::update(bool firstTime)
{
// remembering the current selection, will be restored if the tab still
// exists
const int oldTab = ui->tabWidget->currentIndex();
setWindowTitle(m_mod->name());
// rebuilding the tab widget if needed depending on what tabs are valid for
// the current mod
setTabsVisibility(firstTime);
// updating the data in all tabs
updateTabs();
// switching to the initial tab, if any
if (m_initialTab != ModInfoTabIDs::None) {
switchToTab(m_initialTab);
m_initialTab = ModInfoTabIDs::None;
}
if (ui->tabWidget->currentIndex() == oldTab) {
if (auto* tabInfo = currentTab()) {
// activated() has to be fired manually because the tab index hasn't been
// changed
tabInfo->tab->activated();
} else {
log::error("tab index {} not found", oldTab);
}
}
}
void ModInfoDialog::setTabsVisibility(bool firstTime)
{
// this flag is picked up by onTabSelectionChanged() to avoid triggering
// activation events while moving tabs around
QScopedValueRollback arrangingTabs(m_arrangingTabs, true);
// one bool per tab to indicate whether the tab should be visible
std::vector<bool> visibility(m_tabs.size());
bool changed = false;
for (std::size_t i = 0; i < m_tabs.size(); ++i) {
const auto& tabInfo = m_tabs[i];
bool visible = true;
// a tab is visible if it can handle the current mod
if (m_mod->hasFlag(ModInfo::FLAG_FOREIGN)) {
visible = tabInfo.tab->canHandleUnmanaged();
} else if (m_mod->hasFlag(ModInfo::FLAG_SEPARATOR)) {
visible = tabInfo.tab->canHandleSeparators();
}
// if the visibility of this tab is changing, set changed to true because
// the tabs have to be rebuilt
const auto currentlyVisible = (ui->tabWidget->indexOf(tabInfo.widget) != -1);
if (visible != currentlyVisible) {
changed = true;
}
visibility[i] = visible;
}
// the tabs have to be rebuilt the first time the dialog is shown, or when
// the visibility of any tab has changed
if (!firstTime && !changed) {
return;
}
// save the current order (if necessary) because some tabs will be removed and
// others added
if (!firstTime) {
// but don't do it the first time visibility is set because the tabs are
// in the default order, which will clobber the current settings
saveTabOrder();
}
// remember selection, if any
auto sel = ModInfoTabIDs::None;
if (const auto* tabInfo = currentTab()) {
sel = tabInfo->tab->tabID();
}
// removes all tabs and re-adds the visible ones
reAddTabs(visibility, sel);
}
void ModInfoDialog::reAddTabs(const std::vector<bool>& visibility, ModInfoTabIDs sel)
{
Q_ASSERT(visibility.size() == m_tabs.size());
// ordered tab names from settings
const auto orderedNames = m_core.settings().geometry().modInfoTabOrder();
// whether the tabs can be sorted
//
// if the object name of a tab widget is not found in orderedNames, the list
// cannot be sorted safely; if the list is empty, it's probably a first run
// and there's nothing to sort
bool canSort = !orderedNames.empty();
// gathering visible tabs
std::vector<TabInfo*> visibleTabs;
for (std::size_t i = 0; i < m_tabs.size(); ++i) {
if (!visibility[i]) {
// this tab is not visible, skip it
continue;
}
// this tab is visible
visibleTabs.push_back(&m_tabs[i]);
if (canSort) {
// make sure the widget object name is found in the list
const auto objectName = m_tabs[i].widget->objectName();
auto itor = std::find(orderedNames.begin(), orderedNames.end(), objectName);
if (itor == orderedNames.end()) {
// this shouldn't happen, it means there's a tab in the UI that's no
// in the list
log::error("can't sort tabs, '{}' not found", objectName);
canSort = false;
}
}
}
// sorting tabs
if (canSort) {
std::sort(visibleTabs.begin(), visibleTabs.end(), [&](auto&& a, auto&& b) {
// looking the names in the ordered list
auto aItor =
std::find(orderedNames.begin(), orderedNames.end(), a->widget->objectName());
auto bItor =
std::find(orderedNames.begin(), orderedNames.end(), b->widget->objectName());
// this shouldn't happen, it was checked above
Q_ASSERT(aItor != orderedNames.end() && bItor != orderedNames.end());
return (aItor < bItor);
});
}
// removing all tabs
ui->tabWidget->clear();
// reset real positions
for (auto& tabInfo : m_tabs) {
tabInfo.realPos = -1;
}
// add visible tabs
for (std::size_t i = 0; i < visibleTabs.size(); ++i) {
auto& tabInfo = *visibleTabs[i];
// remembering real position
tabInfo.realPos = static_cast<int>(i);
// adding tab
ui->tabWidget->addTab(tabInfo.widget, tabInfo.icon, tabInfo.caption);
// selecting
if (tabInfo.tab->tabID() == sel) {
ui->tabWidget->setCurrentIndex(static_cast<int>(i));
}
}
}
void ModInfoDialog::updateTabs(bool becauseOriginChanged)
{
auto* origin = getOrigin();
// list of tabs that should be updated
std::vector<TabInfo*> interestedTabs;
for (auto& tabInfo : m_tabs) {
// don't touch invisible tabs
if (!tabInfo.isVisible()) {
continue;
}
// updateTabs() is also called from onOriginModified() to update all the
// tabs that depend on the origin; if updateTabs() is called because the
// origin changed, but the tab doesn't use origin files, it can be safely
// skipped
//
// this happens for tabs like notes and categories, which don't need to
// be updated when files change
if (becauseOriginChanged && !tabInfo.tab->usesOriginFiles()) {
continue;
}
// this tab should be updated
interestedTabs.push_back(&tabInfo);
}
for (auto* tabInfo : interestedTabs) {
// set the current mod
tabInfo->tab->setMod(m_mod, origin);
// clear
tabInfo->tab->clear();
}
// feed all the files from the filesystem
feedFiles(interestedTabs);
// call update() on all tabs
for (auto* tabInfo : interestedTabs) {
tabInfo->tab->update();
}
// update the text colours
setTabsColors();
}
void ModInfoDialog::feedFiles(std::vector<TabInfo*>& interestedTabs)
{
const auto rootPath =
m_mod->absolutePath() + (m_core.managedGame()->modDataDirectory().isEmpty()
? ""
: "/" + m_core.managedGame()->modDataDirectory());
if (rootPath.isEmpty()) {
return;
}
if (fs::exists(rootPath.toStdWString())) {
const fs::path fsPath(rootPath.toStdWString());
for (const auto& entry : fs::recursive_directory_iterator(fsPath)) {
if (!entry.is_regular_file()) {
// skip directories
continue;
}
const auto filePath = QString::fromStdWString(entry.path().native());
// for each tab
for (auto* tabInfo : interestedTabs) {
if (tabInfo->tab->feedFile(rootPath, filePath)) {
break;
}
}
}
}
}
void ModInfoDialog::setTabsColors()
{
const auto p = m_modListView->parentWidget()->palette();
for (const auto& tabInfo : m_tabs) {
if (!tabInfo.isVisible()) {
// don't bother with invisible tabs
continue;
}
const QColor color = tabInfo.tab->hasData()
? QColor::Invalid
: p.color(QPalette::Disabled, QPalette::WindowText);
ui->tabWidget->tabBar()->setTabTextColor(tabInfo.realPos, color);
}
}
void ModInfoDialog::switchToTab(ModInfoTabIDs id)
{
// look a tab with the given id
for (const auto& tabInfo : m_tabs) {
if (tabInfo.tab->tabID() == id) {
// use realPos to select the proper tab in the widget
ui->tabWidget->setCurrentIndex(tabInfo.realPos);
return;
}
}
// this could happen if the tab is not visible right now
log::debug("can't switch to tab ID {}, not available", static_cast<int>(id));
}
MOShared::FilesOrigin* ModInfoDialog::getOrigin()
{
auto* ds = m_core.directoryStructure();
if (!ds->originExists(m_mod->name().toStdWString())) {
return nullptr;
}
auto* origin = &ds->getOriginByName(m_mod->name().toStdWString());
if (origin->isDisabled()) {
return nullptr;
}
return origin;
}
void ModInfoDialog::saveState() const
{
saveTabOrder();
// save state for each tab
for (const auto& tabInfo : m_tabs) {
tabInfo.tab->saveState(m_core.settings());
}
}
void ModInfoDialog::restoreState()
{
// tab order is not restored here, it will be picked up if tabs have to be
// removed and re-added
// restore state for each tab
for (const auto& tabInfo : m_tabs) {
tabInfo.tab->restoreState(m_core.settings());
}
}
void ModInfoDialog::saveTabOrder() const
{
if (static_cast<int>(m_tabs.size()) != ui->tabWidget->count()) {
// only save tab state when all tabs are visible
//
// if not all tabs are visible, it becomes very difficult to figure out in
// what order the user wants these tabs to be, so just avoid saving it
// completely
//
// this means that reordering tabs when not all tabs are visible is not
// saved, but it's better than breaking everything
return;
}
QString names;
for (int i = 0; i < ui->tabWidget->count(); ++i) {
if (!names.isEmpty()) {
names += " ";
}
names += ui->tabWidget->widget(i)->objectName();
}
m_core.settings().geometry().setModInfoTabOrder(names);
// save last opened index
m_core.settings().widgets().saveIndex(ui->tabWidget);
}
void ModInfoDialog::onOriginModified(int originID)
{
// tell the main window the origin changed
emit originModified(originID);
// update tabs that depend on the origin
updateTabs(true);
}
void ModInfoDialog::onDeleteShortcut()
{
// forward the request to the current tab
if (auto* tabInfo = currentTab()) {
tabInfo->tab->deleteRequested();
}
}
void ModInfoDialog::closeEvent(QCloseEvent* e)
{
if (tryClose()) {
e->accept();
} else {
e->ignore();
}
}
void ModInfoDialog::onCloseButton()
{
if (tryClose()) {
close();
}
}
bool ModInfoDialog::tryClose()
{
// cancel the close if any tab returns false; for example. this can happen if
// a tab has unsaved content, pops a confirmation dialog, and the user clicks
// cancel
for (auto& tabInfo : m_tabs) {
if (!tabInfo.tab->canClose()) {
return false;
}
}
return true;
}
void ModInfoDialog::onTabSelectionChanged()
{
if (m_arrangingTabs) {
// this can be fired while re-arranging tabs, which happens before mods
// are given to tabs, and might trigger first activation, which breaks all
// sorts of things
return;
}
// this will call firstActivation() on the tab if needed
if (auto* tabInfo = currentTab()) {
tabInfo->tab->activated();
}
}
void ModInfoDialog::onTabMoved()
{
// reset
for (auto& tabInfo : m_tabs) {
tabInfo.realPos = -1;
}
// for each tab in the widget
for (int i = 0; i < ui->tabWidget->count(); ++i) {
const auto* w = ui->tabWidget->widget(i);
bool found = false;
// find the corresponding tab info
for (auto& tabInfo : m_tabs) {
if (tabInfo.widget == w) {
tabInfo.realPos = i;
found = true;
break;
}
}
if (!found) {
log::error("unknown tab at index {}", i);
}
}
}
void ModInfoDialog::onNextMod()
{
auto index = m_modListView->nextMod(ModInfo::getIndex(m_mod->name()));
if (!index) {
return;
}
auto mod = ModInfo::getByIndex(*index);
if (!mod || mod == m_mod) {
return;
}
setMod(mod);
update();
emit modChanged(*index);
}
void ModInfoDialog::onPreviousMod()
{
auto index = m_modListView->prevMod(ModInfo::getIndex(m_mod->name()));
if (!index) {
return;
}
auto mod = ModInfo::getByIndex(*index);
setMod(mod);
update();
emit modChanged(*index);
}