Skip to content

Commit 4187199

Browse files
Add filter checkbox to data tab to show/hide hidden files
1 parent 8f1dbe9 commit 4187199

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

src/datatab.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ DataTab::DataTab(OrganizerCore& core, PluginContainer& pc, QWidget* parent,
2222
mwui->dataTabRefresh,
2323
mwui->dataTree,
2424
mwui->dataTabShowOnlyConflicts,
25-
mwui->dataTabShowFromArchives},
25+
mwui->dataTabShowFromArchives,
26+
mwui->dataTabShowHiddenFiles},
2627
m_needUpdate(true)
2728
{
2829
m_filetree.reset(new FileTree(core, m_pluginContainer, ui.tree));
@@ -52,6 +53,10 @@ DataTab::DataTab(OrganizerCore& core, PluginContainer& pc, QWidget* parent,
5253
onArchives();
5354
});
5455

56+
connect(ui.hiddenFiles, &QCheckBox::toggled, [&] {
57+
onHiddenFiles();
58+
});
59+
5560
connect(m_filetree.get(), &FileTree::executablesChanged, this,
5661
&DataTab::executablesChanged);
5762

@@ -146,6 +151,11 @@ void DataTab::onArchives()
146151
updateOptions();
147152
}
148153

154+
void DataTab::onHiddenFiles()
155+
{
156+
updateOptions();
157+
}
158+
149159
void DataTab::updateOptions()
150160
{
151161
using M = FileTreeModel;
@@ -160,6 +170,10 @@ void DataTab::updateOptions()
160170
flags |= M::Archives;
161171
}
162172

173+
if (ui.hiddenFiles->isChecked()) {
174+
flags |= M::HiddenFiles;
175+
}
176+
163177
m_filetree->model()->setFlags(flags);
164178
updateTree();
165179
}

src/datatab.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class DataTab : public QObject
5454
QTreeView* tree;
5555
QCheckBox* conflicts;
5656
QCheckBox* archives;
57+
QCheckBox* hiddenFiles;
5758
};
5859

5960
OrganizerCore& m_core;
@@ -69,6 +70,7 @@ class DataTab : public QObject
6970
void onItemExpanded(QTreeWidgetItem* item);
7071
void onConflicts();
7172
void onArchives();
73+
void onHiddenFiles();
7274
void updateOptions();
7375
void ensureFullyLoaded();
7476
bool isActive() const;

src/filetreemodel.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ void* makeInternalPointer(FileTreeItem* item)
182182

183183
FileTreeModel::FileTreeModel(OrganizerCore& core, QObject* parent)
184184
: QAbstractItemModel(parent), m_core(core), m_enabled(true),
185-
m_root(FileTreeItem::createDirectory(this, nullptr, L"", L"")), m_flags(NoFlags),
186-
m_fullyLoaded(false), m_sortingEnabled(true)
185+
m_root(FileTreeItem::createDirectory(this, nullptr, L"", L"")),
186+
m_flags(HiddenFiles), m_fullyLoaded(false), m_sortingEnabled(true)
187187
{
188188
m_root->setExpanded(true);
189189
m_sortTimer.setSingleShot(true);
@@ -269,6 +269,11 @@ bool FileTreeModel::showArchives() const
269269
return (m_flags.testFlag(Archives) && m_core.settings().archiveParsing());
270270
}
271271

272+
bool FileTreeModel::showHiddenFiles() const
273+
{
274+
return m_flags.testAnyFlag(HiddenFiles);
275+
}
276+
272277
QModelIndex FileTreeModel::index(int row, int col, const QModelIndex& parentIndex) const
273278
{
274279
if (auto* parentItem = itemFromIndex(parentIndex)) {
@@ -974,6 +979,11 @@ bool FileTreeModel::shouldShowFile(const FileEntry& file) const
974979
return false;
975980
}
976981

982+
if (!showHiddenFiles() && file.getName().ends_with(L".mohidden")) {
983+
// hidden files shouldn't be shown, but this file is hidden
984+
return false;
985+
}
986+
977987
return true;
978988
}
979989

src/filetreemodel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class FileTreeModel : public QAbstractItemModel
1818
NoFlags = 0x00,
1919
ConflictsOnly = 0x01,
2020
Archives = 0x02,
21-
PruneDirectories = 0x04
21+
PruneDirectories = 0x04,
22+
HiddenFiles = 0x08
2223
};
2324

2425
enum Columns
@@ -102,6 +103,8 @@ class FileTreeModel : public QAbstractItemModel
102103

103104
bool showArchives() const;
104105

106+
bool showHiddenFiles() const;
107+
105108
// for `forFetching`, see top of filetreemodel.cpp
106109
void update(FileTreeItem& parentItem, const MOShared::DirectoryEntry& parentEntry,
107110
const std::wstring& parentPath, bool forFetching);

src/mainwindow.ui

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,25 @@
11801180
</property>
11811181
</widget>
11821182
</item>
1183+
<item>
1184+
<widget class="QCheckBox" name="dataTabShowHiddenFiles">
1185+
<property name="toolTip">
1186+
<string>Filter the list so that hidden files are shown.</string>
1187+
</property>
1188+
<property name="statusTip">
1189+
<string/>
1190+
</property>
1191+
<property name="whatsThis">
1192+
<string>Filter the list so that hidden files are shown.</string>
1193+
</property>
1194+
<property name="text">
1195+
<string>Hidden Files</string>
1196+
</property>
1197+
<property name="checked">
1198+
<bool>true</bool>
1199+
</property>
1200+
</widget>
1201+
</item>
11831202
<item>
11841203
<widget class="QLineEdit" name="dataTabFilter">
11851204
<property name="toolTip">

0 commit comments

Comments
 (0)