Skip to content

Commit ad6ff8d

Browse files
committed
All CC box event are now going through the CC box manager (better to connec the events to a "persistent" object rather than to a transient window)
1 parent 5932c12 commit ad6ff8d

File tree

7 files changed

+105
-77
lines changed

7 files changed

+105
-77
lines changed

LiteEditor.workspace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<Project Name="CallGraph" ConfigName="Win_x86_Release"/>
9696
<Project Name="abbreviation" ConfigName="Win_x86_Release"/>
9797
</WorkspaceConfiguration>
98-
<WorkspaceConfiguration Name="CMake_Release" Selected="yes">
98+
<WorkspaceConfiguration Name="CMake_Release" Selected="no">
9999
<Project Name="ZoomNavigator" ConfigName="DebugUnicode"/>
100100
<Project Name="wxsqlite3" ConfigName="Win_x86_Release"/>
101101
<Project Name="wxshapeframework" ConfigName="Win_x86_Release"/>
@@ -267,7 +267,7 @@
267267
<Project Name="PHPPlugin" ConfigName="Debug_Unix"/>
268268
<Project Name="WordCompletion" ConfigName="DebugUnicode"/>
269269
</WorkspaceConfiguration>
270-
<WorkspaceConfiguration Name="Win_x64_Release" Selected="no">
270+
<WorkspaceConfiguration Name="Win_x64_Release" Selected="yes">
271271
<Project Name="abbreviation" ConfigName="Win_x64_Release"/>
272272
<Project Name="CallGraph" ConfigName="Win_x64_Release"/>
273273
<Project Name="CMakePlugin" ConfigName="Win_x64_Release"/>

LiteEditor/frame.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,8 +2329,6 @@ void clMainFrame::OnClose(wxCloseEvent& event)
23292329
IDebugger* debugger = DebuggerMgr::Get().GetActiveDebugger();
23302330
if(debugger && debugger->IsRunning()) ManagerST::Get()->DbgStop();
23312331

2332-
2333-
23342332
// In case we got some data in the clipboard, flush it so it will be available
23352333
// after our process exits
23362334
wxTheClipboard->Flush();

LiteEditor/manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#include "CompileCommandsCreateor.h"
9999
#include "CompilersModifiedDlg.h"
100100
#include "clKeyboardManager.h"
101+
#include "wxCodeCompletionBoxManager.h"
101102
#include "localworkspace.h"
102103

103104
#ifndef __WXMSW__
@@ -260,6 +261,7 @@ Manager::~Manager(void)
260261
wxDELETE(m_breakptsmgr);
261262
TabGroupsManager::Free();
262263
clKeyboardManager::Release();
264+
wxCodeCompletionBoxManager::Free();
263265
}
264266

265267
//--------------------------- Workspace Loading -----------------------------

Plugin/wxCodeCompletionBox.cpp

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ wxCodeCompletionBox::wxCodeCompletionBox(wxWindow* parent, wxEvtHandler* eventOb
7777
m_canvas->Bind(wxEVT_LEFT_DOWN, &wxCodeCompletionBox::OnLeftDClick, this);
7878
m_canvas->Bind(wxEVT_LEFT_DCLICK, &wxCodeCompletionBox::OnLeftDClick, this);
7979

80-
EventNotifier::Get()->Bind(wxEVT_ALL_EDITORS_CLOSING, &wxCodeCompletionBox::OnDismissBox, this);
81-
EventNotifier::Get()->Bind(wxEVT_ACTIVE_EDITOR_CHANGED, &wxCodeCompletionBox::OnDismissBox, this);
82-
EventNotifier::Get()->Bind(wxEVT_EDITOR_CLOSING, &wxCodeCompletionBox::OnDismissBox, this);
83-
wxTheApp->Bind(wxEVT_ACTIVATE_APP, &wxCodeCompletionBox::OnAppActivate, this);
84-
8580
/// Set the colours
8681
m_lightBorder = wxColour("rgb(77, 77, 77)");
8782
m_darkBorder = wxColour("rgb(54, 54, 54)");
@@ -100,22 +95,7 @@ wxCodeCompletionBox::~wxCodeCompletionBox()
10095
{
10196
m_canvas->Unbind(wxEVT_LEFT_DOWN, &wxCodeCompletionBox::OnLeftDClick, this);
10297
m_canvas->Unbind(wxEVT_LEFT_DCLICK, &wxCodeCompletionBox::OnLeftDClick, this);
103-
if(m_stc) {
104-
m_stc->Unbind(wxEVT_KEY_DOWN, &wxCodeCompletionBox::StcKeyDown, this);
105-
m_stc->Unbind(wxEVT_LEFT_DOWN, &wxCodeCompletionBox::StcLeftDown, this);
106-
}
107-
108-
if(m_tipWindow) {
109-
m_tipWindow->Hide();
110-
m_tipWindow->Destroy();
111-
m_tipWindow = NULL;
112-
m_displayedTip.Clear();
113-
}
114-
115-
wxTheApp->Unbind(wxEVT_ACTIVATE_APP, &wxCodeCompletionBox::OnAppActivate, this);
116-
EventNotifier::Get()->Unbind(wxEVT_ACTIVE_EDITOR_CHANGED, &wxCodeCompletionBox::OnDismissBox, this);
117-
EventNotifier::Get()->Unbind(wxEVT_EDITOR_CLOSING, &wxCodeCompletionBox::OnDismissBox, this);
118-
EventNotifier::Get()->Unbind(wxEVT_ALL_EDITORS_CLOSING, &wxCodeCompletionBox::OnDismissBox, this);
98+
DoDestroyTipWindow();
11999
}
120100

121101
void wxCodeCompletionBox::OnEraseBackground(wxEraseEvent& event) { wxUnusedVar(event); }
@@ -265,9 +245,6 @@ void wxCodeCompletionBox::ShowCompletionBox(wxStyledTextCtrl* ctrl, const wxCode
265245
Show();
266246

267247
if(m_stc) {
268-
m_stc->Bind(wxEVT_KEY_DOWN, &wxCodeCompletionBox::StcKeyDown, this);
269-
m_stc->Bind(wxEVT_LEFT_DOWN, &wxCodeCompletionBox::StcLeftDown, this);
270-
271248
// Set the focus back to the completion control
272249
m_stc->CallAfter(&wxStyledTextCtrl::SetFocus);
273250
}
@@ -289,12 +266,7 @@ void wxCodeCompletionBox::DoDisplayTipWindow()
289266

290267
if(!docComment.IsEmpty() && docComment != m_displayedTip) {
291268
// destroy old tip window
292-
if(m_tipWindow) {
293-
m_displayedTip.Clear();
294-
m_tipWindow->Hide();
295-
m_tipWindow->Destroy();
296-
m_tipWindow = NULL;
297-
}
269+
DoDestroyTipWindow();
298270

299271
// keep the old tip
300272
m_displayedTip = docComment;
@@ -307,12 +279,9 @@ void wxCodeCompletionBox::DoDisplayTipWindow()
307279
m_stc->CallAfter(&wxStyledTextCtrl::SetFocus);
308280
}
309281

310-
} else if(m_tipWindow) {
282+
} else {
311283
// Nothing to display, just destroy the old tooltip
312-
m_displayedTip.Clear();
313-
m_tipWindow->Hide();
314-
m_tipWindow->Destroy();
315-
m_tipWindow = NULL;
284+
DoDestroyTipWindow();
316285
}
317286
}
318287

@@ -379,6 +348,9 @@ void wxCodeCompletionBox::StcKeyDown(wxKeyEvent& event)
379348
case WXK_END:
380349
case WXK_DELETE:
381350
case WXK_NUMPAD_DELETE:
351+
case WXK_ALT:
352+
case WXK_WINDOWS_LEFT:
353+
case WXK_WINDOWS_RIGHT:
382354
DoDestroy();
383355
break;
384356
case WXK_TAB:
@@ -567,19 +539,6 @@ void wxCodeCompletionBox::DoUpdateList()
567539
}
568540
}
569541

570-
void wxCodeCompletionBox::OnAppActivate(wxActivateEvent& event)
571-
{
572-
event.Skip();
573-
// Application lost / got focus - reset the tooltip
574-
DoDestroy();
575-
}
576-
577-
void wxCodeCompletionBox::OnDismissBox(wxCommandEvent& event)
578-
{
579-
event.Skip();
580-
DoDestroy();
581-
}
582-
583542
wxCodeCompletionBoxEntry::Ptr_t wxCodeCompletionBox::TagToEntry(TagEntryPtr tag)
584543
{
585544
wxString text = tag->GetDisplayName().Trim().Trim(false);
@@ -606,10 +565,7 @@ void wxCodeCompletionBox::DoScrollUp()
606565
}
607566
}
608567

609-
void wxCodeCompletionBox::DoDestroy()
610-
{
611-
wxCodeCompletionBoxManager::Get().DestroyCCBox();
612-
}
568+
void wxCodeCompletionBox::DoDestroy() { wxCodeCompletionBoxManager::Get().DestroyCCBox(); }
613569

614570
void wxCodeCompletionBox::DoDrawBottomScrollButton(wxDC& dc)
615571
{
@@ -665,3 +621,13 @@ void wxCodeCompletionBox::DoDrawTopScrollButton(wxDC& dc)
665621
bool wxCodeCompletionBox::CanScrollDown() { return ((m_index + 1) < (int)m_entries.size()); }
666622

667623
bool wxCodeCompletionBox::CanScrollUp() { return ((m_index - 1) >= 0); }
624+
625+
void wxCodeCompletionBox::DoDestroyTipWindow()
626+
{
627+
if(m_tipWindow) {
628+
m_tipWindow->Hide();
629+
m_tipWindow->Destroy();
630+
m_tipWindow = NULL;
631+
m_displayedTip.Clear();
632+
}
633+
}

Plugin/wxCodeCompletionBox.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ class WXDLLIMPEXP_SDK wxCodeCompletionBox : public wxCodeCompletionBoxBase
8181
void OnLeftDClick(wxMouseEvent& event);
8282
void OnEraseBackground(wxEraseEvent& event);
8383
void OnPaint(wxPaintEvent& event);
84-
void OnAppActivate(wxActivateEvent& event);
85-
void OnDismissBox(wxCommandEvent& event);
86-
84+
8785
public:
8886
virtual ~wxCodeCompletionBox();
8987
/**
@@ -126,6 +124,8 @@ class WXDLLIMPEXP_SDK wxCodeCompletionBox : public wxCodeCompletionBoxBase
126124
wxCodeCompletionBoxEntry::Vec_t TagsToEntries(const TagEntryPtrVector_t& tags);
127125
static int GetImageId(TagEntryPtr entry);
128126
void DoDisplayTipWindow();
127+
void DoDestroyTipWindow();
128+
129129
void DoUpdateList();
130130
void DoScrollDown();
131131
void DoScrollUp();

Plugin/wxCodeCompletionBoxManager.cpp

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,41 @@
88
#include "imanager.h"
99
#include "file_logger.h"
1010
#include <wx/app.h>
11+
#include "event_notifier.h"
1112

1213
wxCodeCompletionBoxManager::wxCodeCompletionBoxManager()
1314
: m_box(NULL)
1415
, m_stc(NULL)
1516
{
16-
if(wxTheApp) {
17-
wxTheApp->Bind(wxEVT_STC_MODIFIED, &wxCodeCompletionBoxManager::OnStcModified, this);
18-
wxTheApp->Bind(wxEVT_STC_CHARADDED, &wxCodeCompletionBoxManager::OnStcCharAdded, this);
19-
}
17+
18+
EventNotifier::Get()->Bind(wxEVT_ACTIVE_EDITOR_CHANGED, &wxCodeCompletionBoxManager::OnDismissBox, this);
19+
EventNotifier::Get()->Bind(wxEVT_EDITOR_CLOSING, &wxCodeCompletionBoxManager::OnDismissBox, this);
20+
EventNotifier::Get()->Bind(wxEVT_ALL_EDITORS_CLOSING, &wxCodeCompletionBoxManager::OnDismissBox, this);
21+
22+
wxTheApp->Bind(wxEVT_STC_MODIFIED, &wxCodeCompletionBoxManager::OnStcModified, this);
23+
wxTheApp->Bind(wxEVT_STC_CHARADDED, &wxCodeCompletionBoxManager::OnStcCharAdded, this);
24+
wxTheApp->Bind(wxEVT_ACTIVATE_APP, &wxCodeCompletionBoxManager::OnAppActivate, this);
2025
}
2126

2227
wxCodeCompletionBoxManager::~wxCodeCompletionBoxManager()
2328
{
24-
if(wxTheApp) {
25-
wxTheApp->Unbind(wxEVT_STC_MODIFIED, &wxCodeCompletionBoxManager::OnStcModified, this);
26-
wxTheApp->Unbind(wxEVT_STC_CHARADDED, &wxCodeCompletionBoxManager::OnStcCharAdded, this);
27-
}
29+
DestroyCurrent();
30+
EventNotifier::Get()->Unbind(wxEVT_ACTIVE_EDITOR_CHANGED, &wxCodeCompletionBoxManager::OnDismissBox, this);
31+
EventNotifier::Get()->Unbind(wxEVT_EDITOR_CLOSING, &wxCodeCompletionBoxManager::OnDismissBox, this);
32+
EventNotifier::Get()->Unbind(wxEVT_ALL_EDITORS_CLOSING, &wxCodeCompletionBoxManager::OnDismissBox, this);
33+
34+
wxTheApp->Unbind(wxEVT_STC_MODIFIED, &wxCodeCompletionBoxManager::OnStcModified, this);
35+
wxTheApp->Unbind(wxEVT_STC_CHARADDED, &wxCodeCompletionBoxManager::OnStcCharAdded, this);
36+
wxTheApp->Unbind(wxEVT_ACTIVATE_APP, &wxCodeCompletionBoxManager::OnAppActivate, this);
2837
}
2938

39+
static wxCodeCompletionBoxManager *manager = NULL;
3040
wxCodeCompletionBoxManager& wxCodeCompletionBoxManager::Get()
3141
{
32-
static wxCodeCompletionBoxManager manager;
33-
return manager;
42+
if(!manager) {
43+
manager = new wxCodeCompletionBoxManager();
44+
}
45+
return *manager;
3446
}
3547

3648
void wxCodeCompletionBoxManager::ShowCompletionBox(wxStyledTextCtrl* ctrl,
@@ -66,10 +78,11 @@ void wxCodeCompletionBoxManager::ShowCompletionBox(wxStyledTextCtrl* ctrl,
6678
void wxCodeCompletionBoxManager::DestroyCCBox()
6779
{
6880
if(m_box) {
69-
if(m_box->IsShown()) m_box->Hide();
81+
if(m_box->IsShown()) {
82+
m_box->Hide();
83+
}
7084
m_box->Destroy();
7185
}
72-
7386
m_box = NULL;
7487
m_stc = NULL;
7588
}
@@ -91,10 +104,7 @@ void wxCodeCompletionBoxManager::ShowCompletionBox(wxStyledTextCtrl* ctrl,
91104
CallAfter(&wxCodeCompletionBoxManager::DoShowCCBoxEntries, entries);
92105
}
93106

94-
void wxCodeCompletionBoxManager::DestroyCurrent()
95-
{
96-
DestroyCCBox();
97-
}
107+
void wxCodeCompletionBoxManager::DestroyCurrent() { DestroyCCBox(); }
98108

99109
void wxCodeCompletionBoxManager::InsertSelection(const wxString& selection)
100110
{
@@ -161,12 +171,55 @@ void wxCodeCompletionBoxManager::DoShowCCBoxEntries(const wxCodeCompletionBoxEnt
161171
{
162172
if(m_box && m_stc) {
163173
m_box->ShowCompletionBox(m_stc, entries);
174+
m_stc->Bind(wxEVT_KEY_DOWN, &wxCodeCompletionBoxManager::OnStcKeyDown, this);
175+
m_stc->Bind(wxEVT_LEFT_DOWN, &wxCodeCompletionBoxManager::OnStcLeftDown, this);
164176
}
165177
}
166178

167179
void wxCodeCompletionBoxManager::DoShowCCBoxTags(const TagEntryPtrVector_t& tags)
168180
{
169181
if(m_box && m_stc) {
170182
m_box->ShowCompletionBox(m_stc, tags);
183+
m_stc->Bind(wxEVT_KEY_DOWN, &wxCodeCompletionBoxManager::OnStcKeyDown, this);
184+
m_stc->Bind(wxEVT_LEFT_DOWN, &wxCodeCompletionBoxManager::OnStcLeftDown, this);
185+
}
186+
}
187+
188+
void wxCodeCompletionBoxManager::OnStcKeyDown(wxKeyEvent& event)
189+
{
190+
if(m_box && m_stc && m_box->IsShown() && event.GetEventObject() == m_stc) {
191+
m_box->StcKeyDown(event);
192+
} else {
193+
event.Skip();
194+
}
195+
}
196+
197+
void wxCodeCompletionBoxManager::OnStcLeftDown(wxMouseEvent& event)
198+
{
199+
if(m_box && m_stc && m_box->IsShown() && event.GetEventObject() == m_stc) {
200+
m_box->StcLeftDown(event);
201+
} else {
202+
event.Skip();
203+
}
204+
}
205+
206+
void wxCodeCompletionBoxManager::OnDismissBox(wxCommandEvent& event)
207+
{
208+
event.Skip();
209+
DestroyCCBox();
210+
}
211+
212+
void wxCodeCompletionBoxManager::OnAppActivate(wxActivateEvent& event)
213+
{
214+
event.Skip();
215+
DestroyCCBox();
216+
}
217+
218+
void wxCodeCompletionBoxManager::Free()
219+
{
220+
// Destroy the manager, Unbinding all events
221+
if(manager) {
222+
delete manager;
223+
manager = NULL;
171224
}
172225
}

Plugin/wxCodeCompletionBoxManager.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ class WXDLLIMPEXP_SDK wxCodeCompletionBoxManager : public wxEvtHandler
2626
// Handle the current editor events
2727
void OnStcModified(wxStyledTextEvent& event);
2828
void OnStcCharAdded(wxStyledTextEvent& event);
29-
29+
void OnStcKeyDown(wxKeyEvent& event);
30+
void OnStcLeftDown(wxMouseEvent& event);
31+
void OnDismissBox(wxCommandEvent &event);
32+
void OnAppActivate(wxActivateEvent& event);
33+
3034
void DoShowCCBoxTags(const TagEntryPtrVector_t& tags);
3135
void DoShowCCBoxEntries(const wxCodeCompletionBoxEntry::Vec_t& entries);
3236

3337
public:
3438
static wxCodeCompletionBoxManager& Get();
35-
39+
40+
/**
41+
* @brief uninitialize all event handlers and destroy the CC box manager
42+
*/
43+
static void Free();
44+
3645
/**
3746
* @brief show the completion box
3847
* @param ctrl the wxSTC control requesting the completion box

0 commit comments

Comments
 (0)