1010#include " aui/clAuiToolBarArt.h"
1111#include " clAnsiEscapeCodeColourBuilder.hpp"
1212#include " clSTCHelper.hpp"
13+ #include " cl_aui_tool_stickness.h"
1314#include " cl_config.h"
1415#include " codelite_events.h"
1516#include " event_notifier.h"
@@ -47,28 +48,17 @@ ChatAIWindow::ChatAIWindow(wxWindow* parent)
4748 m_choiceEndpoints->SetToolTip (_ (" Choose the endpoint to use" ));
4849 m_toolbar->AddControl (m_choiceEndpoints);
4950
50- control_size = wxSize{GetTextExtent (" __" + llm::kCacheStaticContent + " __" ).GetWidth (), wxNOT_FOUND};
51- m_choiceCachePolicy = new wxChoice (m_toolbar, wxID_ANY, wxDefaultPosition, control_size);
52- m_choiceCachePolicy->SetToolTip (_ (" Choose the prompt caching policy" ));
53- std::vector<wxString> cache_options{llm::kCacheAuto , llm::kCacheStaticContent , llm::kCacheNone };
54- m_choiceCachePolicy->Append (cache_options);
55- m_choiceCachePolicy->SetStringSelection (conf.GetCachePolicyString ());
56- m_toolbar->AddControl (m_choiceCachePolicy);
57-
5851 m_inputEditHelper = std::make_unique<clEditEventsHandler>(m_stcInput);
5952 m_outputEditHelper = std::make_unique<clEditEventsHandler>(m_stcOutput);
6053
61- m_checkboxEnableTools = new wxCheckBox (m_toolbar, wxID_ANY, _ (" Enable Tools" ));
62- m_checkboxEnableTools->SetToolTip (_ (" Enable Local MCP Tools for the LLM" ));
63- m_checkboxEnableTools->SetValue (conf.AreToolsEnabled ());
64- m_toolbar->AddControl (m_checkboxEnableTools);
65-
66- m_toolbar->AddSeparator ();
6754 clAuiToolBarArt::AddTool (m_toolbar, wxID_EXECUTE, _ (" Submit" ), images->LoadBitmap (" run" ));
6855 clAuiToolBarArt::AddTool (m_toolbar, wxID_STOP, _ (" Stop" ), images->LoadBitmap (" execute_stop" ));
6956 m_toolbar->AddSeparator ();
7057 clAuiToolBarArt::AddTool (m_toolbar, wxID_REFRESH, _ (" Restart the client" ), images->LoadBitmap (" debugger_restart" ));
71- clAuiToolBarArt::AddTool (m_toolbar, XRCID (" chat_history" ), _ (" Show chat history" ), images->LoadBitmap (" history" ));
58+ m_toolbar->AddSeparator ();
59+ clAuiToolBarArt::AddTool (
60+ m_toolbar, XRCID (" wxID_SETTINGS" ), _ (" Options" ), images->LoadBitmap (" cog" ), wxEmptyString, wxITEM_DROPDOWN);
61+
7262 clAuiToolBarArt::AddTool (m_toolbar,
7363 XRCID (" auto_scroll" ),
7464 _ (" Enable auto scrolling" ),
@@ -79,9 +69,8 @@ ChatAIWindow::ChatAIWindow(wxWindow* parent)
7969 clAuiToolBarArt::Finalise (m_toolbar);
8070 m_toolbar->Realize ();
8171
72+ m_toolbar->Bind (wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &ChatAIWindow::OnOptions, this , XRCID (" wxID_SETTINGS" ));
8273 m_choiceEndpoints->Bind (wxEVT_CHOICE, &ChatAIWindow::OnEndpointChanged, this );
83- m_choiceCachePolicy->Bind (wxEVT_CHOICE, &ChatAIWindow::OnCachePolicyChanged, this );
84- m_checkboxEnableTools->Bind (wxEVT_CHECKBOX, &ChatAIWindow::OnToolsEnabled, this );
8574
8675 EventNotifier::Get ()->Bind (wxEVT_CL_THEME_CHANGED, &ChatAIWindow::OnUpdateTheme, this );
8776 EventNotifier::Get ()->Bind (wxEVT_WORKSPACE_LOADED, &ChatAIWindow::OnWorkspaceLoaded, this );
@@ -107,17 +96,14 @@ ChatAIWindow::ChatAIWindow(wxWindow* parent)
10796 Bind (wxEVT_MENU, &ChatAIWindow::OnSend, this , wxID_EXECUTE);
10897 Bind (wxEVT_MENU, &ChatAIWindow::OnStop, this , wxID_STOP);
10998 Bind (wxEVT_MENU, &ChatAIWindow::OnAutoScroll, this , XRCID (" auto_scroll" ));
110- Bind (wxEVT_MENU, &ChatAIWindow::OnHistory, this , XRCID (" chat_history" ));
11199 Bind (wxEVT_MENU, &ChatAIWindow::OnDetachView, this , XRCID (" detach_view" ));
112100
113101 Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnDetachViewUI, this , XRCID (" detach_view" ));
114102 Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnSendUI, this , wxID_EXECUTE);
115103 Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnStopUI, this , wxID_STOP);
116104 Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnClearOutputViewUI, this , wxID_CLEAR);
117105 Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnAutoScrollUI, this , XRCID (" auto_scroll" ));
118- Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnHistoryUI, this , XRCID (" chat_history" ));
119106 m_choiceEndpoints->Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnBusyUI, this );
120- m_choiceCachePolicy->Bind (wxEVT_UPDATE_UI, &ChatAIWindow::OnBusyUI, this );
121107 UpdateChoices ();
122108
123109 m_stcInput->CmdKeyClear (' R' , wxSTC_KEYMOD_CTRL);
@@ -172,7 +158,6 @@ ChatAIWindow::~ChatAIWindow()
172158
173159 auto & conf = llm::Manager::GetInstance ().GetConfig ();
174160 // Store the current session
175- conf.SetToolsEnabled (m_checkboxEnableTools->IsChecked ());
176161 auto active_endpoint = llm::Manager::GetInstance ().GetActiveEndpoint ();
177162 if (active_endpoint.has_value ()) {
178163 auto conversation = llm::Manager::GetInstance ().GetConversation ();
@@ -181,6 +166,82 @@ ChatAIWindow::~ChatAIWindow()
181166 conf.Save ();
182167}
183168
169+ namespace
170+ {
171+ void SetCachePolicy (llm::CachePolicy policy)
172+ {
173+ wxMessageBox (" Setting cache policy: " + std::to_string ((int )policy));
174+ auto & llm_manager = llm::Manager::GetInstance ();
175+ auto & conf = llm_manager.GetConfig ();
176+ conf.SetCachePolicy (policy);
177+ llm_manager.SetCachingPolicy (policy);
178+ conf.Save ();
179+ }
180+ } // namespace
181+
182+ void ChatAIWindow::OnOptions (wxAuiToolBarEvent& event)
183+ {
184+ if (!event.IsDropDownClicked ()) {
185+ return ;
186+ }
187+
188+ auto & llm_manager = llm::Manager::GetInstance ();
189+
190+ wxMenu menu;
191+ wxMenu* caching_policy_menu = new wxMenu;
192+ auto & conf = llm_manager.GetConfig ();
193+ menu.Append (XRCID (" wxID_TOOLS_ENABLED" ), _ (" Enable MCP Tools" ), wxEmptyString, wxITEM_CHECK)
194+ ->Check (conf.AreToolsEnabled ());
195+ menu.Bind (
196+ wxEVT_MENU,
197+ [&conf](wxCommandEvent& e) {
198+ conf.SetToolsEnabled (e.IsChecked ());
199+ conf.Save ();
200+ },
201+ XRCID (" wxID_TOOLS_ENABLED" ));
202+
203+ caching_policy_menu->Append (XRCID (" wxID_CACHING_POLICY_NONE" ), _ (" None" ), wxEmptyString, wxITEM_CHECK)
204+ ->Check (llm_manager.GetCachingPolicy () == llm::CachePolicy::kNone );
205+ caching_policy_menu->Append (XRCID (" wxID_CACHING_POLICY_AUTO" ), _ (" Auto" ), wxEmptyString, wxITEM_CHECK)
206+ ->Check (llm_manager.GetCachingPolicy () == llm::CachePolicy::kAuto );
207+ caching_policy_menu
208+ ->Append (XRCID (" wxID_CACHING_POLICY_STATIC_CONTENT" ), _ (" Static Content" ), wxEmptyString, wxITEM_CHECK)
209+ ->Check (llm_manager.GetCachingPolicy () == llm::CachePolicy::kStatic );
210+
211+ menu.Bind (
212+ wxEVT_MENU,
213+ [](wxCommandEvent& e) {
214+ wxUnusedVar (e);
215+ SetCachePolicy (llm::CachePolicy::kNone );
216+ },
217+ XRCID (" wxID_CACHING_POLICY_NONE" ));
218+ menu.Bind (
219+ wxEVT_MENU,
220+ [](wxCommandEvent& e) {
221+ wxUnusedVar (e);
222+ SetCachePolicy (llm::CachePolicy::kAuto );
223+ },
224+ XRCID (" wxID_CACHING_POLICY_AUTO" ));
225+ menu.Bind (
226+ wxEVT_MENU,
227+ [](wxCommandEvent& e) {
228+ wxUnusedVar (e);
229+ SetCachePolicy (llm::CachePolicy::kStatic );
230+ },
231+ XRCID (" wxID_CACHING_POLICY_STATIC_CONTENT" ));
232+ menu.Append (wxID_ANY, _ (" Prompt Caching" ), caching_policy_menu);
233+ menu.AppendSeparator ();
234+ menu.Append (XRCID (" chat_history" ), _ (" Chat History" ))->Enable (CurrentEndpointHasHistory ());
235+ menu.Bind (wxEVT_MENU, &ChatAIWindow::OnHistory, this , XRCID (" chat_history" ));
236+
237+ clAuiToolStickness stickness{m_toolbar, event.GetId ()};
238+ // line up our menu with the button
239+ wxRect rect = m_toolbar->GetToolRect (event.GetId ());
240+ wxPoint pt = m_toolbar->ClientToScreen (rect.GetBottomLeft ());
241+ pt = ScreenToClient (pt);
242+ PopupMenu (&menu, pt);
243+ }
244+
184245void ChatAIWindow::OnSend (wxCommandEvent& event)
185246{
186247 wxUnusedVar (event);
@@ -227,23 +288,6 @@ void ChatAIWindow::OnSendUI(wxUpdateUIEvent& event)
227288 !m_choiceEndpoints->GetStringSelection ().empty ());
228289}
229290
230- void ChatAIWindow::OnToolsEnabled (wxCommandEvent& event)
231- {
232- wxUnusedVar (event);
233- auto & conf = llm::Manager::GetInstance ().GetConfig ();
234- conf.SetToolsEnabled (m_checkboxEnableTools->IsChecked ());
235- conf.Save ();
236- }
237-
238- void ChatAIWindow::OnCachePolicyChanged (wxCommandEvent& event)
239- {
240- wxUnusedVar (event);
241- auto & conf = llm::Manager::GetInstance ().GetConfig ();
242- conf.SetCachePolicy (m_choiceCachePolicy->GetStringSelection ());
243- conf.Save ();
244- llm::Manager::GetInstance ().SetCachingPolicy (conf.GetCachePolicy ());
245- }
246-
247291void ChatAIWindow::OnEndpointChanged (wxCommandEvent& event)
248292{
249293 wxUnusedVar (event);
@@ -591,12 +635,12 @@ void ChatAIWindow::OnHistory(wxCommandEvent& event)
591635 m_stcInput->CallAfter (&wxStyledTextCtrl::SetFocus);
592636}
593637
594- void ChatAIWindow::OnHistoryUI (wxUpdateUIEvent& event)
638+ bool ChatAIWindow::CurrentEndpointHasHistory () const
595639{
596- const auto & config = llm::Manager::GetInstance ().GetConfig ();
597640 auto active_endpoint = llm::Manager::GetInstance ().GetActiveEndpoint ();
598- event.Enable (active_endpoint.has_value () && !config.GetHistory (active_endpoint.value ()).empty () &&
599- m_state == ChatState::kReady );
641+ auto & config = llm::Manager::GetInstance ().GetConfig ();
642+ return active_endpoint.has_value () && !config.GetHistory (active_endpoint.value ()).empty () &&
643+ m_state == ChatState::kReady ;
600644}
601645
602646void ChatAIWindow::OnStop (wxCommandEvent& event)
0 commit comments