Skip to content

Commit 2d7a816

Browse files
committed
Refactor toolbar options into dropdown menu
Consolidated caching policy and tools settings from toolbar controls into a unified dropdown menu accessed via an Options button. This change improves the toolbar layout by reducing clutter and grouping related settings together. The caching policy selection now displays the current policy state via checked menu items, and the chat history option is conditionally enabled based on whether the active endpoint has conversation history. Added a new GetCachingPolicy() method to LLMManager to support reading the current caching policy state. * Plugin/ai/LLMManager.hpp * Plugin/ai/LLMManager.cpp * Plugin/ai/ChatAIWindow.hpp * Plugin/ai/ChatAIWindow.cpp ** Generated by CodeLite. ** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent d8254a3 commit 2d7a816

File tree

4 files changed

+97
-49
lines changed

4 files changed

+97
-49
lines changed

Plugin/ai/ChatAIWindow.cpp

Lines changed: 86 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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+
184245
void 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-
247291
void 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

602646
void ChatAIWindow::OnStop(wxCommandEvent& event)

Plugin/ai/ChatAIWindow.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class WXDLLIMPEXP_SDK ChatAIWindow : public AssistanceAIChatWindowBase
5656
wxString GetText() const;
5757

5858
protected:
59+
bool CurrentEndpointHasHistory() const;
5960
void OnCharAdded(wxStyledTextEvent& event);
6061
void OnAutoScroll(wxCommandEvent& event);
6162
void OnAutoScrollUI(wxUpdateUIEvent& event);
@@ -64,7 +65,6 @@ class WXDLLIMPEXP_SDK ChatAIWindow : public AssistanceAIChatWindowBase
6465
void OnDetachView(wxCommandEvent& event);
6566
void OnDetachViewUI(wxUpdateUIEvent& event);
6667
void OnHistory(wxCommandEvent& event);
67-
void OnHistoryUI(wxUpdateUIEvent& event);
6868
void OnStop(wxCommandEvent& event);
6969
void OnStopUI(wxUpdateUIEvent& event);
7070
void OnInputUI(wxUpdateUIEvent& event) override;
@@ -73,9 +73,8 @@ class WXDLLIMPEXP_SDK ChatAIWindow : public AssistanceAIChatWindowBase
7373
void OnClearOutputViewUI(wxUpdateUIEvent& event);
7474
void OnUpdateTheme(wxCommandEvent& event);
7575
void OnEndpointChanged(wxCommandEvent& event);
76-
void OnCachePolicyChanged(wxCommandEvent& event);
77-
void OnToolsEnabled(wxCommandEvent& event);
7876
void OnKeyDown(wxKeyEvent& event);
77+
void OnOptions(wxAuiToolBarEvent& event);
7978
void OnNewSession(wxCommandEvent& event);
8079
void OnRestartClient(wxCommandEvent& event);
8180
void UpdateTheme();
@@ -108,8 +107,6 @@ class WXDLLIMPEXP_SDK ChatAIWindow : public AssistanceAIChatWindowBase
108107

109108
private:
110109
wxChoice* m_choiceEndpoints{nullptr};
111-
wxChoice* m_choiceCachePolicy{nullptr};
112-
wxCheckBox* m_checkboxEnableTools{nullptr};
113110
std::unique_ptr<MarkdownStyler> m_markdownStyler;
114111
ChatState m_state{ChatState::kReady};
115112
#if wxCHECK_VERSION(3, 3, 0)

Plugin/ai/LLMManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ Manager::PromptUserYesNoTrustQuestion(const wxString& text, const wxString& code
11491149
return result;
11501150
}
11511151

1152-
void Manager::SetCachingPolicy(assistant::CachePolicy policy)
1152+
void Manager::SetCachingPolicy(llm::CachePolicy policy)
11531153
{
11541154
CHECK_PTR_RET(m_client);
11551155
m_client->SetCachingPolicy(policy);

Plugin/ai/LLMManager.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,14 @@ class WXDLLIMPEXP_SDK Manager : public wxEvtHandler
541541
*
542542
* @return void This function does not return a value.
543543
*/
544-
void SetCachingPolicy(assistant::CachePolicy policy);
544+
void SetCachingPolicy(llm::CachePolicy policy);
545+
llm::CachePolicy GetCachingPolicy() const
546+
{
547+
if (!m_client) {
548+
return llm::CachePolicy::kNone;
549+
}
550+
return m_client->GetCachingPolicy();
551+
}
545552

546553
/**
547554
* @brief Prints a message with an icon to the chat window.

0 commit comments

Comments
 (0)