Skip to content

Commit

Permalink
Deducing shader language/type of shader item
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Sep 26, 2023
1 parent 1659164 commit b843165
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,21 @@ QString FileDialog::getWindowTitle(const QString &fileName)
return "[*]" + getFileTitle(fileName);
}

QString FileDialog::getFileExtension(const QString &fileName)
{
if (isEmptyOrUntitled(fileName))
return "";
return QFileInfo(fileName).suffix().toLower();
}

bool FileDialog::isSessionFileName(const QString &fileName)
{
return fileName.endsWith(SessionFileExtension);
return (getFileExtension(fileName) == SessionFileExtension);
}

bool FileDialog::isShaderFileName(const QString &fileName)
{
const auto extension = QFileInfo(fileName).suffix().toLower();
const auto extension = getFileExtension(fileName);
for (const auto &ext : ShaderFileExtensions)
if (ext == extension)
return true;
Expand All @@ -104,7 +111,7 @@ bool FileDialog::isShaderFileName(const QString &fileName)

bool FileDialog::isScriptFileName(const QString &fileName)
{
const auto extension = QFileInfo(fileName).suffix().toLower();
const auto extension = getFileExtension(fileName);
for (const auto &ext : ScriptFileExtensions)
if (ext == extension)
return true;
Expand All @@ -113,7 +120,7 @@ bool FileDialog::isScriptFileName(const QString &fileName)

bool FileDialog::isTextureFileName(const QString &fileName)
{
const auto extension = QFileInfo(fileName).suffix().toLower();
const auto extension = getFileExtension(fileName);
for (const auto &ext : TextureFileExtensions)
if (ext == extension)
return true;
Expand All @@ -122,7 +129,7 @@ bool FileDialog::isTextureFileName(const QString &fileName)

bool FileDialog::isVideoFileName(const QString &fileName)
{
const auto extension = QFileInfo(fileName).suffix().toLower();
const auto extension = getFileExtension(fileName);
for (const auto &ext : VideoFileExtensions)
if (ext == extension)
return true;
Expand Down
1 change: 1 addition & 0 deletions src/FileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class FileDialog final : public QObject
static QString generateNextUntitledFileName(QString base);
static bool isEmptyOrUntitled(const QString &fileName);
static bool isUntitled(const QString &fileName);
static QString getFileExtension(const QString &fileName);
static QString getFileTitle(const QString &fileName);
static QString getWindowTitle(const QString &fileName);
static QString getFullWindowTitle(const QString &fileName);
Expand Down
21 changes: 21 additions & 0 deletions src/session/SessionProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ SessionProperties::SessionProperties(QWidget *parent)
[this]() { return getFileNames(Item::Type::Shader); });
connect(mShaderProperties->language, &DataComboBox::currentDataChanged,
this, &SessionProperties::updateShaderWidgets);
connect(mShaderProperties->file, &ReferenceComboBox::activated,
this, &SessionProperties::deduceShaderType);

connect(mBufferProperties->fileNew, &QToolButton::clicked,
[this]() { saveCurrentItemFileAs(FileDialog::BinaryExtensions); });
Expand Down Expand Up @@ -655,3 +657,22 @@ void SessionProperties::deduceBlockRowCount()
(binary.size() - offset) / stride);
}
}

void SessionProperties::deduceShaderType()
{
const auto &shader = *mModel.item<Shader>(currentModelIndex());
const auto fileName = mShaderProperties->file->currentData().toString();
auto source = QString();
if (Singletons::fileCache().getSource(fileName, &source)) {
const auto currentSourceType = (shader.fileName.isEmpty() ? SourceType::PlainText :
getSourceType(shader.shaderType, shader.language));
const auto extension = FileDialog::getFileExtension(fileName);
const auto sourceType = deduceSourceType(currentSourceType, extension, source);
if (sourceType != currentSourceType) {
const auto shaderType = getShaderType(sourceType);
const auto shaderLanguage = getShaderLanguage(sourceType);
mModel.setData(mModel.getIndex(currentModelIndex(), SessionModel::ShaderType), shaderType);
mModel.setData(mModel.getIndex(currentModelIndex(), SessionModel::ShaderLanguage), shaderLanguage);
}
}
}
1 change: 1 addition & 0 deletions src/session/SessionProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SessionProperties final : public QScrollArea
void updateShaderWidgets();
void deduceBlockOffset();
void deduceBlockRowCount();
void deduceShaderType();
IEditor* openEditor(const FileItem &fileItem);
void fillComboBoxes();
void switchToCurrentFileItemDirectory();
Expand Down

0 comments on commit b843165

Please sign in to comment.