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

fix: don't create new file from palette #213

Closed
wants to merge 1 commit into from
Closed
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: 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
Loading