From 91f99be92acd333dff9f6cfd491d4f1c10e2d5d8 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 26 Sep 2023 02:09:11 +0200 Subject: [PATCH] script_editor.as: Fixes during review * changed "select+load" to just "load" in menubar. * workaround: clamp error line num.s to actual line count * Renamed "Welcome" tab to "Tutorial.as". * fixed bogus filesize of Recent scripts. --- resources/scripts/script_editor.as | 95 +++++++++++++++++------------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/resources/scripts/script_editor.as b/resources/scripts/script_editor.as index 868e79174e..671ce76461 100644 --- a/resources/scripts/script_editor.as +++ b/resources/scripts/script_editor.as @@ -37,6 +37,7 @@ const int BUFFER_MIN_SIZE = 10000; const int BUFFER_INCREMENT_SIZE = 2500; const color LINKCOLOR = color(0.3, 0.5, 0.9, 1.0); ScriptEditorWindow editorWindow; +const uint FILEINFO_COMPRESSEDSIZE_UNKNOWN = uint(-1); // Config: // ------- @@ -212,7 +213,7 @@ class ScriptEditorWindow // Make sure there's always a tab open () if (tabs.length() == 0) { - this.addTab("Welcome", TUT_SCRIPT); + this.addTab("Tutorial.as", TUT_SCRIPT); this.currentTab = 0; } else @@ -284,21 +285,21 @@ 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(); } @@ -306,6 +307,11 @@ class ScriptEditorWindow // 'SAVE FILE' menu if (ImGui::BeginMenu("Save file")) { + if (!analysisDoneThisFrame) + { + analysisDoneThisFrame = localScriptsRecord.advanceScriptAnalysis(); + } + if (this.saveMenuOpening) { saveFileNameBuf = this.tabs[this.currentTab].bufferName; @@ -331,13 +337,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(); } @@ -348,38 +351,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(); } @@ -445,11 +446,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= bufferLinesMeta.length()) + { + lineIdx = bufferLinesMeta.length() - 1; + } // update line stats if (msgType == asMSGTYPE_ERROR)