Skip to content

Commit

Permalink
Add filter checkbox to data tab to show/hide hidden files (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanFeenstra authored Oct 10, 2024
1 parent 71434ef commit bafc058
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/datatab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ DataTab::DataTab(OrganizerCore& core, PluginContainer& pc, QWidget* parent,
mwui->dataTabRefresh,
mwui->dataTree,
mwui->dataTabShowOnlyConflicts,
mwui->dataTabShowFromArchives},
mwui->dataTabShowFromArchives,
mwui->dataTabShowHiddenFiles},
m_needUpdate(true)
{
m_filetree.reset(new FileTree(core, m_pluginContainer, ui.tree));
Expand Down Expand Up @@ -52,6 +53,10 @@ DataTab::DataTab(OrganizerCore& core, PluginContainer& pc, QWidget* parent,
onArchives();
});

connect(ui.hiddenFiles, &QCheckBox::toggled, [&] {
onHiddenFiles();
});

connect(m_filetree.get(), &FileTree::executablesChanged, this,
&DataTab::executablesChanged);

Expand All @@ -66,6 +71,7 @@ void DataTab::saveState(Settings& s) const
s.geometry().saveState(ui.tree->header());
s.widgets().saveChecked(ui.conflicts);
s.widgets().saveChecked(ui.archives);
s.widgets().saveChecked(ui.hiddenFiles);
}

void DataTab::restoreState(const Settings& s)
Expand All @@ -78,6 +84,7 @@ void DataTab::restoreState(const Settings& s)

s.widgets().restoreChecked(ui.conflicts);
s.widgets().restoreChecked(ui.archives);
s.widgets().restoreChecked(ui.hiddenFiles);
}

void DataTab::activated()
Expand Down Expand Up @@ -146,6 +153,11 @@ void DataTab::onArchives()
updateOptions();
}

void DataTab::onHiddenFiles()
{
updateOptions();
}

void DataTab::updateOptions()
{
using M = FileTreeModel;
Expand All @@ -160,6 +172,10 @@ void DataTab::updateOptions()
flags |= M::Archives;
}

if (ui.hiddenFiles->isChecked()) {
flags |= M::HiddenFiles;
}

m_filetree->model()->setFlags(flags);
updateTree();
}
2 changes: 2 additions & 0 deletions src/datatab.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DataTab : public QObject
QTreeView* tree;
QCheckBox* conflicts;
QCheckBox* archives;
QCheckBox* hiddenFiles;
};

OrganizerCore& m_core;
Expand All @@ -69,6 +70,7 @@ class DataTab : public QObject
void onItemExpanded(QTreeWidgetItem* item);
void onConflicts();
void onArchives();
void onHiddenFiles();
void updateOptions();
void ensureFullyLoaded();
bool isActive() const;
Expand Down
14 changes: 12 additions & 2 deletions src/filetreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ void* makeInternalPointer(FileTreeItem* item)

FileTreeModel::FileTreeModel(OrganizerCore& core, QObject* parent)
: QAbstractItemModel(parent), m_core(core), m_enabled(true),
m_root(FileTreeItem::createDirectory(this, nullptr, L"", L"")), m_flags(NoFlags),
m_fullyLoaded(false), m_sortingEnabled(true)
m_root(FileTreeItem::createDirectory(this, nullptr, L"", L"")),
m_flags(HiddenFiles), m_fullyLoaded(false), m_sortingEnabled(true)
{
m_root->setExpanded(true);
m_sortTimer.setSingleShot(true);
Expand Down Expand Up @@ -269,6 +269,11 @@ bool FileTreeModel::showArchives() const
return (m_flags.testFlag(Archives) && m_core.settings().archiveParsing());
}

bool FileTreeModel::showHiddenFiles() const
{
return m_flags.testAnyFlag(HiddenFiles);
}

QModelIndex FileTreeModel::index(int row, int col, const QModelIndex& parentIndex) const
{
if (auto* parentItem = itemFromIndex(parentIndex)) {
Expand Down Expand Up @@ -974,6 +979,11 @@ bool FileTreeModel::shouldShowFile(const FileEntry& file) const
return false;
}

if (!showHiddenFiles() && file.getName().ends_with(L".mohidden")) {
// hidden files shouldn't be shown, but this file is hidden
return false;
}

return true;
}

Expand Down
5 changes: 4 additions & 1 deletion src/filetreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class FileTreeModel : public QAbstractItemModel
NoFlags = 0x00,
ConflictsOnly = 0x01,
Archives = 0x02,
PruneDirectories = 0x04
PruneDirectories = 0x04,
HiddenFiles = 0x08
};

enum Columns
Expand Down Expand Up @@ -102,6 +103,8 @@ class FileTreeModel : public QAbstractItemModel

bool showArchives() const;

bool showHiddenFiles() const;

// for `forFetching`, see top of filetreemodel.cpp
void update(FileTreeItem& parentItem, const MOShared::DirectoryEntry& parentEntry,
const std::wstring& parentPath, bool forFetching);
Expand Down
19 changes: 19 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,25 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="dataTabShowHiddenFiles">
<property name="toolTip">
<string>Filter the list so that hidden files are shown.</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="whatsThis">
<string>Filter the list so that hidden files are shown.</string>
</property>
<property name="text">
<string>Hidden Files</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="dataTabFilter">
<property name="toolTip">
Expand Down

0 comments on commit bafc058

Please sign in to comment.