Skip to content

Commit

Permalink
script_editor.as: changed "select+load" to just "load" in menubar.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Sep 26, 2023
1 parent b820c7c commit 6112853
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions resources/scripts/script_editor.as
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,33 @@ class ScriptEditorWindow
// 'OPEN FILE' menu
if (ImGui::BeginMenu("Open file"))
{
ImGui::Text("File: "+ fileNameBuf);
if (ImGui::Button("Load##localfile"))
if (!analysisDoneThisFrame)
{
this.addTab(fileNameBuf, game.loadTextResourceAsString(fileNameBuf, RGN_SCRIPTS));
this.currentTab = this.tabs.length() - 1; // Focus the new tab
this.addRecentScript(fileNameBuf);
analysisDoneThisFrame = localScriptsRecord.advanceScriptAnalysis();
}

this.drawSelectableFileList("Recent scripts", recentScriptsRecord, /*&inout*/ fileNameBuf);
bool loadRecentFile = this.drawSelectableFileList("Recent scripts", "Load##recent", recentScriptsRecord, /*&inout*/ fileNameBuf);
ImGui::Separator();
bool loadLocalFile = this.drawSelectableFileList("Local scripts", "Load##local", localScriptsRecord, /*&inout*/ fileNameBuf);

if (!analysisDoneThisFrame)
if (loadRecentFile || loadLocalFile)
{
analysisDoneThisFrame = localScriptsRecord.advanceScriptAnalysis();
}
this.drawSelectableFileList("Local scripts", localScriptsRecord, /*&inout*/ fileNameBuf);
this.addTab(fileNameBuf, game.loadTextResourceAsString(fileNameBuf, RGN_SCRIPTS));
this.currentTab = this.tabs.length() - 1; // Focus the new tab
this.addRecentScript(fileNameBuf);
}

ImGui::EndMenu();
}

// 'SAVE FILE' menu
if (ImGui::BeginMenu("Save file"))
{
if (!analysisDoneThisFrame)
{
analysisDoneThisFrame = localScriptsRecord.advanceScriptAnalysis();
}

if (this.saveMenuOpening)
{
saveFileNameBuf = this.tabs[this.currentTab].bufferName;
Expand All @@ -331,13 +336,10 @@ class ScriptEditorWindow
else if (this.saveFileResult == -1)
ImGui::TextColored(color(1,0.1, 0.2, 1), "Error saving file!");

this.drawSelectableFileList("Recent scripts", recentScriptsRecord, /*&inout*/ fileNameBuf);

if (!analysisDoneThisFrame)
{
analysisDoneThisFrame = localScriptsRecord.advanceScriptAnalysis();
}
this.drawSelectableFileList("Local scripts", localScriptsRecord, /*&inout*/ saveFileNameBuf);
ImGui::Separator();
this.drawSelectableFileList("Recent scripts", "Select##recent", recentScriptsRecord, /*&inout*/ fileNameBuf);
ImGui::Separator();
this.drawSelectableFileList("Local scripts", "Select##local", localScriptsRecord, /*&inout*/ saveFileNameBuf);

ImGui::EndMenu();
}
Expand All @@ -348,38 +350,36 @@ class ScriptEditorWindow

// 'EXAMPLES' menu
if (ImGui::BeginMenu("Examples"))
{
//string loadTextResourceAsString(const std::string& filename, const std::string& resource_group);
ImGui::Text("File: "+ exampleNameBuf);
if (ImGui::Button("Load##example"))
{
this.addTab(exampleNameBuf, game.loadTextResourceAsString(exampleNameBuf, RGN_RESOURCES_SCRIPTS));
this.currentTab = this.tabs.length() - 1; // Focus the new tab
}

{
if (!analysisDoneThisFrame)
{
analysisDoneThisFrame = exampleScriptsRecord.advanceScriptAnalysis();
}
this.drawSelectableFileList("Example scripts", exampleScriptsRecord, /*&inout*/ exampleNameBuf);

bool loadExampleFile = this.drawSelectableFileList("Example scripts", "Load##example", exampleScriptsRecord, /*&inout*/ exampleNameBuf);

if (loadExampleFile)
{
this.addTab(exampleNameBuf, game.loadTextResourceAsString(exampleNameBuf, RGN_RESOURCES_SCRIPTS));
this.currentTab = this.tabs.length() - 1; // Focus the new tab
}

ImGui::EndMenu();
}
if (ImGui::BeginMenu("Includes"))
{
//string loadTextResourceAsString(const std::string& filename, const std::string& resource_group);
ImGui::Text("File: "+ includeNameBuf);
if (ImGui::Button("Load##include"))
if (!analysisDoneThisFrame)
{
this.addTab(includeNameBuf, game.loadTextResourceAsString(includeNameBuf, RGN_RESOURCES_SCRIPTS));
this.currentTab = this.tabs.length() - 1; // Focus the new tab
analysisDoneThisFrame = includeScriptsRecord.advanceScriptAnalysis();
}

if (!analysisDoneThisFrame)
bool loadIncludeFile = this.drawSelectableFileList("Include scripts", "Load##include", includeScriptsRecord, /*&inout*/ includeNameBuf);

if (loadIncludeFile)
{
analysisDoneThisFrame = includeScriptsRecord.advanceScriptAnalysis();
}
this.drawSelectableFileList("Include scripts", includeScriptsRecord, /*&inout*/ includeNameBuf);
this.addTab(includeNameBuf, game.loadTextResourceAsString(includeNameBuf, RGN_RESOURCES_SCRIPTS));
this.currentTab = this.tabs.length() - 1; // Focus the new tab
}

ImGui::EndMenu();
}
Expand Down Expand Up @@ -445,11 +445,10 @@ class ScriptEditorWindow
}
}

private bool drawSelectableFileList(string title, ScriptIndexerRecord@ record, string&inout out_selection)
private bool drawSelectableFileList(string title, string btnText, ScriptIndexerRecord@ record, string&inout out_selection)
{
bool retval = false;

ImGui::Separator();
ImGui::PushID(title);
ImGui::TextDisabled(title+" ("+record.fileinfos.length()+"):");
for (uint i=0; i<record.fileinfos.length(); i++)
Expand All @@ -472,7 +471,7 @@ class ScriptEditorWindow
ImGui::TextWrapped(scriptinfo.text); ImGui::Dummy(vector2(300, 1));
ImGui::EndTooltip();
}
if (ImGui::SmallButton("Select"))
if (ImGui::SmallButton(btnText))
{
out_selection = filename;
retval = true;
Expand Down

0 comments on commit 6112853

Please sign in to comment.