Skip to content

Commit 82fcba0

Browse files
committed
Add Docked Chat AI Support
Make the Chat AI panel respect a persisted docked/undocked preference and reuse a single chat window reference regardless of how it is presented. When docked, the chat UI is added to the bottom bar management window; when undocked, it still opens in its own frame. The options menu now includes a checkable "Dock Chat Window" setting that writes the preference and informs the user that a restart is required for the change to take effect. Chat visibility and focus handling were updated so showing the chat works consistently in both modes. * Chat AI window * Configuration * UI/menus **Generated by CodeLite** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent 99c3635 commit 82fcba0

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

Plugin/ai/ChatAI.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,54 @@
2525
#include "ChatAI.hpp"
2626

2727
#include "ai/LLMManager.hpp"
28+
#include "cl_config.h"
2829
#include "codelite_events.h"
2930
#include "event_notifier.h"
30-
31-
namespace
32-
{
33-
const wxString CHAT_AI_LABEL = _("Chat AI");
34-
} // namespace
31+
#include "globals.h"
3532

3633
ChatAI::ChatAI()
3734
{
35+
m_dock_chat = clConfig::Get().Read(CHAT_AI_DOCKED, m_dock_chat);
3836
llm::Manager::GetInstance().GetConfig().Load();
39-
m_chatWindowFrame = new ChatAIWindowFrame(EventNotifier::Get()->TopFrame(), this);
37+
38+
if (m_dock_chat) {
39+
m_chatWindow = new ChatAIWindow(clGetManager()->BookGet(PaneId::BOTTOM_BAR));
40+
clGetManager()->BookAddPage(PaneId::BOTTOM_BAR, m_chatWindow, CHAT_AI_LABEL);
41+
} else {
42+
m_chatWindowFrame = new ChatAIWindowFrame(EventNotifier::Get()->TopFrame(), this);
43+
m_chatWindow = m_chatWindowFrame->GetChatWindow();
44+
}
4045
EventNotifier::Get()->Bind(wxEVT_INIT_DONE, &ChatAI::OnInitDone, this);
4146
}
4247

43-
ChatAI::~ChatAI() { bool is_docked = m_dockedPaneId.has_value(); }
48+
ChatAI::~ChatAI() { EventNotifier::Get()->Unbind(wxEVT_INIT_DONE, &ChatAI::OnInitDone, this); }
4449

4550
void ChatAI::ShowChatWindow(const wxString& prompt)
4651
{
47-
ChatAIWindow* chat_view = GetChatWindow();
52+
EnsureVisible();
4853
if (!prompt.empty()) {
49-
chat_view->Chat(prompt);
54+
m_chatWindow->Chat(prompt);
5055
}
56+
m_chatWindow->GetStcInput()->CallAfter(&wxStyledTextCtrl::SetFocus);
5157
}
5258

5359
void ChatAI::OnInitDone(wxCommandEvent& event) { event.Skip(); }
5460

55-
ChatAIWindow* ChatAI::GetChatWindow()
61+
void ChatAI::EnsureVisible()
5662
{
57-
if (!m_chatWindowFrame->IsShown()) {
58-
m_chatWindowFrame->Show();
63+
if (m_dock_chat) {
64+
clGetManager()->ShowManagementWindow(CHAT_AI_LABEL, true);
65+
} else {
66+
if (!m_chatWindowFrame->IsShown()) {
67+
m_chatWindowFrame->Show();
68+
}
5969
}
60-
return m_chatWindowFrame->GetChatWindow();
70+
}
71+
72+
ChatAIWindow* ChatAI::GetChatWindow()
73+
{
74+
EnsureVisible();
75+
return m_chatWindow;
6176
}
6277

6378
void ChatAI::AppendTextAndStyle(const wxString& text)

Plugin/ai/ChatAI.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class WXDLLIMPEXP_SDK ChatAI : public wxEvtHandler
6262

6363
private:
6464
void OnInitDone(wxCommandEvent& event);
65+
void EnsureVisible();
6566

6667
ChatAIWindowFrame* m_chatWindowFrame{nullptr};
67-
std::optional<PaneId> m_dockedPaneId{std::nullopt};
68+
ChatAIWindow* m_chatWindow{nullptr};
69+
bool m_dock_chat{true};
6870
};

Plugin/ai/ChatAIWindow.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
namespace
2525
{
26-
const wxString CHAT_AI_LABEL = _("Chat AI");
2726
const wxString LONG_MODEL_NAME = "claude-sonnet-4-5-1234567890";
2827

2928
enum StatusBarIndex {
@@ -180,6 +179,7 @@ void ChatAIWindow::OnOptions(wxAuiToolBarEvent& event)
180179
{
181180
auto& llm_manager = llm::Manager::GetInstance();
182181

182+
bool is_docked = clConfig::Get().Read(CHAT_AI_DOCKED, true);
183183
wxMenu menu;
184184
wxMenu* caching_policy_menu = new wxMenu;
185185
auto& conf = llm_manager.GetConfig();
@@ -240,6 +240,18 @@ void ChatAIWindow::OnOptions(wxAuiToolBarEvent& event)
240240
}
241241
menu.Append(wxID_ANY, _("Insert Prompt"), prompt_selection);
242242
}
243+
menu.AppendSeparator();
244+
menu.Append(XRCID("dock-chat-window"), _("Dock Chat Window"), wxEmptyString, wxITEM_CHECK)->Check(is_docked);
245+
menu.Bind(
246+
wxEVT_MENU,
247+
[](wxCommandEvent& event) {
248+
clConfig::Get().Write(CHAT_AI_DOCKED, event.IsChecked());
249+
::clMessageBox(_("A restart is required for changes to take effect"),
250+
"CodeLite",
251+
wxICON_INFORMATION | wxOK | wxCENTER);
252+
},
253+
XRCID("dock-chat-window"));
254+
243255
menu.AppendSeparator();
244256
menu.Append(XRCID("chat_history"), _("Chat History"))->Enable(CurrentEndpointHasHistory());
245257
menu.Bind(wxEVT_MENU, &ChatAIWindow::OnHistory, this, XRCID("chat_history"));

Plugin/ai/ChatAIWindow.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
class EndpointModelSelector;
1919
using llm::ChatState;
2020

21+
inline const wxString CHAT_AI_LABEL = _("Chat AI");
22+
inline const wxString CHAT_AI_DOCKED = "chat-ai-docked";
23+
2124
class WXDLLIMPEXP_SDK ChatAIWindow : public AssistanceAIChatWindowBase
2225
{
2326
public:

0 commit comments

Comments
 (0)