Skip to content

Commit

Permalink
Moved source type/validation to source editor toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed May 5, 2021
1 parent 56136fd commit 3ecc551
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 217 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ set(SOURCES
src/editors/TextureItem.cpp
src/editors/JsHighlighter.cpp
src/editors/SourceEditor.cpp
src/editors/SourceEditorToolBar.cpp
src/editors/SourceEditorToolBar.ui
src/main.cpp
src/render/GLBuffer.cpp
Expand Down
40 changes: 0 additions & 40 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ MainWindow::MainWindow(QWidget *parent)
mSessionEditor.data(), &SessionEditor::updateItemActions);

auto &synchronizeLogic = Singletons::synchronizeLogic();
connect(mUi->actionSourceValidation, &QAction::toggled,
&synchronizeLogic, &SynchronizeLogic::setValidateSource);
connect(mOutputWindow.data(), &OutputWindow::typeSelectionChanged,
&synchronizeLogic, &SynchronizeLogic::setProcessSourceType);
connect(outputDock, &QDockWidget::visibilityChanged,
Expand Down Expand Up @@ -257,41 +255,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(mUi->actionManageCustomActions, &QAction::triggered,
mCustomActions.data(), &QDialog::show);

auto sourceTypeActionGroup = new QActionGroup(this);
auto sourceTypeButton = qobject_cast<QToolButton*>(
mUi->toolBarMain->widgetForAction(mUi->actionSourceValidation));
sourceTypeButton->setMenu(mUi->menuSourceType);
sourceTypeButton->setPopupMode(QToolButton::MenuButtonPopup);

auto addSourceType = [&](const QString &text, SourceType sourceType) {
auto action = mUi->menuSourceType->addAction(text);
action->setData(static_cast<int>(sourceType));
action->setCheckable(true);
action->setActionGroup(sourceTypeActionGroup);
};
addSourceType(tr("Plaintext"), SourceType::PlainText);
addSourceType(tr("Vertex Shader"), SourceType::VertexShader);
addSourceType(tr("Fragment Shader"), SourceType::FragmentShader);
addSourceType(tr("Geometry Shader"), SourceType::GeometryShader);
addSourceType(tr("Tessellation Control"), SourceType::TessellationControl);
addSourceType(tr("Tessellation Evaluation"), SourceType::TessellationEvaluation);
addSourceType(tr("Compute Shader"), SourceType::ComputeShader);
addSourceType(tr("JavaScript"), SourceType::JavaScript);

connect(mUi->menuSourceType, &QMenu::aboutToShow,
[this, sourceTypeActionGroup]() {
auto sourceType = mEditorManager.currentSourceType();
const auto actions = sourceTypeActionGroup->actions();
for (QAction *action : actions)
action->setChecked(static_cast<SourceType>(
action->data().toInt()) == sourceType);
});
connect(mUi->menuSourceType, &QMenu::triggered,
[this](QAction *action) {
mEditorManager.setCurrentSourceType(
static_cast<SourceType>(action->data().toInt()));
});

auto indentActionGroup = new QActionGroup(this);
connect(indentActionGroup, &QActionGroup::triggered,
[](QAction* a) { Singletons::settings().setTabSize(a->text().toInt()); });
Expand Down Expand Up @@ -496,9 +459,6 @@ void MainWindow::updateFileActions()
mUi->actionReload->setEnabled(hasFile);
mUi->actionReload->setText(tr("&Reload%1").arg(hasFile ? desc : ""));
mUi->actionOpenContainingFolder->setEnabled(hasFile);

auto sourceType = mEditorManager.currentSourceType();
mUi->menuSourceType->setEnabled(sourceType != SourceType::None);
}

void MainWindow::stopEvaluation()
Expand Down
30 changes: 1 addition & 29 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<x>0</x>
<y>0</y>
<width>494</width>
<height>21</height>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -138,14 +138,6 @@
<string>Tab Size</string>
</property>
</widget>
<widget class="QMenu" name="menuSourceType">
<property name="title">
<string>Source &amp;Type</string>
</property>
</widget>
<addaction name="menuSourceType"/>
<addaction name="actionSourceValidation"/>
<addaction name="separator"/>
<addaction name="menuTabSize"/>
<addaction name="actionIndentWithSpaces"/>
<addaction name="actionShowWhiteSpace"/>
Expand Down Expand Up @@ -190,8 +182,6 @@
<addaction name="actionPaste"/>
<addaction name="actionDelete"/>
<addaction name="separator"/>
<addaction name="actionSourceValidation"/>
<addaction name="separator"/>
<addaction name="actionEvalReset"/>
<addaction name="actionEvalManual"/>
<addaction name="actionEvalAuto"/>
Expand Down Expand Up @@ -506,24 +496,6 @@
<string>F9</string>
</property>
</action>
<action name="actionSourceValidation">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/16x16/help-faq.png</normaloff>:/images/16x16/help-faq.png</iconset>
</property>
<property name="text">
<string>Source &amp;Validation</string>
</property>
<property name="shortcut">
<string>F4</string>
</property>
<property name="iconVisibleInMenu">
<bool>false</bool>
</property>
</action>
<action name="actionOnlineHelp">
<property name="icon">
<iconset resource="resources.qrc">
Expand Down
1 change: 0 additions & 1 deletion src/SourceType.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

enum class SourceType
{
None,
PlainText,
VertexShader,
FragmentShader,
Expand Down
41 changes: 22 additions & 19 deletions src/SynchronizeLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ SynchronizeLogic::SynchronizeLogic(QObject *parent)
this, &SynchronizeLogic::handleFileChanged);
connect(&Singletons::editorManager(), &EditorManager::editorRenamed,
this, &SynchronizeLogic::handleEditorFileRenamed);
connect(&Singletons::editorManager(), &EditorManager::sourceTypeChanged,
this, &SynchronizeLogic::handleSourceTypeChanged);

resetRenderSession();

Expand All @@ -51,18 +49,26 @@ SynchronizeLogic::~SynchronizeLogic() = default;

void SynchronizeLogic::setValidateSource(bool validate)
{
if (mValidateSource != validate) {
mValidateSource = validate;
processSource();
}
if (std::exchange(mValidateSource, validate) != validate)
mProcessSourceTimer->start();
}

void SynchronizeLogic::setProcessSourceType(QString type)
{
if (mProcessSourceType != type) {
mProcessSourceType = type;
processSource();
}
if (std::exchange(mProcessSourceType, type) != type)
mProcessSourceTimer->start();
}

void SynchronizeLogic::setCurrentEditorFileName(QString fileName)
{
if (std::exchange(mCurrentEditorFileName, fileName) != fileName)
mProcessSourceTimer->start();
}

void SynchronizeLogic::setCurrentEditorSourceType(SourceType sourceType)
{
if (std::exchange(mCurrentEditorSourceType, sourceType) != sourceType)
mProcessSourceTimer->start();
}

void SynchronizeLogic::resetRenderSession()
Expand Down Expand Up @@ -277,12 +283,6 @@ void SynchronizeLogic::handleFileItemRenamed(const FileItem &item)
Singletons::editorManager().renameEditors(prevFileName, item.fileName);
}

void SynchronizeLogic::handleSourceTypeChanged(SourceType sourceType)
{
Q_UNUSED(sourceType)
processSource();
}

void SynchronizeLogic::handleEvaluateTimout()
{
evaluate(mEvaluationMode == EvaluationMode::Automatic ?
Expand Down Expand Up @@ -386,11 +386,14 @@ void SynchronizeLogic::processSource()
if (!mValidateSource && mProcessSourceType.isEmpty())
return;

if (mCurrentEditorFileName.isEmpty() ||
!Singletons::editorManager().getSourceEditor(mCurrentEditorFileName))
return;

Singletons::fileCache().updateEditorFiles();

mProcessSource->setSource(
Singletons::editorManager().currentEditorFileName(),
Singletons::editorManager().currentSourceType());
mProcessSource->setFileName(mCurrentEditorFileName);
mProcessSource->setSourceType(mCurrentEditorSourceType);
mProcessSource->setValidateSource(mValidateSource);
mProcessSource->setProcessType(mProcessSourceType);
mProcessSource->update();
Expand Down
14 changes: 11 additions & 3 deletions src/SynchronizeLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ class SynchronizeLogic final : public QObject
~SynchronizeLogic() override;

void resetRenderSession();
void setValidateSource(bool validate);
void setProcessSourceType(QString type);

void setEvaluationMode(EvaluationMode mode);
void resetEvaluation();
void manualEvaluation();
void updateEditor(ItemId itemId, bool activated);

void setValidateSource(bool validate);
bool validatingSource() const { return mValidateSource; }
void setProcessSourceType(QString type);
const QString& processSourceType() const { return mProcessSourceType; }
void setCurrentEditorFileName(QString fileName);
void setCurrentEditorSourceType(SourceType sourceType);

void setMousePosition(QPointF pos) { mMousePosition = pos; }
const QPointF &mousePosition() const { return mMousePosition; }

Expand All @@ -38,7 +45,6 @@ class SynchronizeLogic final : public QObject
void handleItemModified(const QModelIndex &index);
void handleItemsModified(const QModelIndex &topLeft,
const QModelIndex &bottomRight, const QVector<int> &roles);
void handleSourceTypeChanged(SourceType sourceType);
void handleEditorFileRenamed(const QString &prevFileName,
const QString &fileName);
void handleFileItemFileChanged(const FileItem &item);
Expand Down Expand Up @@ -66,6 +72,8 @@ class SynchronizeLogic final : public QObject
EvaluationMode mEvaluationMode{ };

bool mValidateSource{ };
QString mCurrentEditorFileName{ };
SourceType mCurrentEditorSourceType{ };
QString mProcessSourceType{ };
QTimer *mProcessSourceTimer{ };
ProcessSource* mProcessSource{ };
Expand Down
3 changes: 2 additions & 1 deletion src/TextureData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ bool TextureData::loadGli(const QString &fileName, bool flipVertically) try
const auto levels = (texture.levels() > 1 ? texture.levels() : 0);

if (!create(target, static_cast<QOpenGLTexture::TextureFormat>(format.Internal),
extent.x, extent.y, extent.z, texture.layers(), 1, levels))
extent.x, extent.y, extent.z, static_cast<int>(texture.layers()), 1,
static_cast<int>(levels)))
return false;

for (auto layer = 0u; layer < texture.layers(); ++layer)
Expand Down
40 changes: 16 additions & 24 deletions src/editors/EditorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Singletons.h"
#include "FileCache.h"
#include "FileDialog.h"
#include "SynchronizeLogic.h"
#include <functional>
#include <QDockWidget>
#include <QAction>
Expand Down Expand Up @@ -32,24 +33,30 @@ void EditorManager::createEditorToolBars(QToolBar *mainToolBar)
mBinaryEditorToolBar = BinaryEditor::createEditorToolBar(widget);
mainToolBar->addWidget(widget);

widget = new QWidget(this);
mSourceEditorToolBar = SourceEditor::createEditorToolBar(widget);
mainToolBar->addWidget(widget);
mSourceEditorToolBar = new SourceEditorToolBar(this);
mainToolBar->addWidget(mSourceEditorToolBar);

connect(mSourceEditorToolBar, &SourceEditorToolBar::validateSourceChanged,
&Singletons::synchronizeLogic(), &SynchronizeLogic::setValidateSource);
connect(mSourceEditorToolBar, &SourceEditorToolBar::sourceTypeChanged,
&Singletons::synchronizeLogic(), &SynchronizeLogic::setCurrentEditorSourceType);
connect(this, &EditorManager::currentEditorChanged,
&Singletons::synchronizeLogic(), &SynchronizeLogic::setCurrentEditorFileName);

updateEditorToolBarVisibility();
}

void EditorManager::updateEditorToolBarVisibility()
{
// setting maximumWidth since simply setting visibility did not work
const auto setVisible = [](const QWidget* child, bool visible) {
child->parentWidget()->setMaximumWidth(visible ? 65536 : 0);
const auto setVisible = [](QWidget* widget, bool visible) {
widget->setMaximumWidth(visible ? 65536 : 0);
};
setVisible(mTextureEditorToolBar->level,
setVisible(mTextureEditorToolBar->level->parentWidget(),
mCurrentDock && qobject_cast<TextureEditor*>(mCurrentDock->widget()));
setVisible(mBinaryEditorToolBar->block,
setVisible(mBinaryEditorToolBar->block->parentWidget(),
mCurrentDock && qobject_cast<BinaryEditor*>(mCurrentDock->widget()));
setVisible(mSourceEditorToolBar->sourceType,
setVisible(mSourceEditorToolBar,
mCurrentDock && qobject_cast<SourceEditor*>(mCurrentDock->widget()));
}

Expand Down Expand Up @@ -93,7 +100,7 @@ void EditorManager::updateCurrentEditor()
if (dock->isAncestorOf(focusWidget)) {
mCurrentDock = dock;
updateDockCurrentProperty(dock, true);
Q_EMIT sourceTypeChanged(currentSourceType());
Q_EMIT currentEditorChanged(editor->fileName());
break;
}
}
Expand Down Expand Up @@ -125,21 +132,6 @@ QDockWidget *EditorManager::findEditorDock(const IEditor *editor) const
return nullptr;
}

SourceType EditorManager::currentSourceType()
{
if (auto editor = currentEditor())
return editor->sourceType();
return SourceType::None;
}

void EditorManager::setCurrentSourceType(SourceType sourceType)
{
if (auto editor = currentEditor()) {
editor->setSourceType(sourceType);
Q_EMIT sourceTypeChanged(sourceType);
}
}

QList<QMetaObject::Connection> EditorManager::connectEditActions(
const EditActions &actions)
{
Expand Down
6 changes: 2 additions & 4 deletions src/editors/EditorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class EditorManager final : public DockWindow
void updateCurrentEditor();
bool hasCurrentEditor() const { return (mCurrentDock != nullptr); }
QString currentEditorFileName();
SourceType currentSourceType();
void setCurrentSourceType(SourceType sourceType);
QList<QMetaObject::Connection> connectEditActions(const EditActions &actions);
void renameEditors(const QString &prevFileName, const QString &fileName);
bool saveEditor();
Expand All @@ -61,7 +59,7 @@ class EditorManager final : public DockWindow

Q_SIGNALS:
void editorRenamed(const QString &prevFileName, const QString &fileName);
void sourceTypeChanged(SourceType sourceType);
void currentEditorChanged(QString fileName);

private:
int getFocusedEditorIndex() const;
Expand All @@ -86,7 +84,7 @@ class EditorManager final : public DockWindow
FindReplaceBar *mFindReplaceBar{ };
Ui::TextureEditorToolBar *mTextureEditorToolBar{ };
Ui::BinaryEditorToolBar *mBinaryEditorToolBar{ };
Ui::SourceEditorToolBar *mSourceEditorToolBar{ };
SourceEditorToolBar *mSourceEditorToolBar{ };
bool mAutoRaise{ true };
};

Expand Down
3 changes: 0 additions & 3 deletions src/editors/IEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define IEDITOR_H

#include "EditActions.h"
#include "SourceType.h"
#include <QList>
#include <QMetaObject>

Expand All @@ -18,8 +17,6 @@ class IEditor
virtual bool reload() = 0;
virtual bool save() = 0;
virtual int tabifyGroup() = 0;
virtual SourceType sourceType() const { return SourceType::None; }
virtual void setSourceType(SourceType) { }
};

#endif // IEDITOR_H
Loading

0 comments on commit 3ecc551

Please sign in to comment.