Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter checkbox to data tab to show/hide hidden files #2136

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/datatab.cpp
Original file line number Diff line number Diff line change
@@ -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));
@@ -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);

@@ -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)
@@ -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()
@@ -146,6 +153,11 @@ void DataTab::onArchives()
updateOptions();
}

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

void DataTab::updateOptions()
{
using M = FileTreeModel;
@@ -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
@@ -54,6 +54,7 @@ class DataTab : public QObject
QTreeView* tree;
QCheckBox* conflicts;
QCheckBox* archives;
QCheckBox* hiddenFiles;
};

OrganizerCore& m_core;
@@ -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;
14 changes: 12 additions & 2 deletions src/filetreemodel.cpp
Original file line number Diff line number Diff line change
@@ -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);
@@ -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)) {
@@ -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;
}

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

enum Columns
@@ -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);
19 changes: 19 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
@@ -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">