11#include " CodeEditorWindow.h"
22
33#include " CodeContextInformation.h"
4+ #include " IconsFontAwesome7.h"
45
56#include " imgui.h"
67
@@ -15,25 +16,42 @@ void CodeEditorWindow::Draw()
1516
1617 ImGui::PushID (" CodeEditorWindow" );
1718
18- if (ImGui::BeginChild ( " CodeEditorChild " , ImVec2 ( 0 , 500 ), ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeY, ImGuiWindowFlags_None ))
19+ if (ImGui::Button (_collapsed ? ICON_FA_CARET_RIGHT " ##CollapseButton " : ICON_FA_CARET_DOWN " ##CollapseButton " ))
1920 {
20- if (ImGui::BeginTabBar (" OpenCodeTabs" , ImGuiTabBarFlags_AutoSelectNewTabs))
21+ _collapsed = !_collapsed;
22+ }
23+
24+ ImGui::SameLine ();
25+
26+ if (!_collapsed)
27+ {
28+ ImGui::SetNextWindowSize (ImVec2 (0 , 500 ), ImGuiCond_FirstUseEver);
29+ ImGui::SetNextWindowBgAlpha (_collapsed ? 0 .0f : 0 .5f );
30+ if (ImGui::BeginChild (" CodeEditorChild" , ImVec2 (0 , 500 ), ImGuiChildFlags_ResizeY, ImGuiWindowFlags_None))
2131 {
22- for ( auto it = begin (_codeEditorTabs); it != end (_codeEditorTabs); )
32+ if ( ImGui::BeginTabBar ( " OpenCodeTabs " , ImGuiTabBarFlags_AutoSelectNewTabs) )
2333 {
24- if (it-> Draw () )
34+ for ( auto it = begin (_codeEditorTabs); it != end (_codeEditorTabs); )
2535 {
26- ++it;
27- continue ;
28- }
36+ if (it->Draw ())
37+ {
38+ ++it;
39+ continue ;
40+ }
2941
30- it = _codeEditorTabs.erase (it);
42+ it = _codeEditorTabs.erase (it);
43+ }
3144 }
3245
3346 ImGui::EndTabBar ();
3447 }
48+ ImGui::EndChild ();
49+ }
50+ else
51+ {
52+ ImGui::SameLine ();
53+ ImGui::TextDisabled (" %s" , (" (" + std::to_string (_codeEditorTabs.size ()) + " Tabs Open)" ).c_str ());
3554 }
36- ImGui::EndChild ();
3755
3856 if (_codeEditorTabs.empty ())
3957 {
@@ -45,6 +63,9 @@ void CodeEditorWindow::Draw()
4563
4664void CodeEditorWindow::OpenCodeInTab (ExpressionCodeTypes type, std::string& code, int index)
4765{
66+ // Fold out the editor if the user opens a new tab or focuses an existing one.
67+ _collapsed = false ;
68+
4869 std::string newTabTitle = CodeContextInformation::GetContextName (type, index);
4970 for (auto & tab : _codeEditorTabs)
5071 {
@@ -55,8 +76,12 @@ void CodeEditorWindow::OpenCodeInTab(ExpressionCodeTypes type, std::string& code
5576 }
5677 }
5778
58- _codeEditorTabs.emplace_back (type, code, index);
79+ CodeEditorTab newCodeEditorTab (type, code, index);
80+ newCodeEditorTab.SetSelected ();
81+ _codeEditorTabs.push_back (std::move (newCodeEditorTab));
82+
5983 _visible = true ;
6084}
6185
86+
6287} // namespace Editor
0 commit comments