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

Add menu for open in external editor in internal editor #314

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
80 changes: 55 additions & 25 deletions src/SHADERed/UI/CodeEditorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@ namespace ed {
Settings::Instance().Editor.StatusBar = !Settings::Instance().Editor.StatusBar;
});
}

void CodeEditorUI::m_openInExternalEditor(int id)
{
if (id >= m_editor.size())
return;

m_editorSaveRequestID = id;

auto openFunc = [this, id](bool success) {
if (!success) return;

std::string const shaderFile = m_getShaderFile(id);
if (!shaderFile.empty())
UIHelper::ShellOpen(m_data->Parser.GetProjectPath(shaderFile));
};

// prompt user to choose a project location first
if (m_data->Parser.GetOpenedFile() == "") {
RequestedProjectSave = true;
m_ui->SaveAsProject(true, openFunc);
} else
openFunc(true);
}

void CodeEditorUI::m_save(int editor_id)
{
if (editor_id >= m_editor.size())
Expand Down Expand Up @@ -196,31 +220,9 @@ namespace ed {

m_save(id);

std::string shaderFile = "";
if (m_items[id]->Type == PipelineItem::ItemType::ShaderPass) {
ed::pipe::ShaderPass* shader = reinterpret_cast<ed::pipe::ShaderPass*>(m_items[id]->Data);
if (m_shaderStage[id] == ShaderStage::Vertex)
shaderFile = shader->VSPath;
else if (m_shaderStage[id] == ShaderStage::Pixel)
shaderFile = shader->PSPath;
else if (m_shaderStage[id] == ShaderStage::Geometry)
shaderFile = shader->GSPath;
else if (m_shaderStage[id] == ShaderStage::TessellationControl)
shaderFile = shader->TCSPath;
else if (m_shaderStage[id] == ShaderStage::TessellationEvaluation)
shaderFile = shader->TESPath;
} else if (m_items[id]->Type == PipelineItem::ItemType::ComputePass) {
ed::pipe::ComputePass* shader = reinterpret_cast<ed::pipe::ComputePass*>(m_items[id]->Data);
shaderFile = shader->Path;
} else if (m_items[id]->Type == PipelineItem::ItemType::AudioPass) {
ed::pipe::AudioPass* shader = reinterpret_cast<ed::pipe::AudioPass*>(m_items[id]->Data);
shaderFile = shader->Path;
} else if (m_items[id]->Type == PipelineItem::ItemType::PluginItem) {
ed::pipe::PluginItemData* shader = reinterpret_cast<ed::pipe::PluginItemData*>(m_items[id]->Data);
shader->Owner->HandleRecompile(m_items[id]->Name);
}

m_data->Renderer.RecompileFile(shaderFile.c_str());
std::string const shaderFile = m_getShaderFile(id);
if (!shaderFile.empty())
m_data->Renderer.RecompileFile(shaderFile.c_str());
}

void CodeEditorUI::OnEvent(const SDL_Event& e) { }
Expand Down Expand Up @@ -270,6 +272,7 @@ namespace ed {
if (ImGui::MenuItem("Save SPIR-V binary")) m_saveAsSPV(i);
if (ImGui::MenuItem("Save as GLSL")) m_saveAsGLSL(i);
if (ImGui::MenuItem("Save as HLSL")) m_saveAsHLSL(i);
if (ImGui::MenuItem("Open in external editor")) m_openInExternalEditor(i);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Code")) {
Expand Down Expand Up @@ -1477,6 +1480,33 @@ namespace ed {
}
}

std::string CodeEditorUI::m_getShaderFile(int id)
{
if (m_items[id]->Type == PipelineItem::ItemType::ShaderPass) {
ed::pipe::ShaderPass* shader = reinterpret_cast<ed::pipe::ShaderPass*>(m_items[id]->Data);
if (m_shaderStage[id] == ShaderStage::Vertex)
return shader->VSPath;
else if (m_shaderStage[id] == ShaderStage::Pixel)
return shader->PSPath;
else if (m_shaderStage[id] == ShaderStage::Geometry)
return shader->GSPath;
else if (m_shaderStage[id] == ShaderStage::TessellationControl)
return shader->TCSPath;
else if (m_shaderStage[id] == ShaderStage::TessellationEvaluation)
return shader->TESPath;
} else if (m_items[id]->Type == PipelineItem::ItemType::ComputePass) {
ed::pipe::ComputePass* shader = reinterpret_cast<ed::pipe::ComputePass*>(m_items[id]->Data);
return shader->Path;
} else if (m_items[id]->Type == PipelineItem::ItemType::AudioPass) {
ed::pipe::AudioPass* shader = reinterpret_cast<ed::pipe::AudioPass*>(m_items[id]->Data);
return shader->Path;
} else if (m_items[id]->Type == PipelineItem::ItemType::PluginItem) {
ed::pipe::PluginItemData* shader = reinterpret_cast<ed::pipe::PluginItemData*>(m_items[id]->Data);
shader->Owner->HandleRecompile(m_items[id]->Name);
}
return {};
}

void CodeEditorUI::StopDebugging()
{
for (int i = 0; i < m_editor.size(); i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/SHADERed/UI/CodeEditorUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ namespace ed {
void m_applyBreakpoints(TextEditor* editor, const std::string& path);

void m_setupPlugin(ed::IPlugin1* plugin);
std::string m_getShaderFile(int id);

std::vector<CodeSnippet> m_snippets;

// code editor font
ImFont* m_font;

// menu bar item actions
void m_openInExternalEditor(int id);
void m_save(int id);
void m_saveAsSPV(int id);
void m_saveAsGLSL(int id);
Expand Down