Commit f72925d1 authored by Yann Boucher's avatar Yann Boucher
Browse files

Added support for automatically detecting new patterns in the pattern library directory

parent aa30c61e
Pipeline #78277 passed with stages
in 17 seconds
......@@ -8,6 +8,7 @@
#include <QDir>
#include <QTreeWidgetItem>
#include <QFileSystemWatcher>
#include "structure.hpp"
......@@ -37,6 +38,7 @@ private slots:
private:
Ui::StructureLibraryView *ui;
QFileSystemWatcher m_watcher;
};
#endif // STRUCTURELIBRARYVIEW_HPP
......@@ -20,6 +20,10 @@ StructureLibraryView::StructureLibraryView(QWidget *parent) :
connect(ui->tree, &QTreeWidget::itemClicked, this, &StructureLibraryView::update_info);
connect(ui->button_copy, &QPushButton::pressed, this, &StructureLibraryView::copy_button_clicked);
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, [this](const QString&)
{
load_structures();
});
}
StructureLibraryView::~StructureLibraryView()
......@@ -29,8 +33,12 @@ StructureLibraryView::~StructureLibraryView()
void StructureLibraryView::load_structures()
{
// clear the previously watched directories
m_watcher.removePaths(m_watcher.directories());
QTreeWidgetItem* pattern_list = add_directory_contents(QDir("patterns/"));
pattern_list->setText(0, "Patterns");
ui->tree->clear();
ui->tree->addTopLevelItem(pattern_list);
pattern_list->setExpanded(true);
}
......@@ -67,6 +75,9 @@ QTreeWidgetItem *StructureLibraryView::add_directory_contents(const QDir &dir)
root->addChild(child);
}
// register this directory for filesystem watching
m_watcher.addPath(dir.absolutePath());
return root;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment