Skip to content

Commit

Permalink
fix: don't create new file from palette
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Oct 30, 2024
1 parent 6e781bc commit 6f12fbe
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/gui/palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ class FileModel : public QAbstractTableModel
endResetModel();
}

bool fileExists(const QString &filename)
{
if (Core::Project::instance()->root().isEmpty())
return false;
auto it = std::find_if(m_files.cbegin(), m_files.cend(), [filename](const auto &fi) {
return fi.fileName == filename;
});
if (it == m_files.cend())
return false;
return true;
}

private:
struct FileInfo
{
Expand Down Expand Up @@ -480,8 +492,10 @@ void Palette::addFileSelector()
auto resetFiles = [model = fileModel.get()]() {
model->resetFileInfo();
};
auto selectFile = [](const QVariant &path) {
Core::Project::instance()->open(path.toString());
auto selectFile = [model = fileModel.get()](const QVariant &path) {
if (model->fileExists(path.toString())) {
Core::Project::instance()->open(path.toString());
}
};
m_selectors.emplace_back("", std::move(fileModel), selectFile, resetFiles);
}
Expand Down

0 comments on commit 6f12fbe

Please sign in to comment.